~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 */
19
 
 
20
 
#ifndef drizzled_item_h
21
 
#define drizzled_item_h
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
22
15
 
23
16
class Protocol;
24
17
struct TableList;
51
44
public:
52
45
  const CHARSET_INFO *collation;
53
46
  enum Derivation derivation;
54
 
  uint32_t repertoire;
 
47
  uint repertoire;
55
48
  
56
49
  void set_repertoire_from_charset(const CHARSET_INFO * const cs)
57
50
  {
84
77
  }
85
78
  void set(const CHARSET_INFO * const collation_arg,
86
79
           Derivation derivation_arg,
87
 
           uint32_t repertoire_arg)
 
80
           uint repertoire_arg)
88
81
  {
89
82
    collation= collation_arg;
90
83
    derivation= derivation_arg;
97
90
  }
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
104
97
  {
168
161
  { val->real/= uint64_t2double(u); }
169
162
 
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;
235
229
};
236
230
 
237
231
 
238
 
void dummy_error_processor(Session *session, void *data);
 
232
void dummy_error_processor(THD *thd, void *data);
239
233
 
240
 
void view_error_processor(Session *session, void *data);
 
234
void view_error_processor(THD *thd, void *data);
241
235
 
242
236
/*
243
237
  Instances of Name_resolution_context store the information necesary for
297
291
    hide underlying tables in errors about views (i.e. it substitute some
298
292
    errors for views)
299
293
  */
300
 
  void (*error_processor)(Session *, void *);
 
294
  void (*error_processor)(THD *, void *);
301
295
  void *error_processor_data;
302
296
 
303
297
  /*
333
327
    resolve_in_select_list= false;
334
328
  }
335
329
 
336
 
  void process_error(Session *session)
 
330
  void process_error(THD *thd)
337
331
  {
338
 
    (*error_processor)(session, error_processor_data);
 
332
    (*error_processor)(thd, error_processor_data);
339
333
  }
340
334
};
341
335
 
413
407
} enum_monotonicity_info;
414
408
 
415
409
/*************************************************************************/
416
 
typedef bool (Item::*Item_processor) (unsigned char *arg);
 
410
typedef bool (Item::*Item_processor) (uchar *arg);
417
411
/*
418
412
  Analyzer function
419
413
    SYNOPSIS
425
419
      false  Don't do it
426
420
 
427
421
*/
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);
431
425
 
432
426
 
436
430
  void operator=(Item &);
437
431
  /* Cache of the result of is_expensive(). */
438
432
  int8_t is_expensive_cache;
439
 
  virtual bool is_expensive_processor(unsigned char *arg __attribute__((unused)))
 
433
  virtual bool is_expensive_processor(uchar *arg __attribute__((unused)))
440
434
  { return 0; }
441
435
 
442
436
public:
465
459
  enum traverse_order { POSTFIX, PREFIX };
466
460
  
467
461
  /* Reuse size, only used by SP local variable assignment, otherwize 0 */
468
 
  uint32_t rsize;
 
462
  uint rsize;
469
463
 
470
464
  /*
471
465
    str_values's main purpose is to be used to cache the value in
477
471
  char * orig_name;
478
472
  Item *next;
479
473
  uint32_t max_length;
480
 
  uint32_t name_length;                     /* Length of name */
 
474
  uint name_length;                     /* Length of name */
481
475
  int8_t marker;
482
476
  uint8_t decimals;
483
477
  bool maybe_null;                      /* If item may be null */
502
496
     top AND/OR structure of WHERE clause to protect it of
503
497
     optimisation changes in prepared statements
504
498
  */
505
 
  Item(Session *session, Item *item);
 
499
  Item(THD *thd, Item *item);
506
500
  virtual ~Item()
507
501
  {
508
502
#ifdef EXTRA_DEBUG
509
503
    name=0;
510
504
#endif
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 **);
519
513
  /*
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); }
745
739
  /* 
773
767
 
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); }
786
780
  /*
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
822
816
  */
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)))
825
819
  { return this; }
826
 
  virtual Item *copy_andor_structure(Session *session  __attribute__((unused)))
 
820
  virtual Item *copy_andor_structure(THD *thd  __attribute__((unused)))
827
821
  { return this; }
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); }
830
824
 
831
825
  static const CHARSET_INFO *default_charset();
