256
256
res->ptr(), res->length(), res->charset(),
257
257
decimal_value) & E_DEC_BAD_NUM)
259
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
259
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
260
260
ER_TRUNCATED_WRONG_VALUE,
261
261
ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
262
262
str_value.c_ptr());
382
382
cmp_context= (Item_result)-1;
384
384
/* Put item in free list so that we can free all items at end */
385
Session *thd= current_thd;
386
next= thd->free_list;
387
thd->free_list= this;
385
Session *session= current_session;
386
next= session->free_list;
387
session->free_list= this;
389
389
Item constructor can be called during execution other then SQL_COM
390
command => we should check thd->lex->current_select on zero (thd->lex
390
command => we should check session->lex->current_select on zero (session->lex
391
391
can be uninitialised)
393
if (thd->lex->current_select)
393
if (session->lex->current_select)
395
395
enum_parsing_place place=
396
thd->lex->current_select->parsing_place;
396
session->lex->current_select->parsing_place;
397
397
if (place == SELECT_LIST ||
398
398
place == IN_HAVING)
399
thd->lex->current_select->select_n_having_items++;
399
session->lex->current_select->select_n_having_items++;
407
407
Used for duplicating lists in processing queries with temporary
410
Item::Item(Session *thd, Item *item):
410
Item::Item(Session *session, Item *item):
411
411
is_expensive_cache(-1),
413
413
str_value(item->str_value),
424
424
collation(item->collation),
425
425
cmp_context(item->cmp_context)
427
next= thd->free_list; // Put in free list
428
thd->free_list= this;
427
next= session->free_list; // Put in free list
428
session->free_list= this;
449
Session *thd= current_thd;
449
Session *session= current_session;
450
450
str->append(STRING_WITH_LEN(" AS "));
451
append_identifier(thd, str, name, (uint) strlen(name));
451
append_identifier(session, str, name, (uint) strlen(name));
508
508
(in particular, in fix_fields!), as only permanent
509
509
transformation of Item trees are allowed at prepare.
510
510
- the transformer function shall allocate new Items in execution
511
memory root (thd->mem_root) and not anywhere else: allocated
511
memory root (session->mem_root) and not anywhere else: allocated
512
512
items will be gone in the end of execution.
514
514
If you don't need to transform an item tree, but only traverse
548
548
Constructor used by Item_field & Item_*_ref (see Item comment)
551
Item_ident::Item_ident(Session *thd, Item_ident *item)
551
Item_ident::Item_ident(Session *session, Item_ident *item)
552
:Item(session, item),
553
553
orig_db_name(item->orig_db_name),
554
554
orig_table_name(item->orig_table_name),
555
555
orig_field_name(item->orig_field_name),
721
721
if (orig_len != length && !is_autogenerated_name)
724
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
724
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
725
725
ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
726
726
str + length - orig_len);
728
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
728
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
729
729
ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
730
730
str + length - orig_len);
832
if (!(ptr= current_thd->strmake(cstr.ptr(), cstr.length())))
832
if (!(ptr= current_session->strmake(cstr.ptr(), cstr.length())))
834
834
conv->str_value.set(ptr, cstr.length(), cstr.charset());
835
835
/* Ensure that no one is going to change the result string */
921
921
char buff[22], *end;
922
922
end= int64_t10_to_str(value, buff, -10);
923
make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
923
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
924
924
buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
972
972
Table *table= field->table;
973
Session *thd= table->in_use;
974
enum_check_fields tmp= thd->count_cuted_fields;
975
ulong sql_mode= thd->variables.sql_mode;
976
thd->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
977
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
973
Session *session= table->in_use;
974
enum_check_fields tmp= session->count_cuted_fields;
975
ulong sql_mode= session->variables.sql_mode;
976
session->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
977
session->count_cuted_fields= CHECK_FIELD_IGNORE;
978
978
res= save_in_field(field, no_conversions);
979
thd->count_cuted_fields= tmp;
980
thd->variables.sql_mode= sql_mode;
979
session->count_cuted_fields= tmp;
980
session->variables.sql_mode= sql_mode;
1008
1008
Move SUM items out from item tree and replace with reference.
1010
@param thd Thread handler
1010
@param session Thread handler
1011
1011
@param ref_pointer_array Pointer to array of reference fields
1012
1012
@param fields All fields in select
1013
1013
@param ref Pointer to item
1020
1020
All found SUM items are added FIRST in the fields list and
1021
1021
we replace the item with a reference.
1023
thd->fatal_error() may be called if we are out of memory
1023
session->fatal_error() may be called if we are out of memory
1026
void Item::split_sum_func2(Session *thd, Item **ref_pointer_array,
1026
void Item::split_sum_func2(Session *session, Item **ref_pointer_array,
1027
1027
List<Item> &fields, Item **ref,
1028
1028
bool skip_registered)
1037
1037
((Item_func *) this)->functype() == Item_func::TRIG_COND_FUNC)))
1039
1039
/* Will split complicated items and ignore simple ones */
1040
split_sum_func(thd, ref_pointer_array, fields);
1040
split_sum_func(session, ref_pointer_array, fields);
1042
1042
else if ((type() == SUM_FUNC_ITEM || (used_tables() & ~PARAM_TABLE_BIT)) &&
1043
1043
type() != SUBSELECT_ITEM &&
1059
1059
Item *real_itm= real_item();
1061
1061
ref_pointer_array[el]= real_itm;
1062
if (!(item_ref= new Item_aggregate_ref(&thd->lex->current_select->context,
1062
if (!(item_ref= new Item_aggregate_ref(&session->lex->current_select->context,
1063
1063
ref_pointer_array + el, 0, name)))
1064
1064
return; // fatal_error is set
1065
1065
if (type() == SUM_FUNC_ITEM)
1066
1066
item_ref->depended_from= ((Item_sum *) this)->depended_from();
1067
1067
fields.push_front(real_itm);
1068
thd->change_item_tree(ref, item_ref);
1068
session->change_item_tree(ref, item_ref);
1385
1385
been created in prepare. In this case register the change for
1388
thd->change_item_tree(arg, conv);
1388
session->change_item_tree(arg, conv);
1390
1390
We do not check conv->fixed, because Item_func_conv_charset which can
1391
1391
be return by safe_charset_converter can't be fixed at creation
1393
conv->fix_fields(thd, arg);
1393
conv->fix_fields(session, arg);
1433
1433
Item_field (this is important in prepared statements).
1436
Item_field::Item_field(Session *thd __attribute__((unused)),
1436
Item_field::Item_field(Session *session __attribute__((unused)),
1437
1437
Name_resolution_context *context_arg,
1439
1439
:Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
1451
1451
field(0), result_field(0), item_equal(0), no_const_subst(0),
1452
1452
have_privileges(0), any_privileges(0)
1454
SELECT_LEX *select= current_thd->lex->current_select;
1454
SELECT_LEX *select= current_session->lex->current_select;
1455
1455
collation.set(DERIVATION_IMPLICIT);
1456
1456
if (select && select->parsing_place != IN_HAVING)
1457
1457
select->select_n_where_fields++;
1461
1461
Constructor need to process subselect with temporary tables (see Item)
1464
Item_field::Item_field(Session *thd, Item_field *item)
1465
:Item_ident(thd, item),
1464
Item_field::Item_field(Session *session, Item_field *item)
1465
:Item_ident(session, item),
1466
1466
field(item->field),
1467
1467
result_field(item->result_field),
1468
1468
item_equal(item->item_equal),
1532
1532
void Item_ident::print(String *str,
1533
1533
enum_query_type query_type __attribute__((unused)))
1535
Session *thd= current_thd;
1535
Session *session= current_session;
1536
1536
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
1537
1537
const char *d_name= db_name, *t_name= table_name;
1538
1538
if (lower_case_table_names== 1 ||
1557
1557
const char *nm= (field_name && field_name[0]) ?
1558
1558
field_name : name ? name : "tmp_field";
1559
append_identifier(thd, str, nm, (uint) strlen(nm));
1559
append_identifier(session, str, nm, (uint) strlen(nm));
1562
1562
if (db_name && db_name[0] && !alias_name_used)
1565
append_identifier(thd, str, d_name, (uint)strlen(d_name));
1565
append_identifier(session, str, d_name, (uint)strlen(d_name));
1566
1566
str->append('.');
1568
append_identifier(thd, str, t_name, (uint)strlen(t_name));
1568
append_identifier(session, str, t_name, (uint)strlen(t_name));
1569
1569
str->append('.');
1570
append_identifier(thd, str, field_name, (uint)strlen(field_name));
1570
append_identifier(session, str, field_name, (uint)strlen(field_name));
1574
1574
if (table_name[0])
1576
append_identifier(thd, str, t_name, (uint) strlen(t_name));
1576
append_identifier(session, str, t_name, (uint) strlen(t_name));
1577
1577
str->append('.');
1578
append_identifier(thd, str, field_name, (uint) strlen(field_name));
1578
append_identifier(session, str, field_name, (uint) strlen(field_name));
1581
append_identifier(thd, str, field_name, (uint) strlen(field_name));
1581
append_identifier(session, str, field_name, (uint) strlen(field_name));
1763
Item *Item_field::get_tmp_table_item(Session *thd)
1763
Item *Item_field::get_tmp_table_item(Session *session)
1765
Item_field *new_item= new Item_field(thd, this);
1765
Item_field *new_item= new Item_field(session, this);
1767
1767
new_item->field= new_item->result_field;
1768
1768
return new_item;
2008
Session *thd= current_thd;
2008
Session *session= current_session;
2009
2009
LEX_STRING utf8_lex_str;
2011
thd->convert_string(&utf8_lex_str,
2011
session->convert_string(&utf8_lex_str,
2012
2012
system_charset_info,
2013
2013
str_value.c_ptr_safe(),
2014
2014
str_value.length(),
2042
2042
We can use str_value.ptr() here as Item_string is gurantee to put an
2045
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2045
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2046
2046
ER_TRUNCATED_WRONG_VALUE,
2047
2047
ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
2048
2048
str_value.ptr());
2073
2073
(end != org_end && !check_if_only_end_space(cs, end, org_end)))
2075
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2075
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2076
2076
ER_TRUNCATED_WRONG_VALUE,
2077
2077
ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
2078
2078
str_value.ptr());
2257
2257
char buff[MAX_DATE_STRING_REP_LENGTH];
2258
2258
uint32_t length= my_TIME_to_str(&value.time, buff);
2259
make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2259
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2260
2260
buff, length, time_type, 0);
2261
2261
set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
2345
2345
case STRING_RESULT:
2347
2347
const CHARSET_INFO * const fromcs= entry->collation.collation;
2348
const CHARSET_INFO * const tocs= thd->variables.collation_connection;
2348
const CHARSET_INFO * const tocs= session->variables.collation_connection;
2349
2349
uint32_t dummy_offset;
2351
2351
value.cs_info.character_set_of_placeholder=
2692
2692
if (value.cs_info.final_character_set_of_str_value !=
2693
2693
value.cs_info.character_set_of_placeholder)
2695
rc= thd->convert_string(&str_value,
2695
rc= session->convert_string(&str_value,
2696
2696
value.cs_info.character_set_of_placeholder,
2697
2697
value.cs_info.final_character_set_of_str_value);
2903
2903
Mark item and SELECT_LEXs as dependent if item was resolved in
2906
@param thd thread handler
2906
@param session thread handler
2907
2907
@param last select from which current item depend
2908
2908
@param current current select
2909
2909
@param resolved_item item which was resolved in outer SELECT(for warning)
2914
static void mark_as_dependent(Session *thd, SELECT_LEX *last, SELECT_LEX *current,
2914
static void mark_as_dependent(Session *session, SELECT_LEX *last, SELECT_LEX *current,
2915
2915
Item_ident *resolved_item,
2916
2916
Item_ident *mark_item)
2924
2924
mark_item->depended_from= last;
2925
2925
current->mark_as_dependent(last);
2926
if (thd->lex->describe & DESCRIBE_EXTENDED)
2926
if (session->lex->describe & DESCRIBE_EXTENDED)
2928
2928
char warn_buff[DRIZZLE_ERRMSG_SIZE];
2929
2929
sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
2931
2931
table_name, (table_name [0] ? "." : ""),
2932
2932
resolved_item->field_name,
2933
2933
current->select_number, last->select_number);
2934
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2934
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2935
2935
ER_WARN_FIELD_RESOLVED, warn_buff);
2941
2941
Mark range of selects and resolved identifier (field/reference)
2942
2942
item as dependent.
2944
@param thd thread handler
2944
@param session thread handler
2945
2945
@param last_select select where resolved_item was resolved
2946
2946
@param current_sel current select (select where resolved_item was placed)
2947
2947
@param found_field field which was found during resolving
2957
2957
resolved identifier.
2960
void mark_select_range_as_dependent(Session *thd,
2960
void mark_select_range_as_dependent(Session *session,
2961
2961
SELECT_LEX *last_select,
2962
2962
SELECT_LEX *current_sel,
2963
2963
Field *found_field, Item *found_item,
2995
2995
prev_subselect_item->used_tables_cache|=
2996
2996
found_field->table->map;
2997
2997
prev_subselect_item->const_item_cache= 0;
2998
mark_as_dependent(thd, last_select, current_sel, resolved_item,
2998
mark_as_dependent(session, last_select, current_sel, resolved_item,
3096
3096
my_error(ER_NON_UNIQ_ERROR, MYF(0),
3097
find_item->full_name(), current_thd->where);
3097
find_item->full_name(), current_session->where);
3120
3120
derived SELECT column. This extension is allowed only if the
3121
3121
MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled.
3123
@param thd current thread
3123
@param session current thread
3124
3124
@param ref column reference being resolved
3125
3125
@param select the select that ref is resolved against
3147
resolve_ref_in_select_and_group(Session *thd, Item_ident *ref, SELECT_LEX *select)
3147
resolve_ref_in_select_and_group(Session *session, Item_ident *ref, SELECT_LEX *select)
3149
3149
Item **group_by_ref= NULL;
3150
3150
Item **select_ref= NULL;
3174
3174
!((*group_by_ref)->eq(*select_ref, 0)))
3176
3176
ambiguous_fields= true;
3177
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
3177
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
3178
3178
ER(ER_NON_UNIQ_ERROR), ref->full_name(),
3179
current_thd->where);
3179
current_session->where);
3217
3217
current select as dependent. The found reference of field should be
3218
3218
provided in 'from_field'.
3220
@param[in] thd current thread
3220
@param[in] session current thread
3221
3221
@param[in,out] from_field found field reference or (Field*)not_found_field
3222
3222
@param[in,out] reference view column if this item was resolved to a
3248
Item_field::fix_outer_field(Session *thd, Field **from_field, Item **reference)
3248
Item_field::fix_outer_field(Session *session, Field **from_field, Item **reference)
3250
3250
enum_parsing_place place= NO_MATTER;
3251
3251
bool field_found= (*from_field != not_found_field);
3263
3263
Name_resolution_context *last_checked_context= context;
3264
3264
Item **ref= (Item **) not_found_item;
3265
SELECT_LEX *current_sel= (SELECT_LEX *) thd->lex->current_select;
3265
SELECT_LEX *current_sel= (SELECT_LEX *) session->lex->current_select;
3266
3266
Name_resolution_context *outer_context= 0;
3267
3267
SELECT_LEX *select= 0;
3268
3268
/* Currently derived tables cannot be correlated */
3292
3292
the found view field into '*reference', in other words, it
3293
3293
substitutes this Item_field with the found expression.
3295
if (field_found || (*from_field= find_field_in_tables(thd, this,
3295
if (field_found || (*from_field= find_field_in_tables(session, this,
3296
3296
outer_context->
3297
3297
first_name_resolution_table,
3298
3298
outer_context->
3327
3327
if (!(rf= new Item_outer_ref(context, this)))
3329
thd->change_item_tree(reference, rf);
3329
session->change_item_tree(reference, rf);
3330
3330
select->inner_refs_list.push_back(rf);
3331
rf->in_sum_func= thd->lex->in_sum_func;
3331
rf->in_sum_func= session->lex->in_sum_func;
3334
3334
A reference is resolved to a nest level that's outer or the same as
3335
3335
the nest level of the enclosing set function : adjust the value of
3336
3336
max_arg_level for the function if it's needed.
3338
if (thd->lex->in_sum_func &&
3339
thd->lex->in_sum_func->nest_level >= select->nest_level)
3338
if (session->lex->in_sum_func &&
3339
session->lex->in_sum_func->nest_level >= select->nest_level)
3341
3341
Item::Type ref_type= (*reference)->type();
3342
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
3342
set_if_bigger(session->lex->in_sum_func->max_arg_level,
3343
3343
select->nest_level);
3344
3344
set_field(*from_field);
3346
mark_as_dependent(thd, last_checked_context->select_lex,
3346
mark_as_dependent(session, last_checked_context->select_lex,
3347
3347
context->select_lex, this,
3348
3348
((ref_type == REF_ITEM ||
3349
3349
ref_type == FIELD_ITEM) ?
3358
3358
(*reference)->used_tables();
3359
3359
prev_subselect_item->const_item_cache&=
3360
3360
(*reference)->const_item();
3361
mark_as_dependent(thd, last_checked_context->select_lex,
3361
mark_as_dependent(session, last_checked_context->select_lex,
3362
3362
context->select_lex, this,
3363
3363
((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
3364
3364
(Item_ident*) (*reference) :
3378
3378
/* Search in SELECT and GROUP lists of the outer select. */
3379
3379
if (place != IN_WHERE && place != IN_ON)
3381
if (!(ref= resolve_ref_in_select_and_group(thd, this, select)))
3381
if (!(ref= resolve_ref_in_select_and_group(session, this, select)))
3382
3382
return -1; /* Some error occurred (e.g. ambiguous names). */
3383
3383
if (ref != not_found_item)
3406
3406
if (upward_lookup)
3408
3408
// We can't say exactly what absent table or field
3409
my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), thd->where);
3409
my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where);
3413
3413
/* Call find_field_in_tables only to report the error */
3414
find_field_in_tables(thd, this,
3414
find_field_in_tables(session, this,
3415
3415
context->first_name_resolution_table,
3416
3416
context->last_name_resolution_table,
3417
3417
reference, REPORT_ALL_ERRORS,
3450
3450
if (place != IN_HAVING && select->group_list.elements)
3452
3452
outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf);
3453
((Item_outer_ref*)rf)->in_sum_func= thd->lex->in_sum_func;
3453
((Item_outer_ref*)rf)->in_sum_func= session->lex->in_sum_func;
3455
thd->change_item_tree(reference, rf);
3455
session->change_item_tree(reference, rf);
3457
3457
rf is Item_ref => never substitute other items (in this case)
3458
3458
during fix_fields() => we can use rf after fix_fields()
3460
3460
assert(!rf->fixed); // Assured by Item_ref()
3461
if (rf->fix_fields(thd, reference) || rf->check_cols(1))
3461
if (rf->fix_fields(session, reference) || rf->check_cols(1))
3464
mark_as_dependent(thd, last_checked_context->select_lex,
3464
mark_as_dependent(session, last_checked_context->select_lex,
3465
3465
context->select_lex, this,
3471
mark_as_dependent(thd, last_checked_context->select_lex,
3471
mark_as_dependent(session, last_checked_context->select_lex,
3472
3472
context->select_lex,
3473
3473
this, (Item_ident*)*reference);
3474
3474
if (last_checked_context->select_lex->having_fix_field)
3479
3479
(char*) cached_table->alias, (char*) field_name);
3482
thd->change_item_tree(reference, rf);
3482
session->change_item_tree(reference, rf);
3484
3484
rf is Item_ref => never substitute other items (in this case)
3485
3485
during fix_fields() => we can use rf after fix_fields()
3487
3487
assert(!rf->fixed); // Assured by Item_ref()
3488
if (rf->fix_fields(thd, reference) || rf->check_cols(1))
3488
if (rf->fix_fields(session, reference) || rf->check_cols(1))
3529
3529
Notice that compared to Item_ref::fix_fields, here we first search the FROM
3530
3530
clause, and then we search the SELECT and GROUP BY clauses.
3532
@param[in] thd current thread
3532
@param[in] session current thread
3533
3533
@param[in,out] reference view column if this item was resolved to a
3552
3552
expression to 'reference', i.e. it substitute that expression instead
3553
3553
of this Item_field
3555
if ((from_field= find_field_in_tables(thd, this,
3555
if ((from_field= find_field_in_tables(session, this,
3556
3556
context->first_name_resolution_table,
3557
3557
context->last_name_resolution_table,
3559
thd->lex->use_only_table_context ?
3559
session->lex->use_only_table_context ?
3560
3560
REPORT_ALL_ERRORS :
3561
3561
IGNORE_EXCEPT_NON_UNIQUE,
3562
3562
!any_privileges,
3567
3567
/* Look up in current select's item_list to find aliased fields */
3568
if (thd->lex->current_select->is_item_list_lookup)
3568
if (session->lex->current_select->is_item_list_lookup)
3570
3570
uint32_t counter;
3571
3571
enum_resolution_type resolution;
3572
Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
3572
Item** res= find_item_in_list(this, session->lex->current_select->item_list,
3573
3573
&counter, REPORT_EXCEPT_NOT_FOUND,
3610
3610
Item_ref *rf= new Item_ref(context, db_name,table_name,field_name);
3613
thd->change_item_tree(reference, rf);
3613
session->change_item_tree(reference, rf);
3615
3615
Because Item_ref never substitutes itself with other items
3616
3616
in Item_ref::fix_fields(), we can safely use the original
3617
3617
pointer to it even after fix_fields()
3619
return rf->fix_fields(thd, reference) || rf->check_cols(1);
3619
return rf->fix_fields(session, reference) || rf->check_cols(1);
3623
if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
3623
if ((ret= fix_outer_field(session, &from_field, reference)) < 0)
3625
3625
outer_fixed= true;
3634
3634
cached_table->select_lex != context->select_lex)
3637
if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
3637
if ((ret= fix_outer_field(session, &from_field, reference)) < 0)
3639
3639
outer_fixed= 1;
3659
3659
set_field(from_field);
3660
if (thd->lex->in_sum_func &&
3661
thd->lex->in_sum_func->nest_level ==
3662
thd->lex->current_select->nest_level)
3663
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
3664
thd->lex->current_select->nest_level);
3660
if (session->lex->in_sum_func &&
3661
session->lex->in_sum_func->nest_level ==
3662
session->lex->current_select->nest_level)
3663
set_if_bigger(session->lex->in_sum_func->max_arg_level,
3664
session->lex->current_select->nest_level);
3666
else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
3666
else if (session->mark_used_columns != MARK_COLUMNS_NONE)
3668
3668
Table *table= field->table;
3669
3669
MY_BITMAP *current_bitmap, *other_bitmap;
3670
if (thd->mark_used_columns == MARK_COLUMNS_READ)
3670
if (session->mark_used_columns == MARK_COLUMNS_READ)
3672
3672
current_bitmap= table->read_set;
3673
3673
other_bitmap= table->write_set;
3982
3982
str->length(), &well_formed_error);
3983
3983
if (wlen < str->length())
3985
Session *thd= current_thd;
3985
Session *session= current_session;
3986
3986
char hexbuf[7];
3987
3987
enum DRIZZLE_ERROR::enum_warning_level level;
3988
3988
uint32_t diff= str->length() - wlen;
4002
push_warning_printf(thd, level, ER_INVALID_CHARACTER_STRING,
4002
push_warning_printf(session, level, ER_INVALID_CHARACTER_STRING,
4003
4003
ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf);
4732
4732
need to set no_errors to prevent warnings about type conversion
4735
Session *thd= field->table->in_use;
4735
Session *session= field->table->in_use;
4738
no_errors= thd->no_errors;
4738
no_errors= session->no_errors;
4739
session->no_errors= 1;
4740
4740
Item::update_null_value();
4741
thd->no_errors= no_errors;
4741
session->no_errors= no_errors;
4866
4866
Item_field::fix_fields, here we first search the SELECT and GROUP BY
4867
4867
clauses, and then we search the FROM clause.
4869
@param[in] thd current thread
4869
@param[in] session current thread
4870
4870
@param[in,out] reference view column if this item was resolved to a
4882
4882
false on success
4885
bool Item_ref::fix_fields(Session *thd, Item **reference)
4885
bool Item_ref::fix_fields(Session *session, Item **reference)
4887
4887
enum_parsing_place place= NO_MATTER;
4888
4888
assert(fixed == 0);
4889
SELECT_LEX *current_sel= thd->lex->current_select;
4889
SELECT_LEX *current_sel= session->lex->current_select;
4891
4891
if (!ref || ref == not_found_item)
4893
if (!(ref= resolve_ref_in_select_and_group(thd, this,
4893
if (!(ref= resolve_ref_in_select_and_group(session, this,
4894
4894
context->select_lex)))
4895
4895
goto error; /* Some error occurred (e.g. ambiguous names). */
4906
4906
/* The current reference cannot be resolved in this query. */
4907
4907
my_error(ER_BAD_FIELD_ERROR,MYF(0),
4908
this->full_name(), current_thd->where);
4908
this->full_name(), current_session->where);
4930
4930
/* Search in the SELECT and GROUP lists of the outer select. */
4931
4931
if (outer_context->resolve_in_select_list)
4933
if (!(ref= resolve_ref_in_select_and_group(thd, this, select)))
4933
if (!(ref= resolve_ref_in_select_and_group(session, this, select)))
4934
4934
goto error; /* Some error occurred (e.g. ambiguous names). */
4935
4935
if (ref != not_found_item)
4967
4967
field expression to 'reference', i.e. it substitute that
4968
4968
expression instead of this Item_ref
4970
from_field= find_field_in_tables(thd, this,
4970
from_field= find_field_in_tables(session, this,
4971
4971
outer_context->
4972
4972
first_name_resolution_table,
4973
4973
outer_context->
4985
4985
prev_subselect_item->const_item_cache&=
4986
4986
(*reference)->const_item();
4987
4987
assert((*reference)->type() == REF_ITEM);
4988
mark_as_dependent(thd, last_checked_context->select_lex,
4988
mark_as_dependent(session, last_checked_context->select_lex,
4989
4989
context->select_lex, this,
4990
4990
((refer_type == REF_ITEM ||
4991
4991
refer_type == FIELD_ITEM) ?
5038
5038
Item_field* fld;
5039
5039
if (!(fld= new Item_field(from_field)))
5041
thd->change_item_tree(reference, fld);
5042
mark_as_dependent(thd, last_checked_context->select_lex,
5043
thd->lex->current_select, this, fld);
5041
session->change_item_tree(reference, fld);
5042
mark_as_dependent(session, last_checked_context->select_lex,
5043
session->lex->current_select, this, fld);
5045
5045
A reference is resolved to a nest level that's outer or the same as
5046
5046
the nest level of the enclosing set function : adjust the value of
5047
5047
max_arg_level for the function if it's needed.
5049
if (thd->lex->in_sum_func &&
5050
thd->lex->in_sum_func->nest_level >=
5049
if (session->lex->in_sum_func &&
5050
session->lex->in_sum_func->nest_level >=
5051
5051
last_checked_context->select_lex->nest_level)
5052
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
5052
set_if_bigger(session->lex->in_sum_func->max_arg_level,
5053
5053
last_checked_context->select_lex->nest_level);
5058
5058
/* The item was not a table field and not a reference */
5059
5059
my_error(ER_BAD_FIELD_ERROR, MYF(0),
5060
this->full_name(), current_thd->where);
5060
this->full_name(), current_session->where);
5063
5063
/* Should be checked in resolve_ref_in_select_and_group(). */
5064
5064
assert(*ref && (*ref)->fixed);
5065
mark_as_dependent(thd, last_checked_context->select_lex,
5065
mark_as_dependent(session, last_checked_context->select_lex,
5066
5066
context->select_lex, this, this);
5068
5068
A reference is resolved to a nest level that's outer or the same as
5069
5069
the nest level of the enclosing set function : adjust the value of
5070
5070
max_arg_level for the function if it's needed.
5072
if (thd->lex->in_sum_func &&
5073
thd->lex->in_sum_func->nest_level >=
5072
if (session->lex->in_sum_func &&
5073
session->lex->in_sum_func->nest_level >=
5074
5074
last_checked_context->select_lex->nest_level)
5075
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
5075
set_if_bigger(session->lex->in_sum_func->max_arg_level,
5076
5076
last_checked_context->select_lex->nest_level);
5147
5147
if ((*ref)->type() != Item::CACHE_ITEM && ref_type() != VIEW_REF &&
5148
5148
!table_name && name && alias_name_used)
5150
Session *thd= current_thd;
5151
append_identifier(thd, str, name, (uint) strlen(name));
5150
Session *session= current_session;
5151
append_identifier(session, str, name, (uint) strlen(name));
5154
5154
(*ref)->print(str, query_type);
5332
Item *Item_ref::get_tmp_table_item(Session *thd)
5332
Item *Item_ref::get_tmp_table_item(Session *session)
5334
5334
if (!result_field)
5335
return (*ref)->get_tmp_table_item(thd);
5335
return (*ref)->get_tmp_table_item(session);
5337
5337
Item_field *item= new Item_field(result_field);
5422
bool Item_direct_view_ref::fix_fields(Session *thd, Item **reference)
5422
bool Item_direct_view_ref::fix_fields(Session *session, Item **reference)
5424
5424
/* view fild reference must be defined */
5426
5426
/* (*ref)->check_cols() will be made in Item_direct_ref::fix_fields */
5427
5427
if (!(*ref)->fixed &&
5428
((*ref)->fix_fields(thd, ref)))
5428
((*ref)->fix_fields(session, ref)))
5430
return Item_direct_ref::fix_fields(thd, reference);
5430
return Item_direct_ref::fix_fields(session, reference);
5446
bool Item_outer_ref::fix_fields(Session *thd, Item **reference)
5446
bool Item_outer_ref::fix_fields(Session *session, Item **reference)
5449
5449
/* outer_ref->check_cols() will be made in Item_direct_ref::fix_fields */
5450
if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(thd, reference)))
5450
if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(session, reference)))
5452
err= Item_direct_ref::fix_fields(thd, reference);
5452
err= Item_direct_ref::fix_fields(session, reference);
5453
5453
if (!outer_ref)
5454
5454
outer_ref= *ref;
5455
5455
if ((*ref)->type() == Item::FIELD_ITEM)
5620
5620
change records at each execution.
5622
5622
if (arg != new_item)
5623
current_thd->change_item_tree(&arg, new_item);
5623
current_session->change_item_tree(&arg, new_item);
5624
5624
return (this->*transformer)(args);
5643
5643
TableList *orig_next_table= context->last_name_resolution_table;
5644
5644
context->last_name_resolution_table= context->first_name_resolution_table;
5645
res= arg->fix_fields(thd, &arg);
5645
res= arg->fix_fields(session, &arg);
5646
5646
context->last_name_resolution_table= orig_next_table;
5775
5775
assert(item_row->cols() == comp_item_row->cols());
5776
5776
col= item_row->cols();
5777
5777
while (col-- > 0)
5778
resolve_const_item(thd, item_row->addr(col),
5778
resolve_const_item(session, item_row->addr(col),
5779
5779
comp_item_row->element_index(col));
6049
6049
bool Item_cache_row::allocate(uint32_t num)
6051
6051
item_count= num;
6052
Session *thd= current_thd;
6052
Session *session= current_session;
6053
6053
return (!(values=
6054
(Item_cache **) thd->calloc(sizeof(Item_cache *)*item_count)));
6054
(Item_cache **) session->calloc(sizeof(Item_cache *)*item_count)));
6134
Item_type_holder::Item_type_holder(Session *thd, Item *item)
6135
:Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
6134
Item_type_holder::Item_type_holder(Session *session, Item *item)
6135
:Item(session, item), enum_set_typelib(0), fld_type(get_real_type(item))
6137
6137
assert(item->fixed);
6138
6138
maybe_null= item->maybe_null;