661
667
column read set or to register used fields in a view
664
bool Item_field::register_field_in_read_map(unsigned char *arg)
670
bool Item_field::register_field_in_read_map(uchar *arg)
666
Table *table= (Table *) arg;
672
TABLE *table= (TABLE *) arg;
667
673
if (field->table == table || !table)
668
674
bitmap_set_bit(field->table->read_set, field->field_index);
669
if (field->vcol_info && field->vcol_info->expr_item)
670
return field->vcol_info->expr_item->walk(&Item::register_field_in_read_map,
676
Mark field in bitmap supplied as *arg
680
bool Item_field::register_field_in_bitmap(unsigned char *arg)
682
MY_BITMAP *bitmap= (MY_BITMAP *) arg;
684
bitmap_set_bit(bitmap, field->field_index);
689
bool Item::check_cols(uint32_t c)
679
bool Item::check_cols(uint c)
909
899
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
910
900
if (!(res=val_str(&tmp)) ||
911
901
str_to_datetime_with_warn(res->ptr(), res->length(),
912
ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
902
ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
917
int64_t value= val_int();
907
longlong value= val_int();
919
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
909
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1LL)
921
911
char buff[22], *end;
922
end= int64_t10_to_str(value, buff, -10);
923
make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
924
buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
912
end= longlong10_to_str(value, buff, -10);
913
make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
914
buff, (int) (end-buff), MYSQL_TIMESTAMP_NONE,
932
memset(ltime, 0, sizeof(*ltime));
922
bzero((char*) ltime,sizeof(*ltime));
969
959
int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
972
Table *table= field->table;
962
TABLE *table= field->table;
973
963
THD *thd= table->in_use;
974
964
enum_check_fields tmp= thd->count_cuted_fields;
965
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
975
966
ulong sql_mode= thd->variables.sql_mode;
976
thd->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
967
thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
977
968
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
978
969
res= save_in_field(field, no_conversions);
979
970
thd->count_cuted_fields= tmp;
971
dbug_tmp_restore_column_map(table->write_set, old_map);
980
972
thd->variables.sql_mode= sql_mode;
1627
1626
return result_field->val_str(str,&str_value);
1630
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1629
bool Item_field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
1632
1631
if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
1634
memset(ltime, 0, sizeof(*ltime));
1633
bzero((char*) ltime,sizeof(*ltime));
1640
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1639
bool Item_field::get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
1642
1641
if ((null_value=result_field->is_null()) ||
1643
1642
result_field->get_date(ltime,fuzzydate))
1645
memset(ltime, 0, sizeof(*ltime));
1644
bzero((char*) ltime,sizeof(*ltime));
1651
bool Item_field::get_time(DRIZZLE_TIME *ltime)
1650
bool Item_field::get_time(MYSQL_TIME *ltime)
1653
1652
if ((null_value=field->is_null()) || field->get_time(ltime))
1655
memset(ltime, 0, sizeof(*ltime));
1654
bzero((char*) ltime,sizeof(*ltime));
1768
1767
return new_item;
1771
int64_t Item_field::val_int_endpoint(bool left_endp __attribute__((unused)),
1772
bool *incl_endp __attribute__((unused)))
1770
longlong Item_field::val_int_endpoint(bool left_endp __attribute__((__unused__)),
1771
bool *incl_endp __attribute__((__unused__)))
1774
int64_t res= val_int();
1775
return null_value? INT64_MIN : res;
1773
longlong res= val_int();
1774
return null_value? LONGLONG_MIN : res;
1779
Create an item from a string we KNOW points to a valid int64_t
1778
Create an item from a string we KNOW points to a valid longlong
1780
1779
end \\0 terminated number string.
1781
1780
This is always 'signed'. Unsigned values are created with Item_uint()
1784
Item_int::Item_int(const char *str_arg, uint32_t length)
1783
Item_int::Item_int(const char *str_arg, uint length)
1786
1785
char *end_ptr= (char*) str_arg + length;
1832
1831
String *Item_uint::val_str(String *str)
1834
1833
// following assert is redundant, because fixed=1 assigned in constructor
1836
str->set((uint64_t) value, &my_charset_bin);
1834
DBUG_ASSERT(fixed == 1);
1835
str->set((ulonglong) value, &my_charset_bin);
1841
1840
void Item_uint::print(String *str,
1842
enum_query_type query_type __attribute__((unused)))
1841
enum_query_type query_type __attribute__((__unused__)))
1844
1843
// latin1 is good enough for numbers
1845
str_value.set((uint64_t) value, default_charset());
1844
str_value.set((ulonglong) value, default_charset());
1846
1845
str->append(str_value);
1850
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1851
const CHARSET_INFO * const charset)
1849
Item_decimal::Item_decimal(const char *str_arg, uint length,
1850
CHARSET_INFO *charset)
1853
1852
str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1854
1853
name= (char*) str_arg;
1855
decimals= (uint8_t) decimal_value.frac;
1854
decimals= (uint8) decimal_value.frac;
1857
1856
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1858
1857
decimals, unsigned_flag);
1861
Item_decimal::Item_decimal(int64_t val, bool unsig)
1860
Item_decimal::Item_decimal(longlong val, bool unsig)
1863
1862
int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
1864
decimals= (uint8_t) decimal_value.frac;
1863
decimals= (uint8) decimal_value.frac;
1866
1865
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1867
1866
decimals, unsigned_flag);
1894
1893
Item_decimal::Item_decimal(my_decimal *value_par)
1896
1895
my_decimal2decimal(value_par, &decimal_value);
1897
decimals= (uint8_t) decimal_value.frac;
1896
decimals= (uint8) decimal_value.frac;
1899
1898
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1900
1899
decimals, unsigned_flag);
1904
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
1903
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
1906
1905
binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1907
1906
&decimal_value, precision, scale);
1908
decimals= (uint8_t) decimal_value.frac;
1907
decimals= (uint8) decimal_value.frac;
1910
1909
max_length= my_decimal_precision_to_length(precision, decimals,
1911
1910
unsigned_flag);
1915
int64_t Item_decimal::val_int()
1914
longlong Item_decimal::val_int()
1918
1917
my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
2090
2089
bool Item_null::eq(const Item *item,
2091
bool binary_cmp __attribute__((unused))) const
2090
bool binary_cmp __attribute__((__unused__))) const
2092
2091
{ return item->type() == type(); }
2095
2094
double Item_null::val_real()
2097
2096
// following assert is redundant, because fixed=1 assigned in constructor
2097
DBUG_ASSERT(fixed == 1);
2102
int64_t Item_null::val_int()
2101
longlong Item_null::val_int()
2104
2103
// following assert is redundant, because fixed=1 assigned in constructor
2104
DBUG_ASSERT(fixed == 1);
2110
String *Item_null::val_str(String *str __attribute__((unused)))
2109
String *Item_null::val_str(String *str __attribute__((__unused__)))
2112
2111
// following assert is redundant, because fixed=1 assigned in constructor
2112
DBUG_ASSERT(fixed == 1);
2118
my_decimal *Item_null::val_decimal(my_decimal *decimal_value __attribute__((unused)))
2117
my_decimal *Item_null::val_decimal(my_decimal *decimal_value __attribute__((__unused__)))
2124
Item *Item_null::safe_charset_converter(const CHARSET_INFO * const tocs)
2123
Item *Item_null::safe_charset_converter(CHARSET_INFO *tocs)
2126
2125
collation.set(tocs);
2138
2137
default_set_param_func(Item_param *param,
2139
unsigned char **pos __attribute__((unused)),
2138
uchar **pos __attribute__((unused)),
2140
2139
ulong len __attribute__((unused)))
2142
2141
param->set_null();
2146
Item_param::Item_param(uint32_t pos_in_query_arg) :
2145
Item_param::Item_param(uint pos_in_query_arg) :
2147
2146
state(NO_VALUE),
2148
2147
item_result_type(STRING_RESULT),
2149
2148
/* Don't pretend to be a literal unless value for this item is set. */
2150
2149
item_type(PARAM_ITEM),
2151
param_type(DRIZZLE_TYPE_VARCHAR),
2150
param_type(MYSQL_TYPE_VARCHAR),
2152
2151
pos_in_query(pos_in_query_arg),
2153
2152
set_param_func(default_set_param_func),
2154
2153
limit_clause_param(false)
2214
2216
internal decimal value.
2217
void Item_param::set_decimal(char *str, ulong length)
2219
void Item_param::set_decimal(const char *str, ulong length)
2222
DBUG_ENTER("Item_param::set_decimal");
2222
str2my_decimal((uint)E_DEC_FATAL_ERROR, str, &decimal_value, &end);
2224
end= (char*) str+length;
2225
str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
2223
2226
state= DECIMAL_VALUE;
2224
2227
decimals= decimal_value.frac;
2225
2228
max_length= my_decimal_precision_to_length(decimal_value.precision(),
2226
2229
decimals, unsigned_flag);
2233
Set parameter value from DRIZZLE_TIME value.
2236
Set parameter value from MYSQL_TIME value.
2235
2238
@param tm datetime value to set (time_type is ignored)
2236
2239
@param type type of datetime value
2242
2245
the fact that even wrong value sent over binary protocol fits into
2243
2246
MAX_DATE_STRING_REP_LENGTH buffer.
2245
void Item_param::set_time(DRIZZLE_TIME *tm,
2246
enum enum_drizzle_timestamp_type time_type,
2247
uint32_t max_length_arg)
2248
void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type,
2249
uint32 max_length_arg)
2251
DBUG_ENTER("Item_param::set_time");
2249
2253
value.time= *tm;
2250
2254
value.time.time_type= time_type;
2252
2256
if (value.time.year > 9999 || value.time.month > 12 ||
2253
2257
value.time.day > 31 ||
2254
((time_type != DRIZZLE_TIMESTAMP_TIME) && value.time.hour > 23) ||
2258
((time_type != MYSQL_TIMESTAMP_TIME) && value.time.hour > 23) ||
2255
2259
value.time.minute > 59 || value.time.second > 59)
2257
2261
char buff[MAX_DATE_STRING_REP_LENGTH];
2258
uint32_t length= my_TIME_to_str(&value.time, buff);
2259
make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2262
uint length= my_TIME_to_str(&value.time, buff);
2263
make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2260
2264
buff, length, time_type, 0);
2261
set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
2265
set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR);
2264
2268
state= TIME_VALUE;
2266
2270
max_length= max_length_arg;
2272
2276
bool Item_param::set_str(const char *str, ulong length)
2278
DBUG_ENTER("Item_param::set_str");
2275
2280
Assign string with no conversion: data is converted only after it's
2276
2281
been written to the binary log.
2278
uint32_t dummy_errors;
2279
2284
if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
2280
2285
&dummy_errors))
2282
2287
state= STRING_VALUE;
2283
2288
max_length= length;
2285
2290
/* max_length and decimals are set after charset conversion */
2286
/* sic: str may be not null-terminated */
2291
/* sic: str may be not null-terminated, don't add DBUG_PRINT here */
2291
2296
bool Item_param::set_longdata(const char *str, ulong length)
2298
DBUG_ENTER("Item_param::set_longdata");
2294
2301
If client character set is multibyte, end of long data packet
2295
2302
may hit at the middle of a multibyte character. Additionally,
2841
bool Item::fix_fields(THD *thd __attribute__((unused)),
2842
Item **ref __attribute__((unused)))
2850
bool Item::fix_fields(THD *thd __attribute__((__unused__)),
2851
Item **ref __attribute__((__unused__)))
2845
2854
// We do not check fields which are fixed during construction
2846
assert(fixed == 0 || basic_const_item());
2855
DBUG_ASSERT(fixed == 0 || basic_const_item());
2851
2860
double Item_ref_null_helper::val_real()
2862
DBUG_ASSERT(fixed == 1);
2854
2863
double tmp= (*ref)->val_result();
2855
2864
owner->was_null|= null_value= (*ref)->null_value;
2860
int64_t Item_ref_null_helper::val_int()
2869
longlong Item_ref_null_helper::val_int()
2863
int64_t tmp= (*ref)->val_int_result();
2871
DBUG_ASSERT(fixed == 1);
2872
longlong tmp= (*ref)->val_int_result();
2864
2873
owner->was_null|= null_value= (*ref)->null_value;
2925
2934
current->mark_as_dependent(last);
2926
2935
if (thd->lex->describe & DESCRIBE_EXTENDED)
2928
char warn_buff[DRIZZLE_ERRMSG_SIZE];
2937
char warn_buff[MYSQL_ERRMSG_SIZE];
2929
2938
sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
2930
2939
db_name, (db_name[0] ? "." : ""),
2931
2940
table_name, (table_name [0] ? "." : ""),
2932
2941
resolved_item->field_name,
2933
2942
current->select_number, last->select_number);
2934
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2943
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2935
2944
ER_WARN_FIELD_RESOLVED, warn_buff);
3787
3797
false otherwise
3790
bool Item_field::subst_argument_checker(unsigned char **arg)
3800
bool Item_field::subst_argument_checker(uchar **arg)
3792
3802
return (result_type() != STRING_RESULT) || (*arg);
3807
Convert a numeric value to a zero-filled string
3809
@param[in,out] item the item to operate on
3810
@param field The field that this value is equated to
3812
This function converts a numeric value to a string. In this conversion
3813
the zero-fill flag of the field is taken into account.
3814
This is required so the resulting string value can be used instead of
3815
the field reference when propagating equalities.
3818
static void convert_zerofill_number_to_string(Item **item, Field_num *field)
3820
char buff[MAX_FIELD_WIDTH],*pos;
3821
String tmp(buff,sizeof(buff), field->charset()), *res;
3823
res= (*item)->val_str(&tmp);
3824
field->prepend_zeros(res);
3825
pos= (char *) sql_strmake (res->ptr(), res->length());
3826
*item= new Item_string(pos, res->length(), field->charset());
3797
3831
Set a pointer to the multiple equality the field reference belongs to
3975
4017
String *Item::check_well_formed_result(String *str, bool send_error)
3977
4019
/* Check whether we got a well-formed string */
3978
const CHARSET_INFO * const cs= str->charset();
4020
CHARSET_INFO *cs= str->charset();
3979
4021
int well_formed_error;
3980
uint32_t wlen= cs->cset->well_formed_len(cs,
4022
uint wlen= cs->cset->well_formed_len(cs,
3981
4023
str->ptr(), str->ptr() + str->length(),
3982
4024
str->length(), &well_formed_error);
3983
4025
if (wlen < str->length())
3985
4027
THD *thd= current_thd;
3986
4028
char hexbuf[7];
3987
enum DRIZZLE_ERROR::enum_warning_level level;
3988
uint32_t diff= str->length() - wlen;
4029
enum MYSQL_ERROR::enum_warning_level level;
4030
uint diff= str->length() - wlen;
3989
4031
set_if_smaller(diff, 3);
3990
4032
octet2hex(hexbuf, str->ptr() + wlen, diff);
3991
4033
if (send_error)
4059
4101
@param table Table for which the field is created
4062
Field *Item::make_string_field(Table *table)
4104
Field *Item::make_string_field(TABLE *table)
4065
assert(collation.collation);
4107
DBUG_ASSERT(collation.collation);
4066
4108
if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
4067
4109
field= new Field_blob(max_length, maybe_null, name,
4068
4110
collation.collation);
4111
/* Item_type_holder holds the exact type, do not change it */
4112
else if (max_length > 0 &&
4113
(type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
4070
4114
field= new Field_varstring(max_length, maybe_null, name, table->s,
4071
4115
collation.collation);
4117
field= new Field_string(max_length, maybe_null, name,
4118
collation.collation);
4074
4120
field->init(table);
4088
4134
\# Created field
4091
Field *Item::tmp_table_field_from_field_type(Table *table, bool fixed_length __attribute__((unused)))
4137
Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length)
4094
4140
The field functions defines a field to be not null if null_ptr is not 0
4096
unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
4142
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
4099
4145
switch (field_type()) {
4100
case DRIZZLE_TYPE_NEWDECIMAL:
4101
field= new Field_new_decimal((unsigned char*) 0, max_length, null_ptr, 0,
4146
case MYSQL_TYPE_NEWDECIMAL:
4147
field= new Field_new_decimal((uchar*) 0, max_length, null_ptr, 0,
4102
4148
Field::NONE, name, decimals, 0,
4103
4149
unsigned_flag);
4105
case DRIZZLE_TYPE_TINY:
4106
field= new Field_tiny((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4107
name, 0, unsigned_flag);
4109
case DRIZZLE_TYPE_LONG:
4110
field= new Field_long((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4111
name, 0, unsigned_flag);
4113
case DRIZZLE_TYPE_LONGLONG:
4114
field= new Field_int64_t((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4151
case MYSQL_TYPE_TINY:
4152
field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4153
name, 0, unsigned_flag);
4155
case MYSQL_TYPE_SHORT:
4156
field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4157
name, 0, unsigned_flag);
4159
case MYSQL_TYPE_LONG:
4160
field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4161
name, 0, unsigned_flag);
4163
case MYSQL_TYPE_LONGLONG:
4164
field= new Field_longlong((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4115
4165
name, 0, unsigned_flag);
4117
case DRIZZLE_TYPE_DOUBLE:
4118
field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4167
case MYSQL_TYPE_FLOAT:
4168
field= new Field_float((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4169
name, decimals, 0, unsigned_flag);
4171
case MYSQL_TYPE_DOUBLE:
4172
field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4119
4173
name, decimals, 0, unsigned_flag);
4121
case DRIZZLE_TYPE_NULL:
4122
field= new Field_null((unsigned char*) 0, max_length, Field::NONE,
4175
case MYSQL_TYPE_NULL:
4176
field= new Field_null((uchar*) 0, max_length, Field::NONE,
4123
4177
name, &my_charset_bin);
4125
case DRIZZLE_TYPE_NEWDATE:
4179
case MYSQL_TYPE_NEWDATE:
4126
4180
field= new Field_newdate(maybe_null, name, &my_charset_bin);
4128
case DRIZZLE_TYPE_TIME:
4182
case MYSQL_TYPE_TIME:
4129
4183
field= new Field_time(maybe_null, name, &my_charset_bin);
4131
case DRIZZLE_TYPE_TIMESTAMP:
4185
case MYSQL_TYPE_TIMESTAMP:
4132
4186
field= new Field_timestamp(maybe_null, name, &my_charset_bin);
4134
case DRIZZLE_TYPE_DATETIME:
4188
case MYSQL_TYPE_DATETIME:
4135
4189
field= new Field_datetime(maybe_null, name, &my_charset_bin);
4191
case MYSQL_TYPE_YEAR:
4192
field= new Field_year((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4138
4196
/* This case should never be chosen */
4198
/* If something goes awfully wrong, it's better to get a string than die */
4199
case MYSQL_TYPE_STRING:
4200
if (fixed_length && max_length < CONVERT_IF_BIGGER_TO_BLOB)
4202
field= new Field_string(max_length, maybe_null, name,
4203
collation.collation);
4140
4206
/* Fall through to make_string_field() */
4141
case DRIZZLE_TYPE_ENUM:
4142
case DRIZZLE_TYPE_VARCHAR:
4207
case MYSQL_TYPE_ENUM:
4208
case MYSQL_TYPE_SET:
4209
case MYSQL_TYPE_VAR_STRING:
4210
case MYSQL_TYPE_VARCHAR:
4143
4211
return make_string_field(table);
4144
case DRIZZLE_TYPE_BLOB:
4212
case MYSQL_TYPE_BLOB:
4145
4213
if (this->type() == Item::TYPE_HOLDER)
4146
4214
field= new Field_blob(max_length, maybe_null, name, collation.collation,
4508
4578
unsigned_flag= 1;
4511
int64_t Item_hex_string::val_int()
4581
longlong Item_hex_string::val_int()
4513
4583
// following assert is redundant, because fixed=1 assigned in constructor
4584
DBUG_ASSERT(fixed == 1);
4515
4585
char *end=(char*) str_value.ptr()+str_value.length(),
4516
*ptr=end-cmin(str_value.length(),(uint32_t)sizeof(int64_t));
4586
*ptr=end-min(str_value.length(),sizeof(longlong));
4519
4589
for (; ptr != end ; ptr++)
4520
value=(value << 8)+ (uint64_t) (unsigned char) *ptr;
4521
return (int64_t) value;
4590
value=(value << 8)+ (ulonglong) (uchar) *ptr;
4591
return (longlong) value;
4525
4595
my_decimal *Item_hex_string::val_decimal(my_decimal *decimal_value)
4527
4597
// following assert is redundant, because fixed=1 assigned in constructor
4529
uint64_t value= (uint64_t)val_int();
4598
DBUG_ASSERT(fixed == 1);
4599
ulonglong value= (ulonglong)val_int();
4530
4600
int2my_decimal(E_DEC_FATAL_ERROR, value, true, decimal_value);
4531
4601
return (decimal_value);
4535
4605
int Item_hex_string::save_in_field(Field *field,
4536
bool no_conversions __attribute__((unused)))
4606
bool no_conversions __attribute__((__unused__)))
4538
4608
field->set_notnull();
4539
4609
if (field->result_type() == STRING_RESULT)
4540
4610
return field->store(str_value.ptr(), str_value.length(),
4541
4611
collation.collation);
4544
uint32_t length= str_value.length();
4614
uint32 length= str_value.length();
4545
4615
if (length > 8)
4547
nr= field->flags & UNSIGNED_FLAG ? UINT64_MAX : INT64_MAX;
4617
nr= field->flags & UNSIGNED_FLAG ? ULONGLONG_MAX : LONGLONG_MAX;
4550
nr= (uint64_t) val_int();
4551
if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > INT64_MAX))
4620
nr= (ulonglong) val_int();
4621
if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
4556
return field->store((int64_t) nr, true); // Assume hex numbers are unsigned
4626
return field->store((longlong) nr, true); // Assume hex numbers are unsigned
4559
if (!field->store((int64_t) nr, true))
4560
field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
4629
if (!field->store((longlong) nr, true))
4630
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
4566
4636
void Item_hex_string::print(String *str,
4567
enum_query_type query_type __attribute__((unused)))
4637
enum_query_type query_type __attribute__((__unused__)))
4569
4639
char *end= (char*) str_value.ptr() + str_value.length(),
4570
*ptr= end - cmin(str_value.length(), (uint32_t)sizeof(int64_t));
4640
*ptr= end - min(str_value.length(), sizeof(longlong));
4571
4641
str->append("0x");
4572
4642
for (; ptr != end ; ptr++)
4574
str->append(_dig_vec_lower[((unsigned char) *ptr) >> 4]);
4575
str->append(_dig_vec_lower[((unsigned char) *ptr) & 0x0F]);
4644
str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
4645
str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
4661
4731
switch ((f_type=field_type())) {
4663
case DRIZZLE_TYPE_NULL:
4664
case DRIZZLE_TYPE_ENUM:
4665
case DRIZZLE_TYPE_BLOB:
4666
case DRIZZLE_TYPE_VARCHAR:
4667
case DRIZZLE_TYPE_NEWDECIMAL:
4733
case MYSQL_TYPE_NULL:
4734
case MYSQL_TYPE_ENUM:
4735
case MYSQL_TYPE_SET:
4736
case MYSQL_TYPE_BLOB:
4737
case MYSQL_TYPE_STRING:
4738
case MYSQL_TYPE_VAR_STRING:
4739
case MYSQL_TYPE_VARCHAR:
4740
case MYSQL_TYPE_NEWDECIMAL:
4670
4743
if ((res=val_str(buffer)))
4671
4744
result= protocol->store(res->ptr(),res->length(),res->charset());
4674
case DRIZZLE_TYPE_TINY:
4747
case MYSQL_TYPE_TINY:
4678
4751
if (!null_value)
4679
4752
result= protocol->store_tiny(nr);
4682
case DRIZZLE_TYPE_LONG:
4755
case MYSQL_TYPE_SHORT:
4756
case MYSQL_TYPE_YEAR:
4761
result= protocol->store_short(nr);
4764
case MYSQL_TYPE_LONG:
4686
4768
if (!null_value)
4687
4769
result= protocol->store_long(nr);
4690
case DRIZZLE_TYPE_LONGLONG:
4772
case MYSQL_TYPE_LONGLONG:
4694
4776
if (!null_value)
4695
result= protocol->store_int64_t(nr, unsigned_flag);
4698
case DRIZZLE_TYPE_DOUBLE:
4777
result= protocol->store_longlong(nr, unsigned_flag);
4780
case MYSQL_TYPE_FLOAT:
4783
nr= (float) val_real();
4785
result= protocol->store(nr, decimals, buffer);
4788
case MYSQL_TYPE_DOUBLE:
4700
4790
double nr= val_real();
4701
4791
if (!null_value)
4702
4792
result= protocol->store(nr, decimals, buffer);
4705
case DRIZZLE_TYPE_DATETIME:
4706
case DRIZZLE_TYPE_TIMESTAMP:
4795
case MYSQL_TYPE_DATETIME:
4796
case MYSQL_TYPE_TIMESTAMP:
4709
4799
get_date(&tm, TIME_FUZZY_DATE);
4710
4800
if (!null_value)
4712
if (f_type == DRIZZLE_TYPE_NEWDATE)
4802
if (f_type == MYSQL_TYPE_NEWDATE)
4713
4803
return protocol->store_date(&tm);
4715
4805
result= protocol->store(&tm);
4719
case DRIZZLE_TYPE_TIME:
4809
case MYSQL_TYPE_TIME:
4723
4813
if (!null_value)
4724
4814
result= protocol->store_time(&tm);
5966
6058
double Item_cache_decimal::val_real()
5970
6062
my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res);
5974
int64_t Item_cache_decimal::val_int()
6066
longlong Item_cache_decimal::val_int()
5978
6070
my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &res);
5982
6074
String* Item_cache_decimal::val_str(String *str)
5985
6077
my_decimal_round(E_DEC_FATAL_ERROR, &decimal_value, decimals, false,
5986
6078
&decimal_value);
5987
6079
my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, str);
5991
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val __attribute__((unused)))
6083
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val __attribute__((__unused__)))
5994
6086
return &decimal_value;
6251
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
6348
bool Item_type_holder::join_types(THD *thd __attribute__((__unused__)),
6254
uint32_t max_length_orig= max_length;
6255
uint32_t decimals_orig= decimals;
6351
uint max_length_orig= max_length;
6352
uint decimals_orig= decimals;
6353
DBUG_ENTER("Item_type_holder::join_types");
6354
DBUG_PRINT("info:", ("was type %d len %d, dec %d name %s",
6355
fld_type, max_length, decimals,
6356
(name ? name : "<NULL>")));
6357
DBUG_PRINT("info:", ("in type %d len %d, dec %d",
6358
get_real_type(item),
6359
item->max_length, item->decimals));
6256
6360
fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6258
6362
int item_decimals= item->decimals;
6259
6363
/* fix variable decimals which always is NOT_FIXED_DEC */
6260
6364
if (Field::result_merge_type(fld_type) == INT_RESULT)
6261
6365
item_decimals= 0;
6262
decimals= cmax((int)decimals, item_decimals);
6366
decimals= max(decimals, item_decimals);
6264
6368
if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6266
decimals= cmin((int)cmax(decimals, item->decimals), DECIMAL_MAX_SCALE);
6267
int precision= cmin(cmax(prev_decimal_int_part, item->decimal_int_part())
6370
decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
6371
int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
6268
6372
+ decimals, DECIMAL_MAX_PRECISION);
6269
6373
unsigned_flag&= item->unsigned_flag;
6270
6374
max_length= my_decimal_precision_to_length(precision, decimals,
6311
6415
int delta1= max_length_orig - decimals_orig;
6312
6416
int delta2= item->max_length - item->decimals;
6313
max_length= cmax(delta1, delta2) + decimals;
6314
if (fld_type == DRIZZLE_TYPE_DOUBLE && max_length > DBL_DIG + 2)
6417
max_length= max(delta1, delta2) + decimals;
6418
if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2)
6420
max_length= FLT_DIG + 6;
6421
decimals= NOT_FIXED_DEC;
6423
if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2)
6316
6425
max_length= DBL_DIG + 7;
6317
6426
decimals= NOT_FIXED_DEC;
6321
max_length= DBL_DIG+7;
6430
max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
6325
max_length= cmax(max_length, display_length(item));
6434
max_length= max(max_length, display_length(item));
6327
6436
maybe_null|= item->maybe_null;
6328
6437
get_full_info(item);
6330
6439
/* Remember decimal integer part to be used in DECIMAL_RESULT handleng */
6331
6440
prev_decimal_int_part= decimal_int_part();
6441
DBUG_PRINT("info", ("become type: %d len: %u dec: %u",
6442
(int) fld_type, max_length, (uint) decimals));
6344
uint32_t Item_type_holder::display_length(Item *item)
6455
uint32 Item_type_holder::display_length(Item *item)
6346
6457
if (item->type() == Item::FIELD_ITEM)
6347
6458
return ((Item_field *)item)->max_disp_length();
6349
6460
switch (item->field_type())
6351
case DRIZZLE_TYPE_TIMESTAMP:
6352
case DRIZZLE_TYPE_TIME:
6353
case DRIZZLE_TYPE_DATETIME:
6354
case DRIZZLE_TYPE_NEWDATE:
6355
case DRIZZLE_TYPE_VARCHAR:
6356
case DRIZZLE_TYPE_NEWDECIMAL:
6357
case DRIZZLE_TYPE_ENUM:
6358
case DRIZZLE_TYPE_BLOB:
6359
case DRIZZLE_TYPE_TINY:
6462
case MYSQL_TYPE_TIMESTAMP:
6463
case MYSQL_TYPE_TIME:
6464
case MYSQL_TYPE_DATETIME:
6465
case MYSQL_TYPE_YEAR:
6466
case MYSQL_TYPE_NEWDATE:
6467
case MYSQL_TYPE_VARCHAR:
6468
case MYSQL_TYPE_NEWDECIMAL:
6469
case MYSQL_TYPE_ENUM:
6470
case MYSQL_TYPE_SET:
6471
case MYSQL_TYPE_BLOB:
6472
case MYSQL_TYPE_VAR_STRING:
6473
case MYSQL_TYPE_STRING:
6474
case MYSQL_TYPE_TINY:
6361
case DRIZZLE_TYPE_LONG:
6476
case MYSQL_TYPE_SHORT:
6478
case MYSQL_TYPE_LONG:
6362
6479
return MY_INT32_NUM_DECIMAL_DIGITS;
6363
case DRIZZLE_TYPE_DOUBLE:
6480
case MYSQL_TYPE_FLOAT:
6482
case MYSQL_TYPE_DOUBLE:
6365
case DRIZZLE_TYPE_NULL:
6484
case MYSQL_TYPE_NULL:
6367
case DRIZZLE_TYPE_LONGLONG:
6486
case MYSQL_TYPE_LONGLONG:
6370
assert(0); // we should never go there
6489
DBUG_ASSERT(0); // we should never go there
6386
Field *Item_type_holder::make_field_by_type(Table *table)
6505
Field *Item_type_holder::make_field_by_type(TABLE *table)
6389
6508
The field functions defines a field to be not null if null_ptr is not 0
6391
unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
6510
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
6394
6513
switch (fld_type) {
6395
case DRIZZLE_TYPE_ENUM:
6396
assert(enum_set_typelib);
6397
field= new Field_enum((unsigned char *) 0, max_length, null_ptr, 0,
6514
case MYSQL_TYPE_ENUM:
6515
DBUG_ASSERT(enum_set_typelib);
6516
field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
6398
6517
Field::NONE, name,
6399
6518
get_enum_pack_length(enum_set_typelib->count),
6400
6519
enum_set_typelib, collation.collation);
6402
6521
field->init(table);
6404
case DRIZZLE_TYPE_NULL:
6523
case MYSQL_TYPE_SET:
6524
DBUG_ASSERT(enum_set_typelib);
6525
field= new Field_set((uchar *) 0, max_length, null_ptr, 0,
6527
get_set_pack_length(enum_set_typelib->count),
6528
enum_set_typelib, collation.collation);
6532
case MYSQL_TYPE_NULL:
6405
6533
return make_string_field(table);
6445
6575
double Item_type_holder::val_real()
6447
assert(0); // should never be called
6577
DBUG_ASSERT(0); // should never be called
6452
int64_t Item_type_holder::val_int()
6582
longlong Item_type_holder::val_int()
6454
assert(0); // should never be called
6584
DBUG_ASSERT(0); // should never be called
6458
6588
my_decimal *Item_type_holder::val_decimal(my_decimal *)
6460
assert(0); // should never be called
6590
DBUG_ASSERT(0); // should never be called
6464
6594
String *Item_type_holder::val_str(String*)
6466
assert(0); // should never be called
6596
DBUG_ASSERT(0); // should never be called
6470
6600
void Item_result_field::cleanup()
6602
DBUG_ENTER("Item_result_field::cleanup()");
6472
6603
Item::cleanup();
6473
6604
result_field= 0;