832
826
  virtual const CHARSET_INFO *compare_collation() { return NULL; }
833
827
 
834
828
  virtual bool walk(Item_processor processor __attribute__((unused)),
835
829
                    bool walk_subquery __attribute__((unused)),
836
 
                    unsigned char *arg)
 
830
                    uchar *arg)
837
831
  {
838
832
    return (this->*processor)(arg);
839
833
  }
840
834
 
841
 
  virtual Item* transform(Item_transformer transformer, unsigned char *arg);
 
835
  virtual Item* transform(Item_transformer transformer, uchar *arg);
842
836
 
843
837
  /*
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
857
851
    bottom-up.      
858
852
  */
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)
861
855
  {
862
856
    if ((this->*analyzer) (arg_p))
863
857
      return ((this->*transformer) (arg_t));
871
865
     (*traverser)(this, arg);
872
866
   }
873
867
 
874
 
  virtual bool remove_dependence_processor(unsigned char * arg __attribute__((unused)))
 
868
  virtual bool remove_dependence_processor(uchar * arg __attribute__((unused)))
875
869
  { return 0; }
876
 
  virtual bool remove_fixed(unsigned char * arg __attribute__((unused)))
 
870
  virtual bool remove_fixed(uchar * arg __attribute__((unused)))
877
871
  {
878
872
    fixed= 0;
879
873
    return 0;
880
874
  }
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)))
883
877
  { return 0; }
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)))
885
879
 { return 0; }
886
 
  virtual bool change_context_processor(unsigned char *context __attribute__((unused)))
887
 
  { return 0; }
888
 
  virtual bool reset_query_id_processor(unsigned char *query_id_arg __attribute__((unused)))
889
 
  { return 0; }
890
 
  virtual bool register_field_in_read_map(unsigned char *arg __attribute__((unused)))
891
 
  { return 0; }
892
 
  /*
893
 
    The next function differs from the previous one that a bitmap to be updated
894
 
    is passed as unsigned char *arg.
895
 
  */
896
 
  virtual bool register_field_in_bitmap(unsigned char *arg __attribute__((unused)))
897
 
  { return 0; }
898
 
  virtual bool subst_argument_checker(unsigned char **arg)
 
880
  virtual bool change_context_processor(uchar *context __attribute__((unused)))
 
881
  { return 0; }
 
882
  virtual bool reset_query_id_processor(uchar *query_id_arg __attribute__((unused)))
 
883
  { return 0; }
 
884
  virtual bool register_field_in_read_map(uchar *arg __attribute__((unused)))
 
885
  { return 0; }
 
886
  virtual bool subst_argument_checker(uchar **arg)
899
887
  {
900
888
    if (*arg)
901
889
      *arg= NULL;
902
890
    return true;
903
891
  }
904
892
 
905
 
  /*
906
 
    Check if an expression/function is allowed for a virtual column
907
 
    SYNOPSIS
908
 
      check_vcol_func_processor()
909
 
      arg is just ignored
910
 
    RETURN VALUE
911
 
      TRUE                           Function not accepted
912
 
      FALSE                          Function accepted
913
 
  */
914
 
  virtual bool check_vcol_func_processor(unsigned char *arg __attribute__((unused))) 
915
 
  { return true; }
916
 
 
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; }
920
 
 
 
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; }
921
896
 
922
897
  /*
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.
932
907
  */
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; }
934
909
 
935
910
  // Row emulation
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; }
947
922
 
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()
952
927
  {
978
953
  virtual bool is_expensive()
979
954
  {
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);
983
958
  }
984
959
  String *check_well_formed_result(String *str, bool send_error= 0);
1003
978
};
1004
979
 
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);
1011
986
 
1012
987
 
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.
1047
1022
  */
1048
 
  uint32_t cached_field_index;
 
1023
  uint cached_field_index;
1049
1024
  /*
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);
1093
1068
 
1094
1069
class Item_equal;
1095
1070
class COND_EQUAL;
1096
 
class user_var_entry;
1097
1071
 
1098
1072
class Item_field :public Item_ident
1099
1073
{
1107
1081
    if any_privileges set to true then here real effective privileges will
1108
1082
    be stored
1109
1083
  */
1110
 
  uint32_t have_privileges;
 
1084
  uint have_privileges;
1111
1085
  /* field need any privileges (for VIEW creation) */
