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
168
166
{ val->real/= uint64_t2double(u); }
170
168
virtual int64_t val_int(Hybrid_type *val,
171
bool unsigned_flag __attribute__((unused))) const
169
bool unsigned_flag __attribute__((__unused__))) const
172
170
{ return (int64_t) 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() {}
194
192
virtual int64_t 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() {};
218
216
{ val->integer/= (int64_t) u; }
220
218
virtual int64_t val_int(Hybrid_type *val,
221
bool unsigned_flag __attribute__((unused))) const
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
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;
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
585
584
- If the value of the function is NULL then the bound is the
586
585
smallest possible value of INT64_MIN
588
virtual int64_t val_int_endpoint(bool left_endp __attribute__((unused)),
589
bool *incl_endp __attribute__((unused)))
587
virtual int64_t val_int_endpoint(bool left_endp __attribute__((__unused__)),
588
bool *incl_endp __attribute__((__unused__)))
590
589
{ assert(0); return 0; }
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()
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)
1045
virtual bool change_context_processor(uchar *cntx)
1066
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,
1167
1147
int64_t 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
1160
bool result_as_int64_t()
1185
1162
return field->can_be_compared_as_int64_t();
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);
1199
1176
friend class Item_default_value;
1222
1199
int save_safe_in_field(Field *field);
1223
1200
bool send(Protocol *protocol, String *str);
1224
1201
enum Item_result result_type () const { return STRING_RESULT; }
1225
enum_field_types field_type() const { return DRIZZLE_TYPE_NULL; }
1202
enum_field_types field_type() const { return MYSQL_TYPE_NULL; }
1226
1203
bool basic_const_item() const { return 1; }
1227
1204
Item *clone_item() { return new Item_null(name); }
1228
1205
bool is_null() { return 1; }
1230
1207
virtual inline void print(String *str,
1231
enum_query_type query_type __attribute__((unused)))
1208
enum_query_type query_type __attribute__((__unused__)))
1233
1210
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)))
1213
Item *safe_charset_converter(CHARSET_INFO *tocs);
1241
1216
class Item_null_result :public Item_null
1293
1266
struct CONVERSION_INFO
1295
const CHARSET_INFO *character_set_client;
1296
const CHARSET_INFO *character_set_of_placeholder;
1268
CHARSET_INFO *character_set_client;
1269
CHARSET_INFO *character_set_of_placeholder;
1298
1271
This points at character set of connection if conversion
1299
1272
to it is required (i. e. if placeholder typecode is not BLOB).
1300
1273
Otherwise it's equal to character_set_client (to simplify
1301
1274
check in convert_str_value()).
1303
const CHARSET_INFO *final_character_set_of_str_value;
1276
CHARSET_INFO *final_character_set_of_str_value;
1308
1281
/* Cached values for virtual methods to save us one switch. */
1313
1286
Used when this item is used in a temporary table.
1314
1287
This is NOT placeholder metadata sent to client, as this value
1315
1288
is assigned after sending metadata (in setup_one_conversion_function).
1316
For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
1289
For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
1317
1290
in result set and placeholders metadata, no matter what type you will
1318
1291
supply for this placeholder in mysql_stmt_execute.
1334
1307
int64_t val_int();
1335
1308
my_decimal *val_decimal(my_decimal*);
1336
1309
String *val_str(String*);
1337
bool get_time(DRIZZLE_TIME *tm);
1338
bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
1310
bool get_time(MYSQL_TIME *tm);
1311
bool get_date(MYSQL_TIME *tm, uint fuzzydate);
1339
1312
int save_in_field(Field *field, bool no_conversions);
1341
1314
void set_null();
1342
void set_int(int64_t i, uint32_t max_length_arg);
1315
void set_int(int64_t i, uint32 max_length_arg);
1343
1316
void set_double(double i);
1344
void set_decimal(char *str, ulong length);
1317
void set_decimal(const char *str, ulong length);
1345
1318
bool set_str(const char *str, ulong length);
1346
1319
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);
1320
void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
1349
1321
bool set_from_user_var(THD *thd, const user_var_entry *entry);
1401
Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS)
1373
Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
1402
1374
:value((int64_t) i)
1403
1375
{ max_length=length; fixed= 1; }
1404
Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1376
Item_int(int64_t i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1406
1378
{ max_length=length; fixed= 1; }
1407
Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1379
Item_int(uint64_t i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1408
1380
:value((int64_t)i)
1409
1381
{ max_length=length; fixed= 1; unsigned_flag= 1; }
1410
Item_int(const char *str_arg,int64_t i,uint32_t length) :value(i)
1382
Item_int(const char *str_arg,int64_t i,uint length) :value(i)
1411
1383
{ max_length=length; name=(char*) str_arg; fixed= 1; }
1412
Item_int(const char *str_arg, uint32_t length=64);
1384
Item_int(const char *str_arg, uint length=64);
1413
1385
enum Type type() const { return INT_ITEM; }
1414
1386
enum Item_result result_type () const { return INT_RESULT; }
1415
enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
1387
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
1416
1388
int64_t val_int() { assert(fixed == 1); return value; }
1417
1389
double val_real() { assert(fixed == 1); return (double) value; }
1418
1390
my_decimal *val_decimal(my_decimal *);
1422
1394
Item *clone_item() { return new Item_int(name,value,max_length); }
1423
1395
virtual void print(String *str, enum_query_type query_type);
1424
1396
Item_num *neg() { value= -value; return this; }
1425
uint32_t decimal_precision() const
1397
uint decimal_precision() const
1426
1398
{ return (uint)(max_length - test(value < 0)); }
1427
1399
bool eq(const Item *, bool binary_cmp) const;
1428
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1433
1403
class Item_uint :public Item_int
1436
Item_uint(const char *str_arg, uint32_t length);
1406
Item_uint(const char *str_arg, uint length);
1437
1407
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, int64_t i, uint length);
1439
1409
double val_real()
1440
1410
{ assert(fixed == 1); return uint64_t2double((uint64_t)value); }
1441
1411
String *val_str(String*);
1456
1424
my_decimal decimal_value;
1458
Item_decimal(const char *str_arg, uint32_t length, const CHARSET_INFO * const charset);
1426
Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset);
1459
1427
Item_decimal(const char *str, const my_decimal *val_arg,
1460
uint32_t decimal_par, uint32_t length);
1428
uint decimal_par, uint length);
1461
1429
Item_decimal(my_decimal *value_par);
1462
1430
Item_decimal(int64_t val, bool unsig);
1463
1431
Item_decimal(double val, int precision, int scale);
1464
Item_decimal(const unsigned char *bin, int precision, int scale);
1432
Item_decimal(const uchar *bin, int precision, int scale);
1466
1434
enum Type type() const { return DECIMAL_ITEM; }
1467
1435
enum Item_result result_type () const { return DECIMAL_RESULT; }
1468
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDECIMAL; }
1436
enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
1469
1437
int64_t val_int();
1470
1438
double val_real();
1471
1439
String *val_str(String*);
1472
my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
1440
my_decimal *val_decimal(my_decimal *val __attribute__((__unused__)))
1473
1441
{ return &decimal_value; }
1474
1442
int save_in_field(Field *field, bool no_conversions);
1475
1443
bool basic_const_item() const { return 1; }
1500
1466
// 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)
1467
Item_float(const char *str_arg, uint length);
1468
Item_float(const char *str,double val_arg,uint decimal_par,uint length)
1503
1469
:value(val_arg)
1505
1471
presentation= name=(char*) str;
1506
decimals=(uint8_t) decimal_par;
1472
decimals=(uint8) decimal_par;
1507
1473
max_length=length;
1510
Item_float(double value_par, uint32_t decimal_par) :presentation(0), value(value_par)
1476
Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1512
decimals= (uint8_t) decimal_par;
1478
decimals= (uint8) decimal_par;
1515
1481
int save_in_field(Field *field, bool no_conversions);
1516
1482
enum Type type() const { return REAL_ITEM; }
1517
enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE; }
1483
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
1518
1484
double val_real() { assert(fixed == 1); return value; }
1519
1485
int64_t val_int()
1545
1511
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)
1513
Item_static_float_func(const char *str, double val_arg, uint decimal_par,
1515
:Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1552
1518
virtual inline void print(String *str,
1553
enum_query_type query_type __attribute__((unused)))
1519
enum_query_type query_type __attribute__((__unused__)))
1555
1521
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)))
1524
Item *safe_charset_converter(CHARSET_INFO *tocs);
1564
1528
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)
1531
Item_string(const char *str,uint length,
1532
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
1533
uint repertoire= MY_REPERTOIRE_UNICODE30)
1570
1534
: m_cs_specified(false)
1572
1536
str_value.set_or_copy_aligned(str, length, cs);
1594
1558
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)
1561
Item_string(const char *name_par, const char *str, uint length,
1562
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
1563
uint repertoire= MY_REPERTOIRE_UNICODE30)
1600
1564
: m_cs_specified(false)
1602
1566
str_value.set_or_copy_aligned(str, length, cs);
1611
1575
This is used in stored procedures to avoid memory leaks and
1612
1576
does a deep copy of its argument.
1614
void set_str_with_copy(const char *str_arg, uint32_t length_arg)
1578
void set_str_with_copy(const char *str_arg, uint length_arg)
1616
1580
str_value.copy(str_arg, length_arg, collation.collation);
1617
1581
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1633
1597
my_decimal *val_decimal(my_decimal *);
1634
1598
int save_in_field(Field *field, bool no_conversions);
1635
1599
enum Item_result result_type () const { return STRING_RESULT; }
1636
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1600
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1637
1601
bool basic_const_item() const { return 1; }
1638
1602
bool eq(const Item *item, bool binary_cmp) const;
1639
1603
Item *clone_item()
1641
1605
return new Item_string(name, str_value.ptr(),
1642
1606
str_value.length(), collation.collation);
1644
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1645
inline void append(char *str, uint32_t length)
1608
Item *safe_charset_converter(CHARSET_INFO *tocs);
1609
inline void append(char *str, uint length)
1647
1611
str_value.append(str, length);
1648
1612
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1700
1662
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,
1664
Item_static_string_func(const char *name_par, const char *str, uint length,
1704
1666
Derivation dv= DERIVATION_COERCIBLE)
1705
:Item_string(NULL, str, length, cs, dv), func_name(name_par)
1667
:Item_string(NullS, str, length, cs, dv), func_name(name_par)
1707
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1669
Item *safe_charset_converter(CHARSET_INFO *tocs);
1709
1671
virtual inline void print(String *str,
1710
enum_query_type query_type __attribute__((unused)))
1672
enum_query_type query_type __attribute__((__unused__)))
1712
1674
str->append(func_name);
1714
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1732
1692
class Item_blob :public Item_string
1735
Item_blob(const char *name, uint32_t length) :
1695
Item_blob(const char *name, uint length) :
1736
1696
Item_string(name, length, &my_charset_bin)
1737
1697
{ max_length= length; }
1738
1698
enum Type type() const { return TYPE_HOLDER; }
1739
enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
1699
enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
1749
1709
class Item_empty_string :public Item_string
1752
Item_empty_string(const char *header,uint32_t length, const CHARSET_INFO * cs= NULL) :
1712
Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) :
1753
1713
Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1754
1714
{ name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1755
1715
void make_field(Send_field *field);
1761
1721
enum_field_types int_field_type;
1763
Item_return_int(const char *name_arg, uint32_t length,
1723
Item_return_int(const char *name_arg, uint length,
1764
1724
enum_field_types field_type_arg, int64_t value= 0)
1765
1725
:Item_int(name_arg, value, length), int_field_type(field_type_arg)
1788
1748
int save_in_field(Field *field, bool no_conversions);
1789
1749
enum Item_result result_type () const { return STRING_RESULT; }
1790
1750
enum Item_result cast_to_int_type() const { return INT_RESULT; }
1791
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1751
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1792
1752
virtual void print(String *str, enum_query_type query_type);
1793
1753
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)))
1754
virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
1800
1758
class Item_bin_string: public Item_hex_string
1803
Item_bin_string(const char *str,uint32_t str_length);
1761
Item_bin_string(const char *str,uint str_length);
1806
1764
class Item_result_field :public Item /* Item with result field */
1914
1870
return ref ? (*ref)->real_item() : this;
1916
bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
1872
bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1917
1873
{ return (*ref)->walk(processor, walk_subquery, arg); }
1918
1874
virtual void print(String *str, enum_query_type query_type);
1919
1875
bool result_as_int64_t()
1926
1882
virtual Ref_Type ref_type() { return REF; }
1928
1884
// Row emulation: forwarding of ROW-related calls to ref
1931
1887
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1933
Item* element_index(uint32_t i)
1889
Item* element_index(uint i)
1935
1891
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1937
Item** addr(uint32_t i)
1939
1895
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1941
bool check_cols(uint32_t c)
1897
bool check_cols(uint c)
1943
1899
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
1944
1900
: Item::check_cols(c);
2091
2047
String* val_str(String* s);
2092
2048
my_decimal *val_decimal(my_decimal *);
2093
2049
bool val_bool();
2094
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
2050
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
2095
2051
virtual void print(String *str, enum_query_type query_type);
2097
2053
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2161
2117
int err_not_used;
2162
2118
char *end_not_used;
2163
2119
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));
2120
my_strntod(str_value.charset(), (char*) str_value.ptr(),
2121
str_value.length(), &end_not_used, &err_not_used));
2167
2123
int64_t val_int()
2170
return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
2171
str_value.length(),10, (char**) 0,
2126
return null_value ? 0LL : my_strntoll(str_value.charset(),str_value.ptr(),
2127
str_value.length(),10, (char**) 0,
2174
2130
String *val_str(String*);
2175
2131
my_decimal *val_decimal(my_decimal *);
2176
2132
void make_field(Send_field *field) { item->make_field(field); }
2178
2134
int save_in_field(Field *field,
2179
bool no_conversions __attribute__((unused)))
2135
bool no_conversions __attribute__((__unused__)))
2181
2137
return save_str_value_in_field(field, &str_value);
2269
2225
int save_in_field(Field *field_arg, bool no_conversions);
2270
2226
table_map used_tables() const { return (table_map)0L; }
2272
bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
2228
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2274
2230
return arg->walk(processor, walk_subquery, args) ||
2275
2231
(this->*processor)(args);
2278
Item *transform(Item_transformer transformer, unsigned char *args);
2234
Item *transform(Item_transformer transformer, uchar *args);
2310
2266
table_map used_tables() const { return RAND_TABLE_BIT; }
2312
bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
2268
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2314
2270
return arg->walk(processor, walk_subquery, args) ||
2315
2271
(this->*processor)(args);
2317
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
2451
2405
String* val_str(String *) { assert(fixed == 1); return value; }
2452
2406
my_decimal *val_decimal(my_decimal *);
2453
2407
enum Item_result result_type() const { return STRING_RESULT; }
2454
const CHARSET_INFO *charset() const { return value->charset(); };
2408
CHARSET_INFO *charset() const { return value->charset(); };
2455
2409
int save_in_field(Field *field, bool no_conversions);
2458
2412
class Item_cache_row: public Item_cache
2460
2414
Item_cache **values;
2461
uint32_t item_count;
2462
2416
bool save_array;
2464
2418
Item_cache_row()
2504
2458
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);
2460
uint cols() { return item_count; }
2461
Item *element_index(uint i) { return values[i]; }
2462
Item **addr(uint i) { return (Item **) (values + i); }
2463
bool check_cols(uint c);
2510
2464
bool null_inside();
2511
2465
void bring_value();
2512
2466
void keep_array() { save_array= 1; }
2550
2504
my_decimal *val_decimal(my_decimal *);
2551
2505
String *val_str(String*);
2552
2506
bool join_types(THD *thd, Item *);
2553
Field *make_field_by_type(Table *table);
2554
static uint32_t display_length(Item *item);
2507
Field *make_field_by_type(TABLE *table);
2508
static uint32 display_length(Item *item);
2555
2509
static enum_field_types get_real_type(Item *);