~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item.h

  • Committer: Monty Taylor
  • Date: 2008-07-15 21:40:58 UTC
  • mfrom: (77.1.113 codestyle32)
  • mto: This revision was merged to the branch mainline in revision 176.
  • Revision ID: mordred@camelot-20080715214058-rm3phulldos9xehv
Merged from codestyle.

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 */
 
15
 
 
16
 
 
17
#ifdef USE_PRAGMA_INTERFACE
 
18
#pragma interface                       /* gcc class implementation */
 
19
#endif
22
20
 
23
21
class Protocol;
24
 
struct TableList;
 
22
struct TABLE_LIST;
25
23
void item_init(void);                   /* Init item functions */
26
24
class Item_field;
27
25
 
49
47
 
50
48
class DTCollation {
51
49
public:
52
 
  const CHARSET_INFO *collation;
 
50
  CHARSET_INFO     *collation;
53
51
  enum Derivation derivation;
54
 
  uint32_t repertoire;
 
52
  uint repertoire;
55
53
  
56
 
  void set_repertoire_from_charset(const CHARSET_INFO * const cs)
 
54
  void set_repertoire_from_charset(CHARSET_INFO *cs)
57
55
  {
58
56
    repertoire= cs->state & MY_CS_PUREASCII ?
59
57
                MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
64
62
    derivation= DERIVATION_NONE;
65
63
    repertoire= MY_REPERTOIRE_UNICODE30;
66
64
  }
67
 
  DTCollation(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
 
65
  DTCollation(CHARSET_INFO *collation_arg, Derivation derivation_arg)
68
66
  {
69
67
    collation= collation_arg;
70
68
    derivation= derivation_arg;
76
74
    derivation= dt.derivation;
77
75
    repertoire= dt.repertoire;
78
76
  }
79
 
  void set(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
 
77
  void set(CHARSET_INFO *collation_arg, Derivation derivation_arg)
80
78
  {
81
79
    collation= collation_arg;
82
80
    derivation= derivation_arg;
83
81
    set_repertoire_from_charset(collation_arg);
84
82
  }
85
 
  void set(const CHARSET_INFO * const collation_arg,
 
83
  void set(CHARSET_INFO *collation_arg,
86
84
           Derivation derivation_arg,
87
 
           uint32_t repertoire_arg)
 
85
           uint repertoire_arg)
88
86
  {
89
87
    collation= collation_arg;
90
88
    derivation= derivation_arg;
91
89
    repertoire= repertoire_arg;
92
90
  }
93
 
  void set(const CHARSET_INFO * const collation_arg)
 
91
  void set(CHARSET_INFO *collation_arg)
94
92
  {
95
93
    collation= collation_arg;
96
94
    set_repertoire_from_charset(collation_arg);
97
95
  }
98
96
  void set(Derivation derivation_arg)
99
97
  { derivation= derivation_arg; }
100
 
  bool aggregate(DTCollation &dt, uint32_t flags= 0);
101
 
  bool set(DTCollation &dt1, DTCollation &dt2, uint32_t flags= 0)
 
98
  bool aggregate(DTCollation &dt, uint flags= 0);
 
99
  bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0)
102
100
  { set(dt1); return aggregate(dt2, flags); }
103
101
  const char *derivation_name() const
104
102
  {
168
166
  { val->real/= uint64_t2double(u); }
169
167
 
170
168
  virtual int64_t val_int(Hybrid_type *val,
171
 
                           bool unsigned_flag __attribute__((unused))) const
 
169
                           bool unsigned_flag __attribute__((__unused__))) const
172
170
  { return (int64_t) rint(val->real); }
173
171
  virtual double val_real(Hybrid_type *val) const { return val->real; }
174
172
  virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
175
 
  virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
 
173
  virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
176
174
  static const Hybrid_type_traits *instance();
177
175
  Hybrid_type_traits() {}
178
176
  virtual ~Hybrid_type_traits() {}
194
192
  virtual int64_t val_int(Hybrid_type *val, bool unsigned_flag) const;
195
193
  virtual double val_real(Hybrid_type *val) const;
196
194
  virtual my_decimal *val_decimal(Hybrid_type *val,
197
 
                                  my_decimal *buf __attribute__((unused))) const
 
195
                                  my_decimal *buf __attribute__((__unused__))) const
198
196
  { return &val->dec_buf[val->used_dec_buf_no]; }
199
 
  virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
 
197
  virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
200
198
  static const Hybrid_type_traits_decimal *instance();
201
199
  Hybrid_type_traits_decimal() {};
202
200
};
218
216
  { val->integer/= (int64_t) u; }
219
217
 
220
218
  virtual int64_t val_int(Hybrid_type *val,
221
 
                           bool unsigned_flag __attribute__((unused))) const
 
219
                           bool unsigned_flag __attribute__((__unused__))) const
222
220
  { return val->integer; }
223
221
  virtual double val_real(Hybrid_type *val) const
224
222
  { return (double) val->integer; }
225
223
  virtual my_decimal *val_decimal(Hybrid_type *val,
226
 
                                  my_decimal *buf __attribute__((unused))) const
 
224
                                  my_decimal *buf __attribute__((__unused__))) const
227
225
  {
228
226
    int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
229
227
    return &val->dec_buf[2];
230
228
  }
231
229
  virtual String *val_str(Hybrid_type *val, String *buf,
232
 
                          uint8_t decimals __attribute__((unused))) const
 
230
                          uint8 decimals __attribute__((__unused__))) const
233
231
  { buf->set(val->integer, &my_charset_bin); return buf;}
234
232
  static const Hybrid_type_traits_integer *instance();
235
233
  Hybrid_type_traits_integer() {};
271
269
    statements we have to change this member dynamically to ensure correct
272
270
    name resolution of different parts of the statement.
273
271
  */
274
 
  TableList *table_list;
 
272
  TABLE_LIST *table_list;
275
273
  /*
276
274
    In most cases the two table references below replace 'table_list' above
277
275
    for the purpose of name resolution. The first and last name resolution
279
277
    join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
280
278
    and JOIN ... ON. 
281
279
  */
282
 
  TableList *first_name_resolution_table;
 
280
  TABLE_LIST *first_name_resolution_table;
283
281
  /*
284
282
    Last table to search in the list of leaf table references that begins
285
283
    with first_name_resolution_table.
286
284
  */
287
 
  TableList *last_name_resolution_table;
 
285
  TABLE_LIST *last_name_resolution_table;
288
286
 
289
287
  /*
290
288
    SELECT_LEX item belong to, in case of merged VIEW it can differ from
328
326
    last_name_resolution_table= NULL;
329
327
  }
330
328
 
331
 
  void resolve_in_table_list_only(TableList *tables)
 
329
  void resolve_in_table_list_only(TABLE_LIST *tables)
332
330
  {
333
331
    table_list= first_name_resolution_table= tables;
334
332
    resolve_in_select_list= false;
348
346
class Name_resolution_context_state
349
347
{
350
348
private:
351
 
  TableList *save_table_list;
352
 
  TableList *save_first_name_resolution_table;
353
 
  TableList *save_next_name_resolution_table;
 
349
  TABLE_LIST *save_table_list;
 
350
  TABLE_LIST *save_first_name_resolution_table;
 
351
  TABLE_LIST *save_next_name_resolution_table;
354
352
  bool        save_resolve_in_select_list;
355
 
  TableList *save_next_local;
 
353
  TABLE_LIST *save_next_local;
356
354
 
357
355
public:
358
356
  Name_resolution_context_state() {}          /* Remove gcc warning */
359
357
 
360
358
public:
361
359
  /* Save the state of a name resolution context. */
362
 
  void save_state(Name_resolution_context *context, TableList *table_list)
 
360
  void save_state(Name_resolution_context *context, TABLE_LIST *table_list)
363
361
  {
364
362
    save_table_list=                  context->table_list;
365
363
    save_first_name_resolution_table= context->first_name_resolution_table;
369
367
  }