1112
1086
  bool any_privileges;
1113
1087
  Item_field(Name_resolution_context *context_arg,
1116
1090
  /*
1117
1091
    Constructor needed to process subselect with temporary tables (see Item)
1118
1092
  */
1119
 
  Item_field(Session *session, Item_field *item);
 
1093
  Item_field(THD *thd, Item_field *item);
1120
1094
  /*
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).
1124
1098
  */
1125
 
  Item_field(Session *session, Name_resolution_context *context_arg, Field *field);
 
1099
  Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
1126
1100
  /*
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)))
1181
 
  { return false; }
 
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()
1184
1155
  {
1185
1156
    return field->can_be_compared_as_int64_t();
1186
1157
  }
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);
1198
1169
 
1199
1170
  friend class Item_default_value;
1234
1205
  }
1235
1206
 
1236
1207
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1237
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1238
 
  { return false; }
1239
1208
};
1240
1209
 
1241
1210
class Item_null_result :public Item_null
1248
1217
  {
1249
1218
    save_in_field(result_field, no_conversions);
1250
1219
  }
1251
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1252
 
  { return true; }
1253
1220
};  
1254
1221
 
1255
1222
/* Item represents one placeholder ('?') of prepared statement */
1322
1289
    Offset of placeholder inside statement text. Used to create
1323
1290
    no-placeholders version of this statement for the binary log.
1324
1291
  */
1325
 
  uint32_t pos_in_query;
 
1292
  uint pos_in_query;
1326
1293
 
1327
 
  Item_param(uint32_t pos_in_query_arg);
 
1294
  Item_param(uint pos_in_query_arg);
1328
1295
 
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);
1340
1307
 
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);
1350
1316
  void reset();
1351
1317
  /*
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.
1356
1322
  */
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);
1358
1324
 
1359
1325
  const String *query_val_str(String *str) const;
1360
1326
 
1361
 
  bool convert_str_value(Session *session);
 
1327
  bool convert_str_value(THD *thd);
1362
1328
 
1363
1329
  /*
1364
1330
    If value for parameter was not set we treat it as non-const
1398
1364
{
1399
1365
public:
1400
1366
  int64_t value;
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)
1405
1371
    :value(i)
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)))
1429
 
  { return false; }
1430
1394
};
1431
1395
 
1432
1396
 
1433
1397
class Item_uint :public Item_int
1434
1398
{
1435
1399
public:
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)))
1448
 
  { return false; }
 
1410
  uint decimal_precision() const { return max_length; }
1449
1411
};
1450
1412
 
1451
1413
 
1455
1417
protected:
1456
1418
  my_decimal decimal_value;
1457
1419
public:
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);
1465
1427
 
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();
1485
1447
    return this;
1486
1448
  }
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)))
1491
 
  { return false; }
1492
1452
};
1493
1453
 
1494
1454
 
1498
1458
public:
1499
1459
  double value;
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)
1504
1464
  {
1505
1465
    presentation= name=(char*) str;
1507
1467
    max_length=length;
1508
1468
    fixed= 1;
1509
1469
  }
1510
 
  Item_float(double value_par, uint32_t decimal_par) :presentation(0), value(value_par)
 
1470
  Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1511
1471
  {
1512
1472
    decimals= (uint8_t) decimal_par;
1513
1473
    fixed= 1;
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; }
1519
 
  int64_t val_int();
 
1479
  int64_t val_int()
 
1480
  {
 
1481
    assert(fixed == 1);
 
1482
    if (value <= (double) INT64_MIN)
 
1483
    {
 
1484
       return INT64_MIN;
 
1485
    }
 
1486
    else if (value >= (double) (uint64_t) INT64_MAX)
 
1487
    {
 
1488
      return INT64_MAX;
 
1489
    }
 
1490
    return (int64_t) rint(value);
 
1491
  }
1520
1492
  String *val_str(String*);
1521
1493
  my_decimal *val_decimal(my_decimal *);
1522
1494
  bool basic_const_item() const { return 1; }
1532
1504
{
1533
1505
  const char *func_name;
1534
1506
public:
1535
 
  Item_static_float_func(const char *str, double val_arg, uint32_t decimal_par,
1536
 
                        uint32_t length)
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,
 
1508
                        uint length)
 
1509
    :Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1538
1510
  {}
1539
1511
 
1540
1512
  virtual inline void print(String *str,
1544
1516
  }
1545
1517
 
1546
1518
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1547
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1548
 
  { return false; }
1549
1519
};
1550
1520
 
1551
1521
 
1552
1522
class Item_string :public Item_basic_constant
1553
1523
{
1554
1524
public:
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)
1559
1529
  {
1560
1530
    str_value.set_or_copy_aligned(str, length, cs);
1582
1552
    decimals= NOT_FIXED_DEC;
1583
1553
    fixed= 1;
1584
1554
  }
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)
1589
1559
  {
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.
1601
1571
  */
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)
1603
1573
  {
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);
1631
1601
  }
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)
1634
1604
  {
1635
1605
    str_value.append(str, length);
1636
1606
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
1675
1645
  {
1676
1646
    m_cs_specified= cs_specified;
1677
1647
  }
1678
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1679
 
  { return false; }
1680
1648
 
1681
1649
private:
1682
1650
  bool m_cs_specified;
1687
1655
{
1688
1656
  const char *func_name;
1689
1657
public:
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)
1694
1662
  {}
1695
1663
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1696
1664
 
1699
1667
  {
1700
1668
    str->append(func_name);
1701
1669
  }
1702
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1703
 
  { return true; }
1704
1670
};
1705
1671
 
