1 /*
2  Copyright 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License, version 2.0,
7  as published by the Free Software Foundation.
8 
9  This program is also distributed with certain software (including
10  but not limited to OpenSSL) that is licensed under separate terms,
11  as designated in a particular file or component or in included license
12  documentation.  The authors of MySQL hereby grant you an additional
13  permission to link the program and your derivative works with the
14  separately licensed software that they have included with MySQL.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  GNU General Public License, version 2.0, for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24 */
25 /*
26  * decimal_utils.hpp
27  */
28 
29 #ifndef decimal_utils_h
30 #define decimal_utils_h
31 
32 /* return values (redeclared here if to be mapped to Java) */
33 #define E_DEC_OK                0
34 #define E_DEC_TRUNCATED         1
35 #define E_DEC_OVERFLOW          2
36 #define E_DEC_BAD_NUM           8
37 #define E_DEC_OOM              16
38 /* return values below here are unique to ndbjtie --
39    not present in MySQL's decimal library */
40 #define E_DEC_BAD_PREC         32
41 #define E_DEC_BAD_SCALE        64
42 
43 /*
44  decimal_str2bin: Convert string directly to on-disk binary format.
45  str  - string to convert
46  len - length of string
47  prec - precision of column
48  scale - scale of column
49  dest - buffer for binary representation
50  len - length of buffer
51 
52  NOTES
53    Added so that NDB API programs can convert directly between  the stored
54    binary format and a string representation without using decimal_t.
55 
56  RETURN VALUE
57    E_DEC_OK/E_DEC_TRUNCATED/E_DEC_OVERFLOW/E_DEC_OOM
58 */
59 int decimal_str2bin(const char *str, int str_len,
60                     int prec, int scale,
61                     void *bin, int bin_len);
62 
63 /*
64  decimal_bin2str():  Convert directly from on-disk binary format to string
65  bin  - value to convert
66  bin_len - length to convert
67  prec - precision of column
68  scale - scale of column
69  dest - buffer for string representation
70  len - length of buffer
71 
72  NOTES
73    Added so that NDB API programs can convert directly between  the stored
74    binary format and a string representation without using decimal_t.
75 
76 
77  RETURN VALUE
78     E_DEC_OK/E_DEC_TRUNCATED/E_DEC_OVERFLOW/E_DEC_BAD_NUM/E_DEC_OOM
79  */
80 int decimal_bin2str(const void *bin, int bin_len,
81                     int prec, int scale,
82                     char *str, int str_len);
83 
84 #endif // decimal_utils_h
85