370
368
 
371
369
  /* Restore a name resolution context from saved state. */
372
 
  void restore_state(Name_resolution_context *context, TableList *table_list)
 
370
  void restore_state(Name_resolution_context *context, TABLE_LIST *table_list)
373
371
  {
374
372
    table_list->next_local=                save_next_local;
375
373
    table_list->next_name_resolution_table= save_next_name_resolution_table;
378
376
    context->resolve_in_select_list=       save_resolve_in_select_list;
379
377
  }
380
378
 
381
 
  TableList *get_first_name_resolution_table()
 
379
  TABLE_LIST *get_first_name_resolution_table()
382
380
  {
383
381
    return save_first_name_resolution_table;
384
382
  }
414
412
} enum_monotonicity_info;
415
413
 
416
414
/*************************************************************************/
417
 
typedef bool (Item::*Item_processor) (unsigned char *arg);
 
415
typedef bool (Item::*Item_processor) (uchar *arg);
418
416
/*
419
417
  Analyzer function
420
418
    SYNOPSIS
426
424
      false  Don't do it
427
425
 
428
426
*/
429
 
typedef bool (Item::*Item_analyzer) (unsigned char **argp);
430
 
typedef Item* (Item::*Item_transformer) (unsigned char *arg);
 
427
typedef bool (Item::*Item_analyzer) (uchar **argp);
 
428
typedef Item* (Item::*Item_transformer) (uchar *arg);
431
429
typedef void (*Cond_traverser) (const Item *item, void *arg);
432
430
 
433
431
 
436
434
  Item(const Item &);                   /* Prevent use of these */
437
435
  void operator=(Item &);
438
436
  /* Cache of the result of is_expensive(). */
439
 
  int8_t is_expensive_cache;
440
 
  virtual bool is_expensive_processor(unsigned char *arg __attribute__((unused)))
 
437
  int8 is_expensive_cache;
 
438
  virtual bool is_expensive_processor(uchar *arg __attribute__((__unused__)))
441
439
  { return 0; }
442
440
 
443
441
public:
445
443
  { return sql_alloc(size); }
446
444
  static void *operator new(size_t size, MEM_ROOT *mem_root)
447
445
  { return alloc_root(mem_root, size); }
448
 
  static void operator delete(void *ptr __attribute__((unused)),
449
 
                              size_t size __attribute__((unused)))
 
446
  static void operator delete(void *ptr __attribute__((__unused__)),
 
447
                              size_t size __attribute__((__unused__)))
450
448
  { TRASH(ptr, size); }
451
 
  static void operator delete(void *ptr __attribute__((unused)),
452
 
                              MEM_ROOT *mem_root __attribute__((unused)))
 
449
  static void operator delete(void *ptr __attribute__((__unused__)),
 
450
                              MEM_ROOT *mem_root __attribute__((__unused__)))
453
451
  {}
454
452
 
455
453
  enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
458
456
             PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
459
457
             FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
460
458
             SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
461
 
             PARAM_ITEM, DECIMAL_ITEM,
 
459
             PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
 
460
             XPATH_NODESET, XPATH_NODESET_CMP,
462
461
             VIEW_FIXER_ITEM};
463
462
 
464
463
  enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
466
465
  enum traverse_order { POSTFIX, PREFIX };
467
466
  
468
467
  /* Reuse size, only used by SP local variable assignment, otherwize 0 */
469
 
  uint32_t rsize;
 
468
  uint rsize;
470
469
 
471
470
  /*
472
471
    str_values's main purpose is to be used to cache the value in
477
476
  /* Original item name (if it was renamed)*/
478
477
  char * orig_name;
479
478
  Item *next;
480
 
  uint32_t max_length;
481
 
  uint32_t name_length;                     /* Length of name */
482
 
  int8_t marker;
483
 
  uint8_t decimals;
484
 
  bool maybe_null;                      /* If item may be null */
485
 
  bool null_value;                      /* if item is null */
486
 
  bool unsigned_flag;
487
 
  bool with_sum_func;
488
 
  bool fixed;                        /* If item fixed with fix_fields */
489
 
  bool is_autogenerated_name;        /* indicate was name of this Item
 
479
  uint32 max_length;
 
480
  uint name_length;                     /* Length of name */
 
481
  int8 marker;
 
482
  uint8 decimals;
 
483
  my_bool maybe_null;                   /* If item may be null */
 
484
  my_bool null_value;                   /* if item is null */
 
485
  my_bool unsigned_flag;
 
486
  my_bool with_sum_func;
 
487
  my_bool fixed;                        /* If item fixed with fix_fields */
 
488
  my_bool is_autogenerated_name;        /* indicate was name of this Item
490
489
                                           autogenerated or set by user */
491
490
  DTCollation collation;
492
 
  bool with_subselect;               /* If this item is a subselect or some
 
491
  my_bool with_subselect;               /* If this item is a subselect or some
493
492
                                           of its arguments is or contains a
494
493
                                           subselect. Computed by fix_fields. */
495
494
  Item_result cmp_context;              /* Comparison context */
510
509
    name=0;
511
510
#endif
512
511
  }             /*lint -e1509 */
513
 
  void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs);
 
512
  void set_name(const char *str, uint length, CHARSET_INFO *cs);
514
513
  void rename(char *new_name);
515
514
  void init_make_field(Send_field *tmp_field,enum enum_field_types type);
516
515
  virtual void cleanup();
517
516
  virtual void make_field(Send_field *field);
518
 
  Field *make_string_field(Table *table);
 
517
  Field *make_string_field(TABLE *table);
519
518
  virtual bool fix_fields(THD *, Item **);
520
519
  /*
521
520
    Fix after some tables has been pulled out. Basically re-calculate all
522
521
    attributes that are dependent on the tables.
523
522
  */
524
 
  virtual void fix_after_pullout(st_select_lex *new_parent __attribute__((unused)),
525
 
                                 Item **ref __attribute__((unused))) {};
 
523
  virtual void fix_after_pullout(st_select_lex *new_parent __attribute__((__unused__)),
 
524
                                 Item **ref __attribute__((__unused__))) {};
526
525
 
527
526
  /*
528
527
    should be used in case where we are sure that we do not need
585
584
        - If the value of the function is NULL then the bound is the
586
585
          smallest possible value of INT64_MIN
587
586
  */
588
 
  virtual int64_t val_int_endpoint(bool left_endp __attribute__((unused)),
589
 
                                    bool *incl_endp __attribute__((unused)))
 
587
  virtual int64_t val_int_endpoint(bool left_endp __attribute__((__unused__)),
 
588
                                    bool *incl_endp __attribute__((__unused__)))
590
589
  { assert(0); return 0; }
591
590
 
592
591
 
699
698
 
700
699
  virtual Field *get_tmp_table_field(void) { return 0; }
701
700
  /* This is also used to create fields in CREATE ... SELECT: */
702
 
  virtual Field *tmp_table_field(Table *t_arg __attribute__((unused)))
 
701
  virtual Field *tmp_table_field(TABLE *t_arg __attribute__((__unused__)))
703
702
  { return 0; }
704
703
  virtual const char *full_name(void) const { return name ? name : "???"; }
705
704
 
738
737
  /* cloning of constant items (0 if it is not const) */
739
738
  virtual Item *clone_item() { return 0; }
740
739
  virtual cond_result eq_cmp_result() const { return COND_OK; }
741
 
  inline uint32_t float_length(uint32_t decimals_par) const
 
740
  inline uint float_length(uint decimals_par) const
742
741
  { return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;}
743
 
  virtual uint32_t decimal_precision() const;
 
742
  virtual uint decimal_precision() const;
744
743
  inline int decimal_int_part() const
745
744
  { return my_decimal_int_part(decimal_precision(), decimals); }
746
745
  /* 
767
766
    mysql_register_view().
768
767
  */
