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