1706
1672
 
1720
1686
class Item_blob :public Item_string
1721
1687
{
1722
1688
public:
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
1738
1704
{
1739
1705
public:
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);
1748
1714
{
1749
1715
  enum_field_types int_field_type;
1750
1716
public:
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)
1754
1720
  {
1762
1728
{
1763
1729
public:
1764
1730
  Item_hex_string() {}
1765
 
  Item_hex_string(const char *str,uint32_t str_length);
 
1731
  Item_hex_string(const char *str,uint str_length);
1766
1732
  enum Type type() const { return VARBIN_ITEM; }
1767
1733
  double val_real()
1768
1734
  { 
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)))
1784
 
  { return false; }
1785
1749
};
1786
1750
 
1787
1751
 
1788
1752
class Item_bin_string: public Item_hex_string
1789
1753
{
1790
1754
public:
1791
 
  Item_bin_string(const char *str,uint32_t str_length);
 
1755
  Item_bin_string(const char *str,uint str_length);
1792
1756
};
1793
1757
 
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)
1802
1766
  {}
1803
1767
  ~Item_result_field() {}                       /* Required with gcc 2.95 */
1804
1768
  Field *get_tmp_table_field() { return result_field; }
1813
1777
    save_in_field(result_field, no_conversions);
1814
1778
  }
1815
1779
  void cleanup();
1816
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1817
 
  { return false; }
1818
1780
};
1819
1781
 
1820
1782
 
1850
1812
           bool alias_name_used_arg= false);
1851
1813
 
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
1857
1819
  { 
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         
1885
1847
  {
1886
1848
    return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables(); 
1901
1863
  {
1902
1864
    return ref ? (*ref)->real_item() : this;
1903
1865
  }
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; }
1915
1877
 
1916
1878
  // Row emulation: forwarding of ROW-related calls to ref
1917
 
  uint32_t cols()
 
1879
  uint cols()
1918
1880
  {
1919
1881
    return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1920
1882
  }
1921
 
  Item* element_index(uint32_t i)
 
1883
  Item* element_index(uint i)
1922
1884
  {
1923
1885
    return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1924
1886
  }
1925
 
  Item** addr(uint32_t i)
 
1887
  Item** addr(uint i)
1926
1888
  {
1927
1889
    return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1928
1890
  }
1929
 
  bool check_cols(uint32_t c)
 
1891
  bool check_cols(uint c)
1930
1892
  {
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)
1960
1922
  {}
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) {}
1963
1925
 
1964
1926
  double val_real();
1965
1927
  int64_t val_int();
1967
1929
  my_decimal *val_decimal(my_decimal *);
1968
1930
  bool val_bool();
1969
1931
  bool is_null();
1970
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
1932
  bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
1971
1933
  virtual Ref_Type ref_type() { return DIRECT_REF; }
1972
1934
};
1973
1935
 
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) {}
1988
1950
 
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)
1992
1954
  {
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;
1995
1957
    return item;
1996
1958
  }
