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, bool unsigned_flag) const
169
{ return (longlong) rint(val->real); }
173
170
virtual double val_real(Hybrid_type *val) const { return val->real; }
174
171
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;
172
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
176
173
static const Hybrid_type_traits *instance();
177
174
Hybrid_type_traits() {}
178
175
virtual ~Hybrid_type_traits() {}
189
186
/* Hybrid_type operations. */
190
187
virtual void set_zero(Hybrid_type *val) const;
191
188
virtual void add(Hybrid_type *val, Field *f) const;
192
virtual void div(Hybrid_type *val, uint64_t u) const;
189
virtual void div(Hybrid_type *val, ulonglong u) const;
194
virtual int64_t val_int(Hybrid_type *val, bool unsigned_flag) const;
191
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const;
195
192
virtual double val_real(Hybrid_type *val) const;
196
virtual my_decimal *val_decimal(Hybrid_type *val,
197
my_decimal *buf __attribute__((unused))) const
193
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
198
194
{ return &val->dec_buf[val->used_dec_buf_no]; }
199
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
195
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
200
196
static const Hybrid_type_traits_decimal *instance();
201
197
Hybrid_type_traits_decimal() {};
214
210
{ val->integer= 0; }
215
211
virtual void add(Hybrid_type *val, Field *f) const
216
212
{ val->integer+= f->val_int(); }
217
virtual void div(Hybrid_type *val, uint64_t u) const
218
{ val->integer/= (int64_t) u; }
213
virtual void div(Hybrid_type *val, ulonglong u) const
214
{ val->integer/= (longlong) u; }
220
virtual int64_t val_int(Hybrid_type *val,
221
bool unsigned_flag __attribute__((unused))) const
216
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const
222
217
{ return val->integer; }
223
218
virtual double val_real(Hybrid_type *val) const
224
219
{ return (double) val->integer; }
225
virtual my_decimal *val_decimal(Hybrid_type *val,
226
my_decimal *buf __attribute__((unused))) const
220
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
228
222
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
229
223
return &val->dec_buf[2];
231
virtual String *val_str(Hybrid_type *val, String *buf,
232
uint8_t decimals __attribute__((unused))) const
225
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const
233
226
{ buf->set(val->integer, &my_charset_bin); return buf;}
234
227
static const Hybrid_type_traits_integer *instance();
235
228
Hybrid_type_traits_integer() {};
348
341
class Name_resolution_context_state
351
TableList *save_table_list;
352
TableList *save_first_name_resolution_table;
353
TableList *save_next_name_resolution_table;
344
TABLE_LIST *save_table_list;
345
TABLE_LIST *save_first_name_resolution_table;
346
TABLE_LIST *save_next_name_resolution_table;
354
347
bool save_resolve_in_select_list;
355
TableList *save_next_local;
348
TABLE_LIST *save_next_local;
358
351
Name_resolution_context_state() {} /* Remove gcc warning */
361
354
/* Save the state of a name resolution context. */
362
void save_state(Name_resolution_context *context, TableList *table_list)
355
void save_state(Name_resolution_context *context, TABLE_LIST *table_list)
364
357
save_table_list= context->table_list;
365
358
save_first_name_resolution_table= context->first_name_resolution_table;
436
429
Item(const Item &); /* Prevent use of these */
437
430
void operator=(Item &);
438
431
/* Cache of the result of is_expensive(). */
439
int8_t is_expensive_cache;
440
virtual bool is_expensive_processor(unsigned char *arg __attribute__((unused)))
432
int8 is_expensive_cache;
433
virtual bool is_expensive_processor(uchar *arg) { return 0; }
444
436
static void *operator new(size_t size)
445
437
{ return sql_alloc(size); }
446
438
static void *operator new(size_t size, MEM_ROOT *mem_root)
447
439
{ return alloc_root(mem_root, size); }
448
static void operator delete(void *ptr __attribute__((unused)),
449
size_t size __attribute__((unused)))
450
{ TRASH(ptr, size); }
451
static void operator delete(void *ptr __attribute__((unused)),
452
MEM_ROOT *mem_root __attribute__((unused)))
440
static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
441
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
455
443
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
456
444
INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
458
446
PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
459
447
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
460
448
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
461
PARAM_ITEM, DECIMAL_ITEM,
449
PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
450
XPATH_NODESET, XPATH_NODESET_CMP,
462
451
VIEW_FIXER_ITEM};
464
453
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
477
466
/* Original item name (if it was renamed)*/
478
467
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
470
uint name_length; /* Length of name */
473
my_bool maybe_null; /* If item may be null */
474
my_bool null_value; /* if item is null */
475
my_bool unsigned_flag;
476
my_bool with_sum_func;
477
my_bool fixed; /* If item fixed with fix_fields */
478
my_bool is_autogenerated_name; /* indicate was name of this Item
490
479
autogenerated or set by user */
491
480
DTCollation collation;
492
bool with_subselect; /* If this item is a subselect or some
481
my_bool with_subselect; /* If this item is a subselect or some
493
482
of its arguments is or contains a
494
483
subselect. Computed by fix_fields. */
495
484
Item_result cmp_context; /* Comparison context */
512
501
} /*lint -e1509 */
513
void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs);
502
void set_name(const char *str, uint length, CHARSET_INFO *cs);
514
503
void rename(char *new_name);
515
504
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
516
505
virtual void cleanup();
517
506
virtual void make_field(Send_field *field);
518
Field *make_string_field(Table *table);
507
Field *make_string_field(TABLE *table);
519
508
virtual bool fix_fields(THD *, Item **);
521
510
Fix after some tables has been pulled out. Basically re-calculate all
522
511
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))) {};
513
virtual void fix_after_pullout(st_select_lex *new_parent, Item **ref) {};
528
516
should be used in case where we are sure that we do not need
690
677
my_decimal *val_decimal_from_string(my_decimal *decimal_value);
691
678
my_decimal *val_decimal_from_date(my_decimal *decimal_value);
692
679
my_decimal *val_decimal_from_time(my_decimal *decimal_value);
693
int64_t val_int_from_decimal();
680
longlong val_int_from_decimal();
694
681
double val_real_from_decimal();
696
683
int save_time_in_field(Field *field);
697
684
int save_date_in_field(Field *field);
698
685
int save_str_value_in_field(Field *field, String *result);
700
virtual Field *get_tmp_table_field(void) { return 0; }
687
virtual Field *get_tmp_table_field() { return 0; }
701
688
/* This is also used to create fields in CREATE ... SELECT: */
702
virtual Field *tmp_table_field(Table *t_arg __attribute__((unused)))
704
virtual const char *full_name(void) const { return name ? name : "???"; }
689
virtual Field *tmp_table_field(TABLE *t_arg) { return 0; }
690
virtual const char *full_name() const { return name ? name : "???"; }
707
693
*result* family of methods is analog of *val* family (see above) but
766
752
query and why they should be generated from the Item-tree, @see
767
753
mysql_register_view().
769
virtual inline void print(String *str,
770
enum_query_type query_type __attribute__((unused)))
755
virtual inline void print(String *str, enum_query_type query_type)
772
757
str->append(full_name());
775
760
void print_item_w_name(String *, enum_query_type query_type);
776
761
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))) {}
762
virtual void split_sum_func(THD *thd, Item **ref_pointer_array,
763
List<Item> &fields) {}
780
764
/* Called for items that really have to be split */
781
765
void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields,
782
766
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)
767
virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
768
virtual bool get_time(MYSQL_TIME *ltime);
769
virtual bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
786
770
{ return get_date(ltime,fuzzydate); }
788
772
The method allows to determine nullness of a complex expression
808
792
Item_cond_and and subquery-related item) enable special optimizations
809
793
when they are "top level".
811
virtual void top_level_item(void) {}
795
virtual void top_level_item() {}
813
797
set field of temporary table for Item which can be switched on temporary
814
798
table during query processing (grouping and so on)
816
virtual void set_result_field(Field *field __attribute__((unused))) {}
817
virtual bool is_result_field(void) { return 0; }
818
virtual bool is_bool_func(void) { return 0; }
819
virtual void save_in_result_field(bool no_conversions __attribute__((unused)))
800
virtual void set_result_field(Field *field) {}
801
virtual bool is_result_field() { return 0; }
802
virtual bool is_bool_func() { return 0; }
803
virtual void save_in_result_field(bool no_conversions) {}
822
805
set value of aggregate function in case of no rows for grouping were found
824
virtual void no_rows_in_result(void) {}
825
virtual Item *copy_or_same(THD *thd __attribute__((unused)))
827
virtual Item *copy_andor_structure(THD *thd __attribute__((unused)))
829
virtual Item *real_item(void) { return this; }
807
virtual void no_rows_in_result() {}
808
virtual Item *copy_or_same(THD *thd) { return this; }
809
virtual Item *copy_andor_structure(THD *thd) { return this; }
810
virtual Item *real_item() { return this; }
830
811
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; }
813
static CHARSET_INFO *default_charset();
814
virtual CHARSET_INFO *compare_collation() { return NULL; }
835
virtual bool walk(Item_processor processor __attribute__((unused)),
836
bool walk_subquery __attribute__((unused)),
816
virtual bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
839
818
return (this->*processor)(arg);
842
virtual Item* transform(Item_transformer transformer, unsigned char *arg);
821
virtual Item* transform(Item_transformer transformer, uchar *arg);
845
824
This function performs a generic "compilation" of the Item tree.
857
836
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)
839
virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
840
Item_transformer transformer, uchar *arg_t)
863
842
if ((this->*analyzer) (arg_p))
864
843
return ((this->*transformer) (arg_t));
868
virtual void traverse_cond(Cond_traverser traverser __attribute__((unused)),
870
traverse_order order __attribute__((unused)))
847
virtual void traverse_cond(Cond_traverser traverser,
848
void *arg, traverse_order order)
872
850
(*traverser)(this, arg);
875
virtual bool remove_dependence_processor(unsigned char * arg __attribute__((unused)))
877
virtual bool remove_fixed(unsigned char * 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)))
885
virtual bool find_item_in_field_list_processor(unsigned char *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)
853
virtual bool remove_dependence_processor(uchar * arg) { return 0; }
854
virtual bool remove_fixed(uchar * arg) { fixed= 0; return 0; }
855
virtual bool cleanup_processor(uchar *arg);
856
virtual bool collect_item_field_processor(uchar * arg) { return 0; }
857
virtual bool find_item_in_field_list_processor(uchar *arg) { return 0; }
858
virtual bool change_context_processor(uchar *context) { return 0; }
859
virtual bool reset_query_id_processor(uchar *query_id_arg) { return 0; }
860
virtual bool register_field_in_read_map(uchar *arg) { return 0; }
861
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; }
868
virtual Item *equal_fields_propagator(uchar * arg) { return this; }
869
virtual bool set_no_const_sub(uchar *arg) { return FALSE; }
870
virtual Item *replace_equal_field(uchar * arg) { return this; }
924
873
For SP local variable returns pointer to Item representing its
925
874
current value and pointer to current Item otherwise.
927
virtual Item *this_item(void) { return this; }
928
virtual const Item *this_item(void) const { return this; }
876
virtual Item *this_item() { return this; }
877
virtual const Item *this_item() const { return this; }
931
880
For SP local variable returns address of pointer to Item representing its
932
881
current value and pointer passed via parameter otherwise.
934
virtual Item **this_item_addr(THD *thd __attribute__((unused)), Item **addr_arg) { return addr_arg; }
883
virtual Item **this_item_addr(THD *thd, 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);
886
virtual uint cols() { return 1; }
887
virtual Item* element_index(uint i) { return this; }
888
virtual Item** addr(uint i) { return 0; }
889
virtual bool check_cols(uint c);
941
890
// It is not row => null inside is impossible
942
891
virtual bool null_inside() { return 0; }
943
892
// used in row subselects to get value of elements
944
893
virtual void bring_value() {}
946
Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
895
Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length);
947
896
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);
898
virtual Item *neg_transformer(THD *thd) { return NULL; }
899
virtual Item *update_value_transformer(uchar *select_arg) { return this; }
900
virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
952
901
void delete_self()
1006
955
bool agg_item_collations(DTCollation &c, const char *name,
1007
Item **items, uint32_t nitems, uint32_t flags, int item_sep);
956
Item **items, uint nitems, uint flags, int item_sep);
1008
957
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
1009
Item **items, uint32_t nitems, uint32_t flags);
958
Item **items, uint nitems, uint flags);
1010
959
bool agg_item_charsets(DTCollation &c, const char *name,
1011
Item **items, uint32_t nitems, uint32_t flags, int item_sep);
960
Item **items, uint nitems, uint flags, int item_sep);
1014
963
class Item_num: public Item_basic_constant
1060
1009
Item_ident(THD *thd, Item_ident *item);
1061
1010
const char *full_name() const;
1062
1011
void cleanup();
1063
bool remove_dependence_processor(unsigned char * arg);
1012
bool remove_dependence_processor(uchar * arg);
1064
1013
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; }
1014
virtual bool change_context_processor(uchar *cntx)
1015
{ context= (Name_resolution_context *)cntx; return FALSE; }
1067
1016
friend bool insert_fields(THD *thd, Name_resolution_context *context,
1068
1017
const char *db_name,
1069
1018
const char *table_name, List_iterator<Item> *it,
1165
1114
return MONOTONIC_STRICT_INCREASING;
1167
int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
1116
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
1168
1117
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);
1118
Field *tmp_table_field(TABLE *t_arg) { return result_field; }
1119
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1120
bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate);
1121
bool get_time(MYSQL_TIME *ltime);
1173
1122
bool is_null() { return field->is_null(); }
1174
1123
void update_null_value();
1175
1124
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)))
1125
bool collect_item_field_processor(uchar * arg);
1126
bool find_item_in_field_list_processor(uchar *arg);
1127
bool register_field_in_read_map(uchar *arg);
1182
1128
void cleanup();
1183
bool result_as_int64_t()
1129
bool result_as_longlong()
1185
return field->can_be_compared_as_int64_t();
1131
return field->can_be_compared_as_longlong();
1187
1133
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(); }
1134
bool subst_argument_checker(uchar **arg);
1135
Item *equal_fields_propagator(uchar *arg);
1136
bool set_no_const_sub(uchar *arg);
1137
Item *replace_equal_field(uchar *arg);
1138
inline uint32 max_disp_length() { return field->max_display_length(); }
1193
1139
Item_field *filed_for_view_update() { return this; }
1194
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1140
Item *safe_charset_converter(CHARSET_INFO *tocs);
1195
1141
int fix_outer_field(THD *thd, Field **field, Item **reference);
1196
virtual Item *update_value_transformer(unsigned char *select_arg);
1142
virtual Item *update_value_transformer(uchar *select_arg);
1197
1143
virtual void print(String *str, enum_query_type query_type);
1148
fprintf(DBUG_FILE, "<field ");
1151
fprintf(DBUG_FILE, "'%s.%s': ", field->table->alias, field->field_name);
1152
field->dbug_print();
1155
fprintf(DBUG_FILE, "NULL");
1157
fprintf(DBUG_FILE, ", result_field: ");
1160
fprintf(DBUG_FILE, "'%s.%s': ",
1161
result_field->table->alias, result_field->field_name);
1162
result_field->dbug_print();
1165
fprintf(DBUG_FILE, "NULL");
1166
fprintf(DBUG_FILE, ">\n");
1199
1170
friend class Item_default_value;
1200
1171
friend class Item_insert_value;
1201
1172
friend class st_select_lex_unit;
1215
1186
enum Type type() const { return NULL_ITEM; }
1216
1187
bool eq(const Item *item, bool binary_cmp) const;
1217
1188
double val_real();
1219
1190
String *val_str(String *str);
1220
1191
my_decimal *val_decimal(my_decimal *);
1221
1192
int save_in_field(Field *field, bool no_conversions);
1222
1193
int save_safe_in_field(Field *field);
1223
1194
bool send(Protocol *protocol, String *str);
1224
1195
enum Item_result result_type () const { return STRING_RESULT; }
1225
enum_field_types field_type() const { return DRIZZLE_TYPE_NULL; }
1196
enum_field_types field_type() const { return MYSQL_TYPE_NULL; }
1226
1197
bool basic_const_item() const { return 1; }
1227
1198
Item *clone_item() { return new Item_null(name); }
1228
1199
bool is_null() { return 1; }
1230
virtual inline void print(String *str,
1231
enum_query_type query_type __attribute__((unused)))
1201
virtual inline void print(String *str, enum_query_type query_type)
1233
1203
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)))
1206
Item *safe_charset_converter(CHARSET_INFO *tocs);
1241
1209
class Item_null_result :public Item_null
1322
1288
Offset of placeholder inside statement text. Used to create
1323
1289
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);
1293
Item_param(uint pos_in_query_arg);
1329
1295
enum Item_result result_type () const { return item_result_type; }
1330
1296
enum Type type() const { return item_type; }
1331
1297
enum_field_types field_type() const { return param_type; }
1333
1299
double val_real();
1335
1301
my_decimal *val_decimal(my_decimal*);
1336
1302
String *val_str(String*);
1337
bool get_time(DRIZZLE_TIME *tm);
1338
bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
1303
bool get_time(MYSQL_TIME *tm);
1304
bool get_date(MYSQL_TIME *tm, uint fuzzydate);
1339
1305
int save_in_field(Field *field, bool no_conversions);
1341
1307
void set_null();
1342
void set_int(int64_t i, uint32_t max_length_arg);
1308
void set_int(longlong i, uint32 max_length_arg);
1343
1309
void set_double(double i);
1344
void set_decimal(char *str, ulong length);
1310
void set_decimal(const char *str, ulong length);
1345
1311
bool set_str(const char *str, ulong length);
1346
1312
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);
1313
void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
1349
1314
bool set_from_user_var(THD *thd, const user_var_entry *entry);
1397
1362
class Item_int :public Item_num
1401
Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS)
1366
Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
1367
:value((longlong) i)
1403
1368
{ max_length=length; fixed= 1; }
1404
Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1369
Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1406
1371
{ max_length=length; fixed= 1; }
1407
Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1372
Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1409
1374
{ max_length=length; fixed= 1; unsigned_flag= 1; }
1410
Item_int(const char *str_arg,int64_t i,uint32_t length) :value(i)
1375
Item_int(const char *str_arg,longlong i,uint length) :value(i)
1411
1376
{ max_length=length; name=(char*) str_arg; fixed= 1; }
1412
Item_int(const char *str_arg, uint32_t length=64);
1377
Item_int(const char *str_arg, uint length=64);
1413
1378
enum Type type() const { return INT_ITEM; }
1414
1379
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; }
1417
double val_real() { assert(fixed == 1); return (double) value; }
1380
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
1381
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
1382
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
1418
1383
my_decimal *val_decimal(my_decimal *);
1419
1384
String *val_str(String*);
1420
1385
int save_in_field(Field *field, bool no_conversions);
1422
1387
Item *clone_item() { return new Item_int(name,value,max_length); }
1423
1388
virtual void print(String *str, enum_query_type query_type);
1424
1389
Item_num *neg() { value= -value; return this; }
1425
uint32_t decimal_precision() const
1390
uint decimal_precision() const
1426
1391
{ return (uint)(max_length - test(value < 0)); }
1427
1392
bool eq(const Item *, bool binary_cmp) const;
1428
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1433
1396
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);
1399
Item_uint(const char *str_arg, uint length);
1400
Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {}
1401
Item_uint(const char *str_arg, longlong i, uint length);
1439
1402
double val_real()
1440
{ assert(fixed == 1); return uint64_t2double((uint64_t)value); }
1403
{ DBUG_ASSERT(fixed == 1); return ulonglong2double((ulonglong)value); }
1441
1404
String *val_str(String*);
1442
1405
Item *clone_item() { return new Item_uint(name, value, max_length); }
1443
1406
int save_in_field(Field *field, bool no_conversions);
1444
1407
virtual void print(String *str, enum_query_type query_type);
1445
1408
Item_num *neg ();
1446
uint32_t decimal_precision() const { return max_length; }
1447
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1409
uint decimal_precision() const { return max_length; }
1456
1417
my_decimal decimal_value;
1458
Item_decimal(const char *str_arg, uint32_t length, const CHARSET_INFO * const charset);
1419
Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset);
1459
1420
Item_decimal(const char *str, const my_decimal *val_arg,
1460
uint32_t decimal_par, uint32_t length);
1421
uint decimal_par, uint length);
1461
1422
Item_decimal(my_decimal *value_par);
1462
Item_decimal(int64_t val, bool unsig);
1423
Item_decimal(longlong val, bool unsig);
1463
1424
Item_decimal(double val, int precision, int scale);
1464
Item_decimal(const unsigned char *bin, int precision, int scale);
1425
Item_decimal(const uchar *bin, int precision, int scale);
1466
1427
enum Type type() const { return DECIMAL_ITEM; }
1467
1428
enum Item_result result_type () const { return DECIMAL_RESULT; }
1468
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDECIMAL; }
1429
enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
1470
1431
double val_real();
1471
1432
String *val_str(String*);
1472
my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
1473
{ return &decimal_value; }
1433
my_decimal *val_decimal(my_decimal *val) { return &decimal_value; }
1474
1434
int save_in_field(Field *field, bool no_conversions);
1475
1435
bool basic_const_item() const { return 1; }
1476
1436
Item *clone_item()
1500
1458
// 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)
1459
Item_float(const char *str_arg, uint length);
1460
Item_float(const char *str,double val_arg,uint decimal_par,uint length)
1503
1461
:value(val_arg)
1505
1463
presentation= name=(char*) str;
1506
decimals=(uint8_t) decimal_par;
1464
decimals=(uint8) decimal_par;
1507
1465
max_length=length;
1510
Item_float(double value_par, uint32_t decimal_par) :presentation(0), value(value_par)
1468
Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1512
decimals= (uint8_t) decimal_par;
1470
decimals= (uint8) decimal_par;
1515
1473
int save_in_field(Field *field, bool no_conversions);
1516
1474
enum Type type() const { return REAL_ITEM; }
1517
enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE; }
1518
double val_real() { assert(fixed == 1); return value; }
1475
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
1476
double val_real() { DBUG_ASSERT(fixed == 1); return value; }
1522
if (value <= (double) INT64_MIN)
1526
else if (value >= (double) (uint64_t) INT64_MAX)
1530
return (int64_t) rint(value);
1479
DBUG_ASSERT(fixed == 1);
1480
if (value <= (double) LONGLONG_MIN)
1482
return LONGLONG_MIN;
1484
else if (value >= (double) (ulonglong) LONGLONG_MAX)
1486
return LONGLONG_MAX;
1488
return (longlong) rint(value);
1532
1490
String *val_str(String*);
1533
1491
my_decimal *val_decimal(my_decimal *);
1545
1503
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)
1505
Item_static_float_func(const char *str, double val_arg, uint decimal_par,
1507
:Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1552
virtual inline void print(String *str,
1553
enum_query_type query_type __attribute__((unused)))
1510
virtual inline void print(String *str, enum_query_type query_type)
1555
1512
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)))
1515
Item *safe_charset_converter(CHARSET_INFO *tocs);
1564
1519
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)
1522
Item_string(const char *str,uint length,
1523
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
1524
uint repertoire= MY_REPERTOIRE_UNICODE30)
1525
: m_cs_specified(FALSE)
1572
1527
str_value.set_or_copy_aligned(str, length, cs);
1573
1528
collation.set(cs, dv, repertoire);
1594
1549
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)
1552
Item_string(const char *name_par, const char *str, uint length,
1553
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
1554
uint repertoire= MY_REPERTOIRE_UNICODE30)
1555
: m_cs_specified(FALSE)
1602
1557
str_value.set_or_copy_aligned(str, length, cs);
1603
1558
collation.set(cs, dv, repertoire);
1700
1653
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,
1655
Item_static_string_func(const char *name_par, const char *str, uint length,
1704
1657
Derivation dv= DERIVATION_COERCIBLE)
1705
:Item_string(NULL, str, length, cs, dv), func_name(name_par)
1658
:Item_string(NullS, str, length, cs, dv), func_name(name_par)
1707
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1660
Item *safe_charset_converter(CHARSET_INFO *tocs);
1709
virtual inline void print(String *str,
1710
enum_query_type query_type __attribute__((unused)))
1662
virtual inline void print(String *str, enum_query_type query_type)
1712
1664
str->append(func_name);
1714
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1776
1726
Item_hex_string() {}
1777
Item_hex_string(const char *str,uint32_t str_length);
1727
Item_hex_string(const char *str,uint str_length);
1778
1728
enum Type type() const { return VARBIN_ITEM; }
1779
1729
double val_real()
1782
return (double) (uint64_t) Item_hex_string::val_int();
1731
DBUG_ASSERT(fixed == 1);
1732
return (double) (ulonglong) Item_hex_string::val_int();
1785
1735
bool basic_const_item() const { return 1; }
1786
String *val_str(String*) { assert(fixed == 1); return &str_value; }
1736
String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; }
1787
1737
my_decimal *val_decimal(my_decimal *);
1788
1738
int save_in_field(Field *field, bool no_conversions);
1789
1739
enum Item_result result_type () const { return STRING_RESULT; }
1790
1740
enum Item_result cast_to_int_type() const { return INT_RESULT; }
1791
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1741
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1792
1742
virtual void print(String *str, enum_query_type query_type);
1793
1743
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)))
1744
virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
1800
1748
class Item_bin_string: public Item_hex_string
1803
Item_bin_string(const char *str,uint32_t str_length);
1751
Item_bin_string(const char *str,uint str_length);
1806
1754
class Item_result_field :public Item /* Item with result field */
2161
2106
int err_not_used;
2162
2107
char *end_not_used;
2163
2108
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));
2109
my_strntod(str_value.charset(), (char*) str_value.ptr(),
2110
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,
2115
return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
2116
str_value.length(),10, (char**) 0,
2174
2119
String *val_str(String*);
2175
2120
my_decimal *val_decimal(my_decimal *);
2176
2121
void make_field(Send_field *field) { item->make_field(field); }
2178
int save_in_field(Field *field,
2179
bool no_conversions __attribute__((unused)))
2123
int save_in_field(Field *field, bool no_conversions)
2181
2125
return save_str_value_in_field(field, &str_value);
2383
2337
class Item_cache_int: public Item_cache
2388
2342
Item_cache_int(): Item_cache(), value(0) {}
2389
2343
Item_cache_int(enum_field_types field_type_arg):
2390
2344
Item_cache(field_type_arg), value(0) {}
2392
2346
void store(Item *item);
2393
void store(Item *item, int64_t val_arg);
2394
double val_real() { assert(fixed == 1); return (double) value; }
2395
int64_t val_int() { assert(fixed == 1); return value; }
2347
void store(Item *item, longlong val_arg);
2348
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
2349
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
2396
2350
String* val_str(String *str);
2397
2351
my_decimal *val_decimal(my_decimal *);
2398
2352
enum Item_result result_type() const { return INT_RESULT; }
2399
bool result_as_int64_t() { return true; }
2353
bool result_as_longlong() { return TRUE; }