17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "drizzled/sql_select.h"
22
#include "drizzled/error.h"
23
#include "drizzled/show.h"
24
#include "drizzled/item/cmpfunc.h"
25
#include "drizzled/item/cache_row.h"
26
#include "drizzled/item/type_holder.h"
27
#include "drizzled/item/sum.h"
28
#include "drizzled/item/copy_string.h"
29
#include "drizzled/function/str/conv_charset.h"
30
#include "drizzled/sql_base.h"
31
#include "drizzled/util/convert.h"
32
#include "drizzled/plugin/client.h"
33
#include "drizzled/time_functions.h"
35
#include "drizzled/field/str.h"
36
#include "drizzled/field/num.h"
37
#include "drizzled/field/blob.h"
38
#include "drizzled/field/enum.h"
39
#include "drizzled/field/null.h"
40
#include "drizzled/field/date.h"
41
#include "drizzled/field/decimal.h"
42
#include "drizzled/field/real.h"
43
#include "drizzled/field/double.h"
44
#include "drizzled/field/long.h"
45
#include "drizzled/field/int64_t.h"
46
#include "drizzled/field/num.h"
47
#include "drizzled/field/timestamp.h"
48
#include "drizzled/field/datetime.h"
49
#include "drizzled/field/varstring.h"
50
#include "drizzled/internal/m_string.h"
21
#include <drizzled/server_includes.h>
22
#include <drizzled/sql_select.h>
23
#include <drizzled/error.h>
24
#include <drizzled/show.h>
25
#include <drizzled/item/cmpfunc.h>
26
#include <drizzled/item/cache_row.h>
27
#include <drizzled/item/type_holder.h>
28
#include <drizzled/item/sum.h>
29
#include <drizzled/item/copy_string.h>
30
#include <drizzled/function/str/conv_charset.h>
31
#include <drizzled/virtual_column_info.h>
32
#include <drizzled/sql_base.h>
33
#include <drizzled/util/convert.h>
36
#include <drizzled/field/str.h>
37
#include <drizzled/field/longstr.h>
38
#include <drizzled/field/num.h>
39
#include <drizzled/field/blob.h>
40
#include <drizzled/field/enum.h>
41
#include <drizzled/field/null.h>
42
#include <drizzled/field/date.h>
43
#include <drizzled/field/decimal.h>
44
#include <drizzled/field/real.h>
45
#include <drizzled/field/double.h>
46
#include <drizzled/field/long.h>
47
#include <drizzled/field/int64_t.h>
48
#include <drizzled/field/num.h>
49
#include <drizzled/field/timestamp.h>
50
#include <drizzled/field/datetime.h>
51
#include <drizzled/field/varstring.h>
61
55
const String my_null_string("NULL", 4, default_charset_info);
57
/*****************************************************************************
59
*****************************************************************************/
63
61
bool Item::is_expensive_processor(unsigned char *)
68
66
void Item::fix_after_pullout(Select_Lex *, Item **)
71
70
Field *Item::tmp_table_field(Table *)
76
76
const char *Item::full_name(void) const
78
78
return name ? name : "???";
81
82
int64_t Item::val_int_endpoint(bool, bool *)
87
/** @todo Make this functions class dependent */
91
Make this functions class dependent
88
94
bool Item::val_bool()
96
switch(result_type()) {
98
return val_int() != 0;
93
return val_int() != 0;
96
my_decimal decimal_value;
97
my_decimal *val= val_decimal(&decimal_value);
99
return !my_decimal_is_zero(val);
104
return val_real() != 0.0;
101
my_decimal decimal_value;
102
my_decimal *val= val_decimal(&decimal_value);
104
return !my_decimal_is_zero(val);
109
return val_real() != 0.0;
113
return false; // Wrong (but safe)
112
118
String *Item::val_string_from_real(String *str)
114
120
double nr= val_real();
122
return NULL; /* purecov: inspected */
118
str->set_real(nr, decimals, &my_charset_bin);
124
str->set_real(nr,decimals, &my_charset_bin);
122
129
String *Item::val_string_from_int(String *str)
124
131
int64_t nr= val_int();
160
170
return decimal_value;
163
174
my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value)
167
178
if (!(res= val_str(&str_value)))
179
return NULL; // NULL or EOM
170
181
end_ptr= (char*) res->ptr()+ res->length();
171
182
if (str2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM,
183
res->ptr(), res->length(), res->charset(),
175
184
decimal_value) & E_DEC_BAD_NUM)
177
push_warning_printf(current_session,
178
DRIZZLE_ERROR::WARN_LEVEL_WARN,
186
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
179
187
ER_TRUNCATED_WRONG_VALUE,
180
188
ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
181
189
str_value.c_ptr());
248
261
return field->store_time(<ime, DRIZZLE_TIMESTAMP_DATETIME);
252
* Check if the Item is null and stores the NULL or the
253
* result value in the field accordingly.
266
Store the string value in field directly
269
Item::save_str_value_in_field()
270
field a pointer to field where to store
271
result the pointer to the string value to be stored
274
The method is used by Item_*::save_in_field implementations
275
when we don't need to calculate the value to store
276
See Item_string::save_in_field() implementation for example
279
Check if the Item is null and stores the NULL or the
280
result value in the field accordingly.
283
Nonzero value if error
255
286
int Item::save_str_value_in_field(Field *field, String *result)
258
289
return set_field_to_null(field);
259
290
field->set_notnull();
260
return field->store(result->ptr(), result->length(), collation.collation);
291
return field->store(result->ptr(), result->length(),
292
collation.collation);
264
is_expensive_cache(-1),
274
unsigned_flag(false),
275
with_sum_func(false),
276
is_autogenerated_name(true),
277
with_subselect(false),
297
is_expensive_cache(-1), name(0), orig_name(0), max_length(0), name_length(0),
298
unsigned_flag(false), fixed(0), is_autogenerated_name(true),
278
299
collation(&my_charset_bin, DERIVATION_COERCIBLE)
304
with_sum_func= false;
305
unsigned_flag= false;
280
308
cmp_context= (Item_result)-1;
282
310
/* Put item in free list so that we can free all items at end */
283
311
Session *session= current_session;
284
312
next= session->free_list;
285
313
session->free_list= this;
288
315
Item constructor can be called during execution other then SQL_COM
289
316
command => we should check session->lex->current_select on zero (session->lex
292
319
if (session->lex->current_select)
294
enum_parsing_place place= session->lex->current_select->parsing_place;
295
if (place == SELECT_LIST || place == IN_HAVING)
321
enum_parsing_place place=
322
session->lex->current_select->parsing_place;
323
if (place == SELECT_LIST ||
296
325
session->lex->current_select->select_n_having_items++;
330
Constructor used by Item_field, Item_ref & aggregate (sum)
333
Used for duplicating lists in processing queries with temporary
300
336
Item::Item(Session *session, Item *item):
301
337
is_expensive_cache(-1),
302
338
str_value(item->str_value),
303
339
name(item->name),
304
name_length(item->name_length),
305
340
orig_name(item->orig_name),
306
341
max_length(item->max_length),
307
342
marker(item->marker),
308
343
decimals(item->decimals),
310
344
maybe_null(item->maybe_null),
311
345
null_value(item->null_value),
312
346
unsigned_flag(item->unsigned_flag),
313
347
with_sum_func(item->with_sum_func),
314
is_autogenerated_name(item->is_autogenerated_name),
315
with_subselect(item->with_subselect),
316
349
collation(item->collation),
317
350
cmp_context(item->cmp_context)
319
/* Put this item in the session's free list */
320
next= session->free_list;
352
next= session->free_list; // Put in free list
321
353
session->free_list= this;
324
uint32_t Item::float_length(uint32_t decimals_par) const
326
return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;
329
357
uint32_t Item::decimal_precision() const
331
359
Item_result restype= result_type();
333
361
if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
334
return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
335
(uint32_t) DECIMAL_MAX_PRECISION);
336
return min(max_length, (uint32_t) DECIMAL_MAX_PRECISION);
362
return cmin(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
363
(unsigned int)DECIMAL_MAX_PRECISION);
364
return cmin(max_length, (uint32_t)DECIMAL_MAX_PRECISION);
339
368
int Item::decimal_int_part() const
341
370
return my_decimal_int_part(decimal_precision(), decimals);
344
374
void Item::print(String *str, enum_query_type)
346
376
str->append(full_name());
349
380
void Item::print_item_w_name(String *str, enum_query_type query_type)
351
382
print(str, query_type);
360
392
void Item::split_sum_func(Session *, Item **, List<Item> &)
363
396
void Item::cleanup()
407
cleanup() item if it is 'fixed'.
409
@param arg a dummy parameter, is not used here
412
bool Item::cleanup_processor(unsigned char *)
421
rename item (used for views, cleanup() return original name).
423
@param new_name new name of item;
372
426
void Item::rename(char *new_name)
375
429
we can compare pointers to names here, because if name was not changed,
376
430
pointer will be same
378
if (! orig_name && new_name != name)
432
if (!orig_name && new_name != name)
439
Traverse item tree possibly transforming it (replacing items).
441
If you don't need to transform an item tree, but only traverse
442
it, please use Item::walk() instead.
444
@param transformer functor that performs transformation of a subtree
445
@param arg opaque argument passed to the functor
448
Returns pointer to the new subtree root. Session::change_item_tree()
449
should be called for it if transformation took place, i.e. if a
450
pointer to newly allocated item is returned.
383
453
Item* Item::transform(Item_transformer transformer, unsigned char *arg)
385
455
return (this->*transformer)(arg);
388
459
bool Item::check_cols(uint32_t c)
392
463
my_error(ER_OPERAND_COLUMNS, MYF(0), c);
398
470
void Item::set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs)
409
481
uint32_t orig_len= length;
410
while (length && ! my_isgraph(cs, *str))
412
/* Fix problem with yacc */
483
This will probably need a better implementation in the future:
484
a function in CHARSET_INFO structure.
486
while (length && !my_isgraph(cs,*str))
487
{ // Fix problem with yacc
416
if (orig_len != length && ! is_autogenerated_name)
491
if (orig_len != length && !is_autogenerated_name)
419
push_warning_printf(current_session,
420
DRIZZLE_ERROR::WARN_LEVEL_WARN,
421
ER_NAME_BECOMES_EMPTY,
422
ER(ER_NAME_BECOMES_EMPTY),
494
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
495
ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
423
496
str + length - orig_len);
425
push_warning_printf(current_session,
426
DRIZZLE_ERROR::WARN_LEVEL_WARN,
428
ER(ER_REMOVED_SPACES),
498
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
499
ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
429
500
str + length - orig_len);
432
name= memory::sql_strmake(str, length);
503
if (!my_charset_same(cs, system_charset_info))
506
name= sql_strmake_with_convert(str, name_length= length, cs,
507
length, system_charset_info,
511
name= sql_strmake(str, length);
517
This function is called when:
518
- Comparing items in the WHERE clause (when doing where optimization)
519
- When trying to find an order_st BY/GROUP BY item in the SELECT part
435
522
bool Item::eq(const Item *item, bool) const
439
526
for all basic constants we have special checks, and Item_param's
440
527
type() can be only among basic constant types.
442
return type() == item->type() &&
445
! my_strcasecmp(system_charset_info, name, item->name);
529
return type() == item->type() && name && item->name &&
530
!my_strcasecmp(system_charset_info,name,item->name);
448
534
Item *Item::safe_charset_converter(const CHARSET_INFO * const tocs)
450
536
Item_func_conv_charset *conv= new Item_func_conv_charset(this, tocs, 1);
451
537
return conv->safe ? conv : NULL;
542
Get the value of the function as a DRIZZLE_TIME structure.
543
As a extra convenience the time structure is reset on error!
454
546
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
456
548
if (result_type() == STRING_RESULT)
469
561
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
471
563
char buff[22], *end;
472
end= internal::int64_t10_to_str(value, buff, -10);
564
end= int64_t10_to_str(value, buff, -10);
473
565
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
474
566
buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
499
598
bool Item::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
501
600
return get_date(ltime,fuzzydate);
504
604
bool Item::is_null()
509
610
void Item::update_null_value ()
511
612
(void) val_int();
514
616
void Item::top_level_item(void)
517
620
void Item::set_result_field(Field *)
520
624
bool Item::is_result_field(void)
525
630
bool Item::is_bool_func(void)
530
636
void Item::save_in_result_field(bool)
533
640
void Item::no_rows_in_result(void)
536
644
Item *Item::copy_or_same(Session *)
541
650
Item *Item::copy_andor_structure(Session *)
546
656
Item *Item::real_item(void)
551
662
const Item *Item::real_item(void) const
556
668
Item *Item::get_tmp_table_item(Session *session)
558
670
return copy_or_same(session);
561
674
const CHARSET_INFO *Item::default_charset()
563
676
return current_session->variables.getCollation();
566
680
const CHARSET_INFO *Item::compare_collation()
571
686
bool Item::walk(Item_processor processor, bool, unsigned char *arg)
573
688
return (this->*processor)(arg);
576
Item* Item::compile(Item_analyzer analyzer,
577
unsigned char **arg_p,
578
Item_transformer transformer,
579
unsigned char *arg_t)
692
Item* Item::compile(Item_analyzer analyzer, unsigned char **arg_p,
693
Item_transformer transformer, unsigned char *arg_t)
581
695
if ((this->*analyzer) (arg_p))
582
696
return ((this->*transformer) (arg_t));
586
701
void Item::traverse_cond(Cond_traverser traverser, void *arg, traverse_order)
588
703
(*traverser)(this, arg);
591
707
bool Item::remove_dependence_processor(unsigned char *)
596
713
bool Item::remove_fixed(unsigned char *)
602
720
bool Item::collect_item_field_processor(unsigned char *)
607
726
bool Item::find_item_in_field_list_processor(unsigned char *)
612
732
bool Item::change_context_processor(unsigned char *)
737
bool Item::reset_query_id_processor(unsigned char *)
617
743
bool Item::register_field_in_read_map(unsigned char *)
749
bool Item::register_field_in_bitmap(unsigned char *)
622
755
bool Item::subst_argument_checker(unsigned char **arg)
693
844
return test(is_expensive_cache);
848
int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
851
Table *table= field->table;
852
Session *session= table->in_use;
853
enum_check_fields tmp= session->count_cuted_fields;
854
ulong sql_mode= session->variables.sql_mode;
855
session->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
856
session->count_cuted_fields= CHECK_FIELD_IGNORE;
857
res= save_in_field(field, no_conversions);
858
session->count_cuted_fields= tmp;
859
session->variables.sql_mode= sql_mode;
697
865
need a special class to adjust printing : references to aggregate functions
698
866
must not be printed as refs because the aggregate functions that are added to
887
Move SUM items out from item tree and replace with reference.
889
@param session Thread handler
890
@param ref_pointer_array Pointer to array of reference fields
891
@param fields All fields in select
892
@param ref Pointer to item
893
@param skip_registered <=> function be must skipped for registered
897
This is from split_sum_func() for items that should be split
899
All found SUM items are added FIRST in the fields list and
900
we replace the item with a reference.
902
session->fatal_error() may be called if we are out of memory
717
905
void Item::split_sum_func(Session *session, Item **ref_pointer_array,
718
906
List<Item> &fields, Item **ref,
719
907
bool skip_registered)
721
909
/* An item of type Item_sum is registered <=> ref_by != 0 */
722
if (type() == SUM_FUNC_ITEM &&
910
if (type() == SUM_FUNC_ITEM && skip_registered &&
724
911
((Item_sum *) this)->ref_by)
727
913
if ((type() != SUM_FUNC_ITEM && with_sum_func) ||
728
914
(type() == FUNC_ITEM &&
729
915
(((Item_func *) this)->functype() == Item_func::ISNOTNULLTEST_FUNC ||
765
951
Functions to convert item to field (for send_fields)
767
955
bool Item::fix_fields(Session *, Item **)
769
/* We do not check fields which are fixed during construction */
770
assert(! fixed || basic_const_item());
958
// We do not check fields which are fixed during construction
959
assert(fixed == 0 || basic_const_item());
966
Mark item and Select_Lexs as dependent if item was resolved in
969
@param session thread handler
970
@param last select from which current item depend
971
@param current current select
972
@param resolved_item item which was resolved in outer SELECT(for warning)
973
@param mark_item item which should be marked (can be differ in case of
775
977
void mark_as_dependent(Session *session, Select_Lex *last, Select_Lex *current,
776
978
Item_ident *resolved_item,
777
979
Item_ident *mark_item)
787
989
if (session->lex->describe & DESCRIBE_EXTENDED)
789
991
char warn_buff[DRIZZLE_ERRMSG_SIZE];
790
snprintf(warn_buff, sizeof(warn_buff), ER(ER_WARN_FIELD_RESOLVED),
992
sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
791
993
db_name, (db_name[0] ? "." : ""),
792
994
table_name, (table_name [0] ? "." : ""),
793
995
resolved_item->field_name,
1004
Mark range of selects and resolved identifier (field/reference)
1007
@param session thread handler
1008
@param last_select select where resolved_item was resolved
1009
@param current_sel current select (select where resolved_item was placed)
1010
@param found_field field which was found during resolving
1011
@param found_item Item which was found during resolving (if resolved
1012
identifier belongs to VIEW)
1013
@param resolved_item Identifier which was resolved
1016
We have to mark all items between current_sel (including) and
1017
last_select (excluding) as dependend (select before last_select should
1018
be marked with actual table mask used by resolved item, all other with
1019
OUTER_REF_TABLE_BIT) and also write dependence information to Item of
1020
resolved identifier.
800
1023
void mark_select_range_as_dependent(Session *session,
801
1024
Select_Lex *last_select,
802
1025
Select_Lex *current_sel,
813
1036
for (; previous_select->outer_select() != last_select;
814
1037
previous_select= previous_select->outer_select())
816
Item_subselect *prev_subselect_item= previous_select->master_unit()->item;
1039
Item_subselect *prev_subselect_item=
1040
previous_select->master_unit()->item;
817
1041
prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
818
1042
prev_subselect_item->const_item_cache= 0;
821
Item_subselect *prev_subselect_item= previous_select->master_unit()->item;
1045
Item_subselect *prev_subselect_item=
1046
previous_select->master_unit()->item;
822
1047
Item_ident *dependent= resolved_item;
823
1048
if (found_field == view_ref_found)
825
1050
Item::Type type= found_item->type();
826
prev_subselect_item->used_tables_cache|= found_item->used_tables();
1051
prev_subselect_item->used_tables_cache|=
1052
found_item->used_tables();
827
1053
dependent= ((type == Item::REF_ITEM || type == Item::FIELD_ITEM) ?
828
1054
(Item_ident*) found_item :
832
prev_subselect_item->used_tables_cache|= found_field->table->map;
1058
prev_subselect_item->used_tables_cache|=
1059
found_field->table->map;
833
1060
prev_subselect_item->const_item_cache= 0;
834
1061
mark_as_dependent(session, last_select, current_sel, resolved_item,
840
1068
Search a GROUP BY clause for a field with a certain name.
850
1078
- the found item on success
851
1079
- NULL if find_item is not in group_list
853
1082
static Item** find_field_in_group_list(Item *find_item, order_st *group_list)
855
1084
const char *db_name;
856
1085
const char *table_name;
857
1086
const char *field_name;
858
order_st *found_group= NULL;
859
int found_match_degree= 0;
1087
order_st *found_group= NULL;
1088
int found_match_degree= 0;
860
1089
Item_ident *cur_field;
861
int cur_match_degree= 0;
862
char name_buff[NAME_LEN+1];
1090
int cur_match_degree= 0;
1091
char name_buff[NAME_LEN+1];
864
1093
if (find_item->type() == Item::FIELD_ITEM ||
865
1094
find_item->type() == Item::REF_ITEM)
867
db_name= ((Item_ident*) find_item)->db_name;
1096
db_name= ((Item_ident*) find_item)->db_name;
868
1097
table_name= ((Item_ident*) find_item)->table_name;
869
1098
field_name= ((Item_ident*) find_item)->field_name;
1103
if (db_name && lower_case_table_names)
876
1105
/* Convert database to lower case for comparison */
877
1106
strncpy(name_buff, db_name, sizeof(name_buff)-1);
942
Item** resolve_ref_in_select_and_group(Session *session, Item_ident *ref, Select_Lex *select)
1174
Resolve a column reference in a sub-select.
1176
Resolve a column reference (usually inside a HAVING clause) against the
1177
SELECT and GROUP BY clauses of the query described by 'select'. The name
1178
resolution algorithm searches both the SELECT and GROUP BY clauses, and in
1179
case of a name conflict prefers GROUP BY column names over SELECT names. If
1180
both clauses contain different fields with the same names, a warning is
1181
issued that name of 'ref' is ambiguous. We extend ANSI SQL in that when no
1182
GROUP BY column is found, then a HAVING name is resolved as a possibly
1183
derived SELECT column. This extension is allowed only if the
1184
MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled.
1186
@param session current thread
1187
@param ref column reference being resolved
1188
@param select the select that ref is resolved against
1191
The resolution procedure is:
1192
- Search for a column or derived column named col_ref_i [in table T_j]
1193
in the SELECT clause of Q.
1194
- Search for a column named col_ref_i [in table T_j]
1195
in the GROUP BY clause of Q.
1196
- If found different columns with the same name in GROUP BY and SELECT
1197
- issue a warning and return the GROUP BY column,
1199
- if the MODE_ONLY_FULL_GROUP_BY mode is enabled return error
1200
- else return the found SELECT column.
1204
- NULL - there was an error, and the error was already reported
1205
- not_found_item - the item was not resolved, no error was reported
1206
- resolved item - if the item was resolved
1210
resolve_ref_in_select_and_group(Session *session, Item_ident *ref, Select_Lex *select)
944
1212
Item **group_by_ref= NULL;
945
1213
Item **select_ref= NULL;
999
1267
return (Item**) not_found_item;
1002
void Item::init_make_field(SendField *tmp_field,
1270
void Item::init_make_field(Send_field *tmp_field,
1003
1271
enum enum_field_types field_type_arg)
1005
1273
char *empty_name= (char*) "";
1006
tmp_field->db_name= empty_name;
1007
tmp_field->org_table_name= empty_name;
1008
tmp_field->org_col_name= empty_name;
1009
tmp_field->table_name= empty_name;
1010
tmp_field->col_name= name;
1011
tmp_field->charsetnr= collation.collation->number;
1012
tmp_field->flags= (maybe_null ? 0 : NOT_NULL_FLAG) |
1013
(my_binary_compare(collation.collation) ?
1015
tmp_field->type= field_type_arg;
1016
tmp_field->length= max_length;
1017
tmp_field->decimals= decimals;
1274
tmp_field->db_name= empty_name;
1275
tmp_field->org_table_name= empty_name;
1276
tmp_field->org_col_name= empty_name;
1277
tmp_field->table_name= empty_name;
1278
tmp_field->col_name= name;
1279
tmp_field->charsetnr= collation.collation->number;
1280
tmp_field->flags= (maybe_null ? 0 : NOT_NULL_FLAG) |
1281
(my_binary_compare(collation.collation) ?
1283
tmp_field->type= field_type_arg;
1284
tmp_field->length=max_length;
1285
tmp_field->decimals=decimals;
1020
void Item::make_field(SendField *tmp_field)
1288
void Item::make_field(Send_field *tmp_field)
1022
1290
init_make_field(tmp_field, field_type());
1025
1294
enum_field_types Item::string_field_type() const
1027
1296
enum_field_types f_type= DRIZZLE_TYPE_VARCHAR;
1366
Compare two items using a given collation
1370
item item to compare with
1371
binary_cmp true <-> compare as binaries
1372
cs collation to use when comparing strings
1375
This method works exactly as Item::eq if the collation cs coincides with
1376
the collation of the compared objects. Otherwise, first the collations that
1377
differ from cs are replaced for cs and then the items are compared by
1378
Item::eq. After the comparison the original collations of items are
1382
1 compared items has been detected as equal
1098
1386
bool Item::eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs)
1100
1388
const CHARSET_INFO *save_cs= 0;
1265
Check if an item is a constant one and can be cached.
1267
@param arg [out] TRUE <=> Cache this item.
1269
@return TRUE Go deeper in item tree.
1270
@return FALSE Don't go deeper in item tree.
1273
bool Item::cache_const_expr_analyzer(unsigned char **arg)
1275
bool *cache_flag= (bool*)*arg;
1278
Item *item= real_item();
1280
Cache constant items unless it's a basic constant, constant field or
1281
a subselect (they use their own cache).
1284
!(item->basic_const_item() || item->type() == Item::FIELD_ITEM ||
1285
item->type() == SUBSELECT_ITEM ||
1287
Do not cache GET_USER_VAR() function as its const_item() may
1288
return TRUE for the current thread but it still may change
1289
during the execution.
1291
(item->type() == Item::FUNC_ITEM &&
1292
((Item_func*)item)->functype() == Item_func::GUSERVAR_FUNC)))
1300
Cache item if needed.
1302
@param arg TRUE <=> Cache this item.
1304
@return cache if cache needed.
1305
@return this otherwise.
1308
Item* Item::cache_const_expr_transformer(unsigned char *arg)
1312
*((bool*)arg)= false;
1313
Item_cache *cache= Item_cache::get_cache(this);
1323
bool Item::send(plugin::Client *client, String *buffer)
1575
This is only called from items that is not of type item_field.
1578
bool Item::send(Protocol *protocol, String *buffer)
1325
1580
bool result= false;
1326
1581
enum_field_types f_type;
1372
1627
DRIZZLE_TIME tm;
1373
1628
get_date(&tm, TIME_FUZZY_DATE);
1374
1629
if (!null_value)
1375
result= client->store(&tm);
1630
result= protocol->store(&tm);
1379
1634
if (null_value)
1380
result= client->store();
1635
result= protocol->store();
1640
bool Item_default_value::eq(const Item *item, bool binary_cmp) const
1642
return item->type() == DEFAULT_VALUE_ITEM &&
1643
((Item_default_value *)item)->arg->eq(arg, binary_cmp);
1647
bool Item_default_value::fix_fields(Session *session, Item **)
1650
Item_field *field_arg;
1659
if (!arg->fixed && arg->fix_fields(session, &arg))
1663
real_arg= arg->real_item();
1664
if (real_arg->type() != FIELD_ITEM)
1666
my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), arg->name);
1670
field_arg= (Item_field *)real_arg;
1671
if (field_arg->field->flags & NO_DEFAULT_VALUE_FLAG)
1673
my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), field_arg->field->field_name);
1676
if (!(def_field= (Field*) sql_alloc(field_arg->field->size_of())))
1678
memcpy(def_field, field_arg->field, field_arg->field->size_of());
1679
def_field->move_field_offset((my_ptrdiff_t)
1680
(def_field->table->s->default_values -
1681
def_field->table->record[0]));
1682
set_field(def_field);
1686
context->process_error(session);
1691
void Item_default_value::print(String *str, enum_query_type query_type)
1695
str->append(STRING_WITH_LEN("default"));
1698
str->append(STRING_WITH_LEN("default("));
1699
arg->print(str, query_type);
1704
int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
1708
if (field_arg->flags & NO_DEFAULT_VALUE_FLAG)
1710
if (field_arg->reset())
1712
my_message(ER_CANT_CREATE_GEOMETRY_OBJECT,
1713
ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0));
1718
push_warning_printf(field_arg->table->in_use,
1719
DRIZZLE_ERROR::WARN_LEVEL_WARN,
1720
ER_NO_DEFAULT_FOR_FIELD,
1721
ER(ER_NO_DEFAULT_FOR_FIELD),
1722
field_arg->field_name);
1726
field_arg->set_default();
1729
return Item_field::save_in_field(field_arg, no_conversions);
1734
This method like the walk method traverses the item tree, but at the
1735
same time it can replace some nodes in the tree.
1738
Item *Item_default_value::transform(Item_transformer transformer, unsigned char *args)
1740
Item *new_item= arg->transform(transformer, args);
1745
Session::change_item_tree() should be called only if the tree was
1746
really transformed, i.e. when a new item has been created.
1747
Otherwise we'll be allocating a lot of unnecessary memory for
1748
change records at each execution.
1750
if (arg != new_item)
1751
current_session->change_item_tree(&arg, new_item);
1752
return (this->*transformer)(args);
1384
1755
Item_result item_cmp_type(Item_result a,Item_result b)
1386
1757
if (a == STRING_RESULT && b == STRING_RESULT)
1630
2018
item->unsigned_flag) - len;
1632
2020
if (overflow > 0)
1633
dec= max(0, dec - overflow); // too long, discard fract
2021
dec= cmax(0, dec - overflow); // too long, discard fract
1635
len-= item->decimals - dec; // corrected value fits
2023
len -= item->decimals - dec; // corrected value fits
1638
new_field= new Field_decimal(len,
1642
item->unsigned_flag);
2026
new_field= new Field_new_decimal(len, maybe_null, item->name,
2027
dec, item->unsigned_flag);
1645
2030
case ROW_RESULT:
1661
2046
return new_field;
1664
Field *create_tmp_field(Session *session,
1670
Field **default_field,
1673
bool make_copy_field,
2049
Field *create_tmp_field(Session *session, Table *table,Item *item,
2050
Item::Type type, Item ***copy_func, Field **from_field,
2051
Field **default_field, bool group, bool modify_item,
2052
bool, bool make_copy_field,
1674
2053
uint32_t convert_blob_length)
1763
} /* namespace drizzled */
2144
Wrapper of hide_view_error call for Name_resolution_context error
2148
hide view underlying tables details in error messages
2151
/*****************************************************************************
2152
** Instantiate templates
2153
*****************************************************************************/
2155
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
2156
template class List<Item>;
2157
template class List_iterator<Item>;
2158
template class List_iterator_fast<Item>;
2159
template class List_iterator_fast<Item_field>;
2160
template class List<List_item>;