769
768
  virtual inline void print(String *str,
770
 
                            enum_query_type query_type __attribute__((unused)))
 
769
                            enum_query_type query_type __attribute__((__unused__)))
771
770
  {
772
771
    str->append(full_name());
773
772
  }
774
773
 
775
774
  void print_item_w_name(String *, enum_query_type query_type);
776
775
  virtual void update_used_tables() {}
777
 
  virtual void split_sum_func(THD *thd __attribute__((unused)),
778
 
                              Item **ref_pointer_array __attribute__((unused)),
779
 
                              List<Item> &fields __attribute__((unused))) {}
 
776
  virtual void split_sum_func(THD *thd __attribute__((__unused__)),
 
777
                              Item **ref_pointer_array __attribute__((__unused__)),
 
778
                              List<Item> &fields __attribute__((__unused__))) {}
780
779
  /* Called for items that really have to be split */
781
780
  void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields,
782
781
                       Item **ref, bool skip_registered);
783
 
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
784
 
  virtual bool get_time(DRIZZLE_TIME *ltime);
785
 
  virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
782
  virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
783
  virtual bool get_time(MYSQL_TIME *ltime);
 
784
  virtual bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
786
785
  { return get_date(ltime,fuzzydate); }
787
786
  /*
788
787
    The method allows to determine nullness of a complex expression 
813
812
    set field of temporary table for Item which can be switched on temporary
814
813
    table during query processing (grouping and so on)
815
814
  */
816
 
  virtual void set_result_field(Field *field __attribute__((unused))) {}
 
815
  virtual void set_result_field(Field *field __attribute__((__unused__))) {}
817
816
  virtual bool is_result_field(void) { return 0; }
818
817
  virtual bool is_bool_func(void) { return 0; }
819
 
  virtual void save_in_result_field(bool no_conversions __attribute__((unused)))
 
818
  virtual void save_in_result_field(bool no_conversions __attribute__((__unused__)))
820
819
  {}
821
820
  /*
822
821
    set value of aggregate function in case of no rows for grouping were found
823
822
  */
824
823
  virtual void no_rows_in_result(void) {}
825
 
  virtual Item *copy_or_same(THD *thd __attribute__((unused)))
 
824
  virtual Item *copy_or_same(THD *thd __attribute__((__unused__)))
826
825
  { return this; }
827
 
  virtual Item *copy_andor_structure(THD *thd  __attribute__((unused)))
 
826
  virtual Item *copy_andor_structure(THD *thd  __attribute__((__unused__)))
828
827
  { return this; }
829
828
  virtual Item *real_item(void) { return this; }
830
829
  virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
831
830
 
832
 
  static const CHARSET_INFO *default_charset();
833
 
  virtual const CHARSET_INFO *compare_collation() { return NULL; }
 
831
  static CHARSET_INFO *default_charset();
 
832
  virtual CHARSET_INFO *compare_collation() { return NULL; }
834
833
 
835
 
  virtual bool walk(Item_processor processor __attribute__((unused)),
836
 
                    bool walk_subquery __attribute__((unused)),
837
 
                    unsigned char *arg)
 
834
  virtual bool walk(Item_processor processor __attribute__((__unused__)),
 
835
                    bool walk_subquery __attribute__((__unused__)),
 
836
                    uchar *arg)
838
837
  {
839
838
    return (this->*processor)(arg);
840
839
  }
841
840
 
842
 
  virtual Item* transform(Item_transformer transformer, unsigned char *arg);
 
841
  virtual Item* transform(Item_transformer transformer, uchar *arg);
843
842
 
844
843
  /*
845
844
    This function performs a generic "compilation" of the Item tree.
857
856
    i.e. analysis is performed top-down while transformation is done
858
857
    bottom-up.      
859
858
  */
860
 
  virtual Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
861
 
                        Item_transformer transformer, unsigned char *arg_t)
 
859
  virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
 
860
                        Item_transformer transformer, uchar *arg_t)
862
861
  {
863
862
    if ((this->*analyzer) (arg_p))
864
863
      return ((this->*transformer) (arg_t));
865
864
    return 0;
866
865
  }
867
866
 
868
 
   virtual void traverse_cond(Cond_traverser traverser __attribute__((unused)),
 
867
   virtual void traverse_cond(Cond_traverser traverser __attribute__((__unused__)),
869
868
                              void *arg,
870
 
                              traverse_order order __attribute__((unused)))
 
869
                              traverse_order order __attribute__((__unused__)))
871
870
   {
872
871
     (*traverser)(this, arg);
873
872
   }
874
873
 
875
 
  virtual bool remove_dependence_processor(unsigned char * arg __attribute__((unused)))
 
874
  virtual bool remove_dependence_processor(uchar * arg __attribute__((__unused__)))
876
875
  { return 0; }
877
 
  virtual bool remove_fixed(unsigned char * arg __attribute__((unused)))
 
876
  virtual bool remove_fixed(uchar * arg __attribute__((__unused__)))
878
877
  {
879
878
    fixed= 0;
880
879
    return 0;
881
880
  }
882
 
  virtual bool cleanup_processor(unsigned char *arg __attribute__((unused)));
883
 
  virtual bool collect_item_field_processor(unsigned char * arg __attribute__((unused)))
 
881
  virtual bool cleanup_processor(uchar *arg __attribute__((__unused__)));
 
882
  virtual bool collect_item_field_processor(uchar * arg __attribute__((__unused__)))
884
883
  { return 0; }
885
 
  virtual bool find_item_in_field_list_processor(unsigned char *arg __attribute__((unused)))
 
884
  virtual bool find_item_in_field_list_processor(uchar *arg __attribute__((__unused__)))
886
885
 { return 0; }
887
 
  virtual bool change_context_processor(unsigned char *context __attribute__((unused)))
888
 
  { return 0; }
889
 
  virtual bool reset_query_id_processor(unsigned char *query_id_arg __attribute__((unused)))
890
 
  { return 0; }
891
 
  virtual bool register_field_in_read_map(unsigned char *arg __attribute__((unused)))
892
 
  { return 0; }
893
 
  /*
894
 
    The next function differs from the previous one that a bitmap to be updated
895
 
    is passed as unsigned char *arg.
896
 
  */
897
 
  virtual bool register_field_in_bitmap(unsigned char *arg __attribute__((unused)))
898
 
  { return 0; }
899
 
  virtual bool subst_argument_checker(unsigned char **arg)
 
886
  virtual bool change_context_processor(uchar *context __attribute__((__unused__)))
 
887
  { return 0; }
 
888
  virtual bool reset_query_id_processor(uchar *query_id_arg __attribute__((__unused__)))
 
889
  { return 0; }
 
890
  virtual bool register_field_in_read_map(uchar *arg __attribute__((__unused__)))
 
891
  { return 0; }
 
892
  virtual bool subst_argument_checker(uchar **arg)
900
893
  {
901
894
    if (*arg)
902
895
      *arg= NULL;
903
896
    return true;
904
897
  }
905
898
 
906
 
  /*
907
 
    Check if an expression/function is allowed for a virtual column
908
 
    SYNOPSIS
909
 
      check_vcol_func_processor()
910
 
      arg is just ignored
911
 
    RETURN VALUE
912
 
      TRUE                           Function not accepted
913
 
      FALSE                          Function accepted
914
 
  */
915
 
  virtual bool check_vcol_func_processor(unsigned char *arg __attribute__((unused))) 
916
 
  { return true; }
917
 
 
918
 
  virtual Item *equal_fields_propagator(unsigned char * arg __attribute__((unused))) { return this; }
919
 
  virtual bool set_no_const_sub(unsigned char *arg __attribute__((unused))) { return false; }
920
 
  virtual Item *replace_equal_field(unsigned char * arg __attribute__((unused))) { return this; }
921
 
 
 
899
  virtual Item *equal_fields_propagator(uchar * arg __attribute__((__unused__))) { return this; }
 
