17
17
#include <drizzled/server_includes.h>
18
18
#include <drizzled/sql_select.h>
19
#include <drizzled/error.h>
22
#if defined(CMATH_NAMESPACE)
23
using namespace CMATH_NAMESPACE;
19
#include <drizzled/drizzled_error_messages.h>
26
21
const String my_null_string("NULL", 4, default_charset_info);
42
37
return &real_traits_instance;
45
int64_t Hybrid_type_traits::val_int(Hybrid_type *val,
48
return (int64_t) rint(val->real);
52
Hybrid_type_traits::val_decimal(Hybrid_type *val, my_decimal *) const
42
Hybrid_type_traits::val_decimal(Hybrid_type *val,
43
my_decimal *to __attribute__((unused))) const
54
45
double2my_decimal(E_DEC_FATAL_ERROR, val->real, val->dec_buf);
55
46
return val->dec_buf;
264
256
res->ptr(), res->length(), res->charset(),
265
257
decimal_value) & E_DEC_BAD_NUM)
267
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
259
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
268
260
ER_TRUNCATED_WRONG_VALUE,
269
261
ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
270
262
str_value.c_ptr());
390
382
cmp_context= (Item_result)-1;
392
384
/* Put item in free list so that we can free all items at end */
393
Session *session= current_session;
394
next= session->free_list;
395
session->free_list= this;
385
THD *thd= current_thd;
386
next= thd->free_list;
387
thd->free_list= this;
397
389
Item constructor can be called during execution other then SQL_COM
398
command => we should check session->lex->current_select on zero (session->lex
390
command => we should check thd->lex->current_select on zero (thd->lex
399
391
can be uninitialised)
401
if (session->lex->current_select)
393
if (thd->lex->current_select)
403
395
enum_parsing_place place=
404
session->lex->current_select->parsing_place;
396
thd->lex->current_select->parsing_place;
405
397
if (place == SELECT_LIST ||
406
398
place == IN_HAVING)
407
session->lex->current_select->select_n_having_items++;
399
thd->lex->current_select->select_n_having_items++;
432
424
collation(item->collation),
433
425
cmp_context(item->cmp_context)
435
next= session->free_list; // Put in free list
436
session->free_list= this;
427
next= thd->free_list; // Put in free list
428
thd->free_list= this;
440
uint32_t Item::decimal_precision() const
432
uint Item::decimal_precision() const
442
434
Item_result restype= result_type();
444
436
if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
445
return cmin(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
446
(unsigned int)DECIMAL_MAX_PRECISION);
447
return cmin(max_length, (uint32_t)DECIMAL_MAX_PRECISION);
437
return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
438
DECIMAL_MAX_PRECISION);
439
return min(max_length, DECIMAL_MAX_PRECISION);
509
501
This function is designed to ease transformation of Item trees.
510
502
Re-execution note: every such transformation is registered for
511
rollback by Session::change_item_tree() and is rolled back at the end
512
of execution by Session::rollback_item_tree_changes().
503
rollback by THD::change_item_tree() and is rolled back at the end
504
of execution by THD::rollback_item_tree_changes().
515
507
- this function can not be used at prepared statement prepare
516
508
(in particular, in fix_fields!), as only permanent
517
509
transformation of Item trees are allowed at prepare.
518
510
- the transformer function shall allocate new Items in execution
519
memory root (session->mem_root) and not anywhere else: allocated
511
memory root (thd->mem_root) and not anywhere else: allocated
520
512
items will be gone in the end of execution.
522
514
If you don't need to transform an item tree, but only traverse
527
519
@param arg opaque argument passed to the functor
530
Returns pointer to the new subtree root. Session::change_item_tree()
522
Returns pointer to the new subtree root. THD::change_item_tree()
531
523
should be called for it if transformation took place, i.e. if a
532
524
pointer to newly allocated item is returned.
535
Item* Item::transform(Item_transformer transformer, unsigned char *arg)
527
Item* Item::transform(Item_transformer transformer, uchar *arg)
537
529
return (this->*transformer)(arg);
556
548
Constructor used by Item_field & Item_*_ref (see Item comment)
559
Item_ident::Item_ident(Session *session, Item_ident *item)
560
:Item(session, item),
551
Item_ident::Item_ident(THD *thd, Item_ident *item)
561
553
orig_db_name(item->orig_db_name),
562
554
orig_table_name(item->orig_table_name),
563
555
orig_field_name(item->orig_field_name),
669
661
column read set or to register used fields in a view
672
bool Item_field::register_field_in_read_map(unsigned char *arg)
664
bool Item_field::register_field_in_read_map(uchar *arg)
674
Table *table= (Table *) arg;
666
TABLE *table= (TABLE *) arg;
675
667
if (field->table == table || !table)
676
668
bitmap_set_bit(field->table->read_set, field->field_index);
677
if (field->vcol_info && field->vcol_info->expr_item)
678
return field->vcol_info->expr_item->walk(&Item::register_field_in_read_map,
684
Mark field in bitmap supplied as *arg
688
bool Item_field::register_field_in_bitmap(unsigned char *arg)
690
MY_BITMAP *bitmap= (MY_BITMAP *) arg;
692
bitmap_set_bit(bitmap, field->field_index);
697
bool Item::check_cols(uint32_t c)
673
bool Item::check_cols(uint c)
729
705
if (orig_len != length && !is_autogenerated_name)
732
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
708
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
733
709
ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
734
710
str + length - orig_len);
736
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
712
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
737
713
ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
738
714
str + length - orig_len);
755
731
This function is called when:
756
732
- Comparing items in the WHERE clause (when doing where optimization)
757
- When trying to find an order_st BY/GROUP BY item in the SELECT part
733
- When trying to find an ORDER BY/GROUP BY item in the SELECT part
760
bool Item::eq(const Item *item, bool) const
736
bool Item::eq(const Item *item, bool binary_cmp __attribute__((unused))) const
763
739
Note, that this is never true if item is a Item_param:
925
901
int64_t value= val_int();
927
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
903
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1LL)
929
905
char buff[22], *end;
930
906
end= int64_t10_to_str(value, buff, -10);
931
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
907
make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
932
908
buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
977
953
int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
980
Table *table= field->table;
981
Session *session= table->in_use;
982
enum_check_fields tmp= session->count_cuted_fields;
983
ulong sql_mode= session->variables.sql_mode;
984
session->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
985
session->count_cuted_fields= CHECK_FIELD_IGNORE;
956
TABLE *table= field->table;
957
THD *thd= table->in_use;
958
enum_check_fields tmp= thd->count_cuted_fields;
959
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
960
ulong sql_mode= thd->variables.sql_mode;
961
thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
962
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
986
963
res= save_in_field(field, no_conversions);
987
session->count_cuted_fields= tmp;
988
session->variables.sql_mode= sql_mode;
964
thd->count_cuted_fields= tmp;
965
dbug_tmp_restore_column_map(table->write_set, old_map);
966
thd->variables.sql_mode= sql_mode;
1028
1006
All found SUM items are added FIRST in the fields list and
1029
1007
we replace the item with a reference.
1031
session->fatal_error() may be called if we are out of memory
1009
thd->fatal_error() may be called if we are out of memory
1034
void Item::split_sum_func2(Session *session, Item **ref_pointer_array,
1012
void Item::split_sum_func2(THD *thd, Item **ref_pointer_array,
1035
1013
List<Item> &fields, Item **ref,
1036
1014
bool skip_registered)
1045
1023
((Item_func *) this)->functype() == Item_func::TRIG_COND_FUNC)))
1047
1025
/* Will split complicated items and ignore simple ones */
1048
split_sum_func(session, ref_pointer_array, fields);
1026
split_sum_func(thd, ref_pointer_array, fields);
1050
1028
else if ((type() == SUM_FUNC_ITEM || (used_tables() & ~PARAM_TABLE_BIT)) &&
1051
1029
type() != SUBSELECT_ITEM &&
1063
1041
Item_ref to allow fields from view being stored in tmp table.
1065
1043
Item_aggregate_ref *item_ref;
1066
uint32_t el= fields.elements;
1044
uint el= fields.elements;
1067
1045
Item *real_itm= real_item();
1069
1047
ref_pointer_array[el]= real_itm;
1070
if (!(item_ref= new Item_aggregate_ref(&session->lex->current_select->context,
1048
if (!(item_ref= new Item_aggregate_ref(&thd->lex->current_select->context,
1071
1049
ref_pointer_array + el, 0, name)))
1072
1050
return; // fatal_error is set
1073
1051
if (type() == SUM_FUNC_ITEM)
1074
1052
item_ref->depended_from= ((Item_sum *) this)->depended_from();
1075
1053
fields.push_front(real_itm);
1076
session->change_item_tree(ref, item_ref);
1054
thd->change_item_tree(ref, item_ref);
1269
1247
bool agg_item_collations(DTCollation &c, const char *fname,
1270
Item **av, uint32_t count, uint32_t flags, int item_sep)
1248
Item **av, uint count, uint flags, int item_sep)
1274
1252
c.set(av[0]->collation);
1275
1253
for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
1293
1271
bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
1294
Item **av, uint32_t count, uint32_t flags)
1272
Item **av, uint count, uint flags)
1296
1274
return (agg_item_collations(c, fname, av, count,
1297
1275
flags | MY_COLL_DISALLOW_NONE, 1));
1320
1298
collect(A,B,C) ::= collect(collect(A,B),C)
1322
Since this function calls Session::change_item_tree() on the passed Item **
1300
Since this function calls THD::change_item_tree() on the passed Item **
1323
1301
pointers, it is necessary to pass the original Item **'s, not copies.
1324
1302
Otherwise their values will not be properly restored (see BUG#20769).
1325
1303
If the items are not consecutive (eg. args[2] and args[5]), use the
1332
1310
bool agg_item_charsets(DTCollation &coll, const char *fname,
1333
Item **args, uint32_t nargs, uint32_t flags, int item_sep)
1311
Item **args, uint nargs, uint flags, int item_sep)
1335
1313
Item **arg, *safe_args[2];
1352
1330
safe_args[1]= args[item_sep];
1355
Session *session= current_session;
1333
THD *thd= current_thd;
1334
Query_arena *arena, backup;
1356
1335
bool res= false;
1338
In case we're in statement prepare, create conversion item
1339
in its memory: it will be reused on each execute.
1359
1343
for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
1393
1377
been created in prepare. In this case register the change for
1396
session->change_item_tree(arg, conv);
1380
thd->change_item_tree(arg, conv);
1398
1382
We do not check conv->fixed, because Item_func_conv_charset which can
1399
1383
be return by safe_charset_converter can't be fixed at creation
1401
conv->fix_fields(session, arg);
1385
conv->fix_fields(thd, arg);
1388
thd->restore_active_arena(arena, &backup);
1421
1406
/**********************************************/
1423
1408
Item_field::Item_field(Field *f)
1424
:Item_ident(0, NULL, *f->table_name, f->field_name),
1409
:Item_ident(0, NullS, *f->table_name, f->field_name),
1425
1410
item_equal(0), no_const_subst(0),
1426
1411
have_privileges(0), any_privileges(0)
1441
1426
Item_field (this is important in prepared statements).
1444
Item_field::Item_field(Session *, Name_resolution_context *context_arg,
1429
Item_field::Item_field(THD *thd __attribute__((unused)),
1430
Name_resolution_context *context_arg,
1446
1432
:Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
1447
1433
item_equal(0), no_const_subst(0),
1458
1444
field(0), result_field(0), item_equal(0), no_const_subst(0),
1459
1445
have_privileges(0), any_privileges(0)
1461
SELECT_LEX *select= current_session->lex->current_select;
1447
SELECT_LEX *select= current_thd->lex->current_select;
1462
1448
collation.set(DERIVATION_IMPLICIT);
1463
1449
if (select && select->parsing_place != IN_HAVING)
1464
1450
select->select_n_where_fields++;
1468
1454
Constructor need to process subselect with temporary tables (see Item)
1471
Item_field::Item_field(Session *session, Item_field *item)
1472
:Item_ident(session, item),
1457
Item_field::Item_field(THD *thd, Item_field *item)
1458
:Item_ident(thd, item),
1473
1459
field(item->field),
1474
1460
result_field(item->result_field),
1475
1461
item_equal(item->item_equal),
1521
1507
tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+
1522
1508
(uint) strlen(field_name)+3);
1523
strxmov(tmp,db_name,".",table_name,".",field_name,NULL);
1509
strxmov(tmp,db_name,".",table_name,".",field_name,NullS);
1529
1515
tmp= (char*) sql_alloc((uint) strlen(table_name) +
1530
1516
(uint) strlen(field_name) + 2);
1531
strxmov(tmp, table_name, ".", field_name, NULL);
1517
strxmov(tmp, table_name, ".", field_name, NullS);
1534
1520
tmp= (char*) field_name;
1539
1525
void Item_ident::print(String *str,
1526
enum_query_type query_type __attribute__((unused)))
1542
Session *session= current_session;
1528
THD *thd= current_thd;
1543
1529
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
1544
1530
const char *d_name= db_name, *t_name= table_name;
1545
1531
if (lower_case_table_names== 1 ||
1548
1534
if (table_name && table_name[0])
1550
my_stpcpy(t_name_buff, table_name);
1536
stpcpy(t_name_buff, table_name);
1551
1537
my_casedn_str(files_charset_info, t_name_buff);
1552
1538
t_name= t_name_buff;
1554
1540
if (db_name && db_name[0])
1556
my_stpcpy(d_name_buff, db_name);
1542
stpcpy(d_name_buff, db_name);
1557
1543
my_casedn_str(files_charset_info, d_name_buff);
1558
1544
d_name= d_name_buff;
1564
1550
const char *nm= (field_name && field_name[0]) ?
1565
1551
field_name : name ? name : "tmp_field";
1566
append_identifier(session, str, nm, (uint) strlen(nm));
1552
append_identifier(thd, str, nm, (uint) strlen(nm));
1569
1555
if (db_name && db_name[0] && !alias_name_used)
1572
append_identifier(session, str, d_name, (uint)strlen(d_name));
1558
append_identifier(thd, str, d_name, (uint)strlen(d_name));
1573
1559
str->append('.');
1575
append_identifier(session, str, t_name, (uint)strlen(t_name));
1561
append_identifier(thd, str, t_name, (uint)strlen(t_name));
1576
1562
str->append('.');
1577
append_identifier(session, str, field_name, (uint)strlen(field_name));
1563
append_identifier(thd, str, field_name, (uint)strlen(field_name));
1581
1567
if (table_name[0])
1583
append_identifier(session, str, t_name, (uint) strlen(t_name));
1569
append_identifier(thd, str, t_name, (uint) strlen(t_name));
1584
1570
str->append('.');
1585
append_identifier(session, str, field_name, (uint) strlen(field_name));
1571
append_identifier(thd, str, field_name, (uint) strlen(field_name));
1588
append_identifier(session, str, field_name, (uint) strlen(field_name));
1574
append_identifier(thd, str, field_name, (uint) strlen(field_name));
1768
Item *Item_field::get_tmp_table_item(Session *session)
1756
Item *Item_field::get_tmp_table_item(THD *thd)
1770
Item_field *new_item= new Item_field(session, this);
1758
Item_field *new_item= new Item_field(thd, this);
1772
1760
new_item->field= new_item->result_field;
1773
1761
return new_item;
1776
int64_t Item_field::val_int_endpoint(bool, bool *)
1764
int64_t Item_field::val_int_endpoint(bool left_endp __attribute__((unused)),
1765
bool *incl_endp __attribute__((unused)))
1778
1767
int64_t res= val_int();
1779
1768
return null_value? INT64_MIN : res;
1821
Item_uint::Item_uint(const char *str_arg, uint32_t length):
1811
Item_uint::Item_uint(const char *str_arg, uint length):
1822
1812
Item_int(str_arg, length)
1824
1814
unsigned_flag= 1;
1828
Item_uint::Item_uint(const char *str_arg, int64_t i, uint32_t length):
1818
Item_uint::Item_uint(const char *str_arg, int64_t i, uint length):
1829
1819
Item_int(str_arg, i, length)
1831
1821
unsigned_flag= 1;
1852
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1843
Item_decimal::Item_decimal(const char *str_arg, uint length,
1853
1844
const CHARSET_INFO * const charset)
1855
1846
str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1873
Item_decimal::Item_decimal(double val, int, int)
1864
Item_decimal::Item_decimal(double val,
1865
int precision __attribute__((unused)),
1866
int scale __attribute__((unused)))
1875
1868
double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
1876
1869
decimals= (uint8_t) decimal_value.frac;
1904
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
1897
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
1906
1899
binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1907
1900
&decimal_value, precision, scale);
1936
void Item_decimal::print(String *str, enum_query_type)
1929
void Item_decimal::print(String *str,
1930
enum_query_type query_type __attribute__((unused)))
1938
1932
my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
1939
1933
str->append(str_value);
1943
bool Item_decimal::eq(const Item *item, bool) const
1937
bool Item_decimal::eq(const Item *item,
1938
bool binary_cmp __attribute__((unused))) const
1945
1940
if (type() == item->type() && item->basic_const_item())
2054
2035
We can use str_value.ptr() here as Item_string is gurantee to put an
2057
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2038
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2058
2039
ER_TRUNCATED_WRONG_VALUE,
2059
2040
ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
2060
2041
str_value.ptr());
2085
2066
(end != org_end && !check_if_only_end_space(cs, end, org_end)))
2087
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2068
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2088
2069
ER_TRUNCATED_WRONG_VALUE,
2089
2070
ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
2090
2071
str_value.ptr());
2149
default_set_param_func(Item_param *param, unsigned char **, ulong)
2131
default_set_param_func(Item_param *param,
2132
uchar **pos __attribute__((unused)),
2133
ulong len __attribute__((unused)))
2151
2135
param->set_null();
2155
Item_param::Item_param(uint32_t pos_in_query_arg) :
2139
Item_param::Item_param(uint pos_in_query_arg) :
2156
2140
state(NO_VALUE),
2157
2141
item_result_type(STRING_RESULT),
2158
2142
/* Don't pretend to be a literal unless value for this item is set. */
2223
2207
internal decimal value.
2226
void Item_param::set_decimal(char *str, ulong length)
2210
void Item_param::set_decimal(const char *str, ulong length)
2231
str2my_decimal((uint)E_DEC_FATAL_ERROR, str, &decimal_value, &end);
2214
end= (char*) str+length;
2215
str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
2232
2216
state= DECIMAL_VALUE;
2233
2217
decimals= decimal_value.frac;
2234
2218
max_length= my_decimal_precision_to_length(decimal_value.precision(),
2264
2247
value.time.minute > 59 || value.time.second > 59)
2266
2249
char buff[MAX_DATE_STRING_REP_LENGTH];
2267
uint32_t length= my_TIME_to_str(&value.time, buff);
2268
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2250
uint length= my_TIME_to_str(&value.time, buff);
2251
make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2269
2252
buff, length, time_type, 0);
2270
2253
set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
2701
2684
if (value.cs_info.final_character_set_of_str_value !=
2702
2685
value.cs_info.character_set_of_placeholder)
2704
rc= session->convert_string(&str_value,
2687
rc= thd->convert_string(&str_value,
2705
2688
value.cs_info.character_set_of_placeholder,
2706
2689
value.cs_info.final_character_set_of_str_value);
2938
2923
table_name, (table_name [0] ? "." : ""),
2939
2924
resolved_item->field_name,
2940
2925
current->select_number, last->select_number);
2941
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2926
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2942
2927
ER_WARN_FIELD_RESOLVED, warn_buff);
3002
2987
prev_subselect_item->used_tables_cache|=
3003
2988
found_field->table->map;
3004
2989
prev_subselect_item->const_item_cache= 0;
3005
mark_as_dependent(session, last_select, current_sel, resolved_item,
2990
mark_as_dependent(thd, last_select, current_sel, resolved_item,
3023
3008
- NULL if find_item is not in group_list
3026
static Item** find_field_in_group_list(Item *find_item, order_st *group_list)
3011
static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
3028
3013
const char *db_name;
3029
3014
const char *table_name;
3030
3015
const char *field_name;
3031
order_st *found_group= NULL;
3016
ORDER *found_group= NULL;
3032
3017
int found_match_degree= 0;
3033
3018
Item_ident *cur_field;
3034
3019
int cur_match_degree= 0;
3154
resolve_ref_in_select_and_group(Session *session, Item_ident *ref, SELECT_LEX *select)
3139
resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
3156
3141
Item **group_by_ref= NULL;
3157
3142
Item **select_ref= NULL;
3158
order_st *group_list= (order_st*) select->group_list.first;
3143
ORDER *group_list= (ORDER*) select->group_list.first;
3159
3144
bool ambiguous_fields= false;
3161
3146
enum_resolution_type resolution;
3181
3166
!((*group_by_ref)->eq(*select_ref, 0)))
3183
3168
ambiguous_fields= true;
3184
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
3169
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
3185
3170
ER(ER_NON_UNIQ_ERROR), ref->full_name(),
3186
current_session->where);
3171
current_thd->where);
3224
3209
current select as dependent. The found reference of field should be
3225
3210
provided in 'from_field'.
3227
@param[in] session current thread
3212
@param[in] thd current thread
3228
3213
@param[in,out] from_field found field reference or (Field*)not_found_field
3229
3214
@param[in,out] reference view column if this item was resolved to a
3299
3284
the found view field into '*reference', in other words, it
3300
3285
substitutes this Item_field with the found expression.
3302
if (field_found || (*from_field= find_field_in_tables(session, this,
3287
if (field_found || (*from_field= find_field_in_tables(thd, this,
3303
3288
outer_context->
3304
3289
first_name_resolution_table,
3305
3290
outer_context->
3334
3319
if (!(rf= new Item_outer_ref(context, this)))
3336
session->change_item_tree(reference, rf);
3321
thd->change_item_tree(reference, rf);
3337
3322
select->inner_refs_list.push_back(rf);
3338
rf->in_sum_func= session->lex->in_sum_func;
3323
rf->in_sum_func= thd->lex->in_sum_func;
3341
3326
A reference is resolved to a nest level that's outer or the same as
3342
3327
the nest level of the enclosing set function : adjust the value of
3343
3328
max_arg_level for the function if it's needed.
3345
if (session->lex->in_sum_func &&
3346
session->lex->in_sum_func->nest_level >= select->nest_level)
3330
if (thd->lex->in_sum_func &&
3331
thd->lex->in_sum_func->nest_level >= select->nest_level)
3348
3333
Item::Type ref_type= (*reference)->type();
3349
set_if_bigger(session->lex->in_sum_func->max_arg_level,
3334
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
3350
3335
select->nest_level);
3351
3336
set_field(*from_field);
3353
mark_as_dependent(session, last_checked_context->select_lex,
3338
mark_as_dependent(thd, last_checked_context->select_lex,
3354
3339
context->select_lex, this,
3355
3340
((ref_type == REF_ITEM ||
3356
3341
ref_type == FIELD_ITEM) ?
3365
3350
(*reference)->used_tables();
3366
3351
prev_subselect_item->const_item_cache&=
3367
3352
(*reference)->const_item();
3368
mark_as_dependent(session, last_checked_context->select_lex,
3353
mark_as_dependent(thd, last_checked_context->select_lex,
3369
3354
context->select_lex, this,
3370
3355
((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
3371
3356
(Item_ident*) (*reference) :
3385
3370
/* Search in SELECT and GROUP lists of the outer select. */
3386
3371
if (place != IN_WHERE && place != IN_ON)
3388
if (!(ref= resolve_ref_in_select_and_group(session, this, select)))
3373
if (!(ref= resolve_ref_in_select_and_group(thd, this, select)))
3389
3374
return -1; /* Some error occurred (e.g. ambiguous names). */
3390
3375
if (ref != not_found_item)
3413
3398
if (upward_lookup)
3415
3400
// We can't say exactly what absent table or field
3416
my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where);
3401
my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), thd->where);
3420
3405
/* Call find_field_in_tables only to report the error */
3421
find_field_in_tables(session, this,
3406
find_field_in_tables(thd, this,
3422
3407
context->first_name_resolution_table,
3423
3408
context->last_name_resolution_table,
3424
3409
reference, REPORT_ALL_ERRORS,
3457
3442
if (place != IN_HAVING && select->group_list.elements)
3459
3444
outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf);
3460
((Item_outer_ref*)rf)->in_sum_func= session->lex->in_sum_func;
3445
((Item_outer_ref*)rf)->in_sum_func= thd->lex->in_sum_func;
3462
session->change_item_tree(reference, rf);
3447
thd->change_item_tree(reference, rf);
3464
3449
rf is Item_ref => never substitute other items (in this case)
3465
3450
during fix_fields() => we can use rf after fix_fields()
3467
3452
assert(!rf->fixed); // Assured by Item_ref()
3468
if (rf->fix_fields(session, reference) || rf->check_cols(1))
3453
if (rf->fix_fields(thd, reference) || rf->check_cols(1))
3471
mark_as_dependent(session, last_checked_context->select_lex,
3456
mark_as_dependent(thd, last_checked_context->select_lex,
3472
3457
context->select_lex, this,
3478
mark_as_dependent(session, last_checked_context->select_lex,
3463
mark_as_dependent(thd, last_checked_context->select_lex,
3479
3464
context->select_lex,
3480
3465
this, (Item_ident*)*reference);
3481
3466
if (last_checked_context->select_lex->having_fix_field)
3486
3471
(char*) cached_table->alias, (char*) field_name);
3489
session->change_item_tree(reference, rf);
3474
thd->change_item_tree(reference, rf);
3491
3476
rf is Item_ref => never substitute other items (in this case)
3492
3477
during fix_fields() => we can use rf after fix_fields()
3494
3479
assert(!rf->fixed); // Assured by Item_ref()
3495
if (rf->fix_fields(session, reference) || rf->check_cols(1))
3480
if (rf->fix_fields(thd, reference) || rf->check_cols(1))
3559
3544
expression to 'reference', i.e. it substitute that expression instead
3560
3545
of this Item_field
3562
if ((from_field= find_field_in_tables(session, this,
3547
if ((from_field= find_field_in_tables(thd, this,
3563
3548
context->first_name_resolution_table,
3564
3549
context->last_name_resolution_table,
3566
session->lex->use_only_table_context ?
3551
thd->lex->use_only_table_context ?
3567
3552
REPORT_ALL_ERRORS :
3568
3553
IGNORE_EXCEPT_NON_UNIQUE,
3569
3554
!any_privileges,
3574
3559
/* Look up in current select's item_list to find aliased fields */
3575
if (session->lex->current_select->is_item_list_lookup)
3560
if (thd->lex->current_select->is_item_list_lookup)
3578
3563
enum_resolution_type resolution;
3579
Item** res= find_item_in_list(this, session->lex->current_select->item_list,
3564
Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
3580
3565
&counter, REPORT_EXCEPT_NOT_FOUND,
3617
3602
Item_ref *rf= new Item_ref(context, db_name,table_name,field_name);
3620
session->change_item_tree(reference, rf);
3605
thd->change_item_tree(reference, rf);
3622
3607
Because Item_ref never substitutes itself with other items
3623
3608
in Item_ref::fix_fields(), we can safely use the original
3624
3609
pointer to it even after fix_fields()
3626
return rf->fix_fields(session, reference) || rf->check_cols(1);
3611
return rf->fix_fields(thd, reference) || rf->check_cols(1);
3630
if ((ret= fix_outer_field(session, &from_field, reference)) < 0)
3615
if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
3632
3617
outer_fixed= true;
3666
3651
set_field(from_field);
3667
if (session->lex->in_sum_func &&
3668
session->lex->in_sum_func->nest_level ==
3669
session->lex->current_select->nest_level)
3670
set_if_bigger(session->lex->in_sum_func->max_arg_level,
3671
session->lex->current_select->nest_level);
3652
if (thd->lex->in_sum_func &&
3653
thd->lex->in_sum_func->nest_level ==
3654
thd->lex->current_select->nest_level)
3655
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
3656
thd->lex->current_select->nest_level);
3673
else if (session->mark_used_columns != MARK_COLUMNS_NONE)
3658
else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
3675
Table *table= field->table;
3660
TABLE *table= field->table;
3676
3661
MY_BITMAP *current_bitmap, *other_bitmap;
3677
if (session->mark_used_columns == MARK_COLUMNS_READ)
3662
if (thd->mark_used_columns == MARK_COLUMNS_READ)
3679
3664
current_bitmap= table->read_set;
3680
3665
other_bitmap= table->write_set;
3984
3971
/* Check whether we got a well-formed string */
3985
3972
const CHARSET_INFO * const cs= str->charset();
3986
3973
int well_formed_error;
3987
uint32_t wlen= cs->cset->well_formed_len(cs,
3974
uint wlen= cs->cset->well_formed_len(cs,
3988
3975
str->ptr(), str->ptr() + str->length(),
3989
3976
str->length(), &well_formed_error);
3990
3977
if (wlen < str->length())
3992
Session *session= current_session;
3979
THD *thd= current_thd;
3993
3980
char hexbuf[7];
3994
3981
enum DRIZZLE_ERROR::enum_warning_level level;
3995
uint32_t diff= str->length() - wlen;
3982
uint diff= str->length() - wlen;
3996
3983
set_if_smaller(diff, 3);
3997
3984
octet2hex(hexbuf, str->ptr() + wlen, diff);
3998
3985
if (send_error)
4095
4082
\# Created field
4098
Field *Item::tmp_table_field_from_field_type(Table *table, bool)
4085
Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length __attribute__((unused)))
4101
4088
The field functions defines a field to be not null if null_ptr is not 0
4103
unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
4090
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
4106
4093
switch (field_type()) {
4107
4094
case DRIZZLE_TYPE_NEWDECIMAL:
4108
field= new Field_new_decimal((unsigned char*) 0, max_length, null_ptr, 0,
4095
field= new Field_new_decimal((uchar*) 0, max_length, null_ptr, 0,
4109
4096
Field::NONE, name, decimals, 0,
4110
4097
unsigned_flag);
4099
case DRIZZLE_TYPE_TINY:
4100
field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4101
name, 0, unsigned_flag);
4103
case DRIZZLE_TYPE_SHORT:
4104
field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4105
name, 0, unsigned_flag);
4112
4107
case DRIZZLE_TYPE_LONG:
4113
field= new Field_long((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4108
field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4114
4109
name, 0, unsigned_flag);
4116
4111
case DRIZZLE_TYPE_LONGLONG:
4117
field= new Field_int64_t((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4112
field= new Field_int64_t((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4118
4113
name, 0, unsigned_flag);
4120
4115
case DRIZZLE_TYPE_DOUBLE:
4121
field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4116
field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4122
4117
name, decimals, 0, unsigned_flag);
4124
4119
case DRIZZLE_TYPE_NULL:
4125
field= new Field_null((unsigned char*) 0, max_length, Field::NONE,
4120
field= new Field_null((uchar*) 0, max_length, Field::NONE,
4126
4121
name, &my_charset_bin);
4128
4123
case DRIZZLE_TYPE_NEWDATE:
4340
int Item_decimal::save_in_field(Field *field, bool)
4338
int Item_decimal::save_in_field(Field *field,
4339
bool no_conversions __attribute__((unused)))
4342
4341
field->set_notnull();
4343
4342
return field->store_decimal(&decimal_value);
4347
bool Item_int::eq(const Item *arg, bool) const
4346
bool Item_int::eq(const Item *arg,
4347
bool binary_cmp __attribute__((unused))) const
4349
4349
/* No need to check for null value as basic constant can't be NULL */
4350
4350
if (arg->basic_const_item() && arg->type() == type())
4509
4512
// following assert is redundant, because fixed=1 assigned in constructor
4510
4513
assert(fixed == 1);
4511
4514
char *end=(char*) str_value.ptr()+str_value.length(),
4512
*ptr=end-cmin(str_value.length(),(uint32_t)sizeof(int64_t));
4515
*ptr=end-min(str_value.length(),sizeof(int64_t));
4514
4517
uint64_t value=0;
4515
4518
for (; ptr != end ; ptr++)
4516
value=(value << 8)+ (uint64_t) (unsigned char) *ptr;
4519
value=(value << 8)+ (uint64_t) (uchar) *ptr;
4517
4520
return (int64_t) value;
4531
int Item_hex_string::save_in_field(Field *field, bool)
4534
int Item_hex_string::save_in_field(Field *field,
4535
bool no_conversions __attribute__((unused)))
4533
4537
field->set_notnull();
4534
4538
if (field->result_type() == STRING_RESULT)
4535
return field->store(str_value.ptr(), str_value.length(),
4539
return field->store(str_value.ptr(), str_value.length(),
4536
4540
collation.collation);
4561
void Item_hex_string::print(String *str, enum_query_type)
4565
void Item_hex_string::print(String *str,
4566
enum_query_type query_type __attribute__((unused)))
4563
4568
char *end= (char*) str_value.ptr() + str_value.length(),
4564
*ptr= end - cmin(str_value.length(), (uint32_t)sizeof(int64_t));
4569
*ptr= end - min(str_value.length(), sizeof(int64_t));
4565
4570
str->append("0x");
4566
4571
for (; ptr != end ; ptr++)
4568
str->append(_dig_vec_lower[((unsigned char) *ptr) >> 4]);
4569
str->append(_dig_vec_lower[((unsigned char) *ptr) & 0x0F]);
4573
str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
4574
str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
4602
4607
In number context this is a int64_t value.
4605
Item_bin_string::Item_bin_string(const char *str, uint32_t str_length)
4610
Item_bin_string::Item_bin_string(const char *str, uint str_length)
4607
4612
const char *end= str + str_length - 1;
4608
unsigned char bits= 0;
4611
4616
max_length= (str_length + 7) >> 3;
4612
4617
char *ptr= (char*) sql_alloc(max_length + 1);
4729
4752
need to set no_errors to prevent warnings about type conversion
4732
Session *session= field->table->in_use;
4755
THD *thd= field->table->in_use;
4735
no_errors= session->no_errors;
4736
session->no_errors= 1;
4758
no_errors= thd->no_errors;
4737
4760
Item::update_null_value();
4738
session->no_errors= no_errors;
4761
thd->no_errors= no_errors;
4761
4784
this field otherwise
4764
Item *Item_field::update_value_transformer(unsigned char *select_arg)
4787
Item *Item_field::update_value_transformer(uchar *select_arg)
4766
4789
SELECT_LEX *select= (SELECT_LEX*)select_arg;
4769
if (field->table != select->context.table_list->table)
4792
if (field->table != select->context.table_list->table &&
4793
type() != Item::TRIGGER_FIELD_ITEM)
4771
4795
List<Item> *all_fields= &select->join->all_fields;
4772
4796
Item **ref_pointer_array= select->ref_pointer_array;
4803
4827
Item **item, const char *table_name_arg,
4804
4828
const char *field_name_arg,
4805
4829
bool alias_name_used_arg)
4806
:Item_ident(context_arg, NULL, table_name_arg, field_name_arg),
4830
:Item_ident(context_arg, NullS, table_name_arg, field_name_arg),
4807
4831
result_field(0), ref(item)
4809
4833
alias_name_used= alias_name_used_arg;
4879
4903
false on success
4882
bool Item_ref::fix_fields(Session *session, Item **reference)
4906
bool Item_ref::fix_fields(THD *thd, Item **reference)
4884
4908
enum_parsing_place place= NO_MATTER;
4885
4909
assert(fixed == 0);
4886
SELECT_LEX *current_sel= session->lex->current_select;
4910
SELECT_LEX *current_sel= thd->lex->current_select;
4888
4912
if (!ref || ref == not_found_item)
4890
if (!(ref= resolve_ref_in_select_and_group(session, this,
4914
if (!(ref= resolve_ref_in_select_and_group(thd, this,
4891
4915
context->select_lex)))
4892
4916
goto error; /* Some error occurred (e.g. ambiguous names). */
4927
4951
/* Search in the SELECT and GROUP lists of the outer select. */
4928
4952
if (outer_context->resolve_in_select_list)
4930
if (!(ref= resolve_ref_in_select_and_group(session, this, select)))
4954
if (!(ref= resolve_ref_in_select_and_group(thd, this, select)))
4931
4955
goto error; /* Some error occurred (e.g. ambiguous names). */
4932
4956
if (ref != not_found_item)
4964
4988
field expression to 'reference', i.e. it substitute that
4965
4989
expression instead of this Item_ref
4967
from_field= find_field_in_tables(session, this,
4991
from_field= find_field_in_tables(thd, this,
4968
4992
outer_context->
4969
4993
first_name_resolution_table,
4970
4994
outer_context->
4982
5006
prev_subselect_item->const_item_cache&=
4983
5007
(*reference)->const_item();
4984
5008
assert((*reference)->type() == REF_ITEM);
4985
mark_as_dependent(session, last_checked_context->select_lex,
5009
mark_as_dependent(thd, last_checked_context->select_lex,
4986
5010
context->select_lex, this,
4987
5011
((refer_type == REF_ITEM ||
4988
5012
refer_type == FIELD_ITEM) ?
5035
5059
Item_field* fld;
5036
5060
if (!(fld= new Item_field(from_field)))
5038
session->change_item_tree(reference, fld);
5039
mark_as_dependent(session, last_checked_context->select_lex,
5040
session->lex->current_select, this, fld);
5062
thd->change_item_tree(reference, fld);
5063
mark_as_dependent(thd, last_checked_context->select_lex,
5064
thd->lex->current_select, this, fld);
5042
5066
A reference is resolved to a nest level that's outer or the same as
5043
5067
the nest level of the enclosing set function : adjust the value of
5044
5068
max_arg_level for the function if it's needed.
5046
if (session->lex->in_sum_func &&
5047
session->lex->in_sum_func->nest_level >=
5070
if (thd->lex->in_sum_func &&
5071
thd->lex->in_sum_func->nest_level >=
5048
5072
last_checked_context->select_lex->nest_level)
5049
set_if_bigger(session->lex->in_sum_func->max_arg_level,
5073
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
5050
5074
last_checked_context->select_lex->nest_level);
5055
5079
/* The item was not a table field and not a reference */
5056
5080
my_error(ER_BAD_FIELD_ERROR, MYF(0),
5057
this->full_name(), current_session->where);
5081
this->full_name(), current_thd->where);
5060
5084
/* Should be checked in resolve_ref_in_select_and_group(). */
5061
5085
assert(*ref && (*ref)->fixed);
5062
mark_as_dependent(session, last_checked_context->select_lex,
5086
mark_as_dependent(thd, last_checked_context->select_lex,
5063
5087
context->select_lex, this, this);
5065
5089
A reference is resolved to a nest level that's outer or the same as
5066
5090
the nest level of the enclosing set function : adjust the value of
5067
5091
max_arg_level for the function if it's needed.
5069
if (session->lex->in_sum_func &&
5070
session->lex->in_sum_func->nest_level >=
5093
if (thd->lex->in_sum_func &&
5094
thd->lex->in_sum_func->nest_level >=
5071
5095
last_checked_context->select_lex->nest_level)
5072
set_if_bigger(session->lex->in_sum_func->max_arg_level,
5096
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
5073
5097
last_checked_context->select_lex->nest_level);
5144
5168
if ((*ref)->type() != Item::CACHE_ITEM && ref_type() != VIEW_REF &&
5145
5169
!table_name && name && alias_name_used)
5147
Session *session= current_session;
5148
append_identifier(session, str, name, (uint) strlen(name));
5171
THD *thd= current_thd;
5172
append_identifier(thd, str, name, (uint) strlen(name));
5151
5175
(*ref)->print(str, query_type);
5419
bool Item_direct_view_ref::fix_fields(Session *session, Item **reference)
5443
bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference)
5421
5445
/* view fild reference must be defined */
5423
5447
/* (*ref)->check_cols() will be made in Item_direct_ref::fix_fields */
5424
5448
if (!(*ref)->fixed &&
5425
((*ref)->fix_fields(session, ref)))
5449
((*ref)->fix_fields(thd, ref)))
5427
return Item_direct_ref::fix_fields(session, reference);
5451
return Item_direct_ref::fix_fields(thd, reference);
5443
bool Item_outer_ref::fix_fields(Session *session, Item **reference)
5467
bool Item_outer_ref::fix_fields(THD *thd, Item **reference)
5446
5470
/* outer_ref->check_cols() will be made in Item_direct_ref::fix_fields */
5447
if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(session, reference)))
5471
if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(thd, reference)))
5449
err= Item_direct_ref::fix_fields(session, reference);
5473
err= Item_direct_ref::fix_fields(thd, reference);
5450
5474
if (!outer_ref)
5451
5475
outer_ref= *ref;
5452
5476
if ((*ref)->type() == Item::FIELD_ITEM)
5601
5628
same time it can replace some nodes in the tree.
5604
Item *Item_default_value::transform(Item_transformer transformer, unsigned char *args)
5631
Item *Item_default_value::transform(Item_transformer transformer, uchar *args)
5606
5633
Item *new_item= arg->transform(transformer, args);
5611
Session::change_item_tree() should be called only if the tree was
5638
THD::change_item_tree() should be called only if the tree was
5612
5639
really transformed, i.e. when a new item has been created.
5613
5640
Otherwise we'll be allocating a lot of unnecessary memory for
5614
5641
change records at each execution.
5616
5643
if (arg != new_item)
5617
current_session->change_item_tree(&arg, new_item);
5644
current_thd->change_item_tree(&arg, new_item);
5618
5645
return (this->*transformer)(args);
5629
bool Item_insert_value::fix_fields(Session *session, Item **)
5656
bool Item_insert_value::fix_fields(THD *thd,
5657
Item **items __attribute__((unused)))
5631
5659
assert(fixed == 0);
5632
5660
/* We should only check that arg is in first table */
5633
5661
if (!arg->fixed)
5636
TableList *orig_next_table= context->last_name_resolution_table;
5664
TABLE_LIST *orig_next_table= context->last_name_resolution_table;
5637
5665
context->last_name_resolution_table= context->first_name_resolution_table;
5638
res= arg->fix_fields(session, &arg);
5666
res= arg->fix_fields(thd, &arg);
5639
5667
context->last_name_resolution_table= orig_next_table;
5776
5804
case REAL_RESULT:
5777
5805
{ // It must REAL_RESULT
5778
5806
double result= item->val_real();
5779
uint32_t length=item->max_length,decimals=item->decimals;
5807
uint length=item->max_length,decimals=item->decimals;
5780
5808
bool null_value=item->null_value;
5781
5809
new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
5782
5810
new Item_float(name, result, decimals, length));
5787
5815
my_decimal decimal_value;
5788
5816
my_decimal *result= item->val_decimal(&decimal_value);
5789
uint32_t length= item->max_length, decimals= item->decimals;
5817
uint length= item->max_length, decimals= item->decimals;
5790
5818
bool null_value= item->null_value;
5791
5819
new_item= (null_value ?
5792
5820
(Item*) new Item_null(name) :
6119
6147
void Item_cache_row::bring_value()
6121
for (uint32_t i= 0; i < item_count; i++)
6149
for (uint i= 0; i < item_count; i++)
6122
6150
values[i]->bring_value();
6127
Item_type_holder::Item_type_holder(Session *session, Item *item)
6128
:Item(session, item), enum_set_typelib(0), fld_type(get_real_type(item))
6155
Item_type_holder::Item_type_holder(THD *thd, Item *item)
6156
:Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
6130
6158
assert(item->fixed);
6131
6159
maybe_null= item->maybe_null;
6232
bool Item_type_holder::join_types(Session *, Item *item)
6260
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
6234
uint32_t max_length_orig= max_length;
6235
uint32_t decimals_orig= decimals;
6263
uint max_length_orig= max_length;
6264
uint decimals_orig= decimals;
6236
6265
fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6238
6267
int item_decimals= item->decimals;
6239
6268
/* fix variable decimals which always is NOT_FIXED_DEC */
6240
6269
if (Field::result_merge_type(fld_type) == INT_RESULT)
6241
6270
item_decimals= 0;
6242
decimals= cmax((int)decimals, item_decimals);
6271
decimals= max(decimals, item_decimals);
6244
6273
if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6246
decimals= cmin((int)cmax(decimals, item->decimals), DECIMAL_MAX_SCALE);
6247
int precision= cmin(cmax(prev_decimal_int_part, item->decimal_int_part())
6275
decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
6276
int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
6248
6277
+ decimals, DECIMAL_MAX_PRECISION);
6249
6278
unsigned_flag&= item->unsigned_flag;
6250
6279
max_length= my_decimal_precision_to_length(precision, decimals,
6365
Field *Item_type_holder::make_field_by_type(Table *table)
6398
Field *Item_type_holder::make_field_by_type(TABLE *table)
6368
6401
The field functions defines a field to be not null if null_ptr is not 0
6370
unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
6403
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
6373
6406
switch (fld_type) {
6374
6407
case DRIZZLE_TYPE_ENUM:
6375
6408
assert(enum_set_typelib);
6376
field= new Field_enum((unsigned char *) 0, max_length, null_ptr, 0,
6409
field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
6377
6410
Field::NONE, name,
6378
6411
get_enum_pack_length(enum_set_typelib->count),
6379
6412
enum_set_typelib, collation.collation);
6381
6414
field->init(table);
6416
case DRIZZLE_TYPE_SET:
6417
assert(enum_set_typelib);
6418
field= new Field_set((uchar *) 0, max_length, null_ptr, 0,
6420
get_set_pack_length(enum_set_typelib->count),
6421
enum_set_typelib, collation.collation);
6383
6425
case DRIZZLE_TYPE_NULL:
6384
6426
return make_string_field(table);