17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <drizzled/charset.h>
23
#include <drizzled/field.h>
22
24
#include <drizzled/item/decimal.h>
27
28
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
28
const CHARSET_INFO * const charset)
29
const charset_info_st * const charset)
30
str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
31
decimal_value.store(E_DEC_FATAL_ERROR, str_arg, length, charset);
31
32
name= (char*) str_arg;
32
33
decimals= (uint8_t) decimal_value.frac;
34
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
35
max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
35
36
decimals, unsigned_flag);
38
39
Item_decimal::Item_decimal(int64_t val, bool unsig)
40
int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
41
int2_class_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
41
42
decimals= (uint8_t) decimal_value.frac;
43
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
44
max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
44
45
decimals, unsigned_flag);
48
49
Item_decimal::Item_decimal(double val, int, int)
50
double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
51
double2_class_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
51
52
decimals= (uint8_t) decimal_value.frac;
53
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
54
max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
54
55
decimals, unsigned_flag);
57
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
58
Item_decimal::Item_decimal(const char *str, const type::Decimal *val_arg,
58
59
uint32_t decimal_par, uint32_t length)
60
my_decimal2decimal(val_arg, &decimal_value);
61
class_decimal2decimal(val_arg, &decimal_value);
62
63
decimals= (uint8_t) decimal_par;
63
64
max_length= length;
68
Item_decimal::Item_decimal(my_decimal *value_par)
69
Item_decimal::Item_decimal(type::Decimal *value_par)
70
my_decimal2decimal(value_par, &decimal_value);
71
class_decimal2decimal(value_par, &decimal_value);
71
72
decimals= (uint8_t) decimal_value.frac;
73
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
74
max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
74
75
decimals, unsigned_flag);
78
79
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
80
binary2my_decimal(E_DEC_FATAL_ERROR, bin,
81
binary2_class_decimal(E_DEC_FATAL_ERROR, bin,
81
82
&decimal_value, precision, scale);
82
83
decimals= (uint8_t) decimal_value.frac;
84
max_length= my_decimal_precision_to_length(precision, decimals,
85
max_length= class_decimal_precision_to_length(precision, decimals,
88
89
int64_t Item_decimal::val_int()
91
my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
92
decimal_value.val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
95
96
double Item_decimal::val_real()
98
my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
99
class_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
102
103
String *Item_decimal::val_str(String *result)
104
105
result->set_charset(&my_charset_bin);
105
my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, result);
106
class_decimal2string(&decimal_value, 0, result);
109
void Item_decimal::print(String *str, enum_query_type)
110
void Item_decimal::print(String *str)
111
my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
112
class_decimal2string(&decimal_value, 0, &str_value);
112
113
str->append(str_value);
123
124
storage and ignore the argument.
125
126
Item *arg= (Item*) item;
126
my_decimal *value= arg->val_decimal(0);
127
return !my_decimal_cmp(&decimal_value, value);
127
type::Decimal *value= arg->val_decimal(0);
128
return !class_decimal_cmp(&decimal_value, value);
133
void Item_decimal::set_decimal_value(my_decimal *value_par)
134
void Item_decimal::set_decimal_value(type::Decimal *value_par)
135
my_decimal2decimal(value_par, &decimal_value);
136
class_decimal2decimal(value_par, &decimal_value);
136
137
decimals= (uint8_t) decimal_value.frac;
137
138
unsigned_flag= !decimal_value.sign();
138
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
139
max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
139
140
decimals, unsigned_flag);