900
  virtual bool set_no_const_sub(uchar *arg __attribute__((__unused__))) { return false; }
 
901
  virtual Item *replace_equal_field(uchar * arg __attribute__((__unused__))) { return this; }
922
902
 
923
903
  /*
924
904
    For SP local variable returns pointer to Item representing its
931
911
    For SP local variable returns address of pointer to Item representing its
932
912
    current value and pointer passed via parameter otherwise.
933
913
  */
934
 
  virtual Item **this_item_addr(THD *thd __attribute__((unused)), Item **addr_arg) { return addr_arg; }
 
914
  virtual Item **this_item_addr(THD *thd __attribute__((__unused__)), Item **addr_arg) { return addr_arg; }
935
915
 
936
916
  // Row emulation
937
 
  virtual uint32_t cols() { return 1; }
938
 
  virtual Item* element_index(uint32_t i __attribute__((unused))) { return this; }
939
 
  virtual Item** addr(uint32_t i __attribute__((unused))) { return 0; }
940
 
  virtual bool check_cols(uint32_t c);
 
917
  virtual uint cols() { return 1; }
 
918
  virtual Item* element_index(uint i __attribute__((__unused__))) { return this; }
 
919
  virtual Item** addr(uint i __attribute__((__unused__))) { return 0; }
 
920
  virtual bool check_cols(uint c);
941
921
  // It is not row => null inside is impossible
942
922
  virtual bool null_inside() { return 0; }
943
923
  // used in row subselects to get value of elements
944
924
  virtual void bring_value() {}
945
925
 
946
 
  Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
 
926
  Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length);
947
927
  virtual Item_field *filed_for_view_update() { return 0; }
948
928
 
949
 
  virtual Item *neg_transformer(THD *thd __attribute__((unused))) { return NULL; }
950
 
  virtual Item *update_value_transformer(unsigned char *select_arg __attribute__((unused))) { return this; }
951
 
  virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
929
  virtual Item *neg_transformer(THD *thd __attribute__((__unused__))) { return NULL; }
 
930
  virtual Item *update_value_transformer(uchar *select_arg __attribute__((__unused__))) { return this; }
 
931
  virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
952
932
  void delete_self()
953
933
  {
954
934
    cleanup();
979
959
  virtual bool is_expensive()
980
960
  {
981
961
    if (is_expensive_cache < 0)
982
 
      is_expensive_cache= walk(&Item::is_expensive_processor, 0, (unsigned char*)0);
 
962
      is_expensive_cache= walk(&Item::is_expensive_processor, 0, (uchar*)0);
983
963
    return test(is_expensive_cache);
984
964
  }
985
965
  String *check_well_formed_result(String *str, bool send_error= 0);
986
 
  bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs); 
 
966
  bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs); 
987
967
};
988
968
 
989
969
 
1004
984
};
1005
985
 
1006
986
bool agg_item_collations(DTCollation &c, const char *name,
1007
 
                         Item **items, uint32_t nitems, uint32_t flags, int item_sep);
 
987
                         Item **items, uint nitems, uint flags, int item_sep);
1008
988
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
1009
 
                                        Item **items, uint32_t nitems, uint32_t flags);
 
989
                                        Item **items, uint nitems, uint flags);
1010
990
bool agg_item_charsets(DTCollation &c, const char *name,
1011
 
                       Item **items, uint32_t nitems, uint32_t flags, int item_sep);
 
991
                       Item **items, uint nitems, uint flags, int item_sep);
1012
992
 
1013
993
 
1014
994
class Item_num: public Item_basic_constant
1016
996
public:
1017
997
  Item_num() {}                               /* Remove gcc warning */
1018
998
  virtual Item_num *neg()= 0;
1019
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
999
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1020
1000
};
1021
1001
 
1022
1002
#define NO_CACHED_FIELD_INDEX ((uint)(-1))
1046
1026
    stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX 
1047
1027
    if index value is not known.
1048
1028
  */
1049
 
  uint32_t cached_field_index;
 
1029
  uint cached_field_index;
1050
1030
  /*
1051
1031
    Cached pointer to table which contains this field, used for the same reason
1052
1032
    by prep. stmt. too in case then we have not-fully qualified field.
1053
1033
    0 - means no cached value.
1054
1034
  */
1055
 
  TableList *cached_table;
 
1035
  TABLE_LIST *cached_table;
1056
1036
  st_select_lex *depended_from;
1057
1037
  Item_ident(Name_resolution_context *context_arg,
1058
1038
             const char *db_name_arg, const char *table_name_arg,
1060
1040
  Item_ident(THD *thd, Item_ident *item);
1061
1041
  const char *full_name() const;
1062
1042
  void cleanup();
1063
 
  bool remove_dependence_processor(unsigned char * arg);
 
1043
  bool remove_dependence_processor(uchar * arg);
1064
1044
  virtual void print(String *str, enum_query_type query_type);
1065
 
  virtual bool change_context_processor(unsigned char *cntx)
 
1045
  virtual bool change_context_processor(uchar *cntx)
1066
1046
    { context= (Name_resolution_context *)cntx; return false; }
1067
1047
  friend bool insert_fields(THD *thd, Name_resolution_context *context,
1068
1048
                            const char *db_name,
1107
1087
    if any_privileges set to true then here real effective privileges will
1108
1088
    be stored
1109
1089
  */
1110
 
  uint32_t have_privileges;
 
1090
  uint have_privileges;
1111
1091
  /* field need any privileges (for VIEW creation) */
1112
1092
  bool any_privileges;
1113
1093
  Item_field(Name_resolution_context *context_arg,
1166
1146
  }
1167
1147
  int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
1168
1148
  Field *get_tmp_table_field() { return result_field; }
1169
 
  Field *tmp_table_field(Table *t_arg __attribute__((unused))) { return result_field; }
1170
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1171
 
  bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1172
 
  bool get_time(DRIZZLE_TIME *ltime);
 
1149
  Field *tmp_table_field(TABLE *t_arg __attribute__((__unused__))) { return result_field; }
 
1150
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
1151
  bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate);
 
1152
  bool get_time(MYSQL_TIME *ltime);
1173
1153
  bool is_null() { return field->is_null(); }
1174
1154
  void update_null_value();
1175
1155
  Item *get_tmp_table_item(THD *thd);
1176
 
  bool collect_item_field_processor(unsigned char * arg);
1177
 
  bool find_item_in_field_list_processor(unsigned char *arg);
1178
 
  bool register_field_in_read_map(unsigned char *arg);
1179
 
  bool register_field_in_bitmap(unsigned char *arg);
1180
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1181
 
  { return false; }
 
1156
  bool collect_item_field_processor(uchar * arg);
 
1157
  bool find_item_in_field_list_processor(uchar *arg);
 
1158
  bool register_field_in_read_map(uchar *arg);
1182
1159
  void cleanup();
1183
1160
  bool result_as_int64_t()
1184
1161
  {
1185
1162
    return field->can_be_compared_as_int64_t();
1186
1163
  }
1187
1164
  Item_equal *find_item_equal(COND_EQUAL *cond_equal);
1188
 
  bool subst_argument_checker(unsigned char **arg);
1189
 
  Item *equal_fields_propagator(unsigned char *arg);
1190
 
  bool set_no_const_sub(unsigned char *arg);
1191
 
  Item *replace_equal_field(unsigned char *arg);
1192
 
  inline uint32_t max_disp_length() { return field->max_display_length(); }
 
1165
  bool subst_argument_checker(uchar **arg);
 
1166
  Item *equal_fields_propagator(uchar *arg);
 
1167
  bool set_no_const_sub(uchar *arg);
 
1168
  Item *replace_equal_field(uchar *arg);
 
1169
  inline uint32 max_disp_length() { return field->max_display_length(); }
1193
1170
  Item_field *filed_for_view_update() { return this; }
1194
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
1171
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1195
1172
  int fix_outer_field(THD *thd, Field **field, Item **reference);
1196
 
  virtual Item *update_value_transformer(unsigned char *select_arg);
 
1173
  virtual Item *update_value_transformer(uchar *select_arg);
1197
1174
  virtual void print(String *str, enum_query_type query_type);
1198
1175
 
1199
1176
  friend class Item_default_value;
1222
1199
  int save_safe_in_field(Field *field);
1223
1200
  bool send(Protocol *protocol, String *str);
1224
1201
  enum Item_result result_type () const { return STRING_RESULT; }
1225
 
  enum_field_types field_type() const   { return DRIZZLE_TYPE_NULL; }
 
1202
  enum_field_types field_type() const   { return MYSQL_TYPE_NULL; }
1226
1203
  bool basic_const_item() const { return 1; }
1227
1204
  Item *clone_item() { return new Item_null(name); }
1228
1205
  bool is_null() { return 1; }
1229
1206
 
1230
1207
  virtual inline void print(String *str,
1231
 
                            enum_query_type query_type __attribute__((unused)))
 
1208
                            enum_query_type query_type __attribute__((__unused__)))
