1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef drizzled_item_h
21
#define drizzled_item_h
1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
#ifdef USE_PRAGMA_INTERFACE
18
#pragma interface /* gcc class implementation */
25
23
void item_init(void); /* Init item functions */
76
74
derivation= dt.derivation;
77
75
repertoire= dt.repertoire;
79
void set(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
77
void set(CHARSET_INFO *collation_arg, Derivation derivation_arg)
81
79
collation= collation_arg;
82
80
derivation= derivation_arg;
83
81
set_repertoire_from_charset(collation_arg);
85
void set(const CHARSET_INFO * const collation_arg,
83
void set(CHARSET_INFO *collation_arg,
86
84
Derivation derivation_arg,
87
uint32_t repertoire_arg)
89
87
collation= collation_arg;
90
88
derivation= derivation_arg;
91
89
repertoire= repertoire_arg;
93
void set(const CHARSET_INFO * const collation_arg)
91
void set(CHARSET_INFO *collation_arg)
95
93
collation= collation_arg;
96
94
set_repertoire_from_charset(collation_arg);
98
96
void set(Derivation derivation_arg)
99
97
{ derivation= derivation_arg; }
100
bool aggregate(DTCollation &dt, uint32_t flags= 0);
101
bool set(DTCollation &dt1, DTCollation &dt2, uint32_t flags= 0)
98
bool aggregate(DTCollation &dt, uint flags= 0);
99
bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0)
102
100
{ set(dt1); return aggregate(dt2, flags); }
103
101
const char *derivation_name() const
164
162
virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
165
163
virtual void add(Hybrid_type *val, Field *f) const
166
164
{ val->real+= f->val_real(); }
167
virtual void div(Hybrid_type *val, uint64_t u) const
168
{ val->real/= uint64_t2double(u); }
165
virtual void div(Hybrid_type *val, ulonglong u) const
166
{ val->real/= ulonglong2double(u); }
170
virtual int64_t val_int(Hybrid_type *val,
171
bool unsigned_flag __attribute__((unused))) const
172
{ return (int64_t) rint(val->real); }
168
virtual longlong val_int(Hybrid_type *val,
169
bool unsigned_flag __attribute__((__unused__))) const
170
{ return (longlong) rint(val->real); }
173
171
virtual double val_real(Hybrid_type *val) const { return val->real; }
174
172
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
175
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
173
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
176
174
static const Hybrid_type_traits *instance();
177
175
Hybrid_type_traits() {}
178
176
virtual ~Hybrid_type_traits() {}
189
187
/* Hybrid_type operations. */
190
188
virtual void set_zero(Hybrid_type *val) const;
191
189
virtual void add(Hybrid_type *val, Field *f) const;
192
virtual void div(Hybrid_type *val, uint64_t u) const;
190
virtual void div(Hybrid_type *val, ulonglong u) const;
194
virtual int64_t val_int(Hybrid_type *val, bool unsigned_flag) const;
192
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const;
195
193
virtual double val_real(Hybrid_type *val) const;
196
194
virtual my_decimal *val_decimal(Hybrid_type *val,
197
my_decimal *buf __attribute__((unused))) const
195
my_decimal *buf __attribute__((__unused__))) const
198
196
{ return &val->dec_buf[val->used_dec_buf_no]; }
199
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
197
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
200
198
static const Hybrid_type_traits_decimal *instance();
201
199
Hybrid_type_traits_decimal() {};
214
212
{ val->integer= 0; }
215
213
virtual void add(Hybrid_type *val, Field *f) const
216
214
{ val->integer+= f->val_int(); }
217
virtual void div(Hybrid_type *val, uint64_t u) const
218
{ val->integer/= (int64_t) u; }
215
virtual void div(Hybrid_type *val, ulonglong u) const
216
{ val->integer/= (longlong) u; }
220
virtual int64_t val_int(Hybrid_type *val,
221
bool unsigned_flag __attribute__((unused))) const
218
virtual longlong val_int(Hybrid_type *val,
219
bool unsigned_flag __attribute__((__unused__))) const
222
220
{ return val->integer; }
223
221
virtual double val_real(Hybrid_type *val) const
224
222
{ return (double) val->integer; }
225
223
virtual my_decimal *val_decimal(Hybrid_type *val,
226
my_decimal *buf __attribute__((unused))) const
224
my_decimal *buf __attribute__((__unused__))) const
228
226
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
229
227
return &val->dec_buf[2];
231
229
virtual String *val_str(Hybrid_type *val, String *buf,
232
uint8_t decimals __attribute__((unused))) const
230
uint8 decimals __attribute__((__unused__))) const
233
231
{ buf->set(val->integer, &my_charset_bin); return buf;}
234
232
static const Hybrid_type_traits_integer *instance();
235
233
Hybrid_type_traits_integer() {};
279
277
join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
282
TableList *first_name_resolution_table;
280
TABLE_LIST *first_name_resolution_table;
284
282
Last table to search in the list of leaf table references that begins
285
283
with first_name_resolution_table.
287
TableList *last_name_resolution_table;
285
TABLE_LIST *last_name_resolution_table;
290
288
SELECT_LEX item belong to, in case of merged VIEW it can differ from
302
300
void *error_processor_data;
305
When true items are resolved in this context both against the
306
SELECT list and this->table_list. If false, items are resolved
303
When TRUE items are resolved in this context both against the
304
SELECT list and this->table_list. If FALSE, items are resolved
307
305
only against this->table_list.
309
307
bool resolve_in_select_list;
325
resolve_in_select_list= false;
323
resolve_in_select_list= FALSE;
326
324
error_processor= &dummy_error_processor;
327
325
first_name_resolution_table= NULL;
328
326
last_name_resolution_table= NULL;
331
void resolve_in_table_list_only(TableList *tables)
329
void resolve_in_table_list_only(TABLE_LIST *tables)
333
331
table_list= first_name_resolution_table= tables;
334
resolve_in_select_list= false;
332
resolve_in_select_list= FALSE;
337
335
void process_error(THD *thd)
348
346
class Name_resolution_context_state
351
TableList *save_table_list;
352
TableList *save_first_name_resolution_table;
353
TableList *save_next_name_resolution_table;
349
TABLE_LIST *save_table_list;
350
TABLE_LIST *save_first_name_resolution_table;
351
TABLE_LIST *save_next_name_resolution_table;
354
352
bool save_resolve_in_select_list;
355
TableList *save_next_local;
353
TABLE_LIST *save_next_local;
358
356
Name_resolution_context_state() {} /* Remove gcc warning */
361
359
/* Save the state of a name resolution context. */
362
void save_state(Name_resolution_context *context, TableList *table_list)
360
void save_state(Name_resolution_context *context, TABLE_LIST *table_list)
364
362
save_table_list= context->table_list;
365
363
save_first_name_resolution_table= context->first_name_resolution_table;
422
420
OUT: Parameter to be passed to the transformer
425
true Invoke the transformer
423
TRUE Invoke the transformer
429
typedef bool (Item::*Item_analyzer) (unsigned char **argp);
430
typedef Item* (Item::*Item_transformer) (unsigned char *arg);
427
typedef bool (Item::*Item_analyzer) (uchar **argp);
428
typedef Item* (Item::*Item_transformer) (uchar *arg);
431
429
typedef void (*Cond_traverser) (const Item *item, void *arg);
445
443
{ return sql_alloc(size); }
446
444
static void *operator new(size_t size, MEM_ROOT *mem_root)
447
445
{ return alloc_root(mem_root, size); }
448
static void operator delete(void *ptr __attribute__((unused)),
449
size_t size __attribute__((unused)))
446
static void operator delete(void *ptr __attribute__((__unused__)),
447
size_t size __attribute__((__unused__)))
450
448
{ TRASH(ptr, size); }
451
static void operator delete(void *ptr __attribute__((unused)),
452
MEM_ROOT *mem_root __attribute__((unused)))
449
static void operator delete(void *ptr __attribute__((__unused__)),
450
MEM_ROOT *mem_root __attribute__((__unused__)))
455
453
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
458
456
PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
459
457
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
460
458
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
461
PARAM_ITEM, DECIMAL_ITEM,
459
PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
460
XPATH_NODESET, XPATH_NODESET_CMP,
462
461
VIEW_FIXER_ITEM};
464
463
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
477
476
/* Original item name (if it was renamed)*/
478
477
char * orig_name;
481
uint32_t name_length; /* Length of name */
484
bool maybe_null; /* If item may be null */
485
bool null_value; /* if item is null */
488
bool fixed; /* If item fixed with fix_fields */
489
bool is_autogenerated_name; /* indicate was name of this Item
480
uint name_length; /* Length of name */
483
my_bool maybe_null; /* If item may be null */
484
my_bool null_value; /* if item is null */
485
my_bool unsigned_flag;
486
my_bool with_sum_func;
487
my_bool fixed; /* If item fixed with fix_fields */
488
my_bool is_autogenerated_name; /* indicate was name of this Item
490
489
autogenerated or set by user */
491
490
DTCollation collation;
492
bool with_subselect; /* If this item is a subselect or some
491
my_bool with_subselect; /* If this item is a subselect or some
493
492
of its arguments is or contains a
494
493
subselect. Computed by fix_fields. */
495
494
Item_result cmp_context; /* Comparison context */
512
511
} /*lint -e1509 */
513
void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs);
512
void set_name(const char *str, uint length, CHARSET_INFO *cs);
514
513
void rename(char *new_name);
515
514
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
516
515
virtual void cleanup();
517
516
virtual void make_field(Send_field *field);
518
Field *make_string_field(Table *table);
517
Field *make_string_field(TABLE *table);
519
518
virtual bool fix_fields(THD *, Item **);
521
520
Fix after some tables has been pulled out. Basically re-calculate all
522
521
attributes that are dependent on the tables.
524
virtual void fix_after_pullout(st_select_lex *new_parent __attribute__((unused)),
525
Item **ref __attribute__((unused))) {};
523
virtual void fix_after_pullout(st_select_lex *new_parent __attribute__((__unused__)),
524
Item **ref __attribute__((__unused__))) {};
528
527
should be used in case where we are sure that we do not need
559
558
val_int_endpoint()
560
left_endp false <=> The interval is "x < const" or "x <= const"
561
true <=> The interval is "x > const" or "x >= const"
559
left_endp FALSE <=> The interval is "x < const" or "x <= const"
560
TRUE <=> The interval is "x > const" or "x >= const"
563
incl_endp IN true <=> the comparison is '<' or '>'
564
false <=> the comparison is '<=' or '>='
562
incl_endp IN TRUE <=> the comparison is '<' or '>'
563
FALSE <=> the comparison is '<=' or '>='
565
564
OUT The same but for the "F(x) $CMP$ F(const)" comparison
584
583
The output range bound, which equal to the value of val_int()
585
584
- If the value of the function is NULL then the bound is the
586
smallest possible value of INT64_MIN
585
smallest possible value of LONGLONG_MIN
588
virtual int64_t val_int_endpoint(bool left_endp __attribute__((unused)),
589
bool *incl_endp __attribute__((unused)))
587
virtual longlong val_int_endpoint(bool left_endp __attribute__((__unused__)),
588
bool *incl_endp __attribute__((__unused__)))
590
589
{ assert(0); return 0; }
612
In case of NULL value return 0 and set null_value flag to true.
613
If value is not null null_value flag will be reset to false.
611
In case of NULL value return 0 and set null_value flag to TRUE.
612
If value is not null null_value flag will be reset to FALSE.
615
virtual int64_t val_int()=0;
614
virtual longlong val_int()=0;
617
616
This is just a shortcut to avoid the cast. You should still use
618
617
unsigned_flag to check the sign of the item.
620
inline uint64_t val_uint() { return (uint64_t) val_int(); }
619
inline ulonglong val_uint() { return (ulonglong) val_int(); }
622
621
Return string representation of this item object.
669
668
Return pointer on my_decimal (it can be other then passed via argument)
670
if value is not NULL (null_value flag will be reset to false).
669
if value is not NULL (null_value flag will be reset to FALSE).
671
670
In case of NULL value it return 0 pointer and set null_value flag
674
673
virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
676
675
Return boolean value of item.
679
false value is false or NULL
680
true value is true (not equal to 0)
678
FALSE value is false or NULL
679
TRUE value is true (not equal to 0)
682
681
virtual bool val_bool();
683
682
virtual String *val_nodeset(String*) { return 0; }
710
709
way as *val* methods do it.
712
711
virtual double val_result() { return val_real(); }
713
virtual int64_t val_int_result() { return val_int(); }
712
virtual longlong val_int_result() { return val_int(); }
714
713
virtual String *str_result(String* tmp) { return val_str(tmp); }
715
714
virtual my_decimal *val_decimal_result(my_decimal *val)
716
715
{ return val_decimal(val); }
738
737
/* cloning of constant items (0 if it is not const) */
739
738
virtual Item *clone_item() { return 0; }
740
739
virtual cond_result eq_cmp_result() const { return COND_OK; }
741
inline uint32_t float_length(uint32_t decimals_par) const
740
inline uint float_length(uint decimals_par) const
742
741
{ return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;}
743
virtual uint32_t decimal_precision() const;
742
virtual uint decimal_precision() const;
744
743
inline int decimal_int_part() const
745
744
{ return my_decimal_int_part(decimal_precision(), decimals); }
767
766
mysql_register_view().
769
768
virtual inline void print(String *str,
770
enum_query_type query_type __attribute__((unused)))
769
enum_query_type query_type __attribute__((__unused__)))
772
771
str->append(full_name());
775
774
void print_item_w_name(String *, enum_query_type query_type);
776
775
virtual void update_used_tables() {}
777
virtual void split_sum_func(THD *thd __attribute__((unused)),
778
Item **ref_pointer_array __attribute__((unused)),
779
List<Item> &fields __attribute__((unused))) {}
776
virtual void split_sum_func(THD *thd __attribute__((__unused__)),
777
Item **ref_pointer_array __attribute__((__unused__)),
778
List<Item> &fields __attribute__((__unused__))) {}
780
779
/* Called for items that really have to be split */
781
780
void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields,
782
781
Item **ref, bool skip_registered);
783
virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
784
virtual bool get_time(DRIZZLE_TIME *ltime);
785
virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
782
virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
783
virtual bool get_time(MYSQL_TIME *ltime);
784
virtual bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
786
785
{ return get_date(ltime,fuzzydate); }
788
787
The method allows to determine nullness of a complex expression
813
812
set field of temporary table for Item which can be switched on temporary
814
813
table during query processing (grouping and so on)
816
virtual void set_result_field(Field *field __attribute__((unused))) {}
815
virtual void set_result_field(Field *field __attribute__((__unused__))) {}
817
816
virtual bool is_result_field(void) { return 0; }
818
817
virtual bool is_bool_func(void) { return 0; }
819
virtual void save_in_result_field(bool no_conversions __attribute__((unused)))
818
virtual void save_in_result_field(bool no_conversions __attribute__((__unused__)))
822
821
set value of aggregate function in case of no rows for grouping were found
824
823
virtual void no_rows_in_result(void) {}
825
virtual Item *copy_or_same(THD *thd __attribute__((unused)))
824
virtual Item *copy_or_same(THD *thd __attribute__((__unused__)))
827
virtual Item *copy_andor_structure(THD *thd __attribute__((unused)))
826
virtual Item *copy_andor_structure(THD *thd __attribute__((__unused__)))
829
828
virtual Item *real_item(void) { return this; }
830
829
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
832
static const CHARSET_INFO *default_charset();
833
virtual const CHARSET_INFO *compare_collation() { return NULL; }
831
static CHARSET_INFO *default_charset();
832
virtual CHARSET_INFO *compare_collation() { return NULL; }
835
virtual bool walk(Item_processor processor __attribute__((unused)),
836
bool walk_subquery __attribute__((unused)),
834
virtual bool walk(Item_processor processor __attribute__((__unused__)),
835
bool walk_subquery __attribute__((__unused__)),
839
838
return (this->*processor)(arg);
842
virtual Item* transform(Item_transformer transformer, unsigned char *arg);
841
virtual Item* transform(Item_transformer transformer, uchar *arg);
845
844
This function performs a generic "compilation" of the Item tree.
857
856
i.e. analysis is performed top-down while transformation is done
860
virtual Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
861
Item_transformer transformer, unsigned char *arg_t)
859
virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
860
Item_transformer transformer, uchar *arg_t)
863
862
if ((this->*analyzer) (arg_p))
864
863
return ((this->*transformer) (arg_t));
868
virtual void traverse_cond(Cond_traverser traverser __attribute__((unused)),
867
virtual void traverse_cond(Cond_traverser traverser __attribute__((__unused__)),
870
traverse_order order __attribute__((unused)))
869
traverse_order order __attribute__((__unused__)))
872
871
(*traverser)(this, arg);
875
virtual bool remove_dependence_processor(unsigned char * arg __attribute__((unused)))
874
virtual bool remove_dependence_processor(uchar * arg __attribute__((__unused__)))
877
virtual bool remove_fixed(unsigned char * arg __attribute__((unused)))
876
virtual bool remove_fixed(uchar * arg __attribute__((__unused__)))
882
virtual bool cleanup_processor(unsigned char *arg __attribute__((unused)));
883
virtual bool collect_item_field_processor(unsigned char * arg __attribute__((unused)))
881
virtual bool cleanup_processor(uchar *arg __attribute__((__unused__)));
882
virtual bool collect_item_field_processor(uchar * arg __attribute__((__unused__)))
885
virtual bool find_item_in_field_list_processor(unsigned char *arg __attribute__((unused)))
884
virtual bool find_item_in_field_list_processor(uchar *arg __attribute__((__unused__)))
887
virtual bool change_context_processor(unsigned char *context __attribute__((unused)))
889
virtual bool reset_query_id_processor(unsigned char *query_id_arg __attribute__((unused)))
891
virtual bool register_field_in_read_map(unsigned char *arg __attribute__((unused)))
894
The next function differs from the previous one that a bitmap to be updated
895
is passed as unsigned char *arg.
897
virtual bool register_field_in_bitmap(unsigned char *arg __attribute__((unused)))
899
virtual bool subst_argument_checker(unsigned char **arg)
886
virtual bool change_context_processor(uchar *context __attribute__((__unused__)))
888
virtual bool reset_query_id_processor(uchar *query_id_arg __attribute__((__unused__)))
890
virtual bool register_field_in_read_map(uchar *arg __attribute__((__unused__)))
892
virtual bool subst_argument_checker(uchar **arg)
907
Check if an expression/function is allowed for a virtual column
909
check_vcol_func_processor()
912
TRUE Function not accepted
913
FALSE Function accepted
915
virtual bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
918
virtual Item *equal_fields_propagator(unsigned char * arg __attribute__((unused))) { return this; }
919
virtual bool set_no_const_sub(unsigned char *arg __attribute__((unused))) { return false; }
920
virtual Item *replace_equal_field(unsigned char * arg __attribute__((unused))) { return this; }
899
virtual Item *equal_fields_propagator(uchar * arg __attribute__((__unused__))) { return this; }
900
virtual bool set_no_const_sub(uchar *arg __attribute__((__unused__))) { return false; }
901
virtual Item *replace_equal_field(uchar * arg __attribute__((__unused__))) { return this; }
924
904
For SP local variable returns pointer to Item representing its
931
911
For SP local variable returns address of pointer to Item representing its
932
912
current value and pointer passed via parameter otherwise.
934
virtual Item **this_item_addr(THD *thd __attribute__((unused)), Item **addr_arg) { return addr_arg; }
914
virtual Item **this_item_addr(THD *thd __attribute__((__unused__)), Item **addr_arg) { return addr_arg; }
937
virtual uint32_t cols() { return 1; }
938
virtual Item* element_index(uint32_t i __attribute__((unused))) { return this; }
939
virtual Item** addr(uint32_t i __attribute__((unused))) { return 0; }
940
virtual bool check_cols(uint32_t c);
917
virtual uint cols() { return 1; }
918
virtual Item* element_index(uint i __attribute__((__unused__))) { return this; }
919
virtual Item** addr(uint i __attribute__((__unused__))) { return 0; }
920
virtual bool check_cols(uint c);
941
921
// It is not row => null inside is impossible
942
922
virtual bool null_inside() { return 0; }
943
923
// used in row subselects to get value of elements
944
924
virtual void bring_value() {}
946
Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
926
Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length);
947
927
virtual Item_field *filed_for_view_update() { return 0; }
949
virtual Item *neg_transformer(THD *thd __attribute__((unused))) { return NULL; }
950
virtual Item *update_value_transformer(unsigned char *select_arg __attribute__((unused))) { return this; }
951
virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
929
virtual Item *neg_transformer(THD *thd __attribute__((__unused__))) { return NULL; }
930
virtual Item *update_value_transformer(uchar *select_arg __attribute__((__unused__))) { return this; }
931
virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
952
932
void delete_self()
959
result_as_int64_t() must return true for Items representing DATE/TIME
939
result_as_longlong() must return TRUE for Items representing DATE/TIME
960
940
functions and DATE/TIME table fields.
961
941
Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
962
942
their values should be compared as integers (because the integer
963
943
representation is more precise than the string one).
965
virtual bool result_as_int64_t() { return false; }
945
virtual bool result_as_longlong() { return FALSE; }
966
946
bool is_datetime();
979
959
virtual bool is_expensive()
981
961
if (is_expensive_cache < 0)
982
is_expensive_cache= walk(&Item::is_expensive_processor, 0, (unsigned char*)0);
962
is_expensive_cache= walk(&Item::is_expensive_processor, 0, (uchar*)0);
983
963
return test(is_expensive_cache);
985
965
String *check_well_formed_result(String *str, bool send_error= 0);
986
bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs);
966
bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs);
1006
986
bool agg_item_collations(DTCollation &c, const char *name,
1007
Item **items, uint32_t nitems, uint32_t flags, int item_sep);
987
Item **items, uint nitems, uint flags, int item_sep);
1008
988
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
1009
Item **items, uint32_t nitems, uint32_t flags);
989
Item **items, uint nitems, uint flags);
1010
990
bool agg_item_charsets(DTCollation &c, const char *name,
1011
Item **items, uint32_t nitems, uint32_t flags, int item_sep);
991
Item **items, uint nitems, uint flags, int item_sep);
1014
994
class Item_num: public Item_basic_constant
1046
1026
stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
1047
1027
if index value is not known.
1049
uint32_t cached_field_index;
1029
uint cached_field_index;
1051
1031
Cached pointer to table which contains this field, used for the same reason
1052
1032
by prep. stmt. too in case then we have not-fully qualified field.
1053
1033
0 - means no cached value.
1055
TableList *cached_table;
1035
TABLE_LIST *cached_table;
1056
1036
st_select_lex *depended_from;
1057
1037
Item_ident(Name_resolution_context *context_arg,
1058
1038
const char *db_name_arg, const char *table_name_arg,
1060
1040
Item_ident(THD *thd, Item_ident *item);
1061
1041
const char *full_name() const;
1062
1042
void cleanup();
1063
bool remove_dependence_processor(unsigned char * arg);
1043
bool remove_dependence_processor(uchar * arg);
1064
1044
virtual void print(String *str, enum_query_type query_type);
1065
virtual bool change_context_processor(unsigned char *cntx)
1066
{ context= (Name_resolution_context *)cntx; return false; }
1045
virtual bool change_context_processor(uchar *cntx)
1046
{ context= (Name_resolution_context *)cntx; return FALSE; }
1067
1047
friend bool insert_fields(THD *thd, Name_resolution_context *context,
1068
1048
const char *db_name,
1069
1049
const char *table_name, List_iterator<Item> *it,
1086
1066
enum Type type() const { return FIELD_ITEM; }
1087
1067
double val_real() { return field->val_real(); }
1088
int64_t val_int() { return field->val_int(); }
1068
longlong val_int() { return field->val_int(); }
1089
1069
String *val_str(String *str) { return field->val_str(str); }
1090
1070
my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); }
1091
1071
void make_field(Send_field *tmp_field);
1132
1112
enum Type type() const { return FIELD_ITEM; }
1133
1113
bool eq(const Item *item, bool binary_cmp) const;
1134
1114
double val_real();
1136
1116
my_decimal *val_decimal(my_decimal *);
1137
1117
String *val_str(String*);
1138
1118
double val_result();
1139
int64_t val_int_result();
1119
longlong val_int_result();
1140
1120
String *str_result(String* tmp);
1141
1121
my_decimal *val_decimal_result(my_decimal *);
1142
1122
bool val_bool_result();
1165
1145
return MONOTONIC_STRICT_INCREASING;
1167
int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
1147
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
1168
1148
Field *get_tmp_table_field() { return result_field; }
1169
Field *tmp_table_field(Table *t_arg __attribute__((unused))) { return result_field; }
1170
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1171
bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1172
bool get_time(DRIZZLE_TIME *ltime);
1149
Field *tmp_table_field(TABLE *t_arg __attribute__((__unused__))) { return result_field; }
1150
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1151
bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate);
1152
bool get_time(MYSQL_TIME *ltime);
1173
1153
bool is_null() { return field->is_null(); }
1174
1154
void update_null_value();
1175
1155
Item *get_tmp_table_item(THD *thd);
1176
bool collect_item_field_processor(unsigned char * arg);
1177
bool find_item_in_field_list_processor(unsigned char *arg);
1178
bool register_field_in_read_map(unsigned char *arg);
1179
bool register_field_in_bitmap(unsigned char *arg);
1180
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1156
bool collect_item_field_processor(uchar * arg);
1157
bool find_item_in_field_list_processor(uchar *arg);
1158
bool register_field_in_read_map(uchar *arg);
1182
1159
void cleanup();
1183
bool result_as_int64_t()
1160
bool result_as_longlong()
1185
return field->can_be_compared_as_int64_t();
1162
return field->can_be_compared_as_longlong();
1187
1164
Item_equal *find_item_equal(COND_EQUAL *cond_equal);
1188
bool subst_argument_checker(unsigned char **arg);
1189
Item *equal_fields_propagator(unsigned char *arg);
1190
bool set_no_const_sub(unsigned char *arg);
1191
Item *replace_equal_field(unsigned char *arg);
1192
inline uint32_t max_disp_length() { return field->max_display_length(); }
1165
bool subst_argument_checker(uchar **arg);
1166
Item *equal_fields_propagator(uchar *arg);
1167
bool set_no_const_sub(uchar *arg);
1168
Item *replace_equal_field(uchar *arg);
1169
inline uint32 max_disp_length() { return field->max_display_length(); }
1193
1170
Item_field *filed_for_view_update() { return this; }
1194
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1171
Item *safe_charset_converter(CHARSET_INFO *tocs);
1195
1172
int fix_outer_field(THD *thd, Field **field, Item **reference);
1196
virtual Item *update_value_transformer(unsigned char *select_arg);
1173
virtual Item *update_value_transformer(uchar *select_arg);
1197
1174
virtual void print(String *str, enum_query_type query_type);
1176
void dbug_print() {}
1199
1178
friend class Item_default_value;
1200
1179
friend class Item_insert_value;
1201
1180
friend class st_select_lex_unit;
1215
1194
enum Type type() const { return NULL_ITEM; }
1216
1195
bool eq(const Item *item, bool binary_cmp) const;
1217
1196
double val_real();
1219
1198
String *val_str(String *str);
1220
1199
my_decimal *val_decimal(my_decimal *);
1221
1200
int save_in_field(Field *field, bool no_conversions);
1222
1201
int save_safe_in_field(Field *field);
1223
1202
bool send(Protocol *protocol, String *str);
1224
1203
enum Item_result result_type () const { return STRING_RESULT; }
1225
enum_field_types field_type() const { return DRIZZLE_TYPE_NULL; }
1204
enum_field_types field_type() const { return MYSQL_TYPE_NULL; }
1226
1205
bool basic_const_item() const { return 1; }
1227
1206
Item *clone_item() { return new Item_null(name); }
1228
1207
bool is_null() { return 1; }
1230
1209
virtual inline void print(String *str,
1231
enum_query_type query_type __attribute__((unused)))
1210
enum_query_type query_type __attribute__((__unused__)))
1233
1212
str->append(STRING_WITH_LEN("NULL"));
1236
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1237
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1215
Item *safe_charset_converter(CHARSET_INFO *tocs);
1241
1218
class Item_null_result :public Item_null
1293
1268
struct CONVERSION_INFO
1295
const CHARSET_INFO *character_set_client;
1296
const CHARSET_INFO *character_set_of_placeholder;
1270
CHARSET_INFO *character_set_client;
1271
CHARSET_INFO *character_set_of_placeholder;
1298
1273
This points at character set of connection if conversion
1299
1274
to it is required (i. e. if placeholder typecode is not BLOB).
1300
1275
Otherwise it's equal to character_set_client (to simplify
1301
1276
check in convert_str_value()).
1303
const CHARSET_INFO *final_character_set_of_str_value;
1278
CHARSET_INFO *final_character_set_of_str_value;
1308
1283
/* Cached values for virtual methods to save us one switch. */
1313
1288
Used when this item is used in a temporary table.
1314
1289
This is NOT placeholder metadata sent to client, as this value
1315
1290
is assigned after sending metadata (in setup_one_conversion_function).
1316
For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
1291
For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
1317
1292
in result set and placeholders metadata, no matter what type you will
1318
1293
supply for this placeholder in mysql_stmt_execute.
1322
1297
Offset of placeholder inside statement text. Used to create
1323
1298
no-placeholders version of this statement for the binary log.
1325
uint32_t pos_in_query;
1327
Item_param(uint32_t pos_in_query_arg);
1302
Item_param(uint pos_in_query_arg);
1329
1304
enum Item_result result_type () const { return item_result_type; }
1330
1305
enum Type type() const { return item_type; }
1331
1306
enum_field_types field_type() const { return param_type; }
1333
1308
double val_real();
1335
1310
my_decimal *val_decimal(my_decimal*);
1336
1311
String *val_str(String*);
1337
bool get_time(DRIZZLE_TIME *tm);
1338
bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
1312
bool get_time(MYSQL_TIME *tm);
1313
bool get_date(MYSQL_TIME *tm, uint fuzzydate);
1339
1314
int save_in_field(Field *field, bool no_conversions);
1341
1316
void set_null();
1342
void set_int(int64_t i, uint32_t max_length_arg);
1317
void set_int(longlong i, uint32 max_length_arg);
1343
1318
void set_double(double i);
1344
void set_decimal(char *str, ulong length);
1319
void set_decimal(const char *str, ulong length);
1345
1320
bool set_str(const char *str, ulong length);
1346
1321
bool set_longdata(const char *str, ulong length);
1347
void set_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type type,
1348
uint32_t max_length_arg);
1322
void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
1349
1323
bool set_from_user_var(THD *thd, const user_var_entry *entry);
1379
1353
words, avoid pointing at one item from two different nodes of the tree.
1380
1354
Return a new basic constant item if parameter value is a basic
1381
1355
constant, assert otherwise. This method is called only if
1382
basic_const_item returned true.
1356
basic_const_item returned TRUE.
1384
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1358
Item *safe_charset_converter(CHARSET_INFO *tocs);
1385
1359
Item *clone_item();
1387
1361
Implement by-value equality evaluation if parameter value
1388
1362
is set and is a basic constant (integer, real or string).
1389
Otherwise return false.
1363
Otherwise return FALSE.
1391
1365
bool eq(const Item *item, bool binary_cmp) const;
1392
1366
/** Item is a argument to a limit clause. */
1397
1371
class Item_int :public Item_num
1401
Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS)
1375
Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
1376
:value((longlong) i)
1403
1377
{ max_length=length; fixed= 1; }
1404
Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1378
Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1406
1380
{ max_length=length; fixed= 1; }
1407
Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1381
Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1409
1383
{ max_length=length; fixed= 1; unsigned_flag= 1; }
1410
Item_int(const char *str_arg,int64_t i,uint32_t length) :value(i)
1384
Item_int(const char *str_arg,longlong i,uint length) :value(i)
1411
1385
{ max_length=length; name=(char*) str_arg; fixed= 1; }
1412
Item_int(const char *str_arg, uint32_t length=64);
1386
Item_int(const char *str_arg, uint length=64);
1413
1387
enum Type type() const { return INT_ITEM; }
1414
1388
enum Item_result result_type () const { return INT_RESULT; }
1415
enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
1416
int64_t val_int() { assert(fixed == 1); return value; }
1389
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
1390
longlong val_int() { assert(fixed == 1); return value; }
1417
1391
double val_real() { assert(fixed == 1); return (double) value; }
1418
1392
my_decimal *val_decimal(my_decimal *);
1419
1393
String *val_str(String*);
1422
1396
Item *clone_item() { return new Item_int(name,value,max_length); }
1423
1397
virtual void print(String *str, enum_query_type query_type);
1424
1398
Item_num *neg() { value= -value; return this; }
1425
uint32_t decimal_precision() const
1399
uint decimal_precision() const
1426
1400
{ return (uint)(max_length - test(value < 0)); }
1427
1401
bool eq(const Item *, bool binary_cmp) const;
1428
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1433
1405
class Item_uint :public Item_int
1436
Item_uint(const char *str_arg, uint32_t length);
1437
Item_uint(uint64_t i) :Item_int((uint64_t) i, 10) {}
1438
Item_uint(const char *str_arg, int64_t i, uint32_t length);
1408
Item_uint(const char *str_arg, uint length);
1409
Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {}
1410
Item_uint(const char *str_arg, longlong i, uint length);
1439
1411
double val_real()
1440
{ assert(fixed == 1); return uint64_t2double((uint64_t)value); }
1412
{ assert(fixed == 1); return ulonglong2double((ulonglong)value); }
1441
1413
String *val_str(String*);
1442
1414
Item *clone_item() { return new Item_uint(name, value, max_length); }
1443
1415
int save_in_field(Field *field, bool no_conversions);
1444
1416
virtual void print(String *str, enum_query_type query_type);
1445
1417
Item_num *neg ();
1446
uint32_t decimal_precision() const { return max_length; }
1447
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1418
uint decimal_precision() const { return max_length; }
1456
1426
my_decimal decimal_value;
1458
Item_decimal(const char *str_arg, uint32_t length, const CHARSET_INFO * const charset);
1428
Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset);
1459
1429
Item_decimal(const char *str, const my_decimal *val_arg,
1460
uint32_t decimal_par, uint32_t length);
1430
uint decimal_par, uint length);
1461
1431
Item_decimal(my_decimal *value_par);
1462
Item_decimal(int64_t val, bool unsig);
1432
Item_decimal(longlong val, bool unsig);
1463
1433
Item_decimal(double val, int precision, int scale);
1464
Item_decimal(const unsigned char *bin, int precision, int scale);
1434
Item_decimal(const uchar *bin, int precision, int scale);
1466
1436
enum Type type() const { return DECIMAL_ITEM; }
1467
1437
enum Item_result result_type () const { return DECIMAL_RESULT; }
1468
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDECIMAL; }
1438
enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
1470
1440
double val_real();
1471
1441
String *val_str(String*);
1472
my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
1442
my_decimal *val_decimal(my_decimal *val __attribute__((__unused__)))
1473
1443
{ return &decimal_value; }
1474
1444
int save_in_field(Field *field, bool no_conversions);
1475
1445
bool basic_const_item() const { return 1; }
1500
1468
// Item_real() :value(0) {}
1501
Item_float(const char *str_arg, uint32_t length);
1502
Item_float(const char *str,double val_arg,uint32_t decimal_par,uint32_t length)
1469
Item_float(const char *str_arg, uint length);
1470
Item_float(const char *str,double val_arg,uint decimal_par,uint length)
1503
1471
:value(val_arg)
1505
1473
presentation= name=(char*) str;
1506
decimals=(uint8_t) decimal_par;
1474
decimals=(uint8) decimal_par;
1507
1475
max_length=length;
1510
Item_float(double value_par, uint32_t decimal_par) :presentation(0), value(value_par)
1478
Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1512
decimals= (uint8_t) decimal_par;
1480
decimals= (uint8) decimal_par;
1515
1483
int save_in_field(Field *field, bool no_conversions);
1516
1484
enum Type type() const { return REAL_ITEM; }
1517
enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE; }
1485
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
1518
1486
double val_real() { assert(fixed == 1); return value; }
1521
1489
assert(fixed == 1);
1522
if (value <= (double) INT64_MIN)
1526
else if (value >= (double) (uint64_t) INT64_MAX)
1530
return (int64_t) rint(value);
1490
if (value <= (double) LONGLONG_MIN)
1492
return LONGLONG_MIN;
1494
else if (value >= (double) (ulonglong) LONGLONG_MAX)
1496
return LONGLONG_MAX;
1498
return (longlong) rint(value);
1532
1500
String *val_str(String*);
1533
1501
my_decimal *val_decimal(my_decimal *);
1545
1513
const char *func_name;
1547
Item_static_float_func(const char *str, double val_arg, uint32_t decimal_par,
1549
:Item_float(NULL, val_arg, decimal_par, length), func_name(str)
1515
Item_static_float_func(const char *str, double val_arg, uint decimal_par,
1517
:Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1552
1520
virtual inline void print(String *str,
1553
enum_query_type query_type __attribute__((unused)))
1521
enum_query_type query_type __attribute__((__unused__)))
1555
1523
str->append(func_name);
1558
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1559
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1526
Item *safe_charset_converter(CHARSET_INFO *tocs);
1564
1530
class Item_string :public Item_basic_constant
1567
Item_string(const char *str,uint32_t length,
1568
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1569
uint32_t repertoire= MY_REPERTOIRE_UNICODE30)
1570
: m_cs_specified(false)
1533
Item_string(const char *str,uint length,
1534
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
1535
uint repertoire= MY_REPERTOIRE_UNICODE30)
1536
: m_cs_specified(FALSE)
1572
1538
str_value.set_or_copy_aligned(str, length, cs);
1573
1539
collation.set(cs, dv, repertoire);
1594
1560
decimals= NOT_FIXED_DEC;
1597
Item_string(const char *name_par, const char *str, uint32_t length,
1598
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1599
uint32_t repertoire= MY_REPERTOIRE_UNICODE30)
1600
: m_cs_specified(false)
1563
Item_string(const char *name_par, const char *str, uint length,
1564
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
1565
uint repertoire= MY_REPERTOIRE_UNICODE30)
1566
: m_cs_specified(FALSE)
1602
1568
str_value.set_or_copy_aligned(str, length, cs);
1603
1569
collation.set(cs, dv, repertoire);
1611
1577
This is used in stored procedures to avoid memory leaks and
1612
1578
does a deep copy of its argument.
1614
void set_str_with_copy(const char *str_arg, uint32_t length_arg)
1580
void set_str_with_copy(const char *str_arg, uint length_arg)
1616
1582
str_value.copy(str_arg, length_arg, collation.collation);
1617
1583
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1633
1599
my_decimal *val_decimal(my_decimal *);
1634
1600
int save_in_field(Field *field, bool no_conversions);
1635
1601
enum Item_result result_type () const { return STRING_RESULT; }
1636
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1602
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1637
1603
bool basic_const_item() const { return 1; }
1638
1604
bool eq(const Item *item, bool binary_cmp) const;
1639
1605
Item *clone_item()
1641
1607
return new Item_string(name, str_value.ptr(),
1642
1608
str_value.length(), collation.collation);
1644
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1645
inline void append(char *str, uint32_t length)
1610
Item *safe_charset_converter(CHARSET_INFO *tocs);
1611
inline void append(char *str, uint length)
1647
1613
str_value.append(str, length);
1648
1614
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1700
1664
const char *func_name;
1702
Item_static_string_func(const char *name_par, const char *str, uint32_t length,
1703
const CHARSET_INFO * const cs,
1666
Item_static_string_func(const char *name_par, const char *str, uint length,
1704
1668
Derivation dv= DERIVATION_COERCIBLE)
1705
:Item_string(NULL, str, length, cs, dv), func_name(name_par)
1669
:Item_string(NullS, str, length, cs, dv), func_name(name_par)
1707
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1671
Item *safe_charset_converter(CHARSET_INFO *tocs);
1709
1673
virtual inline void print(String *str,
1710
enum_query_type query_type __attribute__((unused)))
1674
enum_query_type query_type __attribute__((__unused__)))
1712
1676
str->append(func_name);
1714
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1732
1694
class Item_blob :public Item_string
1735
Item_blob(const char *name, uint32_t length) :
1697
Item_blob(const char *name, uint length) :
1736
1698
Item_string(name, length, &my_charset_bin)
1737
1699
{ max_length= length; }
1738
1700
enum Type type() const { return TYPE_HOLDER; }
1739
enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
1701
enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
1749
1711
class Item_empty_string :public Item_string
1752
Item_empty_string(const char *header,uint32_t length, const CHARSET_INFO * cs= NULL) :
1714
Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) :
1753
1715
Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1754
1716
{ name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1755
1717
void make_field(Send_field *field);
1761
1723
enum_field_types int_field_type;
1763
Item_return_int(const char *name_arg, uint32_t length,
1764
enum_field_types field_type_arg, int64_t value= 0)
1725
Item_return_int(const char *name_arg, uint length,
1726
enum_field_types field_type_arg, longlong value= 0)
1765
1727
:Item_int(name_arg, value, length), int_field_type(field_type_arg)
1767
1729
unsigned_flag=1;
1776
1738
Item_hex_string() {}
1777
Item_hex_string(const char *str,uint32_t str_length);
1739
Item_hex_string(const char *str,uint str_length);
1778
1740
enum Type type() const { return VARBIN_ITEM; }
1779
1741
double val_real()
1781
1743
assert(fixed == 1);
1782
return (double) (uint64_t) Item_hex_string::val_int();
1744
return (double) (ulonglong) Item_hex_string::val_int();
1785
1747
bool basic_const_item() const { return 1; }
1786
1748
String *val_str(String*) { assert(fixed == 1); return &str_value; }
1787
1749
my_decimal *val_decimal(my_decimal *);
1788
1750
int save_in_field(Field *field, bool no_conversions);
1789
1751
enum Item_result result_type () const { return STRING_RESULT; }
1790
1752
enum Item_result cast_to_int_type() const { return INT_RESULT; }
1791
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1753
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1792
1754
virtual void print(String *str, enum_query_type query_type);
1793
1755
bool eq(const Item *item, bool binary_cmp) const;
1794
virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1795
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1756
virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
1800
1760
class Item_bin_string: public Item_hex_string
1803
Item_bin_string(const char *str,uint32_t str_length);
1763
Item_bin_string(const char *str,uint str_length);
1806
1766
class Item_result_field :public Item /* Item with result field */
1860
1818
Item_ref(Name_resolution_context *context_arg, Item **item,
1861
1819
const char *table_name_arg, const char *field_name_arg,
1862
bool alias_name_used_arg= false);
1820
bool alias_name_used_arg= FALSE);
1864
1822
/* Constructor need to process subselect with temporary tables (see Item) */
1865
1823
Item_ref(THD *thd, Item_ref *item)
1871
1829
return ref && (*ref)->eq(it, binary_cmp);
1873
1831
double val_real();
1875
1833
my_decimal *val_decimal(my_decimal *);
1876
1834
bool val_bool();
1877
1835
String *val_str(String* tmp);
1878
1836
bool is_null();
1879
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1837
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1880
1838
double val_result();
1881
int64_t val_int_result();
1839
longlong val_int_result();
1882
1840
String *str_result(String* tmp);
1883
1841
my_decimal *val_decimal_result(my_decimal *);
1884
1842
bool val_bool_result();
1914
1872
return ref ? (*ref)->real_item() : this;
1916
bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
1874
bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1917
1875
{ return (*ref)->walk(processor, walk_subquery, arg); }
1918
1876
virtual void print(String *str, enum_query_type query_type);
1919
bool result_as_int64_t()
1877
bool result_as_longlong()
1921
return (*ref)->result_as_int64_t();
1879
return (*ref)->result_as_longlong();
1923
1881
void cleanup();
1924
1882
Item_field *filed_for_view_update()
1926
1884
virtual Ref_Type ref_type() { return REF; }
1928
1886
// Row emulation: forwarding of ROW-related calls to ref
1931
1889
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1933
Item* element_index(uint32_t i)
1891
Item* element_index(uint i)
1935
1893
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1937
Item** addr(uint32_t i)
1939
1897
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1941
bool check_cols(uint32_t c)
1899
bool check_cols(uint c)
1943
1901
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
1944
1902
: Item::check_cols(c);
1966
1924
Item_direct_ref(Name_resolution_context *context_arg, Item **item,
1967
1925
const char *table_name_arg,
1968
1926
const char *field_name_arg,
1969
bool alias_name_used_arg= false)
1927
bool alias_name_used_arg= FALSE)
1970
1928
:Item_ref(context_arg, item, table_name_arg,
1971
1929
field_name_arg, alias_name_used_arg)
1974
1932
Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
1976
1934
double val_real();
1978
1936
String *val_str(String* tmp);
1979
1937
my_decimal *val_decimal(my_decimal *);
1980
1938
bool val_bool();
1981
1939
bool is_null();
1982
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1940
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1983
1941
virtual Ref_Type ref_type() { return DIRECT_REF; }
2087
2045
:Item_ref(context_arg, item, table_name_arg, field_name_arg),
2088
2046
owner(master) {}
2089
2047
double val_real();
2091
2049
String* val_str(String* s);
2092
2050
my_decimal *val_decimal(my_decimal *);
2093
2051
bool val_bool();
2094
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
2052
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
2095
2053
virtual void print(String *str, enum_query_type query_type);
2097
2055
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2161
2119
int err_not_used;
2162
2120
char *end_not_used;
2163
2121
return (null_value ? 0.0 :
2164
my_strntod(str_value.charset(), (char*) str_value.ptr(),
2165
str_value.length(), &end_not_used, &err_not_used));
2122
my_strntod(str_value.charset(), (char*) str_value.ptr(),
2123
str_value.length(), &end_not_used, &err_not_used));
2170
return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
2171
str_value.length(),10, (char**) 0,
2128
return null_value ? 0LL : my_strntoll(str_value.charset(),str_value.ptr(),
2129
str_value.length(),10, (char**) 0,
2174
2132
String *val_str(String*);
2175
2133
my_decimal *val_decimal(my_decimal *);
2176
2134
void make_field(Send_field *field) { item->make_field(field); }
2178
2136
int save_in_field(Field *field,
2179
bool no_conversions __attribute__((unused)))
2137
bool no_conversions __attribute__((__unused__)))
2181
2139
return save_str_value_in_field(field, &str_value);
2237
2195
class Cached_item_field :public Cached_item
2239
unsigned char *buff;
2205
org_ptr= field->ptr;
2206
fprintf(DBUG_FILE, "new: ");
2207
field->dbug_print();
2209
fprintf(DBUG_FILE, ", old: ");
2210
field->dbug_print();
2211
field->ptr= org_ptr;
2212
fprintf(DBUG_FILE, "\n");
2244
2214
Cached_item_field(Field *arg_field) : field(arg_field)
2246
2216
field= arg_field;
2247
2217
/* TODO: take the memory allocation below out of the constructor. */
2248
buff= (unsigned char*) sql_calloc(length=field->pack_length());
2218
buff= (uchar*) sql_calloc(length=field->pack_length());
2250
2220
bool cmp(void);
2269
2239
int save_in_field(Field *field_arg, bool no_conversions);
2270
2240
table_map used_tables() const { return (table_map)0L; }
2272
bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
2242
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2274
2244
return arg->walk(processor, walk_subquery, args) ||
2275
2245
(this->*processor)(args);
2278
Item *transform(Item_transformer transformer, unsigned char *args);
2248
Item *transform(Item_transformer transformer, uchar *args);
2310
2280
table_map used_tables() const { return RAND_TABLE_BIT; }
2312
bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
2282
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2314
2284
return arg->walk(processor, walk_subquery, args) ||
2315
2285
(this->*processor)(args);
2317
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
2370
2338
virtual void print(String *str, enum_query_type query_type);
2371
2339
bool eq_def(Field *field)
2373
return cached_field ? cached_field->eq_def (field) : false;
2341
return cached_field ? cached_field->eq_def (field) : FALSE;
2375
2343
bool eq(const Item *item,
2376
bool binary_cmp __attribute__((unused))) const
2344
bool binary_cmp __attribute__((__unused__))) const
2378
2346
return this == item;
2383
2351
class Item_cache_int: public Item_cache
2388
2356
Item_cache_int(): Item_cache(), value(0) {}
2389
2357
Item_cache_int(enum_field_types field_type_arg):
2390
2358
Item_cache(field_type_arg), value(0) {}
2392
2360
void store(Item *item);
2393
void store(Item *item, int64_t val_arg);
2361
void store(Item *item, longlong val_arg);
2394
2362
double val_real() { assert(fixed == 1); return (double) value; }
2395
int64_t val_int() { assert(fixed == 1); return value; }
2363
longlong val_int() { assert(fixed == 1); return value; }
2396
2364
String* val_str(String *str);
2397
2365
my_decimal *val_decimal(my_decimal *);
2398
2366
enum Item_result result_type() const { return INT_RESULT; }
2399
bool result_as_int64_t() { return true; }
2367
bool result_as_longlong() { return TRUE; }
2442
2410
Item_cache(), value(0),
2443
2411
is_varbinary(item->type() == FIELD_ITEM &&
2444
2412
((const Item_field *) item)->field->type() ==
2445
DRIZZLE_TYPE_VARCHAR &&
2413
MYSQL_TYPE_VARCHAR &&
2446
2414
!((const Item_field *) item)->field->has_charset())
2448
2416
void store(Item *item);
2449
2417
double val_real();
2451
2419
String* val_str(String *) { assert(fixed == 1); return value; }
2452
2420
my_decimal *val_decimal(my_decimal *);
2453
2421
enum Item_result result_type() const { return STRING_RESULT; }
2454
const CHARSET_INFO *charset() const { return value->charset(); };
2422
CHARSET_INFO *charset() const { return value->charset(); };
2455
2423
int save_in_field(Field *field, bool no_conversions);
2458
2426
class Item_cache_row: public Item_cache
2460
2428
Item_cache **values;
2461
uint32_t item_count;
2462
2430
bool save_array;
2464
2432
Item_cache_row()
2504
2472
enum Item_result result_type() const { return ROW_RESULT; }
2506
uint32_t cols() { return item_count; }
2507
Item *element_index(uint32_t i) { return values[i]; }
2508
Item **addr(uint32_t i) { return (Item **) (values + i); }
2509
bool check_cols(uint32_t c);
2474
uint cols() { return item_count; }
2475
Item *element_index(uint i) { return values[i]; }
2476
Item **addr(uint i) { return (Item **) (values + i); }
2477
bool check_cols(uint c);
2510
2478
bool null_inside();
2511
2479
void bring_value();
2512
2480
void keep_array() { save_array= 1; }
2546
2514
enum_field_types field_type() const { return fld_type; };
2547
2515
enum Type type() const { return TYPE_HOLDER; }
2548
2516
double val_real();
2550
2518
my_decimal *val_decimal(my_decimal *);
2551
2519
String *val_str(String*);
2552
2520
bool join_types(THD *thd, Item *);
2553
Field *make_field_by_type(Table *table);
2554
static uint32_t display_length(Item *item);
2521
Field *make_field_by_type(TABLE *table);
2522
static uint32 display_length(Item *item);
2555
2523
static enum_field_types get_real_type(Item *);