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 */
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
91
98
void set(Derivation derivation_arg)
92
99
{ derivation= derivation_arg; }
93
bool aggregate(DTCollation &dt, uint flags= 0);
94
bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0)
100
bool aggregate(DTCollation &dt, uint32_t flags= 0);
101
bool set(DTCollation &dt1, DTCollation &dt2, uint32_t flags= 0)
95
102
{ set(dt1); return aggregate(dt2, flags); }
96
103
const char *derivation_name() const
161
168
{ val->real/= uint64_t2double(u); }
163
170
virtual int64_t val_int(Hybrid_type *val,
164
bool unsigned_flag __attribute__((unused))) const
165
{ return (int64_t) rint(val->real); }
171
bool unsigned_flag) const;
166
172
virtual double val_real(Hybrid_type *val) const { return val->real; }
167
173
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
168
174
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
232
void dummy_error_processor(THD *thd, void *data);
238
void dummy_error_processor(Session *session, void *data);
234
void view_error_processor(THD *thd, void *data);
240
void view_error_processor(Session *session, void *data);
237
243
Instances of Name_resolution_context store the information necesary for
327
333
resolve_in_select_list= false;
330
void process_error(THD *thd)
336
void process_error(Session *session)
332
(*error_processor)(thd, error_processor_data);
338
(*error_processor)(session, error_processor_data);
419
425
false Don't do it
422
typedef bool (Item::*Item_analyzer) (uchar **argp);
423
typedef Item* (Item::*Item_transformer) (uchar *arg);
428
typedef bool (Item::*Item_analyzer) (unsigned char **argp);
429
typedef Item* (Item::*Item_transformer) (unsigned char *arg);
424
430
typedef void (*Cond_traverser) (const Item *item, void *arg);
496
502
top AND/OR structure of WHERE clause to protect it of
497
503
optimisation changes in prepared statements
499
Item(THD *thd, Item *item);
505
Item(Session *session, Item *item);
502
508
#ifdef EXTRA_DEBUG
505
511
} /*lint -e1509 */
506
void set_name(const char *str, uint length, const CHARSET_INFO * const cs);
512
void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs);
507
513
void rename(char *new_name);
508
514
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
509
515
virtual void cleanup();
510
516
virtual void make_field(Send_field *field);
511
517
Field *make_string_field(Table *table);
512
virtual bool fix_fields(THD *, Item **);
518
virtual bool fix_fields(Session *, Item **);
514
520
Fix after some tables has been pulled out. Basically re-calculate all
515
521
attributes that are dependent on the tables.
731
737
/* cloning of constant items (0 if it is not const) */
732
738
virtual Item *clone_item() { return 0; }
733
739
virtual cond_result eq_cmp_result() const { return COND_OK; }
734
inline uint float_length(uint decimals_par) const
740
inline uint32_t float_length(uint32_t decimals_par) const
735
741
{ return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;}
736
virtual uint decimal_precision() const;
742
virtual uint32_t decimal_precision() const;
737
743
inline int decimal_int_part() const
738
744
{ return my_decimal_int_part(decimal_precision(), decimals); }
768
774
void print_item_w_name(String *, enum_query_type query_type);
769
775
virtual void update_used_tables() {}
770
virtual void split_sum_func(THD *thd __attribute__((unused)),
776
virtual void split_sum_func(Session *session __attribute__((unused)),
771
777
Item **ref_pointer_array __attribute__((unused)),
772
778
List<Item> &fields __attribute__((unused))) {}
773
779
/* Called for items that really have to be split */
774
void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields,
780
void split_sum_func2(Session *session, Item **ref_pointer_array, List<Item> &fields,
775
781
Item **ref, bool skip_registered);
776
virtual bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
782
virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
777
783
virtual bool get_time(DRIZZLE_TIME *ltime);
778
virtual bool get_date_result(DRIZZLE_TIME *ltime,uint fuzzydate)
784
virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
779
785
{ return get_date(ltime,fuzzydate); }
781
787
The method allows to determine nullness of a complex expression
815
821
set value of aggregate function in case of no rows for grouping were found
817
823
virtual void no_rows_in_result(void) {}
818
virtual Item *copy_or_same(THD *thd __attribute__((unused)))
824
virtual Item *copy_or_same(Session *session __attribute__((unused)))
820
virtual Item *copy_andor_structure(THD *thd __attribute__((unused)))
826
virtual Item *copy_andor_structure(Session *session __attribute__((unused)))
822
828
virtual Item *real_item(void) { return this; }
823
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
829
virtual Item *get_tmp_table_item(Session *session) { return copy_or_same(session); }
825
831
static const CHARSET_INFO *default_charset();
826
832
virtual const CHARSET_INFO *compare_collation() { return NULL; }
828
834
virtual bool walk(Item_processor processor __attribute__((unused)),
829
835
bool walk_subquery __attribute__((unused)),
832
838
return (this->*processor)(arg);
835
virtual Item* transform(Item_transformer transformer, uchar *arg);
841
virtual Item* transform(Item_transformer transformer, unsigned char *arg);
838
844
This function performs a generic "compilation" of the Item tree.
850
856
i.e. analysis is performed top-down while transformation is done
853
virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
854
Item_transformer transformer, uchar *arg_t)
859
virtual Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
860
Item_transformer transformer, unsigned char *arg_t)
856
862
if ((this->*analyzer) (arg_p))
857
863
return ((this->*transformer) (arg_t));
865
871
(*traverser)(this, arg);
868
virtual bool remove_dependence_processor(uchar * arg __attribute__((unused)))
874
virtual bool remove_dependence_processor(unsigned char * arg __attribute__((unused)))
870
virtual bool remove_fixed(uchar * arg __attribute__((unused)))
876
virtual bool remove_fixed(unsigned char * arg __attribute__((unused)))
875
virtual bool cleanup_processor(uchar *arg __attribute__((unused)));
876
virtual bool collect_item_field_processor(uchar * arg __attribute__((unused)))
881
virtual bool cleanup_processor(unsigned char *arg __attribute__((unused)));
882
virtual bool collect_item_field_processor(unsigned char * arg __attribute__((unused)))
878
virtual bool find_item_in_field_list_processor(uchar *arg __attribute__((unused)))
884
virtual bool find_item_in_field_list_processor(unsigned char *arg __attribute__((unused)))
880
virtual bool change_context_processor(uchar *context __attribute__((unused)))
882
virtual bool reset_query_id_processor(uchar *query_id_arg __attribute__((unused)))
884
virtual bool register_field_in_read_map(uchar *arg __attribute__((unused)))
886
virtual bool subst_argument_checker(uchar **arg)
886
virtual bool change_context_processor(unsigned char *context __attribute__((unused)))
888
virtual bool reset_query_id_processor(unsigned char *query_id_arg __attribute__((unused)))
890
virtual bool register_field_in_read_map(unsigned char *arg __attribute__((unused)))
893
The next function differs from the previous one that a bitmap to be updated
894
is passed as unsigned char *arg.
896
virtual bool register_field_in_bitmap(unsigned char *arg __attribute__((unused)))
898
virtual bool subst_argument_checker(unsigned char **arg)
893
virtual Item *equal_fields_propagator(uchar * arg __attribute__((unused))) { return this; }
894
virtual bool set_no_const_sub(uchar *arg __attribute__((unused))) { return false; }
895
virtual Item *replace_equal_field(uchar * arg __attribute__((unused))) { return this; }
906
Check if an expression/function is allowed for a virtual column
908
check_vcol_func_processor()
911
TRUE Function not accepted
912
FALSE Function accepted
914
virtual bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
917
virtual Item *equal_fields_propagator(unsigned char * arg __attribute__((unused))) { return this; }
918
virtual bool set_no_const_sub(unsigned char *arg __attribute__((unused))) { return false; }
919
virtual Item *replace_equal_field(unsigned char * arg __attribute__((unused))) { return this; }
898
923
For SP local variable returns pointer to Item representing its
905
930
For SP local variable returns address of pointer to Item representing its
906
931
current value and pointer passed via parameter otherwise.
908
virtual Item **this_item_addr(THD *thd __attribute__((unused)), Item **addr_arg) { return addr_arg; }
933
virtual Item **this_item_addr(Session *session __attribute__((unused)), Item **addr_arg) { return addr_arg; }
911
virtual uint cols() { return 1; }
912
virtual Item* element_index(uint i __attribute__((unused))) { return this; }
913
virtual Item** addr(uint i __attribute__((unused))) { return 0; }
914
virtual bool check_cols(uint c);
936
virtual uint32_t cols() { return 1; }
937
virtual Item* element_index(uint32_t i __attribute__((unused))) { return this; }
938
virtual Item** addr(uint32_t i __attribute__((unused))) { return 0; }
939
virtual bool check_cols(uint32_t c);
915
940
// It is not row => null inside is impossible
916
941
virtual bool null_inside() { return 0; }
917
942
// used in row subselects to get value of elements
920
945
Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
921
946
virtual Item_field *filed_for_view_update() { return 0; }
923
virtual Item *neg_transformer(THD *thd __attribute__((unused))) { return NULL; }
924
virtual Item *update_value_transformer(uchar *select_arg __attribute__((unused))) { return this; }
948
virtual Item *neg_transformer(Session *session __attribute__((unused))) { return NULL; }
949
virtual Item *update_value_transformer(unsigned char *select_arg __attribute__((unused))) { return this; }
925
950
virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
926
951
void delete_self()
953
978
virtual bool is_expensive()
955
980
if (is_expensive_cache < 0)
956
is_expensive_cache= walk(&Item::is_expensive_processor, 0, (uchar*)0);
981
is_expensive_cache= walk(&Item::is_expensive_processor, 0, (unsigned char*)0);
957
982
return test(is_expensive_cache);
959
984
String *check_well_formed_result(String *str, bool send_error= 0);
980
1005
bool agg_item_collations(DTCollation &c, const char *name,
981
Item **items, uint nitems, uint flags, int item_sep);
1006
Item **items, uint32_t nitems, uint32_t flags, int item_sep);
982
1007
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
983
Item **items, uint nitems, uint flags);
1008
Item **items, uint32_t nitems, uint32_t flags);
984
1009
bool agg_item_charsets(DTCollation &c, const char *name,
985
Item **items, uint nitems, uint flags, int item_sep);
1010
Item **items, uint32_t nitems, uint32_t flags, int item_sep);
988
1013
class Item_num: public Item_basic_constant
1020
1045
stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
1021
1046
if index value is not known.
1023
uint cached_field_index;
1048
uint32_t cached_field_index;
1025
1050
Cached pointer to table which contains this field, used for the same reason
1026
1051
by prep. stmt. too in case then we have not-fully qualified field.
1031
1056
Item_ident(Name_resolution_context *context_arg,
1032
1057
const char *db_name_arg, const char *table_name_arg,
1033
1058
const char *field_name_arg);
1034
Item_ident(THD *thd, Item_ident *item);
1059
Item_ident(Session *session, Item_ident *item);
1035
1060
const char *full_name() const;
1036
1061
void cleanup();
1037
bool remove_dependence_processor(uchar * arg);
1062
bool remove_dependence_processor(unsigned char * arg);
1038
1063
virtual void print(String *str, enum_query_type query_type);
1039
virtual bool change_context_processor(uchar *cntx)
1064
virtual bool change_context_processor(unsigned char *cntx)
1040
1065
{ context= (Name_resolution_context *)cntx; return false; }
1041
friend bool insert_fields(THD *thd, Name_resolution_context *context,
1066
friend bool insert_fields(Session *session, Name_resolution_context *context,
1042
1067
const char *db_name,
1043
1068
const char *table_name, List_iterator<Item> *it,
1044
1069
bool any_privileges);
1091
1117
Constructor needed to process subselect with temporary tables (see Item)
1093
Item_field(THD *thd, Item_field *item);
1119
Item_field(Session *session, Item_field *item);
1095
1121
Constructor used inside setup_wild(), ensures that field, table,
1096
1122
and database names will live as long as Item_field (this is important
1097
1123
in prepared statements).
1099
Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
1125
Item_field(Session *session, Name_resolution_context *context_arg, Field *field);
1101
1127
If this constructor is used, fix_fields() won't work, because
1102
1128
db_name, table_name and column_name are unknown. It's necessary to call
1116
1142
bool val_bool_result();
1117
1143
bool send(Protocol *protocol, String *str_arg);
1118
1144
void reset_field(Field *f);
1119
bool fix_fields(THD *, Item **);
1145
bool fix_fields(Session *, Item **);
1120
1146
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1121
1147
void make_field(Send_field *tmp_field);
1122
1148
int save_in_field(Field *field,bool no_conversions);
1141
1167
int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
1142
1168
Field *get_tmp_table_field() { return result_field; }
1143
1169
Field *tmp_table_field(Table *t_arg __attribute__((unused))) { return result_field; }
1144
bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
1145
bool get_date_result(DRIZZLE_TIME *ltime,uint fuzzydate);
1170
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1171
bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1146
1172
bool get_time(DRIZZLE_TIME *ltime);
1147
1173
bool is_null() { return field->is_null(); }
1148
1174
void update_null_value();
1149
Item *get_tmp_table_item(THD *thd);
1150
bool collect_item_field_processor(uchar * arg);
1151
bool find_item_in_field_list_processor(uchar *arg);
1152
bool register_field_in_read_map(uchar *arg);
1175
Item *get_tmp_table_item(Session *session);
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)))
1153
1182
void cleanup();
1154
1183
bool result_as_int64_t()
1156
1185
return field->can_be_compared_as_int64_t();
1158
1187
Item_equal *find_item_equal(COND_EQUAL *cond_equal);
1159
bool subst_argument_checker(uchar **arg);
1160
Item *equal_fields_propagator(uchar *arg);
1161
bool set_no_const_sub(uchar *arg);
1162
Item *replace_equal_field(uchar *arg);
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);
1163
1192
inline uint32_t max_disp_length() { return field->max_display_length(); }
1164
1193
Item_field *filed_for_view_update() { return this; }
1165
1194
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1166
int fix_outer_field(THD *thd, Field **field, Item **reference);
1167
virtual Item *update_value_transformer(uchar *select_arg);
1195
int fix_outer_field(Session *session, Field **field, Item **reference);
1196
virtual Item *update_value_transformer(unsigned char *select_arg);
1168
1197
virtual void print(String *str, enum_query_type query_type);
1170
1199
friend class Item_default_value;
1289
1322
Offset of placeholder inside statement text. Used to create
1290
1323
no-placeholders version of this statement for the binary log.
1325
uint32_t pos_in_query;
1294
Item_param(uint pos_in_query_arg);
1327
Item_param(uint32_t pos_in_query_arg);
1296
1329
enum Item_result result_type () const { return item_result_type; }
1297
1330
enum Type type() const { return item_type; }
1302
1335
my_decimal *val_decimal(my_decimal*);
1303
1336
String *val_str(String*);
1304
1337
bool get_time(DRIZZLE_TIME *tm);
1305
bool get_date(DRIZZLE_TIME *tm, uint fuzzydate);
1338
bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
1306
1339
int save_in_field(Field *field, bool no_conversions);
1308
1341
void set_null();
1311
1344
void set_decimal(char *str, ulong length);
1312
1345
bool set_str(const char *str, ulong length);
1313
1346
bool set_longdata(const char *str, ulong length);
1314
void set_time(DRIZZLE_TIME *tm, timestamp_type type, uint32_t max_length_arg);
1315
bool set_from_user_var(THD *thd, const user_var_entry *entry);
1347
void set_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type type,
1348
uint32_t max_length_arg);
1349
bool set_from_user_var(Session *session, const user_var_entry *entry);
1318
1352
Assign placeholder value from bind data.
1320
1354
don't need to check that packet is not broken there). See
1321
1355
sql_prepare.cc for details.
1323
void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
1357
void (*set_param_func)(Item_param *param, unsigned char **pos, ulong len);
1325
1359
const String *query_val_str(String *str) const;
1327
bool convert_str_value(THD *thd);
1361
bool convert_str_value(Session *session);
1330
1364
If value for parameter was not set we treat it as non-const
1367
Item_int(int32_t i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
1401
Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS)
1368
1402
:value((int64_t) i)
1369
1403
{ max_length=length; fixed= 1; }
1370
Item_int(int64_t i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1404
Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1372
1406
{ max_length=length; fixed= 1; }
1373
Item_int(uint64_t i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1407
Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1374
1408
:value((int64_t)i)
1375
1409
{ max_length=length; fixed= 1; unsigned_flag= 1; }
1376
Item_int(const char *str_arg,int64_t i,uint length) :value(i)
1410
Item_int(const char *str_arg,int64_t i,uint32_t length) :value(i)
1377
1411
{ max_length=length; name=(char*) str_arg; fixed= 1; }
1378
Item_int(const char *str_arg, uint length=64);
1412
Item_int(const char *str_arg, uint32_t length=64);
1379
1413
enum Type type() const { return INT_ITEM; }
1380
1414
enum Item_result result_type () const { return INT_RESULT; }
1381
1415
enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
1388
1422
Item *clone_item() { return new Item_int(name,value,max_length); }
1389
1423
virtual void print(String *str, enum_query_type query_type);
1390
1424
Item_num *neg() { value= -value; return this; }
1391
uint decimal_precision() const
1425
uint32_t decimal_precision() const
1392
1426
{ return (uint)(max_length - test(value < 0)); }
1393
1427
bool eq(const Item *, bool binary_cmp) const;
1428
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1397
1433
class Item_uint :public Item_int
1400
Item_uint(const char *str_arg, uint length);
1436
Item_uint(const char *str_arg, uint32_t length);
1401
1437
Item_uint(uint64_t i) :Item_int((uint64_t) i, 10) {}
1402
Item_uint(const char *str_arg, int64_t i, uint length);
1438
Item_uint(const char *str_arg, int64_t i, uint32_t length);
1403
1439
double val_real()
1404
1440
{ assert(fixed == 1); return uint64_t2double((uint64_t)value); }
1405
1441
String *val_str(String*);
1407
1443
int save_in_field(Field *field, bool no_conversions);
1408
1444
virtual void print(String *str, enum_query_type query_type);
1409
1445
Item_num *neg ();
1410
uint decimal_precision() const { return max_length; }
1446
uint32_t decimal_precision() const { return max_length; }
1447
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1418
1456
my_decimal decimal_value;
1420
Item_decimal(const char *str_arg, uint length, const CHARSET_INFO * const charset);
1458
Item_decimal(const char *str_arg, uint32_t length, const CHARSET_INFO * const charset);
1421
1459
Item_decimal(const char *str, const my_decimal *val_arg,
1422
uint decimal_par, uint length);
1460
uint32_t decimal_par, uint32_t length);
1423
1461
Item_decimal(my_decimal *value_par);
1424
1462
Item_decimal(int64_t val, bool unsig);
1425
1463
Item_decimal(double val, int precision, int scale);
1426
Item_decimal(const uchar *bin, int precision, int scale);
1464
Item_decimal(const unsigned char *bin, int precision, int scale);
1428
1466
enum Type type() const { return DECIMAL_ITEM; }
1429
1467
enum Item_result result_type () const { return DECIMAL_RESULT; }
1446
1484
unsigned_flag= !decimal_value.sign();
1449
uint decimal_precision() const { return decimal_value.precision(); }
1487
uint32_t decimal_precision() const { return decimal_value.precision(); }
1450
1488
bool eq(const Item *, bool binary_cmp) const;
1451
1489
void set_decimal_value(my_decimal *value_par);
1490
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1460
1500
// Item_real() :value(0) {}
1461
Item_float(const char *str_arg, uint length);
1462
Item_float(const char *str,double val_arg,uint decimal_par,uint length)
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)
1463
1503
:value(val_arg)
1465
1505
presentation= name=(char*) str;
1476
1516
enum Type type() const { return REAL_ITEM; }
1477
1517
enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE; }
1478
1518
double val_real() { assert(fixed == 1); return value; }
1482
if (value <= (double) INT64_MIN)
1486
else if (value >= (double) (uint64_t) INT64_MAX)
1490
return (int64_t) rint(value);
1492
1520
String *val_str(String*);
1493
1521
my_decimal *val_decimal(my_decimal *);
1494
1522
bool basic_const_item() const { return 1; }
1505
1533
const char *func_name;
1507
Item_static_float_func(const char *str, double val_arg, uint decimal_par,
1509
:Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1535
Item_static_float_func(const char *str, double val_arg, uint32_t decimal_par,
1537
:Item_float(NULL, val_arg, decimal_par, length), func_name(str)
1512
1540
virtual inline void print(String *str,
1518
1546
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1547
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1522
1552
class Item_string :public Item_basic_constant
1525
Item_string(const char *str,uint length,
1555
Item_string(const char *str,uint32_t length,
1526
1556
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1527
uint repertoire= MY_REPERTOIRE_UNICODE30)
1557
uint32_t repertoire= MY_REPERTOIRE_UNICODE30)
1528
1558
: m_cs_specified(false)
1530
1560
str_value.set_or_copy_aligned(str, length, cs);
1552
1582
decimals= NOT_FIXED_DEC;
1555
Item_string(const char *name_par, const char *str, uint length,
1585
Item_string(const char *name_par, const char *str, uint32_t length,
1556
1586
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1557
uint repertoire= MY_REPERTOIRE_UNICODE30)
1587
uint32_t repertoire= MY_REPERTOIRE_UNICODE30)
1558
1588
: m_cs_specified(false)
1560
1590
str_value.set_or_copy_aligned(str, length, cs);
1569
1599
This is used in stored procedures to avoid memory leaks and
1570
1600
does a deep copy of its argument.
1572
void set_str_with_copy(const char *str_arg, uint length_arg)
1602
void set_str_with_copy(const char *str_arg, uint32_t length_arg)
1574
1604
str_value.copy(str_arg, length_arg, collation.collation);
1575
1605
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1600
1630
str_value.length(), collation.collation);
1602
1632
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1603
inline void append(char *str, uint length)
1633
inline void append(char *str, uint32_t length)
1605
1635
str_value.append(str, length);
1606
1636
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1656
1688
const char *func_name;
1658
Item_static_string_func(const char *name_par, const char *str, uint length,
1690
Item_static_string_func(const char *name_par, const char *str, uint32_t length,
1659
1691
const CHARSET_INFO * const cs,
1660
1692
Derivation dv= DERIVATION_COERCIBLE)
1661
:Item_string(NullS, str, length, cs, dv), func_name(name_par)
1693
:Item_string(NULL, str, length, cs, dv), func_name(name_par)
1663
1695
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1686
1720
class Item_blob :public Item_string
1689
Item_blob(const char *name, uint length) :
1723
Item_blob(const char *name, uint32_t length) :
1690
1724
Item_string(name, length, &my_charset_bin)
1691
1725
{ max_length= length; }
1692
1726
enum Type type() const { return TYPE_HOLDER; }
1703
1737
class Item_empty_string :public Item_string
1706
Item_empty_string(const char *header,uint length, const CHARSET_INFO * cs= NULL) :
1740
Item_empty_string(const char *header,uint32_t length, const CHARSET_INFO * cs= NULL) :
1707
1741
Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1708
1742
{ name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1709
1743
void make_field(Send_field *field);
1715
1749
enum_field_types int_field_type;
1717
Item_return_int(const char *name_arg, uint length,
1751
Item_return_int(const char *name_arg, uint32_t length,
1718
1752
enum_field_types field_type_arg, int64_t value= 0)
1719
1753
:Item_int(name_arg, value, length), int_field_type(field_type_arg)
1746
1780
virtual void print(String *str, enum_query_type query_type);
1747
1781
bool eq(const Item *item, bool binary_cmp) const;
1748
1782
virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1783
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1752
1788
class Item_bin_string: public Item_hex_string
1755
Item_bin_string(const char *str,uint str_length);
1791
Item_bin_string(const char *str,uint32_t str_length);
1758
1794
class Item_result_field :public Item /* Item with result field */
1761
1797
Field *result_field; /* Save result here */
1762
1798
Item_result_field() :result_field(0) {}
1763
1799
// Constructor used for Item_sum/Item_cond_and/or (see Item comment)
1764
Item_result_field(THD *thd, Item_result_field *item):
1765
Item(thd, item), result_field(item->result_field)
1800
Item_result_field(Session *session, Item_result_field *item):
1801
Item(session, item), result_field(item->result_field)
1767
1803
~Item_result_field() {} /* Required with gcc 2.95 */
1768
1804
Field *get_tmp_table_field() { return result_field; }
1812
1850
bool alias_name_used_arg= false);
1814
1852
/* Constructor need to process subselect with temporary tables (see Item) */
1815
Item_ref(THD *thd, Item_ref *item)
1816
:Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {}
1853
Item_ref(Session *session, Item_ref *item)
1854
:Item_ident(session, item), result_field(item->result_field), ref(item->ref) {}
1817
1855
enum Type type() const { return REF_ITEM; }
1818
1856
bool eq(const Item *item, bool binary_cmp) const
1826
1864
bool val_bool();
1827
1865
String *val_str(String* tmp);
1828
1866
bool is_null();
1829
bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
1867
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1830
1868
double val_result();
1831
1869
int64_t val_int_result();
1832
1870
String *str_result(String* tmp);
1834
1872
bool val_bool_result();
1835
1873
bool send(Protocol *prot, String *tmp);
1836
1874
void make_field(Send_field *field);
1837
bool fix_fields(THD *, Item **);
1875
bool fix_fields(Session *, Item **);
1838
1876
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1839
1877
int save_in_field(Field *field, bool no_conversions);
1840
1878
void save_org_in_field(Field *field);
1842
1880
enum_field_types field_type() const { return (*ref)->field_type(); }
1843
1881
Field *get_tmp_table_field()
1844
1882
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); }
1845
Item *get_tmp_table_item(THD *thd);
1883
Item *get_tmp_table_item(Session *session);
1846
1884
table_map used_tables() const
1848
1886
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
1864
1902
return ref ? (*ref)->real_item() : this;
1866
bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1904
bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
1867
1905
{ return (*ref)->walk(processor, walk_subquery, arg); }
1868
1906
virtual void print(String *str, enum_query_type query_type);
1869
1907
bool result_as_int64_t()
1876
1914
virtual Ref_Type ref_type() { return REF; }
1878
1916
// Row emulation: forwarding of ROW-related calls to ref
1881
1919
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1883
Item* element_index(uint i)
1921
Item* element_index(uint32_t i)
1885
1923
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1925
Item** addr(uint32_t i)
1889
1927
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1891
bool check_cols(uint c)
1929
bool check_cols(uint32_t c)
1893
1931
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
1894
1932
: Item::check_cols(c);
1921
1959
field_name_arg, alias_name_used_arg)
1923
1961
/* Constructor need to process subselect with temporary tables (see Item) */
1924
Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
1962
Item_direct_ref(Session *session, Item_direct_ref *item) : Item_ref(session, item) {}
1926
1964
double val_real();
1927
1965
int64_t val_int();
1945
1983
const char *field_name_arg)
1946
1984
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg) {}
1947
1985
/* Constructor need to process subselect with temporary tables (see Item) */
1948
Item_direct_view_ref(THD *thd, Item_direct_ref *item)
1949
:Item_direct_ref(thd, item) {}
1986
Item_direct_view_ref(Session *session, Item_direct_ref *item)
1987
:Item_direct_ref(session, item) {}
1951
bool fix_fields(THD *, Item **);
1989
bool fix_fields(Session *, Item **);
1952
1990
bool eq(const Item *item, bool binary_cmp) const;
1953
Item *get_tmp_table_item(THD *thd)
1991
Item *get_tmp_table_item(Session *session)
1955
Item *item= Item_ref::get_tmp_table_item(thd);
1993
Item *item= Item_ref::get_tmp_table_item(session);
1956
1994
item->name= name;
2005
2043
outer_ref->save_org_in_field(result_field);
2007
bool fix_fields(THD *, Item **);
2045
bool fix_fields(Session *, Item **);
2008
2046
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
2009
2047
table_map used_tables() const
2041
2079
String* val_str(String* s);
2042
2080
my_decimal *val_decimal(my_decimal *);
2043
2081
bool val_bool();
2044
bool get_date(DRIZZLE_TIME *ltime, uint fuzzydate);
2082
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
2045
2083
virtual void print(String *str, enum_query_type query_type);
2047
2085
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2111
2149
int err_not_used;
2112
2150
char *end_not_used;
2113
2151
return (null_value ? 0.0 :
2114
my_strntod(str_value.charset(), (char*) str_value.ptr(),
2115
str_value.length(), &end_not_used, &err_not_used));
2152
my_strntod(str_value.charset(), (char*) str_value.ptr(),
2153
str_value.length(), &end_not_used, &err_not_used));
2117
2155
int64_t val_int()
2120
return null_value ? 0LL : my_strntoll(str_value.charset(),str_value.ptr(),
2121
str_value.length(),10, (char**) 0,
2158
return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
2159
str_value.length(),10, (char**) 0,
2124
2162
String *val_str(String*);
2125
2163
my_decimal *val_decimal(my_decimal *);
2215
2253
enum Type type() const { return DEFAULT_VALUE_ITEM; }
2216
2254
bool eq(const Item *item, bool binary_cmp) const;
2217
bool fix_fields(THD *, Item **);
2255
bool fix_fields(Session *, Item **);
2218
2256
virtual void print(String *str, enum_query_type query_type);
2219
2257
int save_in_field(Field *field_arg, bool no_conversions);
2220
2258
table_map used_tables() const { return (table_map)0L; }
2222
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2260
bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
2224
2262
return arg->walk(processor, walk_subquery, args) ||
2225
2263
(this->*processor)(args);
2228
Item *transform(Item_transformer transformer, uchar *args);
2266
Item *transform(Item_transformer transformer, unsigned char *args);
2247
2285
(const char *)NULL),
2249
2287
bool eq(const Item *item, bool binary_cmp) const;
2250
bool fix_fields(THD *, Item **);
2288
bool fix_fields(Session *, Item **);
2251
2289
virtual void print(String *str, enum_query_type query_type);
2252
2290
int save_in_field(Field *field_arg, bool no_conversions)
2260
2298
table_map used_tables() const { return RAND_TABLE_BIT; }
2262
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2300
bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
2264
2302
return arg->walk(processor, walk_subquery, args) ||
2265
2303
(this->*processor)(args);
2305
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
2452
2492
enum Item_result result_type() const { return ROW_RESULT; }
2454
uint cols() { return item_count; }
2455
Item *element_index(uint i) { return values[i]; }
2456
Item **addr(uint i) { return (Item **) (values + i); }
2457
bool check_cols(uint c);
2494
uint32_t cols() { return item_count; }
2495
Item *element_index(uint32_t i) { return values[i]; }
2496
Item **addr(uint32_t i) { return (Item **) (values + i); }
2497
bool check_cols(uint32_t c);
2458
2498
bool null_inside();
2459
2499
void bring_value();
2460
2500
void keep_array() { save_array= 1; }
2488
2528
/* It is used to count decimal precision in join_types */
2489
2529
int prev_decimal_int_part;
2491
Item_type_holder(THD*, Item*);
2531
Item_type_holder(Session*, Item*);
2493
2533
Item_result result_type() const;
2494
2534
enum_field_types field_type() const { return fld_type; };
2497
2537
int64_t val_int();
2498
2538
my_decimal *val_decimal(my_decimal *);
2499
2539
String *val_str(String*);
2500
bool join_types(THD *thd, Item *);
2540
bool join_types(Session *session, Item *);
2501
2541
Field *make_field_by_type(Table *table);
2502
2542
static uint32_t display_length(Item *item);
2503
2543
static enum_field_types get_real_type(Item *);
2507
2547
class st_select_lex;
2508
void mark_select_range_as_dependent(THD *thd,
2548
void mark_select_range_as_dependent(Session *session,
2509
2549
st_select_lex *last_select,
2510
2550
st_select_lex *current_sel,
2511
2551
Field *found_field, Item *found_item,
2512
2552
Item_ident *resolved_item);
2514
extern Cached_item *new_Cached_item(THD *thd, Item *item,
2554
extern Cached_item *new_Cached_item(Session *session, Item *item,
2515
2555
bool use_result_field);
2516
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
2556
extern void resolve_const_item(Session *session, Item **ref, Item *cmp_item);
2517
2557
extern bool field_is_equal_to_item(Field *field,Item *item);