1232
1209
  {
1233
1210
    str->append(STRING_WITH_LEN("NULL"));
1234
1211
  }
1235
1212
 
1236
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1237
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1238
 
  { return false; }
 
1213
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1239
1214
};
1240
1215
 
1241
1216
class Item_null_result :public Item_null
1248
1223
  {
1249
1224
    save_in_field(result_field, no_conversions);
1250
1225
  }
1251
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1252
 
  { return true; }
1253
1226
};  
1254
1227
 
1255
1228
/* Item represents one placeholder ('?') of prepared statement */
1292
1265
    */
1293
1266
    struct CONVERSION_INFO
1294
1267
    {
1295
 
      const CHARSET_INFO *character_set_client;
1296
 
      const CHARSET_INFO *character_set_of_placeholder;
 
1268
      CHARSET_INFO *character_set_client;
 
1269
      CHARSET_INFO *character_set_of_placeholder;
1297
1270
      /*
1298
1271
        This points at character set of connection if conversion
1299
1272
        to it is required (i. e. if placeholder typecode is not BLOB).
1300
1273
        Otherwise it's equal to character_set_client (to simplify
1301
1274
        check in convert_str_value()).
1302
1275
      */
1303
 
      const CHARSET_INFO *final_character_set_of_str_value;
 
1276
      CHARSET_INFO *final_character_set_of_str_value;
1304
1277
    } cs_info;
1305
 
    DRIZZLE_TIME     time;
 
1278
    MYSQL_TIME     time;
1306
1279
  } value;
1307
1280
 
1308
1281
  /* Cached values for virtual methods to save us one switch.  */
1313
1286
    Used when this item is used in a temporary table.
1314
1287
    This is NOT placeholder metadata sent to client, as this value
1315
1288
    is assigned after sending metadata (in setup_one_conversion_function).
1316
 
    For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
 
1289
    For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
1317
1290
    in result set and placeholders metadata, no matter what type you will
1318
1291
    supply for this placeholder in mysql_stmt_execute.
1319
1292
  */
1322
1295
    Offset of placeholder inside statement text. Used to create
1323
1296
    no-placeholders version of this statement for the binary log.
1324
1297
  */
1325
 
  uint32_t pos_in_query;
 
1298
  uint pos_in_query;
1326
1299
 
1327
 
  Item_param(uint32_t pos_in_query_arg);
 
1300
  Item_param(uint pos_in_query_arg);
1328
1301
 
1329
1302
  enum Item_result result_type () const { return item_result_type; }
1330
1303
  enum Type type() const { return item_type; }
1334
1307
  int64_t val_int();
1335
1308
  my_decimal *val_decimal(my_decimal*);
1336
1309
  String *val_str(String*);
1337
 
  bool get_time(DRIZZLE_TIME *tm);
1338
 
  bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
 
1310
  bool get_time(MYSQL_TIME *tm);
 
1311
  bool get_date(MYSQL_TIME *tm, uint fuzzydate);
1339
1312
  int  save_in_field(Field *field, bool no_conversions);
1340
1313
 
1341
1314
  void set_null();
1342
 
  void set_int(int64_t i, uint32_t max_length_arg);
 
1315
  void set_int(int64_t i, uint32 max_length_arg);
1343
1316
  void set_double(double i);
1344
 
  void set_decimal(char *str, ulong length);
 
1317
  void set_decimal(const char *str, ulong length);
1345
1318
  bool set_str(const char *str, ulong length);
1346
1319
  bool set_longdata(const char *str, ulong length);
1347
 
  void set_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type type,
1348
 
                uint32_t max_length_arg);
 
1320
  void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
1349
1321
  bool set_from_user_var(THD *thd, const user_var_entry *entry);
1350
1322
  void reset();
1351
1323
  /*
1354
1326
    don't need to check that packet is not broken there). See
1355
1327
    sql_prepare.cc for details.
1356
1328
  */
1357
 
  void (*set_param_func)(Item_param *param, unsigned char **pos, ulong len);
 
1329
  void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
1358
1330
 
1359
1331
  const String *query_val_str(String *str) const;
1360
1332
 
1381
1353
    constant, assert otherwise. This method is called only if
1382
1354
    basic_const_item returned true.
1383
1355
  */
1384
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
1356
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1385
1357
  Item *clone_item();
