893
893
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
894
894
if (!(res=val_str(&tmp)) ||
895
895
str_to_datetime_with_warn(res->ptr(), res->length(),
896
ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
896
ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
901
901
int64_t value= val_int();
903
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
903
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1LL)
905
905
char buff[22], *end;
906
906
end= int64_t10_to_str(value, buff, -10);
907
make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
908
buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
907
make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
908
buff, (int) (end-buff), MYSQL_TIMESTAMP_NONE,
916
memset(ltime, 0, sizeof(*ltime));
916
bzero((char*) ltime,sizeof(*ltime));
953
953
int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
956
Table *table= field->table;
956
TABLE *table= field->table;
957
957
THD *thd= table->in_use;
958
958
enum_check_fields tmp= thd->count_cuted_fields;
959
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
959
960
ulong sql_mode= thd->variables.sql_mode;
960
thd->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
961
thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
961
962
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
962
963
res= save_in_field(field, no_conversions);
963
964
thd->count_cuted_fields= tmp;
965
dbug_tmp_restore_column_map(table->write_set, old_map);
964
966
thd->variables.sql_mode= sql_mode;
1611
1620
return result_field->val_str(str,&str_value);
1614
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1623
bool Item_field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
1616
1625
if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
1618
memset(ltime, 0, sizeof(*ltime));
1627
bzero((char*) ltime,sizeof(*ltime));
1624
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1633
bool Item_field::get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
1626
1635
if ((null_value=result_field->is_null()) ||
1627
1636
result_field->get_date(ltime,fuzzydate))
1629
memset(ltime, 0, sizeof(*ltime));
1638
bzero((char*) ltime,sizeof(*ltime));
1635
bool Item_field::get_time(DRIZZLE_TIME *ltime)
1644
bool Item_field::get_time(MYSQL_TIME *ltime)
1637
1646
if ((null_value=field->is_null()) || field->get_time(ltime))
1639
memset(ltime, 0, sizeof(*ltime));
1648
bzero((char*) ltime,sizeof(*ltime));
1878
1887
Item_decimal::Item_decimal(my_decimal *value_par)
1880
1889
my_decimal2decimal(value_par, &decimal_value);
1881
decimals= (uint8_t) decimal_value.frac;
1890
decimals= (uint8) decimal_value.frac;
1883
1892
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1884
1893
decimals, unsigned_flag);
1888
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
1897
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
1890
1899
binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1891
1900
&decimal_value, precision, scale);
1892
decimals= (uint8_t) decimal_value.frac;
1901
decimals= (uint8) decimal_value.frac;
1894
1903
max_length= my_decimal_precision_to_length(precision, decimals,
1895
1904
unsigned_flag);
2122
2131
default_set_param_func(Item_param *param,
2123
unsigned char **pos __attribute__((unused)),
2132
uchar **pos __attribute__((unused)),
2124
2133
ulong len __attribute__((unused)))
2126
2135
param->set_null();
2130
Item_param::Item_param(uint32_t pos_in_query_arg) :
2139
Item_param::Item_param(uint pos_in_query_arg) :
2131
2140
state(NO_VALUE),
2132
2141
item_result_type(STRING_RESULT),
2133
2142
/* Don't pretend to be a literal unless value for this item is set. */
2134
2143
item_type(PARAM_ITEM),
2135
param_type(DRIZZLE_TYPE_VARCHAR),
2144
param_type(MYSQL_TYPE_VARCHAR),
2136
2145
pos_in_query(pos_in_query_arg),
2137
2146
set_param_func(default_set_param_func),
2138
2147
limit_clause_param(false)
2226
2235
the fact that even wrong value sent over binary protocol fits into
2227
2236
MAX_DATE_STRING_REP_LENGTH buffer.
2229
void Item_param::set_time(DRIZZLE_TIME *tm,
2230
enum enum_drizzle_timestamp_type time_type,
2231
uint32_t max_length_arg)
2238
void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type,
2239
uint32 max_length_arg)
2233
2241
value.time= *tm;
2234
2242
value.time.time_type= time_type;
2236
2244
if (value.time.year > 9999 || value.time.month > 12 ||
2237
2245
value.time.day > 31 ||
2238
((time_type != DRIZZLE_TIMESTAMP_TIME) && value.time.hour > 23) ||
2246
((time_type != MYSQL_TIMESTAMP_TIME) && value.time.hour > 23) ||
2239
2247
value.time.minute > 59 || value.time.second > 59)
2241
2249
char buff[MAX_DATE_STRING_REP_LENGTH];
2242
uint32_t length= my_TIME_to_str(&value.time, buff);
2243
make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2250
uint length= my_TIME_to_str(&value.time, buff);
2251
make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2244
2252
buff, length, time_type, 0);
2245
set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
2253
set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR);
2248
2256
state= TIME_VALUE;
2909
2917
current->mark_as_dependent(last);
2910
2918
if (thd->lex->describe & DESCRIBE_EXTENDED)
2912
char warn_buff[DRIZZLE_ERRMSG_SIZE];
2920
char warn_buff[MYSQL_ERRMSG_SIZE];
2913
2921
sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
2914
2922
db_name, (db_name[0] ? "." : ""),
2915
2923
table_name, (table_name [0] ? "." : ""),
2916
2924
resolved_item->field_name,
2917
2925
current->select_number, last->select_number);
2918
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2926
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2919
2927
ER_WARN_FIELD_RESOLVED, warn_buff);
3771
3779
false otherwise
3774
bool Item_field::subst_argument_checker(unsigned char **arg)
3782
bool Item_field::subst_argument_checker(uchar **arg)
3776
3784
return (result_type() != STRING_RESULT) || (*arg);
3789
Convert a numeric value to a zero-filled string
3791
@param[in,out] item the item to operate on
3792
@param field The field that this value is equated to
3794
This function converts a numeric value to a string. In this conversion
3795
the zero-fill flag of the field is taken into account.
3796
This is required so the resulting string value can be used instead of
3797
the field reference when propagating equalities.
3800
static void convert_zerofill_number_to_string(Item **item, Field_num *field)
3802
char buff[MAX_FIELD_WIDTH],*pos;
3803
String tmp(buff,sizeof(buff), field->charset()), *res;
3805
res= (*item)->val_str(&tmp);
3806
field->prepend_zeros(res);
3807
pos= (char *) sql_strmake (res->ptr(), res->length());
3808
*item= new Item_string(pos, res->length(), field->charset());
3781
3813
Set a pointer to the multiple equality the field reference belongs to
3961
3999
String *Item::check_well_formed_result(String *str, bool send_error)
3963
4001
/* Check whether we got a well-formed string */
3964
const CHARSET_INFO * const cs= str->charset();
4002
CHARSET_INFO *cs= str->charset();
3965
4003
int well_formed_error;
3966
uint32_t wlen= cs->cset->well_formed_len(cs,
4004
uint wlen= cs->cset->well_formed_len(cs,
3967
4005
str->ptr(), str->ptr() + str->length(),
3968
4006
str->length(), &well_formed_error);
3969
4007
if (wlen < str->length())
3971
4009
THD *thd= current_thd;
3972
4010
char hexbuf[7];
3973
enum DRIZZLE_ERROR::enum_warning_level level;
3974
uint32_t diff= str->length() - wlen;
4011
enum MYSQL_ERROR::enum_warning_level level;
4012
uint diff= str->length() - wlen;
3975
4013
set_if_smaller(diff, 3);
3976
4014
octet2hex(hexbuf, str->ptr() + wlen, diff);
3977
4015
if (send_error)
4045
4083
@param table Table for which the field is created
4048
Field *Item::make_string_field(Table *table)
4086
Field *Item::make_string_field(TABLE *table)
4051
4089
assert(collation.collation);
4052
4090
if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
4053
4091
field= new Field_blob(max_length, maybe_null, name,
4054
4092
collation.collation);
4093
/* Item_type_holder holds the exact type, do not change it */
4094
else if (max_length > 0 &&
4095
(type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
4056
4096
field= new Field_varstring(max_length, maybe_null, name, table->s,
4057
4097
collation.collation);
4099
field= new Field_string(max_length, maybe_null, name,
4100
collation.collation);
4060
4102
field->init(table);
4074
4116
\# Created field
4077
Field *Item::tmp_table_field_from_field_type(Table *table, bool fixed_length __attribute__((unused)))
4119
Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length)
4080
4122
The field functions defines a field to be not null if null_ptr is not 0
4082
unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
4124
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
4085
4127
switch (field_type()) {
4086
case DRIZZLE_TYPE_NEWDECIMAL:
4087
field= new Field_new_decimal((unsigned char*) 0, max_length, null_ptr, 0,
4128
case MYSQL_TYPE_NEWDECIMAL:
4129
field= new Field_new_decimal((uchar*) 0, max_length, null_ptr, 0,
4088
4130
Field::NONE, name, decimals, 0,
4089
4131
unsigned_flag);
4091
case DRIZZLE_TYPE_TINY:
4092
field= new Field_tiny((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4093
name, 0, unsigned_flag);
4095
case DRIZZLE_TYPE_LONG:
4096
field= new Field_long((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4097
name, 0, unsigned_flag);
4099
case DRIZZLE_TYPE_LONGLONG:
4100
field= new Field_int64_t((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4133
case MYSQL_TYPE_TINY:
4134
field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4135
name, 0, unsigned_flag);
4137
case MYSQL_TYPE_SHORT:
4138
field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4139
name, 0, unsigned_flag);
4141
case MYSQL_TYPE_LONG:
4142
field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4143
name, 0, unsigned_flag);
4145
case MYSQL_TYPE_LONGLONG:
4146
field= new Field_int64_t((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4101
4147
name, 0, unsigned_flag);
4103
case DRIZZLE_TYPE_DOUBLE:
4104
field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4149
case MYSQL_TYPE_FLOAT:
4150
field= new Field_float((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4151
name, decimals, 0, unsigned_flag);
4153
case MYSQL_TYPE_DOUBLE:
4154
field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4105
4155
name, decimals, 0, unsigned_flag);
4107
case DRIZZLE_TYPE_NULL:
4108
field= new Field_null((unsigned char*) 0, max_length, Field::NONE,
4157
case MYSQL_TYPE_NULL:
4158
field= new Field_null((uchar*) 0, max_length, Field::NONE,
4109
4159
name, &my_charset_bin);
4111
case DRIZZLE_TYPE_NEWDATE:
4161
case MYSQL_TYPE_NEWDATE:
4112
4162
field= new Field_newdate(maybe_null, name, &my_charset_bin);
4114
case DRIZZLE_TYPE_TIME:
4164
case MYSQL_TYPE_TIME:
4115
4165
field= new Field_time(maybe_null, name, &my_charset_bin);
4117
case DRIZZLE_TYPE_TIMESTAMP:
4167
case MYSQL_TYPE_TIMESTAMP:
4118
4168
field= new Field_timestamp(maybe_null, name, &my_charset_bin);
4120
case DRIZZLE_TYPE_DATETIME:
4170
case MYSQL_TYPE_DATETIME:
4121
4171
field= new Field_datetime(maybe_null, name, &my_charset_bin);
4173
case MYSQL_TYPE_YEAR:
4174
field= new Field_year((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4124
4178
/* This case should never be chosen */
4180
/* If something goes awfully wrong, it's better to get a string than die */
4181
case MYSQL_TYPE_STRING:
4182
if (fixed_length && max_length < CONVERT_IF_BIGGER_TO_BLOB)
4184
field= new Field_string(max_length, maybe_null, name,
4185
collation.collation);
4126
4188
/* Fall through to make_string_field() */
4127
case DRIZZLE_TYPE_ENUM:
4128
case DRIZZLE_TYPE_VARCHAR:
4189
case MYSQL_TYPE_ENUM:
4190
case MYSQL_TYPE_SET:
4191
case MYSQL_TYPE_VAR_STRING:
4192
case MYSQL_TYPE_VARCHAR:
4129
4193
return make_string_field(table);
4130
case DRIZZLE_TYPE_BLOB:
4194
case MYSQL_TYPE_BLOB:
4131
4195
if (this->type() == Item::TYPE_HOLDER)
4132
4196
field= new Field_blob(max_length, maybe_null, name, collation.collation,
4527
4591
collation.collation);
4530
uint32_t length= str_value.length();
4594
uint32 length= str_value.length();
4531
4595
if (length > 8)
4533
nr= field->flags & UNSIGNED_FLAG ? UINT64_MAX : INT64_MAX;
4597
nr= field->flags & UNSIGNED_FLAG ? ULONGLONG_MAX : LONGLONG_MAX;
4536
4600
nr= (uint64_t) val_int();
4537
if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > INT64_MAX))
4601
if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
4542
4606
return field->store((int64_t) nr, true); // Assume hex numbers are unsigned
4545
4609
if (!field->store((int64_t) nr, true))
4546
field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
4610
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
4552
4616
void Item_hex_string::print(String *str,
4553
enum_query_type query_type __attribute__((unused)))
4617
enum_query_type query_type __attribute__((__unused__)))
4555
4619
char *end= (char*) str_value.ptr() + str_value.length(),
4556
*ptr= end - cmin(str_value.length(), (uint32_t)sizeof(int64_t));
4620
*ptr= end - min(str_value.length(), sizeof(int64_t));
4557
4621
str->append("0x");
4558
4622
for (; ptr != end ; ptr++)
4560
str->append(_dig_vec_lower[((unsigned char) *ptr) >> 4]);
4561
str->append(_dig_vec_lower[((unsigned char) *ptr) & 0x0F]);
4624
str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
4625
str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
4681
4757
result= protocol->store_int64_t(nr, unsigned_flag);
4684
case DRIZZLE_TYPE_DOUBLE:
4760
case MYSQL_TYPE_FLOAT:
4763
nr= (float) val_real();
4765
result= protocol->store(nr, decimals, buffer);
4768
case MYSQL_TYPE_DOUBLE:
4686
4770
double nr= val_real();
4687
4771
if (!null_value)
4688
4772
result= protocol->store(nr, decimals, buffer);
4691
case DRIZZLE_TYPE_DATETIME:
4692
case DRIZZLE_TYPE_TIMESTAMP:
4775
case MYSQL_TYPE_DATETIME:
4776
case MYSQL_TYPE_TIMESTAMP:
4695
4779
get_date(&tm, TIME_FUZZY_DATE);
4696
4780
if (!null_value)
4698
if (f_type == DRIZZLE_TYPE_NEWDATE)
4782
if (f_type == MYSQL_TYPE_NEWDATE)
4699
4783
return protocol->store_date(&tm);
4701
4785
result= protocol->store(&tm);
4705
case DRIZZLE_TYPE_TIME:
4789
case MYSQL_TYPE_TIME:
4709
4793
if (!null_value)
4710
4794
result= protocol->store_time(&tm);
6237
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
6325
bool Item_type_holder::join_types(THD *thd __attribute__((__unused__)),
6240
uint32_t max_length_orig= max_length;
6241
uint32_t decimals_orig= decimals;
6328
uint max_length_orig= max_length;
6329
uint decimals_orig= decimals;
6242
6330
fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6244
6332
int item_decimals= item->decimals;
6245
6333
/* fix variable decimals which always is NOT_FIXED_DEC */
6246
6334
if (Field::result_merge_type(fld_type) == INT_RESULT)
6247
6335
item_decimals= 0;
6248
decimals= cmax((int)decimals, item_decimals);
6336
decimals= max(decimals, item_decimals);
6250
6338
if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6252
decimals= cmin((int)cmax(decimals, item->decimals), DECIMAL_MAX_SCALE);
6253
int precision= cmin(cmax(prev_decimal_int_part, item->decimal_int_part())
6340
decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
6341
int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
6254
6342
+ decimals, DECIMAL_MAX_PRECISION);
6255
6343
unsigned_flag&= item->unsigned_flag;
6256
6344
max_length= my_decimal_precision_to_length(precision, decimals,
6330
uint32_t Item_type_holder::display_length(Item *item)
6423
uint32 Item_type_holder::display_length(Item *item)
6332
6425
if (item->type() == Item::FIELD_ITEM)
6333
6426
return ((Item_field *)item)->max_disp_length();
6335
6428
switch (item->field_type())
6337
case DRIZZLE_TYPE_TIMESTAMP:
6338
case DRIZZLE_TYPE_TIME:
6339
case DRIZZLE_TYPE_DATETIME:
6340
case DRIZZLE_TYPE_NEWDATE:
6341
case DRIZZLE_TYPE_VARCHAR:
6342
case DRIZZLE_TYPE_NEWDECIMAL:
6343
case DRIZZLE_TYPE_ENUM:
6344
case DRIZZLE_TYPE_BLOB:
6345
case DRIZZLE_TYPE_TINY:
6430
case MYSQL_TYPE_TIMESTAMP:
6431
case MYSQL_TYPE_TIME:
6432
case MYSQL_TYPE_DATETIME:
6433
case MYSQL_TYPE_YEAR:
6434
case MYSQL_TYPE_NEWDATE:
6435
case MYSQL_TYPE_VARCHAR:
6436
case MYSQL_TYPE_NEWDECIMAL:
6437
case MYSQL_TYPE_ENUM:
6438
case MYSQL_TYPE_SET:
6439
case MYSQL_TYPE_BLOB:
6440
case MYSQL_TYPE_VAR_STRING:
6441
case MYSQL_TYPE_STRING:
6442
case MYSQL_TYPE_TINY:
6347
case DRIZZLE_TYPE_LONG:
6444
case MYSQL_TYPE_SHORT:
6446
case MYSQL_TYPE_LONG:
6348
6447
return MY_INT32_NUM_DECIMAL_DIGITS;
6349
case DRIZZLE_TYPE_DOUBLE:
6448
case MYSQL_TYPE_FLOAT:
6450
case MYSQL_TYPE_DOUBLE:
6351
case DRIZZLE_TYPE_NULL:
6452
case MYSQL_TYPE_NULL:
6353
case DRIZZLE_TYPE_LONGLONG:
6454
case MYSQL_TYPE_LONGLONG:
6356
6457
assert(0); // we should never go there
6372
Field *Item_type_holder::make_field_by_type(Table *table)
6473
Field *Item_type_holder::make_field_by_type(TABLE *table)
6375
6476
The field functions defines a field to be not null if null_ptr is not 0
6377
unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
6478
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
6380
6481
switch (fld_type) {
6381
case DRIZZLE_TYPE_ENUM:
6482
case MYSQL_TYPE_ENUM:
6382
6483
assert(enum_set_typelib);
6383
field= new Field_enum((unsigned char *) 0, max_length, null_ptr, 0,
6484
field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
6384
6485
Field::NONE, name,
6385
6486
get_enum_pack_length(enum_set_typelib->count),
6386
6487
enum_set_typelib, collation.collation);
6388
6489
field->init(table);
6390
case DRIZZLE_TYPE_NULL:
6491
case MYSQL_TYPE_SET:
6492
assert(enum_set_typelib);
6493
field= new Field_set((uchar *) 0, max_length, null_ptr, 0,
6495
get_set_pack_length(enum_set_typelib->count),
6496
enum_set_typelib, collation.collation);
6500
case MYSQL_TYPE_NULL:
6391
6501
return make_string_field(table);