565
Item *Item_static_float_func::safe_charset_converter(const CHARSET_INFO * const)
569
String *s, tmp(buf, sizeof(buf), &my_charset_bin);
571
if ((conv= new Item_static_string_func(func_name, s->ptr(), s->length(),
574
conv->str_value.copy();
575
conv->str_value.mark_as_const();
581
Item *Item_string::safe_charset_converter(const CHARSET_INFO * const tocs)
584
uint32_t conv_errors;
586
String tmp, cstr, *ostr= val_str(&tmp);
587
cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
588
if (conv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(),
590
collation.derivation)))
593
Safe conversion is not possible (or EOM).
594
We could not convert a string into the requested character set
595
without data loss. The target charset does not cover all the
596
characters from the string. Operation cannot be done correctly.
600
if (!(ptr= current_session->strmake(cstr.ptr(), cstr.length())))
602
conv->str_value.set(ptr, cstr.length(), cstr.charset());
603
/* Ensure that no one is going to change the result string */
604
conv->str_value.mark_as_const();
609
Item *Item_static_string_func::safe_charset_converter(const CHARSET_INFO * const tocs)
612
uint32_t conv_errors;
613
String tmp, cstr, *ostr= val_str(&tmp);
614
cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
616
!(conv= new Item_static_string_func(func_name,
617
cstr.ptr(), cstr.length(),
619
collation.derivation)))
622
Safe conversion is not possible (or EOM).
623
We could not convert a string into the requested character set
624
without data loss. The target charset does not cover all the
625
characters from the string. Operation cannot be done correctly.
629
conv->str_value.copy();
630
/* Ensure that no one is going to change the result string */
631
conv->str_value.mark_as_const();
636
bool Item_string::eq(const Item *item, bool binary_cmp) const
638
if (type() == item->type() && item->basic_const_item())
641
return !stringcmp(&str_value, &item->str_value);
642
return (collation.collation == item->collation.collation &&
643
!sortcmp(&str_value, &item->str_value, collation.collation));
650
566
Get the value of the function as a DRIZZLE_TIME structure.
651
567
As a extra convenience the time structure is reset on error!
1054
Create an item from a string we KNOW points to a valid int64_t
1055
end \\0 terminated number string.
1056
This is always 'signed'. Unsigned values are created with Item_uint()
1059
Item_int::Item_int(const char *str_arg, uint32_t length)
1061
char *end_ptr= (char*) str_arg + length;
1063
value= my_strtoll10(str_arg, &end_ptr, &error);
1064
max_length= (uint) (end_ptr - str_arg);
1065
name= (char*) str_arg;
1070
my_decimal *Item_int::val_decimal(my_decimal *decimal_value)
1072
int2my_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_value);
1073
return decimal_value;
1076
String *Item_int::val_str(String *str)
1078
// following assert is redundant, because fixed=1 assigned in constructor
1080
str->set(value, &my_charset_bin);
1084
void Item_int::print(String *str, enum_query_type)
1086
// my_charset_bin is good enough for numbers
1087
str_value.set(value, &my_charset_bin);
1088
str->append(str_value);
1092
Item_uint::Item_uint(const char *str_arg, uint32_t length):
1093
Item_int(str_arg, length)
1099
Item_uint::Item_uint(const char *str_arg, int64_t i, uint32_t length):
1100
Item_int(str_arg, i, length)
1106
String *Item_uint::val_str(String *str)
1108
// following assert is redundant, because fixed=1 assigned in constructor
1110
str->set((uint64_t) value, &my_charset_bin);
1115
void Item_uint::print(String *str, enum_query_type)
1117
// latin1 is good enough for numbers
1118
str_value.set((uint64_t) value, default_charset());
1119
str->append(str_value);
1123
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1124
const CHARSET_INFO * const charset)
1126
str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1127
name= (char*) str_arg;
1128
decimals= (uint8_t) decimal_value.frac;
1130
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1131
decimals, unsigned_flag);
1134
Item_decimal::Item_decimal(int64_t val, bool unsig)
1136
int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
1137
decimals= (uint8_t) decimal_value.frac;
1139
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1140
decimals, unsigned_flag);
1144
Item_decimal::Item_decimal(double val, int, int)
1146
double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
1147
decimals= (uint8_t) decimal_value.frac;
1149
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1150
decimals, unsigned_flag);
1154
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
1155
uint32_t decimal_par, uint32_t length)
1157
my_decimal2decimal(val_arg, &decimal_value);
1159
decimals= (uint8_t) decimal_par;
1165
Item_decimal::Item_decimal(my_decimal *value_par)
1167
my_decimal2decimal(value_par, &decimal_value);
1168
decimals= (uint8_t) decimal_value.frac;
1170
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1171
decimals, unsigned_flag);
1175
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
1177
binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1178
&decimal_value, precision, scale);
1179
decimals= (uint8_t) decimal_value.frac;
1181
max_length= my_decimal_precision_to_length(precision, decimals,
1186
int64_t Item_decimal::val_int()
1189
my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
1193
double Item_decimal::val_real()
1196
my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
1200
String *Item_decimal::val_str(String *result)
1202
result->set_charset(&my_charset_bin);
1203
my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, result);
1207
void Item_decimal::print(String *str, enum_query_type)
1209
my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
1210
str->append(str_value);
1214
bool Item_decimal::eq(const Item *item, bool) const
1216
if (type() == item->type() && item->basic_const_item())
1219
We need to cast off const to call val_decimal(). This should
1220
be OK for a basic constant. Additionally, we can pass 0 as
1221
a true decimal constant will return its internal decimal
1222
storage and ignore the argument.
1224
Item *arg= (Item*) item;
1225
my_decimal *value= arg->val_decimal(0);
1226
return !my_decimal_cmp(&decimal_value, value);
1232
void Item_decimal::set_decimal_value(my_decimal *value_par)
1234
my_decimal2decimal(value_par, &decimal_value);
1235
decimals= (uint8_t) decimal_value.frac;
1236
unsigned_flag= !decimal_value.sign();
1237
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1238
decimals, unsigned_flag);
1242
String *Item_float::val_str(String *str)
1244
// following assert is redundant, because fixed=1 assigned in constructor
1246
str->set_real(value,decimals,&my_charset_bin);
1251
int64_t Item_float::val_int()
1254
if (value <= (double) INT64_MIN)
1258
else if (value >= (double) (uint64_t) INT64_MAX)
1262
return (int64_t) rint(value);
1265
my_decimal *Item_float::val_decimal(my_decimal *decimal_value)
1267
// following assert is redundant, because fixed=1 assigned in constructor
1269
double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_value);
1270
return (decimal_value);
1274
void Item_string::print(String *str, enum_query_type query_type)
1276
if (query_type == QT_ORDINARY && is_cs_specified())
1279
str->append(collation.collation->csname);
1284
if (query_type == QT_ORDINARY ||
1285
my_charset_same(str_value.charset(), system_charset_info))
1287
str_value.print(str);
1291
Session *session= current_session;
1292
LEX_STRING utf8_lex_str;
1294
session->convert_string(&utf8_lex_str,
1295
system_charset_info,
1296
str_value.c_ptr_safe(),
1298
str_value.charset());
1300
String utf8_str(utf8_lex_str.str,
1301
utf8_lex_str.length,
1302
system_charset_info);
1304
utf8_str.print(str);
1311
double Item_string::val_real()
1315
char *end, *org_end;
1317
const CHARSET_INFO * const cs= str_value.charset();
1319
org_end= (char*) str_value.ptr() + str_value.length();
1320
tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end,
1322
if (error || (end != org_end && !check_if_only_end_space(cs, end, org_end)))
1325
We can use str_value.ptr() here as Item_string is gurantee to put an
1328
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1329
ER_TRUNCATED_WRONG_VALUE,
1330
ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
1339
Give error if we wanted a signed integer and we got an unsigned one
1341
int64_t Item_string::val_int()
1346
char *end= (char*) str_value.ptr()+ str_value.length();
1348
const CHARSET_INFO * const cs= str_value.charset();
1350
tmp= (*(cs->cset->strtoll10))(cs, str_value.ptr(), &end, &err);
1352
TODO: Give error if we wanted a signed integer and we got an unsigned
1356
(end != org_end && !check_if_only_end_space(cs, end, org_end)))
1358
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1359
ER_TRUNCATED_WRONG_VALUE,
1360
ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
1367
my_decimal *Item_string::val_decimal(my_decimal *decimal_value)
1369
return val_decimal_from_string(decimal_value);
1372
968
/****************************************************************************
1373
969
Item_copy_string
1374
970
****************************************************************************/
2149
static uint32_t nr_of_decimals(const char *str, const char *end)
2151
const char *decimal_point;
2153
/* Find position for '.' */
2158
if (*str == 'e' || *str == 'E')
2159
return NOT_FIXED_DEC;
2164
for (; my_isdigit(system_charset_info, *str) ; str++)
2166
if (*str == 'e' || *str == 'E')
2167
return NOT_FIXED_DEC;
2168
return (uint) (str - decimal_point);
2173
This function is only called during parsing. We will signal an error if
2174
value is not a true double value (overflow)
2177
Item_float::Item_float(const char *str_arg, uint32_t length)
2181
value= my_strntod(&my_charset_bin, (char*) str_arg, length, &end_not_used,
2186
Note that we depend on that str_arg is null terminated, which is true
2187
when we are in the parser
2189
assert(str_arg[length] == 0);
2190
my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "double", (char*) str_arg);
2192
presentation= name=(char*) str_arg;
2193
decimals=(uint8_t) nr_of_decimals(str_arg, str_arg+length);
2199
int Item_float::save_in_field(Field *field, bool)
2201
double nr= val_real();
2203
return set_field_to_null(field);
2204
field->set_notnull();
2205
return field->store(nr);
2209
void Item_float::print(String *str, enum_query_type)
2213
str->append(presentation);
2217
String num(buffer, sizeof(buffer), &my_charset_bin);
2218
num.set_real(value, decimals, &my_charset_bin);
2225
In string context this is a binary string.
2226
In number context this is a int64_t value.
2229
bool Item_float::eq(const Item *arg, bool) const
2231
if (arg->basic_const_item() && arg->type() == type())
2234
We need to cast off const to call val_int(). This should be OK for
2237
Item *item= (Item*) arg;
2238
return item->val_real() == value;
2244
1697
inline uint32_t char_val(char X)
2246
1699
return (uint) (X >= '0' && X <= '9' ? X-'0' :