1386
1358
  /*
1387
1359
    Implement by-value equality evaluation if parameter value
1398
1370
{
1399
1371
public:
1400
1372
  int64_t value;
1401
 
  Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS)
 
1373
  Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
1402
1374
    :value((int64_t) i)
1403
1375
    { max_length=length; fixed= 1; }
1404
 
  Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
 
1376
  Item_int(int64_t i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1405
1377
    :value(i)
1406
1378
    { max_length=length; fixed= 1; }
1407
 
  Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
 
1379
  Item_int(uint64_t i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1408
1380
    :value((int64_t)i)
1409
1381
    { max_length=length; fixed= 1; unsigned_flag= 1; }
1410
 
  Item_int(const char *str_arg,int64_t i,uint32_t length) :value(i)
 
1382
  Item_int(const char *str_arg,int64_t i,uint length) :value(i)
1411
1383
    { max_length=length; name=(char*) str_arg; fixed= 1; }
1412
 
  Item_int(const char *str_arg, uint32_t length=64);
 
1384
  Item_int(const char *str_arg, uint length=64);
1413
1385
  enum Type type() const { return INT_ITEM; }
1414
1386
  enum Item_result result_type () const { return INT_RESULT; }
1415
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
 
1387
  enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
1416
1388
  int64_t val_int() { assert(fixed == 1); return value; }
1417
1389
  double val_real() { assert(fixed == 1); return (double) value; }
1418
1390
  my_decimal *val_decimal(my_decimal *);
1422
1394
  Item *clone_item() { return new Item_int(name,value,max_length); }
1423
1395
  virtual void print(String *str, enum_query_type query_type);
1424
1396
  Item_num *neg() { value= -value; return this; }
1425
 
  uint32_t decimal_precision() const
 
1397
  uint decimal_precision() const
1426
1398
  { return (uint)(max_length - test(value < 0)); }
1427
1399
  bool eq(const Item *, bool binary_cmp) const;
1428
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1429
 
  { return false; }
1430
1400
};
1431
1401
 
1432
1402
 
1433
1403
class Item_uint :public Item_int
1434
1404
{
1435
1405
public:
1436
 
  Item_uint(const char *str_arg, uint32_t length);
 
1406
  Item_uint(const char *str_arg, uint length);
1437
1407
  Item_uint(uint64_t i) :Item_int((uint64_t) i, 10) {}
1438
 
  Item_uint(const char *str_arg, int64_t i, uint32_t length);
 
1408
  Item_uint(const char *str_arg, int64_t i, uint length);
1439
1409
  double val_real()
1440
1410
    { assert(fixed == 1); return uint64_t2double((uint64_t)value); }
1441
1411
  String *val_str(String*);
1443
1413
  int save_in_field(Field *field, bool no_conversions);
1444
1414
  virtual void print(String *str, enum_query_type query_type);
1445
1415
  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; }
 
1416
  uint decimal_precision() const { return max_length; }
1449
1417
};
1450
1418
 
1451
1419
 
1455
1423
protected:
1456
1424
  my_decimal decimal_value;
1457
1425
public:
1458
 
  Item_decimal(const char *str_arg, uint32_t length, const CHARSET_INFO * const charset);
 
1426
  Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset);
1459
1427
  Item_decimal(const char *str, const my_decimal *val_arg,
1460
 
               uint32_t decimal_par, uint32_t length);
 
1428
               uint decimal_par, uint length);
1461
1429
  Item_decimal(my_decimal *value_par);
1462
1430
  Item_decimal(int64_t val, bool unsig);
1463
1431
  Item_decimal(double val, int precision, int scale);
1464
 
  Item_decimal(const unsigned char *bin, int precision, int scale);
 
1432
  Item_decimal(const uchar *bin, int precision, int scale);
1465
1433
 
1466
1434
  enum Type type() const { return DECIMAL_ITEM; }
1467
1435
  enum Item_result result_type () const { return DECIMAL_RESULT; }
1468
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDECIMAL; }
 
1436
  enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
1469
1437
  int64_t val_int();
1470
1438
  double val_real();
1471
1439
  String *val_str(String*);
1472
 
  my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
 
1440
  my_decimal *val_decimal(my_decimal *val __attribute__((__unused__)))
1473
1441
  { return &decimal_value; }
1474
1442
  int save_in_field(Field *field, bool no_conversions);
1475
1443
  bool basic_const_item() const { return 1; }
1484
1452
    unsigned_flag= !decimal_value.sign();
1485
1453
    return this;
1486
1454
  }
1487
 
  uint32_t decimal_precision() const { return decimal_value.precision(); }
 
1455
  uint decimal_precision() const { return decimal_value.precision(); }
1488
1456
  bool eq(const Item *, bool binary_cmp) const;
1489
1457
  void set_decimal_value(my_decimal *value_par);
1490
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1491
 
  { return false; }
1492
1458
};
1493
1459
 
1494
1460
 
1498
1464
public:
1499
1465
  double value;
1500
1466
  // Item_real() :value(0) {}
1501
 
  Item_float(const char *str_arg, uint32_t length);
1502
 
  Item_float(const char *str,double val_arg,uint32_t decimal_par,uint32_t length)
 
1467
  Item_float(const char *str_arg, uint length);
 
1468
  Item_float(const char *str,double val_arg,uint decimal_par,uint length)
1503
1469
    :value(val_arg)
1504
1470
  {
1505
1471
    presentation= name=(char*) str;
1506
 
    decimals=(uint8_t) decimal_par;
 
1472
    decimals=(uint8) decimal_par;
1507
1473
    max_length=length;
1508
1474
    fixed= 1;
1509
1475
  }
1510
 
  Item_float(double value_par, uint32_t decimal_par) :presentation(0), value(value_par)
 
1476
  Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1511
1477
  {
1512
 
    decimals= (uint8_t) decimal_par;
 
1478
    decimals= (uint8) decimal_par;
1513
1479
    fixed= 1;
1514
1480
  }
1515
1481
  int save_in_field(Field *field, bool no_conversions);
1516
1482
  enum Type type() const { return REAL_ITEM; }
1517
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE; }
 
1483
  enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
1518
1484
  double val_real() { assert(fixed == 1); return value; }
1519
1485
  int64_t val_int()
1520
1486
  {
1544
1510
{
1545
1511
  const char *func_name;
1546
1512
public:
1547
 
  Item_static_float_func(const char *str, double val_arg, uint32_t decimal_par,
1548
 
                        uint32_t length)
1549
 
    :Item_float(NULL, val_arg, decimal_par, length), func_name(str)
 
1513
  Item_static_float_func(const char *str, double val_arg, uint decimal_par,
 
1514
                        uint length)
 
1515
    :Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1550
1516
  {}
1551
1517
 
1552
1518
  virtual inline void print(String *str,
1553
 
                            enum_query_type query_type __attribute__((unused)))
 
1519
                            enum_query_type query_type __attribute__((__unused__)))
1554
1520
  {
1555
1521
    str->append(func_name);
1556
1522
  }
1557
1523
 
1558
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1559
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1560
 
  { return false; }
 
1524
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1561
1525
};
1562
1526
 
1563
1527
 
1564
1528
class Item_string :public Item_basic_constant
1565
1529
{
1566
1530
public:
1567
 
  Item_string(const char *str,uint32_t length,
1568
 
              const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1569
 
              uint32_t repertoire= MY_REPERTOIRE_UNICODE30)
 
1531
  Item_string(const char *str,uint length,
 
1532
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
 
1533
              uint repertoire= MY_REPERTOIRE_UNICODE30)
1570
1534
    : m_cs_specified(false)
1571
1535
  {
1572
1536
    str_value.set_or_copy_aligned(str, length, cs);
1585
1549
    fixed= 1;
1586
1550
  }
1587
1551
  /* Just create an item and do not fill string representation */
1588
 
  Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
 
