603
606
@param arg pointer to a List<Item_field>
606
false to force the evaluation of collect_item_field_processor
609
FALSE to force the evaluation of collect_item_field_processor
607
610
for the subsequent items.
610
bool Item_field::collect_item_field_processor(unsigned char *arg)
613
bool Item_field::collect_item_field_processor(uchar *arg)
615
DBUG_ENTER("Item_field::collect_item_field_processor");
616
DBUG_PRINT("info", ("%s", field->field_name ? field->field_name : "noname"));
612
617
List<Item_field> *item_list= (List<Item_field>*) arg;
613
618
List_iterator<Item_field> item_list_it(*item_list);
614
619
Item_field *curr_item;
615
620
while ((curr_item= item_list_it++))
617
622
if (curr_item->eq(this, 1))
618
return(false); /* Already in the set. */
623
DBUG_RETURN(FALSE); /* Already in the set. */
620
625
item_list->push_back(this);
661
666
column read set or to register used fields in a view
664
bool Item_field::register_field_in_read_map(unsigned char *arg)
669
bool Item_field::register_field_in_read_map(uchar *arg)
666
Table *table= (Table *) arg;
671
TABLE *table= (TABLE *) arg;
667
672
if (field->table == table || !table)
668
673
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)
678
bool Item::check_cols(uint c)
909
898
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
910
899
if (!(res=val_str(&tmp)) ||
911
900
str_to_datetime_with_warn(res->ptr(), res->length(),
912
ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
901
ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
917
int64_t value= val_int();
906
longlong value= val_int();
919
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
908
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == LL(-1))
921
910
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,
911
end= longlong10_to_str(value, buff, -10);
912
make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
913
buff, (int) (end-buff), MYSQL_TIMESTAMP_NONE,
932
memset(ltime, 0, sizeof(*ltime));
921
bzero((char*) ltime,sizeof(*ltime));
1269
1260
if (c.aggregate((*arg)->collation, flags))
1271
1262
my_coll_agg_error(av, count, fname, item_sep);
1275
1266
if ((flags & MY_COLL_DISALLOW_NONE) &&
1276
1267
c.derivation == DERIVATION_NONE)
1278
1269
my_coll_agg_error(av, count, fname, item_sep);
1285
1276
bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
1286
Item **av, uint32_t count, uint32_t flags)
1277
Item **av, uint count, uint flags)
1288
1279
return (agg_item_collations(c, fname, av, count,
1289
1280
flags | MY_COLL_DISALLOW_NONE, 1));
1627
1623
return result_field->val_str(str,&str_value);
1630
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1626
bool Item_field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
1632
1628
if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
1634
memset(ltime, 0, sizeof(*ltime));
1630
bzero((char*) ltime,sizeof(*ltime));
1640
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1636
bool Item_field::get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
1642
1638
if ((null_value=result_field->is_null()) ||
1643
1639
result_field->get_date(ltime,fuzzydate))
1645
memset(ltime, 0, sizeof(*ltime));
1641
bzero((char*) ltime,sizeof(*ltime));
1651
bool Item_field::get_time(DRIZZLE_TIME *ltime)
1647
bool Item_field::get_time(MYSQL_TIME *ltime)
1653
1649
if ((null_value=field->is_null()) || field->get_time(ltime))
1655
memset(ltime, 0, sizeof(*ltime));
1651
bzero((char*) ltime,sizeof(*ltime));
1832
1824
String *Item_uint::val_str(String *str)
1834
1826
// following assert is redundant, because fixed=1 assigned in constructor
1836
str->set((uint64_t) value, &my_charset_bin);
1827
DBUG_ASSERT(fixed == 1);
1828
str->set((ulonglong) value, &my_charset_bin);
1841
void Item_uint::print(String *str,
1842
enum_query_type query_type __attribute__((unused)))
1833
void Item_uint::print(String *str, enum_query_type query_type)
1844
1835
// latin1 is good enough for numbers
1845
str_value.set((uint64_t) value, default_charset());
1836
str_value.set((ulonglong) value, default_charset());
1846
1837
str->append(str_value);
1850
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1851
const CHARSET_INFO * const charset)
1841
Item_decimal::Item_decimal(const char *str_arg, uint length,
1842
CHARSET_INFO *charset)
1853
1844
str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1854
1845
name= (char*) str_arg;
1855
decimals= (uint8_t) decimal_value.frac;
1846
decimals= (uint8) decimal_value.frac;
1857
1848
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1858
1849
decimals, unsigned_flag);
1861
Item_decimal::Item_decimal(int64_t val, bool unsig)
1852
Item_decimal::Item_decimal(longlong val, bool unsig)
1863
1854
int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
1864
decimals= (uint8_t) decimal_value.frac;
1855
decimals= (uint8) decimal_value.frac;
1866
1857
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1867
1858
decimals, unsigned_flag);
1871
Item_decimal::Item_decimal(double val,
1872
int precision __attribute__((unused)),
1873
int scale __attribute__((unused)))
1862
Item_decimal::Item_decimal(double val, int precision, int scale)
1875
1864
double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
1876
decimals= (uint8_t) decimal_value.frac;
1865
decimals= (uint8) decimal_value.frac;
1878
1867
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1879
1868
decimals, unsigned_flag);
1894
1883
Item_decimal::Item_decimal(my_decimal *value_par)
1896
1885
my_decimal2decimal(value_par, &decimal_value);
1897
decimals= (uint8_t) decimal_value.frac;
1886
decimals= (uint8) decimal_value.frac;
1899
1888
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1900
1889
decimals, unsigned_flag);
1904
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
1893
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
1906
1895
binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1907
1896
&decimal_value, precision, scale);
1908
decimals= (uint8_t) decimal_value.frac;
1897
decimals= (uint8) decimal_value.frac;
1910
1899
max_length= my_decimal_precision_to_length(precision, decimals,
1911
1900
unsigned_flag);
1915
int64_t Item_decimal::val_int()
1904
longlong Item_decimal::val_int()
1918
1907
my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
2090
bool Item_null::eq(const Item *item,
2091
bool binary_cmp __attribute__((unused))) const
2077
bool Item_null::eq(const Item *item, bool binary_cmp) const
2092
2078
{ return item->type() == type(); }
2095
2081
double Item_null::val_real()
2097
2083
// following assert is redundant, because fixed=1 assigned in constructor
2084
DBUG_ASSERT(fixed == 1);
2102
int64_t Item_null::val_int()
2088
longlong Item_null::val_int()
2104
2090
// following assert is redundant, because fixed=1 assigned in constructor
2091
DBUG_ASSERT(fixed == 1);
2110
String *Item_null::val_str(String *str __attribute__((unused)))
2096
String *Item_null::val_str(String *str)
2112
2098
// following assert is redundant, because fixed=1 assigned in constructor
2099
DBUG_ASSERT(fixed == 1);
2118
my_decimal *Item_null::val_decimal(my_decimal *decimal_value __attribute__((unused)))
2104
my_decimal *Item_null::val_decimal(my_decimal *decimal_value)
2124
Item *Item_null::safe_charset_converter(const CHARSET_INFO * const tocs)
2110
Item *Item_null::safe_charset_converter(CHARSET_INFO *tocs)
2126
2112
collation.set(tocs);
2138
2124
default_set_param_func(Item_param *param,
2139
unsigned char **pos __attribute__((unused)),
2125
uchar **pos __attribute__((unused)),
2140
2126
ulong len __attribute__((unused)))
2142
2128
param->set_null();
2146
Item_param::Item_param(uint32_t pos_in_query_arg) :
2132
Item_param::Item_param(uint pos_in_query_arg) :
2147
2133
state(NO_VALUE),
2148
2134
item_result_type(STRING_RESULT),
2149
2135
/* Don't pretend to be a literal unless value for this item is set. */
2150
2136
item_type(PARAM_ITEM),
2151
param_type(DRIZZLE_TYPE_VARCHAR),
2137
param_type(MYSQL_TYPE_VARCHAR),
2152
2138
pos_in_query(pos_in_query_arg),
2153
2139
set_param_func(default_set_param_func),
2154
limit_clause_param(false)
2140
limit_clause_param(FALSE)
2156
2142
name= (char*) "?";
2214
2203
internal decimal value.
2217
void Item_param::set_decimal(char *str, ulong length)
2206
void Item_param::set_decimal(const char *str, ulong length)
2209
DBUG_ENTER("Item_param::set_decimal");
2222
str2my_decimal((uint)E_DEC_FATAL_ERROR, str, &decimal_value, &end);
2211
end= (char*) str+length;
2212
str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
2223
2213
state= DECIMAL_VALUE;
2224
2214
decimals= decimal_value.frac;
2225
2215
max_length= my_decimal_precision_to_length(decimal_value.precision(),
2226
2216
decimals, unsigned_flag);
2233
Set parameter value from DRIZZLE_TIME value.
2223
Set parameter value from MYSQL_TIME value.
2235
2225
@param tm datetime value to set (time_type is ignored)
2236
2226
@param type type of datetime value
2242
2232
the fact that even wrong value sent over binary protocol fits into
2243
2233
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)
2235
void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type,
2236
uint32 max_length_arg)
2238
DBUG_ENTER("Item_param::set_time");
2249
2240
value.time= *tm;
2250
2241
value.time.time_type= time_type;
2252
2243
if (value.time.year > 9999 || value.time.month > 12 ||
2253
2244
value.time.day > 31 ||
2254
((time_type != DRIZZLE_TIMESTAMP_TIME) && value.time.hour > 23) ||
2245
((time_type != MYSQL_TIMESTAMP_TIME) && value.time.hour > 23) ||
2255
2246
value.time.minute > 59 || value.time.second > 59)
2257
2248
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,
2249
uint length= my_TIME_to_str(&value.time, buff);
2250
make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2260
2251
buff, length, time_type, 0);
2261
set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
2252
set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR);
2264
2255
state= TIME_VALUE;
2266
2257
max_length= max_length_arg;
2272
2263
bool Item_param::set_str(const char *str, ulong length)
2265
DBUG_ENTER("Item_param::set_str");
2275
2267
Assign string with no conversion: data is converted only after it's
2276
2268
been written to the binary log.
2278
uint32_t dummy_errors;
2279
2271
if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
2280
2272
&dummy_errors))
2282
2274
state= STRING_VALUE;
2283
2275
max_length= length;
2285
2277
/* max_length and decimals are set after charset conversion */
2286
/* sic: str may be not null-terminated */
2278
/* sic: str may be not null-terminated, don't add DBUG_PRINT here */
2291
2283
bool Item_param::set_longdata(const char *str, ulong length)
2285
DBUG_ENTER("Item_param::set_longdata");
2294
2288
If client character set is multibyte, end of long data packet
2295
2289
may hit at the middle of a multibyte character. Additionally,
2925
2919
current->mark_as_dependent(last);
2926
2920
if (thd->lex->describe & DESCRIBE_EXTENDED)
2928
char warn_buff[DRIZZLE_ERRMSG_SIZE];
2922
char warn_buff[MYSQL_ERRMSG_SIZE];
2929
2923
sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
2930
2924
db_name, (db_name[0] ? "." : ""),
2931
2925
table_name, (table_name [0] ? "." : ""),
2932
2926
resolved_item->field_name,
2933
2927
current->select_number, last->select_number);
2934
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2928
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2935
2929
ER_WARN_FIELD_RESOLVED, warn_buff);
3782
3777
a comparison predicate.
3785
true substitution is valid
3780
TRUE substitution is valid
3790
bool Item_field::subst_argument_checker(unsigned char **arg)
3785
bool Item_field::subst_argument_checker(uchar **arg)
3792
3787
return (result_type() != STRING_RESULT) || (*arg);
3792
Convert a numeric value to a zero-filled string
3794
@param[in,out] item the item to operate on
3795
@param field The field that this value is equated to
3797
This function converts a numeric value to a string. In this conversion
3798
the zero-fill flag of the field is taken into account.
3799
This is required so the resulting string value can be used instead of
3800
the field reference when propagating equalities.
3803
static void convert_zerofill_number_to_string(Item **item, Field_num *field)
3805
char buff[MAX_FIELD_WIDTH],*pos;
3806
String tmp(buff,sizeof(buff), field->charset()), *res;
3808
res= (*item)->val_str(&tmp);
3809
field->prepend_zeros(res);
3810
pos= (char *) sql_strmake (res->ptr(), res->length());
3811
*item= new Item_string(pos, res->length(), field->charset());
3797
3816
Set a pointer to the multiple equality the field reference belongs to
3962
3991
switch (field_type())
3964
case DRIZZLE_TYPE_NEWDATE:
3965
case DRIZZLE_TYPE_DATETIME:
3966
case DRIZZLE_TYPE_TIMESTAMP:
3993
case MYSQL_TYPE_DATE:
3994
case MYSQL_TYPE_DATETIME:
3995
case MYSQL_TYPE_TIMESTAMP:
3975
4004
String *Item::check_well_formed_result(String *str, bool send_error)
3977
4006
/* Check whether we got a well-formed string */
3978
const CHARSET_INFO * const cs= str->charset();
4007
CHARSET_INFO *cs= str->charset();
3979
4008
int well_formed_error;
3980
uint32_t wlen= cs->cset->well_formed_len(cs,
4009
uint wlen= cs->cset->well_formed_len(cs,
3981
4010
str->ptr(), str->ptr() + str->length(),
3982
4011
str->length(), &well_formed_error);
3983
4012
if (wlen < str->length())
3985
4014
THD *thd= current_thd;
3986
4015
char hexbuf[7];
3987
enum DRIZZLE_ERROR::enum_warning_level level;
3988
uint32_t diff= str->length() - wlen;
4016
enum MYSQL_ERROR::enum_warning_level level;
4017
uint diff= str->length() - wlen;
3989
4018
set_if_smaller(diff, 3);
3990
4019
octet2hex(hexbuf, str->ptr() + wlen, diff);
3991
4020
if (send_error)
4059
4088
@param table Table for which the field is created
4062
Field *Item::make_string_field(Table *table)
4091
Field *Item::make_string_field(TABLE *table)
4065
assert(collation.collation);
4094
DBUG_ASSERT(collation.collation);
4066
4095
if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
4067
4096
field= new Field_blob(max_length, maybe_null, name,
4068
4097
collation.collation);
4098
/* Item_type_holder holds the exact type, do not change it */
4099
else if (max_length > 0 &&
4100
(type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
4070
4101
field= new Field_varstring(max_length, maybe_null, name, table->s,
4071
4102
collation.collation);
4104
field= new Field_string(max_length, maybe_null, name,
4105
collation.collation);
4074
4107
field->init(table);
4088
4121
\# Created field
4091
Field *Item::tmp_table_field_from_field_type(Table *table, bool fixed_length __attribute__((unused)))
4124
Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length)
4094
4127
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;
4129
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
4099
4132
switch (field_type()) {
4100
case DRIZZLE_TYPE_NEWDECIMAL:
4101
field= new Field_new_decimal((unsigned char*) 0, max_length, null_ptr, 0,
4133
case MYSQL_TYPE_DECIMAL:
4134
case MYSQL_TYPE_NEWDECIMAL:
4135
field= new Field_new_decimal((uchar*) 0, max_length, null_ptr, 0,
4102
4136
Field::NONE, name, decimals, 0,
4103
4137
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,
4139
case MYSQL_TYPE_TINY:
4140
field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4141
name, 0, unsigned_flag);
4143
case MYSQL_TYPE_SHORT:
4144
field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4145
name, 0, unsigned_flag);
4147
case MYSQL_TYPE_LONG:
4148
field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4149
name, 0, unsigned_flag);
4151
#ifdef HAVE_LONG_LONG
4152
case MYSQL_TYPE_LONGLONG:
4153
field= new Field_longlong((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4115
4154
name, 0, unsigned_flag);
4117
case DRIZZLE_TYPE_DOUBLE:
4118
field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4157
case MYSQL_TYPE_FLOAT:
4158
field= new Field_float((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4159
name, decimals, 0, unsigned_flag);
4161
case MYSQL_TYPE_DOUBLE:
4162
field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4119
4163
name, decimals, 0, unsigned_flag);
4121
case DRIZZLE_TYPE_NULL:
4122
field= new Field_null((unsigned char*) 0, max_length, Field::NONE,
4165
case MYSQL_TYPE_NULL:
4166
field= new Field_null((uchar*) 0, max_length, Field::NONE,
4123
4167
name, &my_charset_bin);
4125
case DRIZZLE_TYPE_NEWDATE:
4169
case MYSQL_TYPE_INT24:
4170
field= new Field_medium((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4171
name, 0, unsigned_flag);
4173
case MYSQL_TYPE_NEWDATE:
4174
case MYSQL_TYPE_DATE:
4126
4175
field= new Field_newdate(maybe_null, name, &my_charset_bin);
4128
case DRIZZLE_TYPE_TIME:
4177
case MYSQL_TYPE_TIME:
4129
4178
field= new Field_time(maybe_null, name, &my_charset_bin);
4131
case DRIZZLE_TYPE_TIMESTAMP:
4180
case MYSQL_TYPE_TIMESTAMP:
4132
4181
field= new Field_timestamp(maybe_null, name, &my_charset_bin);
4134
case DRIZZLE_TYPE_DATETIME:
4183
case MYSQL_TYPE_DATETIME:
4135
4184
field= new Field_datetime(maybe_null, name, &my_charset_bin);
4186
case MYSQL_TYPE_YEAR:
4187
field= new Field_year((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4190
case MYSQL_TYPE_BIT:
4191
field= new Field_bit_as_char(NULL, max_length, null_ptr, 0,
4138
4195
/* This case should never be chosen */
4197
/* If something goes awfully wrong, it's better to get a string than die */
4198
case MYSQL_TYPE_STRING:
4199
if (fixed_length && max_length < CONVERT_IF_BIGGER_TO_BLOB)
4201
field= new Field_string(max_length, maybe_null, name,
4202
collation.collation);
4140
4205
/* Fall through to make_string_field() */
4141
case DRIZZLE_TYPE_ENUM:
4142
case DRIZZLE_TYPE_VARCHAR:
4206
case MYSQL_TYPE_ENUM:
4207
case MYSQL_TYPE_SET:
4208
case MYSQL_TYPE_VAR_STRING:
4209
case MYSQL_TYPE_VARCHAR:
4143
4210
return make_string_field(table);
4144
case DRIZZLE_TYPE_BLOB:
4211
case MYSQL_TYPE_TINY_BLOB:
4212
case MYSQL_TYPE_MEDIUM_BLOB:
4213
case MYSQL_TYPE_LONG_BLOB:
4214
case MYSQL_TYPE_BLOB:
4145
4215
if (this->type() == Item::TYPE_HOLDER)
4146
4216
field= new Field_blob(max_length, maybe_null, name, collation.collation,
4508
4573
unsigned_flag= 1;
4511
int64_t Item_hex_string::val_int()
4576
longlong Item_hex_string::val_int()
4513
4578
// following assert is redundant, because fixed=1 assigned in constructor
4579
DBUG_ASSERT(fixed == 1);
4515
4580
char *end=(char*) str_value.ptr()+str_value.length(),
4516
*ptr=end-cmin(str_value.length(),(uint32_t)sizeof(int64_t));
4581
*ptr=end-min(str_value.length(),sizeof(longlong));
4519
4584
for (; ptr != end ; ptr++)
4520
value=(value << 8)+ (uint64_t) (unsigned char) *ptr;
4521
return (int64_t) value;
4585
value=(value << 8)+ (ulonglong) (uchar) *ptr;
4586
return (longlong) value;
4525
4590
my_decimal *Item_hex_string::val_decimal(my_decimal *decimal_value)
4527
4592
// following assert is redundant, because fixed=1 assigned in constructor
4529
uint64_t value= (uint64_t)val_int();
4530
int2my_decimal(E_DEC_FATAL_ERROR, value, true, decimal_value);
4593
DBUG_ASSERT(fixed == 1);
4594
ulonglong value= (ulonglong)val_int();
4595
int2my_decimal(E_DEC_FATAL_ERROR, value, TRUE, decimal_value);
4531
4596
return (decimal_value);
4535
int Item_hex_string::save_in_field(Field *field,
4536
bool no_conversions __attribute__((unused)))
4600
int Item_hex_string::save_in_field(Field *field, bool no_conversions)
4538
4602
field->set_notnull();
4539
4603
if (field->result_type() == STRING_RESULT)
4540
4604
return field->store(str_value.ptr(), str_value.length(),
4541
4605
collation.collation);
4544
uint32_t length= str_value.length();
4608
uint32 length= str_value.length();
4545
4609
if (length > 8)
4547
nr= field->flags & UNSIGNED_FLAG ? UINT64_MAX : INT64_MAX;
4611
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))
4614
nr= (ulonglong) val_int();
4615
if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
4556
return field->store((int64_t) nr, true); // Assume hex numbers are unsigned
4620
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,
4623
if (!field->store((longlong) nr, TRUE))
4624
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
4566
void Item_hex_string::print(String *str,
4567
enum_query_type query_type __attribute__((unused)))
4630
void Item_hex_string::print(String *str, enum_query_type query_type)
4569
4632
char *end= (char*) str_value.ptr() + str_value.length(),
4570
*ptr= end - cmin(str_value.length(), (uint32_t)sizeof(int64_t));
4633
*ptr= end - min(str_value.length(), sizeof(longlong));
4571
4634
str->append("0x");
4572
4635
for (; ptr != end ; ptr++)
4574
str->append(_dig_vec_lower[((unsigned char) *ptr) >> 4]);
4575
str->append(_dig_vec_lower[((unsigned char) *ptr) & 0x0F]);
4637
str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
4638
str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
4661
4723
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:
4725
case MYSQL_TYPE_NULL:
4726
case MYSQL_TYPE_DECIMAL:
4727
case MYSQL_TYPE_ENUM:
4728
case MYSQL_TYPE_SET:
4729
case MYSQL_TYPE_TINY_BLOB:
4730
case MYSQL_TYPE_MEDIUM_BLOB:
4731
case MYSQL_TYPE_LONG_BLOB:
4732
case MYSQL_TYPE_BLOB:
4733
case MYSQL_TYPE_STRING:
4734
case MYSQL_TYPE_VAR_STRING:
4735
case MYSQL_TYPE_VARCHAR:
4736
case MYSQL_TYPE_BIT:
4737
case MYSQL_TYPE_NEWDECIMAL:
4670
4740
if ((res=val_str(buffer)))
4671
4741
result= protocol->store(res->ptr(),res->length(),res->charset());
4674
case DRIZZLE_TYPE_TINY:
4744
case MYSQL_TYPE_TINY:
4678
4748
if (!null_value)
4679
4749
result= protocol->store_tiny(nr);
4682
case DRIZZLE_TYPE_LONG:
4752
case MYSQL_TYPE_SHORT:
4753
case MYSQL_TYPE_YEAR:
4758
result= protocol->store_short(nr);
4761
case MYSQL_TYPE_INT24:
4762
case MYSQL_TYPE_LONG:
4686
4766
if (!null_value)
4687
4767
result= protocol->store_long(nr);
4690
case DRIZZLE_TYPE_LONGLONG:
4770
case MYSQL_TYPE_LONGLONG:
4694
4774
if (!null_value)
4695
result= protocol->store_int64_t(nr, unsigned_flag);
4698
case DRIZZLE_TYPE_DOUBLE:
4775
result= protocol->store_longlong(nr, unsigned_flag);
4778
case MYSQL_TYPE_FLOAT:
4781
nr= (float) val_real();
4783
result= protocol->store(nr, decimals, buffer);
4786
case MYSQL_TYPE_DOUBLE:
4700
4788
double nr= val_real();
4701
4789
if (!null_value)
4702
4790
result= protocol->store(nr, decimals, buffer);
4705
case DRIZZLE_TYPE_DATETIME:
4706
case DRIZZLE_TYPE_TIMESTAMP:
4793
case MYSQL_TYPE_DATETIME:
4794
case MYSQL_TYPE_DATE:
4795
case MYSQL_TYPE_TIMESTAMP:
4709
4798
get_date(&tm, TIME_FUZZY_DATE);
4710
4799
if (!null_value)
4712
if (f_type == DRIZZLE_TYPE_NEWDATE)
4801
if (f_type == MYSQL_TYPE_DATE)
4713
4802
return protocol->store_date(&tm);
4715
4804
result= protocol->store(&tm);
4719
case DRIZZLE_TYPE_TIME:
4808
case MYSQL_TYPE_TIME:
4723
4812
if (!null_value)
4724
4813
result= protocol->store_time(&tm);
5966
6052
double Item_cache_decimal::val_real()
5970
6056
my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res);
5974
int64_t Item_cache_decimal::val_int()
6060
longlong Item_cache_decimal::val_int()
5978
6064
my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &res);
5982
6068
String* Item_cache_decimal::val_str(String *str)
5985
my_decimal_round(E_DEC_FATAL_ERROR, &decimal_value, decimals, false,
6071
my_decimal_round(E_DEC_FATAL_ERROR, &decimal_value, decimals, FALSE,
5986
6072
&decimal_value);
5987
6073
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)))
6077
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val)
5994
6080
return &decimal_value;
6243
6334
@param item given item to join its parameters with this item ones
6246
true error - types are incompatible
6337
TRUE error - types are incompatible
6251
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
6342
bool Item_type_holder::join_types(THD *thd, Item *item)
6254
uint32_t max_length_orig= max_length;
6255
uint32_t decimals_orig= decimals;
6344
uint max_length_orig= max_length;
6345
uint decimals_orig= decimals;
6346
DBUG_ENTER("Item_type_holder::join_types");
6347
DBUG_PRINT("info:", ("was type %d len %d, dec %d name %s",
6348
fld_type, max_length, decimals,
6349
(name ? name : "<NULL>")));
6350
DBUG_PRINT("info:", ("in type %d len %d, dec %d",
6351
get_real_type(item),
6352
item->max_length, item->decimals));
6256
6353
fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6258
6355
int item_decimals= item->decimals;
6259
6356
/* fix variable decimals which always is NOT_FIXED_DEC */
6260
6357
if (Field::result_merge_type(fld_type) == INT_RESULT)
6261
6358
item_decimals= 0;
6262
decimals= cmax((int)decimals, item_decimals);
6359
decimals= max(decimals, item_decimals);
6264
6361
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())
6363
decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
6364
int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
6268
6365
+ decimals, DECIMAL_MAX_PRECISION);
6269
6366
unsigned_flag&= item->unsigned_flag;
6270
6367
max_length= my_decimal_precision_to_length(precision, decimals,
6311
6408
int delta1= max_length_orig - decimals_orig;
6312
6409
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)
6410
max_length= max(delta1, delta2) + decimals;
6411
if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2)
6413
max_length= FLT_DIG + 6;
6414
decimals= NOT_FIXED_DEC;
6416
if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2)
6316
6418
max_length= DBL_DIG + 7;
6317
6419
decimals= NOT_FIXED_DEC;
6321
max_length= DBL_DIG+7;
6423
max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
6325
max_length= cmax(max_length, display_length(item));
6427
max_length= max(max_length, display_length(item));
6327
6429
maybe_null|= item->maybe_null;
6328
6430
get_full_info(item);
6330
6432
/* Remember decimal integer part to be used in DECIMAL_RESULT handleng */
6331
6433
prev_decimal_int_part= decimal_int_part();
6434
DBUG_PRINT("info", ("become type: %d len: %u dec: %u",
6435
(int) fld_type, max_length, (uint) decimals));
6344
uint32_t Item_type_holder::display_length(Item *item)
6448
uint32 Item_type_holder::display_length(Item *item)
6346
6450
if (item->type() == Item::FIELD_ITEM)
6347
6451
return ((Item_field *)item)->max_disp_length();
6349
6453
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:
6455
case MYSQL_TYPE_DECIMAL:
6456
case MYSQL_TYPE_TIMESTAMP:
6457
case MYSQL_TYPE_DATE:
6458
case MYSQL_TYPE_TIME:
6459
case MYSQL_TYPE_DATETIME:
6460
case MYSQL_TYPE_YEAR:
6461
case MYSQL_TYPE_NEWDATE:
6462
case MYSQL_TYPE_VARCHAR:
6463
case MYSQL_TYPE_BIT:
6464
case MYSQL_TYPE_NEWDECIMAL:
6465
case MYSQL_TYPE_ENUM:
6466
case MYSQL_TYPE_SET:
6467
case MYSQL_TYPE_TINY_BLOB:
6468
case MYSQL_TYPE_MEDIUM_BLOB:
6469
case MYSQL_TYPE_LONG_BLOB:
6470
case MYSQL_TYPE_BLOB:
6471
case MYSQL_TYPE_VAR_STRING:
6472
case MYSQL_TYPE_STRING:
6473
case MYSQL_TYPE_GEOMETRY:
6474
return item->max_length;
6475
case MYSQL_TYPE_TINY:
6361
case DRIZZLE_TYPE_LONG:
6477
case MYSQL_TYPE_SHORT:
6479
case MYSQL_TYPE_LONG:
6362
6480
return MY_INT32_NUM_DECIMAL_DIGITS;
6363
case DRIZZLE_TYPE_DOUBLE:
6481
case MYSQL_TYPE_FLOAT:
6483
case MYSQL_TYPE_DOUBLE:
6365
case DRIZZLE_TYPE_NULL:
6485
case MYSQL_TYPE_NULL:
6367
case DRIZZLE_TYPE_LONGLONG:
6487
case MYSQL_TYPE_LONGLONG:
6489
case MYSQL_TYPE_INT24:
6370
assert(0); // we should never go there
6492
DBUG_ASSERT(0); // we should never go there
6386
Field *Item_type_holder::make_field_by_type(Table *table)
6508
Field *Item_type_holder::make_field_by_type(TABLE *table)
6389
6511
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;
6513
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
6394
6516
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,
6517
case MYSQL_TYPE_ENUM:
6518
DBUG_ASSERT(enum_set_typelib);
6519
field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
6398
6520
Field::NONE, name,
6399
6521
get_enum_pack_length(enum_set_typelib->count),
6400
6522
enum_set_typelib, collation.collation);
6402
6524
field->init(table);
6404
case DRIZZLE_TYPE_NULL:
6526
case MYSQL_TYPE_SET:
6527
DBUG_ASSERT(enum_set_typelib);
6528
field= new Field_set((uchar *) 0, max_length, null_ptr, 0,
6530
get_set_pack_length(enum_set_typelib->count),
6531
enum_set_typelib, collation.collation);
6535
case MYSQL_TYPE_NULL:
6405
6536
return make_string_field(table);