2042
2004
  {
2043
2005
    outer_ref->save_org_in_field(result_field);
2044
2006
  }
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
2048
2010
  {
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);
2084
2046
  /*
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));
2154
2116
  }
2155
2117
  int64_t val_int()
2156
2118
  {
2157
2119
    int err;
2158
 
    return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
2159
 
                                        str_value.length(),10, (char**) 0,
2160
 
                                        &err);
 
2120
    return null_value ? 0LL : my_strntoll(str_value.charset(),str_value.ptr(),
 
2121
                                            str_value.length(),10, (char**) 0,
 
2122
                                            &err); 
2161
2123
  }
2162
2124
  String *val_str(String*);
2163
2125
  my_decimal *val_decimal(my_decimal *);
2188
2150
  Item *item;
2189
2151
  String value,tmp_value;
2190
2152
public:
2191
 
  Cached_item_str(Session *session, Item *arg);
 
2153
  Cached_item_str(THD *thd, Item *arg);
2192
2154
  bool cmp(void);
2193
2155
  ~Cached_item_str();                           // Deallocate String:s
2194
2156
};
2224
2186
 
2225
2187
class Cached_item_field :public Cached_item
2226
2188
{
2227
 
  unsigned char *buff;
 
2189
  uchar *buff;
2228
2190
  Field *field;
2229
 
  uint32_t length;
 
2191
  uint length;
2230
2192
 
2231
2193
public:
2232
2194
  Cached_item_field(Field *arg_field) : field(arg_field)
2233
2195
  {
2234
2196
    field= arg_field;
2235
2197
    /* TODO: take the memory allocation below out of the constructor. */
2236
 
    buff= (unsigned char*) sql_calloc(length=field->pack_length());
 
2198
    buff= (uchar*) sql_calloc(length=field->pack_length());
2237
2199
  }
2238
2200
  bool cmp(void);
2239
2201
};
2252
2214
     arg(a) {}
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; }
2259
2221
 
2260
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
 
2222
  bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2261
2223
  {
2262
2224
    return arg->walk(processor, walk_subquery, args) ||
2263
2225
      (this->*processor)(args);
2264
2226
  }
2265
2227
 
2266
 
  Item *transform(Item_transformer transformer, unsigned char *args);
 
2228
  Item *transform(Item_transformer transformer, uchar *args);
2267
2229
};
2268
2230
 
2269
2231
/*
2285
2247
               (const char *)NULL),
2286
2248
     arg(a) {}
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)
2291
2253
  {
2297
2259
  */
2298
2260
  table_map used_tables() const { return RAND_TABLE_BIT; }
2299
2261
 
2300
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
 
2262
  bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2301
2263
  {
2302
2264
    return arg->walk(processor, walk_subquery, args) ||
2303
2265
            (this->*processor)(args);
2304
2266
  }
2305
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
2306
 
  { return true; }
2307
2267
};
2308
2268
 
2309
2269
 
2336
2296
 
2337
2297
  void set_used_tables(table_map map) { used_table_map= map; }
2338
2298
 
2339
 
  virtual bool allocate(uint32_t i __attribute__((unused)))
 
2299
  virtual bool allocate(uint i __attribute__((unused)))
2340
2300
  { return 0; }
2341
2301
  virtual bool setup(Item *item)
2342
2302
  {
2446
2406
class Item_cache_row: public Item_cache
2447
2407
{
2448
2408
  Item_cache  **values;
2449
 
  uint32_t item_count;
 
2409
  uint item_count;
2450
2410
  bool save_array;
2451
2411
public:
2452
2412
  Item_cache_row()
2456
2416
    'allocate' used only in row transformer, to preallocate space for row 
2457
2417
    cache.
2458
2418
  */
2459
 
  bool allocate(uint32_t num);
 
2419
  bool allocate(uint num);
2460
2420
  /*
2461
2421
    'setup' is needed only by row => it not called by simple row subselect
2462
2422
    (only by IN subselect (in subselect optimizer))
2491
2451
 
2492
2452
  enum Item_result result_type() const { return ROW_RESULT; }
2493
2453
  
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;
2530
2490
public:
2531
 
  Item_type_holder(Session*, Item*);
 
2491
  Item_type_holder(THD*, Item*);
2532
2492
 
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 *);
2545
2505
 
2546
2506
 
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);
2553
2513
 
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);
2558
 
 
2559
 
#endif