1552
  Item_string(CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
1589
1553
    : m_cs_specified(false)
1590
1554
  {
1591
1555
    collation.set(cs, dv);
1594
1558
    decimals= NOT_FIXED_DEC;
1595
1559
    fixed= 1;
1596
1560
  }
1597
 
  Item_string(const char *name_par, const char *str, uint32_t length,
1598
 
              const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1599
 
              uint32_t repertoire= MY_REPERTOIRE_UNICODE30)
 
1561
  Item_string(const char *name_par, const char *str, uint length,
 
1562
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
 
1563
              uint repertoire= MY_REPERTOIRE_UNICODE30)
1600
1564
    : m_cs_specified(false)
1601
1565
  {
1602
1566
    str_value.set_or_copy_aligned(str, length, cs);
1611
1575
    This is used in stored procedures to avoid memory leaks and
1612
1576
    does a deep copy of its argument.
1613
1577
  */
1614
 
  void set_str_with_copy(const char *str_arg, uint32_t length_arg)
 
1578
  void set_str_with_copy(const char *str_arg, uint length_arg)
1615
1579
  {
1616
1580
    str_value.copy(str_arg, length_arg, collation.collation);
1617
1581
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
1633
1597
  my_decimal *val_decimal(my_decimal *);
1634
1598
  int save_in_field(Field *field, bool no_conversions);
1635
1599
  enum Item_result result_type () const { return STRING_RESULT; }
1636
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
 
1600
  enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1637
1601
  bool basic_const_item() const { return 1; }
1638
1602
  bool eq(const Item *item, bool binary_cmp) const;
1639
1603
  Item *clone_item() 
1641
1605
    return new Item_string(name, str_value.ptr(), 
1642
1606
                           str_value.length(), collation.collation);
1643
1607
  }
1644
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1645
 
  inline void append(char *str, uint32_t length)
 
1608
  Item *safe_charset_converter(CHARSET_INFO *tocs);
 
1609
  inline void append(char *str, uint length)
1646
1610
  {
1647
1611
    str_value.append(str, length);
1648
1612
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
1687
1651
  {
1688
1652
    m_cs_specified= cs_specified;
1689
1653
  }
1690
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1691
 
  { return false; }
1692
1654
 
1693
1655
private:
1694
1656
  bool m_cs_specified;
1699
1661
{
1700
1662
  const char *func_name;
1701
1663
public:
1702
 
  Item_static_string_func(const char *name_par, const char *str, uint32_t length,
1703
 
                          const CHARSET_INFO * const cs,
 
1664
  Item_static_string_func(const char *name_par, const char *str, uint length,
 
1665
                          CHARSET_INFO *cs,
1704
1666
                          Derivation dv= DERIVATION_COERCIBLE)
1705
 
    :Item_string(NULL, str, length, cs, dv), func_name(name_par)
 
1667
    :Item_string(NullS, str, length, cs, dv), func_name(name_par)
1706
1668
  {}
1707
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
1669
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1708
1670
 
1709
1671
  virtual inline void print(String *str,
1710
 
                            enum_query_type query_type __attribute__((unused)))
 
1672
                            enum_query_type query_type __attribute__((__unused__)))
1711
1673
  {
1712
1674
    str->append(func_name);
1713
1675
  }
1714
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1715
 
  { return true; }
1716
1676
};
1717
1677
 
1718
1678
 
1732
1692
class Item_blob :public Item_string
1733
1693
{
1734
1694
public:
1735
 
  Item_blob(const char *name, uint32_t length) :
 
1695
  Item_blob(const char *name, uint length) :
1736
1696
    Item_string(name, length, &my_charset_bin)
1737
1697
  { max_length= length; }
1738
1698
  enum Type type() const { return TYPE_HOLDER; }
1739
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
 
1699
  enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
1740
1700
};
1741
1701
 
1742
1702
 
1749
1709
class Item_empty_string :public Item_string
1750
1710
{
1751
1711
public:
1752
 
  Item_empty_string(const char *header,uint32_t length, const CHARSET_INFO * cs= NULL) :
 
1712
  Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) :
1753
1713
    Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1754
1714
    { name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1755
1715
  void make_field(Send_field *field);
1760
1720
{
1761
1721
  enum_field_types int_field_type;
1762
1722
public:
1763
 
  Item_return_int(const char *name_arg, uint32_t length,
 
1723
  Item_return_int(const char *name_arg, uint length,
1764
1724
                  enum_field_types field_type_arg, int64_t value= 0)
1765
1725
    :Item_int(name_arg, value, length), int_field_type(field_type_arg)
1766
1726
  {
1774
1734
{
1775
1735
public:
1776
1736
  Item_hex_string() {}
1777
 
  Item_hex_string(const char *str,uint32_t str_length);
 
1737
  Item_hex_string(const char *str,uint str_length);
1778
1738
  enum Type type() const { return VARBIN_ITEM; }
1779
1739
  double val_real()
1780
1740
  { 
1788
1748
  int save_in_field(Field *field, bool no_conversions);
1789
1749
  enum Item_result result_type () const { return STRING_RESULT; }
1790
1750
  enum Item_result cast_to_int_type() const { return INT_RESULT; }
1791
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
 
1751
  enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1792
1752
  virtual void print(String *str, enum_query_type query_type);
1793
1753
  bool eq(const Item *item, bool binary_cmp) const;
1794
 
  virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1795
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1796
 
  { return false; }
 
1754
  virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
1797
1755
};
1798
1756
 
1799
1757
 
1800
1758
class Item_bin_string: public Item_hex_string
1801
1759
{
1802
1760
public:
1803
 
  Item_bin_string(const char *str,uint32_t str_length);
 
1761
  Item_bin_string(const char *str,uint str_length);
1804
1762
};
1805
1763
 
1806
1764
class Item_result_field :public Item    /* Item with result field */
1814
1772
  {}
1815
1773
  ~Item_result_field() {}                       /* Required with gcc 2.95 */
1816
1774
  Field *get_tmp_table_field() { return result_field; }
1817
 
  Field *tmp_table_field(Table *t_arg __attribute__((unused)))
 
1775
  Field *tmp_table_field(TABLE *t_arg __attribute__((__unused__)))
1818
1776
  { return result_field; }
1819
1777
  table_map used_tables() const { return 1; }
1820
1778
  virtual void fix_length_and_dec()=0;
1825
1783
    save_in_field(result_field, no_conversions);
1826
1784
  }
1827
1785
  void cleanup();
1828
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1829
 
  { return false; }
1830
1786
};
1831
1787
 
1832
1788
 
1876
1832
  bool val_bool();
1877
1833
  String *val_str(String* tmp);
1878
1834
  bool is_null();
1879
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
1835
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1880
1836
  double val_result();
1881
1837
  int64_t val_int_result();
1882
1838
  String *str_result(String* tmp);
1913
1869
  {
1914
1870
    return ref ? (*ref)->real_item() : this;
1915
1871
  }
1916
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
 
1872
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1917
1873
  { return (*ref)->walk(processor, walk_subquery, arg); }
1918
1874
  virtual void print(String *str, enum_query_type query_type);
1919
1875
  bool result_as_int64_t()
1926
1882
  virtual Ref_Type ref_type() { return REF; }
1927
1883
 
1928
1884
  // Row emulation: forwarding of ROW-related calls to ref
1929
 
  uint32_t cols()
 
1885
  uint cols()
1930
1886
  {
1931
1887
    return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1932
1888
  }
1933
 
  Item* element_index(uint32_t i)
 
1889
  Item* element_index(uint i)
1934
1890
  {
1935
1891
    return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1936
1892
  }
1937
 
  Item** addr(uint32_t i)
 
1893
  Item** addr(uint i)
1938
1894
  {
1939
1895
    return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1940
1896
  }
1941
 
  bool check_cols(uint32_t c)
 
1897
  bool check_cols(uint c)
1942
1898
  {
1943
1899
    return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c) 
1944
1900
                                              : Item::check_cols(c);
1979
1935
  my_decimal *val_decimal(my_decimal *);
1980
1936
  bool val_bool();
1981
1937
  bool is_null();
1982
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
1938
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1983
1939
  virtual Ref_Type ref_type() { return DIRECT_REF; }
1984
1940
};
1985
1941
 
2050
2006
                     alias_name_used_arg),
2051
2007
    outer_ref(0), in_sum_func(0), found_in_select_list(1)
2052
2008
  {}
2053
 
  void save_in_result_field(bool no_conversions __attribute__((unused)))
 
2009
  void save_in_result_field(bool no_conversions __attribute__((__unused__)))
2054
2010
  {
2055
2011
    outer_ref->save_org_in_field(result_field);
2056
2012
  }
2091
2047
  String* val_str(String* s);
2092
2048
  my_decimal *val_decimal(my_decimal *);
2093
2049
  bool val_bool();
2094
 
  bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
 
2050
  bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
2095
2051
  virtual void print(String *str, enum_query_type query_type);
2096
2052
  /*
2097
2053
    we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2117
2073
{
2118
2074
  Item *ref;
2119
2075
public:
2120
 
  Item_int_with_ref(int64_t i, Item *ref_arg, bool unsigned_arg) :
 
2076
  Item_int_with_ref(int64_t i, Item *ref_arg, my_bool unsigned_arg) :
2121
2077
    Item_int(i), ref(ref_arg)
2122
2078
  {
2123
2079
    unsigned_flag= unsigned_arg;
2130
2086
  virtual Item *real_item() { return ref; }
2131
2087
};
2132
2088
 
2133
 
#ifdef DRIZZLE_SERVER
 
2089
#ifdef MYSQL_SERVER
2134
2090
#include "item_sum.h"
2135
2091
#include "item_func.h"
2136
2092
#include "item_row.h"
2147
2103
  Item *item;
2148
2104
  Item_copy_string(Item *i) :item(i)
2149
2105
  {
2150
 
    null_value= maybe_null= item->maybe_null;
 
2106
    null_value=maybe_null=item->maybe_null;
2151
2107
    decimals=item->decimals;
2152
2108
    max_length=item->max_length;
2153
2109
    name=item->name;
2161
2117
    int err_not_used;
2162
2118
    char *end_not_used;
2163
2119
    return (null_value ? 0.0 :
2164
 
            my_strntod(str_value.charset(), (char*) str_value.ptr(),
2165
 
                       str_value.length(), &end_not_used, &err_not_used));
 
2120
            my_strntod(str_value.charset(), (char*) str_value.ptr(),
 
2121
                       str_value.length(), &end_not_used, &err_not_used));
2166
2122
  }
2167
2123
  int64_t val_int()
2168
2124
  {
2169
2125
    int err;
2170
 
    return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
2171
 
                                        str_value.length(),10, (char**) 0,
2172
 
                                        &err);
 
2126
    return null_value ? 0LL : my_strntoll(str_value.charset(),str_value.ptr(),
 
2127
                                            str_value.length(),10, (char**) 0,
 
2128
                                            &err); 
2173
2129
  }
2174
2130
  String *val_str(String*);
2175
2131
  my_decimal *val_decimal(my_decimal *);
2176
2132
  void make_field(Send_field *field) { item->make_field(field); }
2177
2133
  void copy();
2178
2134
  int save_in_field(Field *field,
2179
 
                    bool no_conversions __attribute__((unused)))
 
2135
                    bool no_conversions __attribute__((__unused__)))
2180
2136
  {
2181
2137
    return save_str_value_in_field(field, &str_value);
2182
2138
  }
2189
2145
class Cached_item :public Sql_alloc
2190
2146
{
2191
2147
public:
2192
 
  bool null_value;
 
2148
  my_bool null_value;
2193
2149
  Cached_item() :null_value(0) {}
2194
2150
  virtual bool cmp(void)=0;
2195
2151
  virtual ~Cached_item(); /*line -e1509 */
2236
2192
 
2237
2193
class Cached_item_field :public Cached_item
2238
2194
{
2239
 
  unsigned char *buff;
 
2195
  uchar *buff;
2240
2196
  Field *field;
2241
 
  uint32_t length;
 
2197
  uint length;
2242
2198
 
2243
2199
public:
2244
2200
  Cached_item_field(Field *arg_field) : field(arg_field)
2245
2201
  {
2246
2202
    field= arg_field;
2247
2203
    /* TODO: take the memory allocation below out of the constructor. */
2248
 
    buff= (unsigned char*) sql_calloc(length=field->pack_length());
 
2204
    buff= (uchar*) sql_calloc(length=field->pack_length());
2249
2205
  }
2250
2206
  bool cmp(void);
2251
2207
};
2269
2225
  int save_in_field(Field *field_arg, bool no_conversions);
2270
2226
  table_map used_tables() const { return (table_map)0L; }
2271
2227
 
2272
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
 
2228
  bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2273
2229
  {
2274
2230
    return arg->walk(processor, walk_subquery, args) ||
2275
2231
      (this->*processor)(args);
2276
2232
  }
2277
2233
 
2278
 
  Item *transform(Item_transformer transformer, unsigned char *args);
 
2234
  Item *transform(Item_transformer transformer, uchar *args);
2279
2235
};
2280
2236
 
2281
2237
/*
2309
2265
  */
2310
2266
  table_map used_tables() const { return RAND_TABLE_BIT; }
2311
2267
 
2312
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
 
2268
  bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2313
2269
  {
2314
2270
    return arg->walk(processor, walk_subquery, args) ||
2315
2271
            (this->*processor)(args);
2316
2272
  }
2317
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
2318
 
  { return true; }
2319
2273
};
2320
2274
 
2321
2275
 
2334
2288
  enum enum_field_types cached_field_type;
2335
2289
public:
2336
2290
  Item_cache(): 
2337
 
    example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR) 
 
2291
    example(0), used_table_map(0), cached_field(0), cached_field_type(MYSQL_TYPE_STRING) 
2338
2292
  {
2339
2293
    fixed= 1; 
2340
2294
    null_value= 1;
2348
2302
 
2349
2303
  void set_used_tables(table_map map) { used_table_map= map; }
2350
2304
 
2351
 
  virtual bool allocate(uint32_t i __attribute__((unused)))
 
2305
  virtual bool allocate(uint i __attribute__((__unused__)))
2352
2306
  { return 0; }
2353
2307
  virtual bool setup(Item *item)
2354
2308
  {
2373
2327
    return cached_field ? cached_field->eq_def (field) : false;
2374
2328
  }
2375
2329
  bool eq(const Item *item,
2376
 
          bool binary_cmp __attribute__((unused))) const
 
2330
          bool binary_cmp __attribute__((__unused__))) const
2377
2331
  {
2378
2332
    return this == item;
2379
2333
  }
2442
2396
    Item_cache(), value(0),
2443
2397
    is_varbinary(item->type() == FIELD_ITEM &&
2444
2398
                 ((const Item_field *) item)->field->type() ==
2445
 
                   DRIZZLE_TYPE_VARCHAR &&
 
2399
                   MYSQL_TYPE_VARCHAR &&
2446
2400
                 !((const Item_field *) item)->field->has_charset())
2447
2401
  {}
2448
2402
  void store(Item *item);
2451
2405
  String* val_str(String *) { assert(fixed == 1); return value; }
2452
2406
  my_decimal *val_decimal(my_decimal *);
2453
2407
  enum Item_result result_type() const { return STRING_RESULT; }
2454
 
  const CHARSET_INFO *charset() const { return value->charset(); };
 
2408
  CHARSET_INFO *charset() const { return value->charset(); };
2455
2409
  int save_in_field(Field *field, bool no_conversions);
2456
2410
};
2457
2411
 
