1426
1424
Item_field (this is important in prepared statements).
1429
Item_field::Item_field(THD *thd __attribute__((__unused__)),
1427
Item_field::Item_field(THD *thd __attribute__((unused)),
1430
1428
Name_resolution_context *context_arg,
1432
1430
:Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
1846
1844
str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1847
1845
name= (char*) str_arg;
1848
decimals= (uint8) decimal_value.frac;
1846
decimals= (uint8_t) decimal_value.frac;
1850
1848
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1851
1849
decimals, unsigned_flag);
1854
1852
Item_decimal::Item_decimal(int64_t val, bool unsig)
1856
1854
int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
1857
decimals= (uint8) decimal_value.frac;
1855
decimals= (uint8_t) decimal_value.frac;
1859
1857
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1860
1858
decimals, unsigned_flag);
1864
1862
Item_decimal::Item_decimal(double val,
1865
int precision __attribute__((__unused__)),
1866
int scale __attribute__((__unused__)))
1863
int precision __attribute__((unused)),
1864
int scale __attribute__((unused)))
1868
1866
double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
1869
decimals= (uint8) decimal_value.frac;
1867
decimals= (uint8_t) decimal_value.frac;
1871
1869
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1872
1870
decimals, unsigned_flag);
1887
1885
Item_decimal::Item_decimal(my_decimal *value_par)
1889
1887
my_decimal2decimal(value_par, &decimal_value);
1890
decimals= (uint8) decimal_value.frac;
1888
decimals= (uint8_t) decimal_value.frac;
1892
1890
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1893
1891
decimals, unsigned_flag);
1899
1897
binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1900
1898
&decimal_value, precision, scale);
1901
decimals= (uint8) decimal_value.frac;
1899
decimals= (uint8_t) decimal_value.frac;
1903
1901
max_length= my_decimal_precision_to_length(precision, decimals,
1904
1902
unsigned_flag);
1956
1954
void Item_decimal::set_decimal_value(my_decimal *value_par)
1958
1956
my_decimal2decimal(value_par, &decimal_value);
1959
decimals= (uint8) decimal_value.frac;
1957
decimals= (uint8_t) decimal_value.frac;
1960
1958
unsigned_flag= !decimal_value.sign();
1961
1959
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1962
1960
decimals, unsigned_flag);
2141
2139
item_result_type(STRING_RESULT),
2142
2140
/* Don't pretend to be a literal unless value for this item is set. */
2143
2141
item_type(PARAM_ITEM),
2144
param_type(MYSQL_TYPE_VARCHAR),
2142
param_type(DRIZZLE_TYPE_VARCHAR),
2145
2143
pos_in_query(pos_in_query_arg),
2146
2144
set_param_func(default_set_param_func),
2147
2145
limit_clause_param(false)
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());
3813
3787
Set a pointer to the multiple equality the field reference belongs to
3971
3939
switch (result_type()) {
3972
3940
case STRING_RESULT: return string_field_type();
3973
case INT_RESULT: return MYSQL_TYPE_LONGLONG;
3974
case DECIMAL_RESULT: return MYSQL_TYPE_NEWDECIMAL;
3975
case REAL_RESULT: return MYSQL_TYPE_DOUBLE;
3941
case INT_RESULT: return DRIZZLE_TYPE_LONGLONG;
3942
case DECIMAL_RESULT: return DRIZZLE_TYPE_NEWDECIMAL;
3943
case REAL_RESULT: return DRIZZLE_TYPE_DOUBLE;
3976
3944
case ROW_RESULT:
3979
return MYSQL_TYPE_VARCHAR;
3947
return DRIZZLE_TYPE_VARCHAR;
4092
4060
collation.collation);
4093
4061
/* Item_type_holder holds the exact type, do not change it */
4094
4062
else if (max_length > 0 &&
4095
(type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
4063
(type() != Item::TYPE_HOLDER || field_type() != DRIZZLE_TYPE_STRING))
4096
4064
field= new Field_varstring(max_length, maybe_null, name, table->s,
4097
4065
collation.collation);
4127
4095
switch (field_type()) {
4128
case MYSQL_TYPE_NEWDECIMAL:
4096
case DRIZZLE_TYPE_NEWDECIMAL:
4129
4097
field= new Field_new_decimal((uchar*) 0, max_length, null_ptr, 0,
4130
4098
Field::NONE, name, decimals, 0,
4131
4099
unsigned_flag);
4133
case MYSQL_TYPE_TINY:
4101
case DRIZZLE_TYPE_TINY:
4134
4102
field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4135
4103
name, 0, unsigned_flag);
4137
case MYSQL_TYPE_SHORT:
4105
case DRIZZLE_TYPE_SHORT:
4138
4106
field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4139
4107
name, 0, unsigned_flag);
4141
case MYSQL_TYPE_LONG:
4109
case DRIZZLE_TYPE_LONG:
4142
4110
field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4143
4111
name, 0, unsigned_flag);
4145
case MYSQL_TYPE_LONGLONG:
4113
case DRIZZLE_TYPE_LONGLONG:
4146
4114
field= new Field_int64_t((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4147
4115
name, 0, unsigned_flag);
4149
case MYSQL_TYPE_DOUBLE:
4117
case DRIZZLE_TYPE_DOUBLE:
4150
4118
field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4151
4119
name, decimals, 0, unsigned_flag);
4153
case MYSQL_TYPE_NULL:
4121
case DRIZZLE_TYPE_NULL:
4154
4122
field= new Field_null((uchar*) 0, max_length, Field::NONE,
4155
4123
name, &my_charset_bin);
4157
case MYSQL_TYPE_NEWDATE:
4125
case DRIZZLE_TYPE_NEWDATE:
4158
4126
field= new Field_newdate(maybe_null, name, &my_charset_bin);
4160
case MYSQL_TYPE_TIME:
4128
case DRIZZLE_TYPE_TIME:
4161
4129
field= new Field_time(maybe_null, name, &my_charset_bin);
4163
case MYSQL_TYPE_TIMESTAMP:
4131
case DRIZZLE_TYPE_TIMESTAMP:
4164
4132
field= new Field_timestamp(maybe_null, name, &my_charset_bin);
4166
case MYSQL_TYPE_DATETIME:
4134
case DRIZZLE_TYPE_DATETIME:
4167
4135
field= new Field_datetime(maybe_null, name, &my_charset_bin);
4169
case MYSQL_TYPE_YEAR:
4170
field= new Field_year((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4174
4138
/* This case should never be chosen */
4176
4140
/* If something goes awfully wrong, it's better to get a string than die */
4177
case MYSQL_TYPE_STRING:
4141
case DRIZZLE_TYPE_STRING:
4178
4142
if (fixed_length && max_length < CONVERT_IF_BIGGER_TO_BLOB)
4180
4144
field= new Field_string(max_length, maybe_null, name,
4184
4148
/* Fall through to make_string_field() */
4185
case MYSQL_TYPE_ENUM:
4186
case MYSQL_TYPE_SET:
4187
case MYSQL_TYPE_VAR_STRING:
4188
case MYSQL_TYPE_VARCHAR:
4149
case DRIZZLE_TYPE_ENUM:
4150
case DRIZZLE_TYPE_SET:
4151
case DRIZZLE_TYPE_VAR_STRING:
4152
case DRIZZLE_TYPE_VARCHAR:
4189
4153
return make_string_field(table);
4190
case MYSQL_TYPE_BLOB:
4154
case DRIZZLE_TYPE_BLOB:
4191
4155
if (this->type() == Item::TYPE_HOLDER)
4192
4156
field= new Field_blob(max_length, maybe_null, name, collation.collation,
4471
4435
my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "double", (char*) str_arg);
4473
4437
presentation= name=(char*) str_arg;
4474
decimals=(uint8) nr_of_decimals(str_arg, str_arg+length);
4438
decimals=(uint8_t) nr_of_decimals(str_arg, str_arg+length);
4475
4439
max_length=length;
4480
4444
int Item_float::save_in_field(Field *field,
4481
bool no_conversions __attribute__((__unused__)))
4445
bool no_conversions __attribute__((unused)))
4483
4447
double nr= val_real();
4484
4448
if (null_value)
4707
4671
switch ((f_type=field_type())) {
4709
case MYSQL_TYPE_NULL:
4710
case MYSQL_TYPE_ENUM:
4711
case MYSQL_TYPE_SET:
4712
case MYSQL_TYPE_BLOB:
4713
case MYSQL_TYPE_STRING:
4714
case MYSQL_TYPE_VAR_STRING:
4715
case MYSQL_TYPE_VARCHAR:
4716
case MYSQL_TYPE_NEWDECIMAL:
4673
case DRIZZLE_TYPE_NULL:
4674
case DRIZZLE_TYPE_ENUM:
4675
case DRIZZLE_TYPE_SET:
4676
case DRIZZLE_TYPE_BLOB:
4677
case DRIZZLE_TYPE_STRING:
4678
case DRIZZLE_TYPE_VAR_STRING:
4679
case DRIZZLE_TYPE_VARCHAR:
4680
case DRIZZLE_TYPE_NEWDECIMAL:
4719
4683
if ((res=val_str(buffer)))
4720
4684
result= protocol->store(res->ptr(),res->length(),res->charset());
4723
case MYSQL_TYPE_TINY:
4687
case DRIZZLE_TYPE_TINY:
4753
4716
result= protocol->store_int64_t(nr, unsigned_flag);
4756
case MYSQL_TYPE_DOUBLE:
4719
case DRIZZLE_TYPE_DOUBLE:
4758
4721
double nr= val_real();
4759
4722
if (!null_value)
4760
4723
result= protocol->store(nr, decimals, buffer);
4763
case MYSQL_TYPE_DATETIME:
4764
case MYSQL_TYPE_TIMESTAMP:
4726
case DRIZZLE_TYPE_DATETIME:
4727
case DRIZZLE_TYPE_TIMESTAMP:
4767
4730
get_date(&tm, TIME_FUZZY_DATE);
4768
4731
if (!null_value)
4770
if (f_type == MYSQL_TYPE_NEWDATE)
4733
if (f_type == DRIZZLE_TYPE_NEWDATE)
4771
4734
return protocol->store_date(&tm);
4773
4736
result= protocol->store(&tm);
4777
case MYSQL_TYPE_TIME:
4740
case DRIZZLE_TYPE_TIME:
6249
6212
Field *field= ((Item_field *) item)->field;
6250
6213
enum_field_types type= field->real_type();
6251
6214
if (field->is_created_from_null_item)
6252
return MYSQL_TYPE_NULL;
6215
return DRIZZLE_TYPE_NULL;
6253
6216
/* work around about varchar type field detection */
6254
if (type == MYSQL_TYPE_STRING && field->type() == MYSQL_TYPE_VAR_STRING)
6255
return MYSQL_TYPE_VAR_STRING;
6217
if (type == DRIZZLE_TYPE_STRING && field->type() == DRIZZLE_TYPE_VAR_STRING)
6218
return DRIZZLE_TYPE_VAR_STRING;
6258
6221
case SUM_FUNC_ITEM:
6278
6241
switch (item->result_type()) {
6279
6242
case STRING_RESULT:
6280
return MYSQL_TYPE_VAR_STRING;
6243
return DRIZZLE_TYPE_VAR_STRING;
6281
6244
case INT_RESULT:
6282
return MYSQL_TYPE_LONGLONG;
6245
return DRIZZLE_TYPE_LONGLONG;
6283
6246
case REAL_RESULT:
6284
return MYSQL_TYPE_DOUBLE;
6247
return DRIZZLE_TYPE_DOUBLE;
6285
6248
case DECIMAL_RESULT:
6286
return MYSQL_TYPE_NEWDECIMAL;
6249
return DRIZZLE_TYPE_NEWDECIMAL;
6287
6250
case ROW_RESULT:
6290
return MYSQL_TYPE_VAR_STRING;
6253
return DRIZZLE_TYPE_VAR_STRING;
6406
uint32 Item_type_holder::display_length(Item *item)
6369
uint32_t Item_type_holder::display_length(Item *item)
6408
6371
if (item->type() == Item::FIELD_ITEM)
6409
6372
return ((Item_field *)item)->max_disp_length();
6411
6374
switch (item->field_type())
6413
case MYSQL_TYPE_TIMESTAMP:
6414
case MYSQL_TYPE_TIME:
6415
case MYSQL_TYPE_DATETIME:
6416
case MYSQL_TYPE_YEAR:
6417
case MYSQL_TYPE_NEWDATE:
6418
case MYSQL_TYPE_VARCHAR:
6419
case MYSQL_TYPE_NEWDECIMAL:
6420
case MYSQL_TYPE_ENUM:
6421
case MYSQL_TYPE_SET:
6422
case MYSQL_TYPE_BLOB:
6423
case MYSQL_TYPE_VAR_STRING:
6424
case MYSQL_TYPE_STRING:
6425
case MYSQL_TYPE_TINY:
6376
case DRIZZLE_TYPE_TIMESTAMP:
6377
case DRIZZLE_TYPE_TIME:
6378
case DRIZZLE_TYPE_DATETIME:
6379
case DRIZZLE_TYPE_NEWDATE:
6380
case DRIZZLE_TYPE_VARCHAR:
6381
case DRIZZLE_TYPE_NEWDECIMAL:
6382
case DRIZZLE_TYPE_ENUM:
6383
case DRIZZLE_TYPE_SET:
6384
case DRIZZLE_TYPE_BLOB:
6385
case DRIZZLE_TYPE_VAR_STRING:
6386
case DRIZZLE_TYPE_STRING:
6387
case DRIZZLE_TYPE_TINY:
6427
case MYSQL_TYPE_SHORT:
6389
case DRIZZLE_TYPE_SHORT:
6429
case MYSQL_TYPE_LONG:
6391
case DRIZZLE_TYPE_LONG:
6430
6392
return MY_INT32_NUM_DECIMAL_DIGITS;
6431
case MYSQL_TYPE_DOUBLE:
6393
case DRIZZLE_TYPE_DOUBLE:
6433
case MYSQL_TYPE_NULL:
6395
case DRIZZLE_TYPE_NULL:
6435
case MYSQL_TYPE_LONGLONG:
6397
case DRIZZLE_TYPE_LONGLONG:
6438
6400
assert(0); // we should never go there
6507
6469
field (or MIN|MAX(enum|set field)) and number of NULL fields
6509
6471
assert((enum_set_typelib &&
6510
get_real_type(item) == MYSQL_TYPE_NULL) ||
6472
get_real_type(item) == DRIZZLE_TYPE_NULL) ||
6511
6473
(!enum_set_typelib &&
6512
6474
item->type() == Item::FIELD_ITEM &&
6513
(get_real_type(item) == MYSQL_TYPE_ENUM ||
6514
get_real_type(item) == MYSQL_TYPE_SET) &&
6475
(get_real_type(item) == DRIZZLE_TYPE_ENUM ||
6476
get_real_type(item) == DRIZZLE_TYPE_SET) &&
6515
6477
((Field_enum*)((Item_field *) item)->field)->typelib));
6516
6478
if (!enum_set_typelib)