2458
2412
class Item_cache_row: public Item_cache
2459
2413
{
2460
2414
  Item_cache  **values;
2461
 
  uint32_t item_count;
 
2415
  uint item_count;
2462
2416
  bool save_array;
2463
2417
public:
2464
2418
  Item_cache_row()
2468
2422
    'allocate' used only in row transformer, to preallocate space for row 
2469
2423
    cache.
2470
2424
  */
2471
 
  bool allocate(uint32_t num);
 
2425
  bool allocate(uint num);
2472
2426
  /*
2473
2427
    'setup' is needed only by row => it not called by simple row subselect
2474
2428
    (only by IN subselect (in subselect optimizer))
2495
2449
    illegal_method_call((const char*)"val_str");
2496
2450
    return 0;
2497
2451
  };
2498
 
  my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
 
2452
  my_decimal *val_decimal(my_decimal *val __attribute__((__unused__)))
2499
2453
  {
2500
2454
    illegal_method_call((const char*)"val_decimal");
2501
2455
    return 0;
2503
2457
 
2504
2458
  enum Item_result result_type() const { return ROW_RESULT; }
2505
2459
  
2506
 
  uint32_t cols() { return item_count; }
2507
 
  Item *element_index(uint32_t i) { return values[i]; }
2508
 
  Item **addr(uint32_t i) { return (Item **) (values + i); }
2509
 
  bool check_cols(uint32_t c);
 
2460
  uint cols() { return item_count; }
 
2461
  Item *element_index(uint i) { return values[i]; }
 
2462
  Item **addr(uint i) { return (Item **) (values + i); }
 
2463
  bool check_cols(uint c);
2510
2464
  bool null_inside();
2511
2465
  void bring_value();
2512
2466
  void keep_array() { save_array= 1; }
2514
2468
  {
2515
2469
    Item_cache::cleanup();
2516
2470
    if (save_array)
2517
 
      memset(values, 0, item_count*sizeof(Item**));
 
2471
      bzero(values, item_count*sizeof(Item**));
2518
2472
    else
2519
2473
      values= 0;
2520
2474
    return;
2550
2504
  my_decimal *val_decimal(my_decimal *);
2551
2505
  String *val_str(String*);
2552
2506
  bool join_types(THD *thd, Item *);
2553
 
  Field *make_field_by_type(Table *table);
2554
 
  static uint32_t display_length(Item *item);
 
2507
  Field *make_field_by_type(TABLE *table);
 
2508
  static uint32 display_length(Item *item);
2555
2509
  static enum_field_types get_real_type(Item *);
2556
2510
};
2557
2511
 
2567
2521
                                    bool use_result_field);
2568
2522
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
2569
2523
extern bool field_is_equal_to_item(Field *field,Item *item);
2570
 
 
2571
 
#endif