~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item.h

MergingĀ mainline

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
  {
126
124
 
127
125
struct Hybrid_type
128
126
{
129
 
  int64_t integer;
 
127
  longlong integer;
130
128
 
131
129
  double real;
132
130
  /*
164
162
  virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
165
163
  virtual void add(Hybrid_type *val, Field *f) const
166
164
  { val->real+= f->val_real(); }
167
 
  virtual void div(Hybrid_type *val, uint64_t u) const
168
 
  { val->real/= uint64_t2double(u); }
 
165
  virtual void div(Hybrid_type *val, ulonglong u) const
 
166
  { val->real/= ulonglong2double(u); }
169
167
 
170
 
  virtual int64_t val_int(Hybrid_type *val,
171
 
                           bool unsigned_flag __attribute__((unused))) const
172
 
  { return (int64_t) rint(val->real); }
 
168
  virtual longlong val_int(Hybrid_type *val,
 
169
                           bool unsigned_flag __attribute__((__unused__))) const
 
170
  { return (longlong) 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() {}
189
187
  /* Hybrid_type operations. */
190
188
  virtual void set_zero(Hybrid_type *val) const;
191
189
  virtual void add(Hybrid_type *val, Field *f) const;
192
 
  virtual void div(Hybrid_type *val, uint64_t u) const;
 
190
  virtual void div(Hybrid_type *val, ulonglong u) const;
193
191
 
194
 
  virtual int64_t val_int(Hybrid_type *val, bool unsigned_flag) const;
 
192
  virtual longlong 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
};
214
212
  { val->integer= 0; }
215
213
  virtual void add(Hybrid_type *val, Field *f) const
216
214
  { val->integer+= f->val_int(); }
217
 
  virtual void div(Hybrid_type *val, uint64_t u) const
218
 
  { val->integer/= (int64_t) u; }
 
215
  virtual void div(Hybrid_type *val, ulonglong u) const
 
216
  { val->integer/= (longlong) u; }
219
217
 
220
 
  virtual int64_t val_int(Hybrid_type *val,
221
 
                           bool unsigned_flag __attribute__((unused))) const
 
218
  virtual longlong val_int(Hybrid_type *val,
 
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
302
300
  void *error_processor_data;
303
301
 
304
302
  /*
305
 
    When true items are resolved in this context both against the
306
 
    SELECT list and this->table_list. If false, items are resolved
 
303
    When TRUE items are resolved in this context both against the
 
304
    SELECT list and this->table_list. If FALSE, items are resolved
307
305
    only against this->table_list.
308
306
  */
309
307
  bool resolve_in_select_list;
322
320
 
323
321
  void init()
324
322
  {
325
 
    resolve_in_select_list= false;
 
323
    resolve_in_select_list= FALSE;
326
324
    error_processor= &dummy_error_processor;
327
325
    first_name_resolution_table= NULL;
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
 
    resolve_in_select_list= false;
 
332
    resolve_in_select_list= FALSE;
335
333
  }
336
334
 
337
335
  void process_error(THD *thd)
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
  }
393
391
  etc etc). An Item* tree is assumed to have the same monotonicity properties
394
392
  as its correspoinding function F:
395
393
 
396
 
  [signed] int64_t F(field1, field2, ...) {
 
394
  [signed] longlong F(field1, field2, ...) {
397
395
    put values of field_i into table record buffer;
398
396
    return item->val_int(); 
399
397
  }
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
422
420
                    OUT: Parameter to be passed to the transformer
423
421
 
424
422
    RETURN 
425
 
      true   Invoke the transformer
426
 
      false  Don't do it
 
423
      TRUE   Invoke the transformer
 
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
557
556
 
558
557
    SYNOPSIS
559
558
      val_int_endpoint()
560
 
        left_endp  false  <=> The interval is "x < const" or "x <= const"
561
 
                   true   <=> The interval is "x > const" or "x >= const"
 
559
        left_endp  FALSE  <=> The interval is "x < const" or "x <= const"
 
560
                   TRUE   <=> The interval is "x > const" or "x >= const"
562
561
 
563
 
        incl_endp  IN   true <=> the comparison is '<' or '>'
564
 
                        false <=> the comparison is '<=' or '>='
 
562
        incl_endp  IN   TRUE <=> the comparison is '<' or '>'
 
563
                        FALSE <=> the comparison is '<=' or '>='
565
564
                   OUT  The same but for the "F(x) $CMP$ F(const)" comparison
566
565
 
567
566
    DESCRIPTION
583
582
    RETURN
584
583
      The output range bound, which equal to the value of val_int()
585
584
        - If the value of the function is NULL then the bound is the
586
 
          smallest possible value of INT64_MIN
 
585
          smallest possible value of LONGLONG_MIN
587
586
  */
588
 
  virtual int64_t val_int_endpoint(bool left_endp __attribute__((unused)),
589
 
                                    bool *incl_endp __attribute__((unused)))
 
587
  virtual longlong val_int_endpoint(bool left_endp __attribute__((__unused__)),
 
588
                                    bool *incl_endp __attribute__((__unused__)))
590
589
  { assert(0); return 0; }
591
590
 
592
591
 
598
597
      val_real()
599
598
 
600
599
    RETURN
601
 
      In case of NULL value return 0.0 and set null_value flag to true.
602
 
      If value is not null null_value flag will be reset to false.
 
600
      In case of NULL value return 0.0 and set null_value flag to TRUE.
 
601
      If value is not null null_value flag will be reset to FALSE.
603
602
  */
604
603
  virtual double val_real()=0;
605
604
  /*
609
608
      val_int()
610
609
 
611
610
    RETURN
612
 
      In case of NULL value return 0 and set null_value flag to true.
613
 
      If value is not null null_value flag will be reset to false.
 
611
      In case of NULL value return 0 and set null_value flag to TRUE.
 
612
      If value is not null null_value flag will be reset to FALSE.
614
613
  */
615
 
  virtual int64_t val_int()=0;
 
614
  virtual longlong val_int()=0;
616
615
  /*
617
616
    This is just a shortcut to avoid the cast. You should still use
618
617
    unsigned_flag to check the sign of the item.
619
618
  */
620
 
  inline uint64_t val_uint() { return (uint64_t) val_int(); }
 
619
  inline ulonglong val_uint() { return (ulonglong) val_int(); }
621
620
  /*
622
621
    Return string representation of this item object.
623
622
 
649
648
 
650
649
    RETURN
651
650
      In case of NULL value return 0 (NULL pointer) and set null_value flag
652
 
      to true.
653
 
      If value is not null null_value flag will be reset to false.
 
651
      to TRUE.
 
652
      If value is not null null_value flag will be reset to FALSE.
654
653
  */
655
654
  virtual String *val_str(String *str)=0;
656
655
  /*
667
666
 
668
667
    RETURN
669
668
      Return pointer on my_decimal (it can be other then passed via argument)
670
 
        if value is not NULL (null_value flag will be reset to false).
 
669
        if value is not NULL (null_value flag will be reset to FALSE).
671
670
      In case of NULL value it return 0 pointer and set null_value flag
672
 
        to true.
 
671
        to TRUE.
673
672
  */
674
673
  virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
675
674
  /*
676
675
    Return boolean value of item.
677
676
 
678
677
    RETURN
679
 
      false value is false or NULL
680
 
      true value is true (not equal to 0)
 
678
      FALSE value is false or NULL
 
679
      TRUE value is true (not equal to 0)
681
680
  */
682
681
  virtual bool val_bool();
683
682
  virtual String *val_nodeset(String*) { return 0; }
690
689
  my_decimal *val_decimal_from_string(my_decimal *decimal_value);
691
690
  my_decimal *val_decimal_from_date(my_decimal *decimal_value);
692
691
  my_decimal *val_decimal_from_time(my_decimal *decimal_value);
693
 
  int64_t val_int_from_decimal();
 
692
  longlong val_int_from_decimal();
694
693
  double val_real_from_decimal();
695
694
 
696
695
  int save_time_in_field(Field *field);
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
 
710
709
    way as *val* methods do it.
711
710
  */
712
711
  virtual double  val_result() { return val_real(); }
713
 
  virtual int64_t val_int_result() { return val_int(); }
 
712
  virtual longlong val_int_result() { return val_int(); }
714
713
  virtual String *str_result(String* tmp) { return val_str(tmp); }
715
714
  virtual my_decimal *val_decimal_result(my_decimal *val)
716
715
  { return val_decimal(val); }
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 
800
799
 
801
800
  /*
802
801
    Inform the item that there will be no distinction between its result
803
 
    being false or NULL.
 
802
    being FALSE or NULL.
804
803
 
805
804
    NOTE
806
805
      This function will be called for eg. Items that are top-level AND-parts
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();
956
936
  }
957
937
 
958
938
  /*
959
 
    result_as_int64_t() must return true for Items representing DATE/TIME
 
939
    result_as_longlong() must return TRUE for Items representing DATE/TIME
960
940
    functions and DATE/TIME table fields.
961
941
    Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
962
942
    their values should be compared as integers (because the integer
963
943
    representation is more precise than the string one).
964
944
  */
965
 
  virtual bool result_as_int64_t() { return false; }
 
945
  virtual bool result_as_longlong() { return FALSE; }
966
946
  bool is_datetime();
967
947
 
968
948
  /*
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)
1066
 
    { context= (Name_resolution_context *)cntx; return false; }
 
1045
  virtual bool change_context_processor(uchar *cntx)
 
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,
1069
1049
                            const char *table_name, List_iterator<Item> *it,
1085
1065
 
1086
1066
  enum Type type() const { return FIELD_ITEM; }
1087
1067
  double val_real() { return field->val_real(); }
1088
 
  int64_t val_int() { return field->val_int(); }
 
1068
  longlong val_int() { return field->val_int(); }
1089
1069
  String *val_str(String *str) { return field->val_str(str); }
1090
1070
  my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); }
1091
1071
  void make_field(Send_field *tmp_field);
1104
1084
  Item_equal *item_equal;
1105
1085
  bool no_const_subst;
1106
1086
  /*
1107
 
    if any_privileges set to true then here real effective privileges will
 
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,
1132
1112
  enum Type type() const { return FIELD_ITEM; }
1133
1113
  bool eq(const Item *item, bool binary_cmp) const;
1134
1114
  double val_real();
1135
 
  int64_t val_int();
 
1115
  longlong val_int();
1136
1116
  my_decimal *val_decimal(my_decimal *);
1137
1117
  String *val_str(String*);
1138
1118
  double val_result();
1139
 
  int64_t val_int_result();
 
1119
  longlong val_int_result();
1140
1120
  String *str_result(String* tmp);
1141
1121
  my_decimal *val_decimal_result(my_decimal *);
1142
1122
  bool val_bool_result();
1164
1144
  {
1165
1145
    return MONOTONIC_STRICT_INCREASING;
1166
1146
  }
1167
 
  int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
 
1147
  longlong 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
 
  bool result_as_int64_t()
 
1160
  bool result_as_longlong()
1184
1161
  {
1185
 
    return field->can_be_compared_as_int64_t();
 
1162
    return field->can_be_compared_as_longlong();
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
 
 
1176
  void dbug_print() {}
 
1177
 
1199
1178
  friend class Item_default_value;
1200
1179
  friend class Item_insert_value;
1201
1180
  friend class st_select_lex_unit;
1206
1185
public:
1207
1186
  Item_null(char *name_par=0)
1208
1187
  {
1209
 
    maybe_null= null_value= true;
 
1188
    maybe_null= null_value= TRUE;
1210
1189
    max_length= 0;
1211
1190
    name= name_par ? name_par : (char*) "NULL";
1212
1191
    fixed= 1;
1215
1194
  enum Type type() const { return NULL_ITEM; }
1216
1195
  bool eq(const Item *item, bool binary_cmp) const;
1217
1196
  double val_real();
1218
 
  int64_t val_int();
 
1197
  longlong val_int();
1219
1198
  String *val_str(String *str);
1220
1199
  my_decimal *val_decimal(my_decimal *);
1221
1200
  int save_in_field(Field *field, bool no_conversions);
1222
1201
  int save_safe_in_field(Field *field);
1223
1202
  bool send(Protocol *protocol, String *str);
1224
1203
  enum Item_result result_type () const { return STRING_RESULT; }
1225
 
  enum_field_types field_type() const   { return DRIZZLE_TYPE_NULL; }
 
1204
  enum_field_types field_type() const   { return MYSQL_TYPE_NULL; }
1226
1205
  bool basic_const_item() const { return 1; }
1227
1206
  Item *clone_item() { return new Item_null(name); }
1228
1207
  bool is_null() { return 1; }
1229
1208
 
1230
1209
  virtual inline void print(String *str,
1231
 
                            enum_query_type query_type __attribute__((unused)))
 
1210
                            enum_query_type query_type __attribute__((__unused__)))
1232
1211
  {
1233
1212
    str->append(STRING_WITH_LEN("NULL"));
1234
1213
  }
1235
1214
 
1236
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1237
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1238
 
  { return false; }
 
1215
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1239
1216
};
1240
1217
 
1241
1218
class Item_null_result :public Item_null
1248
1225
  {
1249
1226
    save_in_field(result_field, no_conversions);
1250
1227
  }
1251
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1252
 
  { return true; }
1253
1228
};  
1254
1229
 
1255
1230
/* Item represents one placeholder ('?') of prepared statement */
1282
1257
  my_decimal decimal_value;
1283
1258
  union
1284
1259
  {
1285
 
    int64_t integer;
 
1260
    longlong integer;
1286
1261
    double   real;
1287
1262
    /*
1288
1263
      Character sets conversion info for string values.
1292
1267
    */
1293
1268
    struct CONVERSION_INFO
1294
1269
    {
1295
 
      const CHARSET_INFO *character_set_client;
1296
 
      const CHARSET_INFO *character_set_of_placeholder;
 
1270
      CHARSET_INFO *character_set_client;
 
1271
      CHARSET_INFO *character_set_of_placeholder;
1297
1272
      /*
1298
1273
        This points at character set of connection if conversion
1299
1274
        to it is required (i. e. if placeholder typecode is not BLOB).
1300
1275
        Otherwise it's equal to character_set_client (to simplify
1301
1276
        check in convert_str_value()).
1302
1277
      */
1303
 
      const CHARSET_INFO *final_character_set_of_str_value;
 
1278
      CHARSET_INFO *final_character_set_of_str_value;
1304
1279
    } cs_info;
1305
 
    DRIZZLE_TIME     time;
 
1280
    MYSQL_TIME     time;
1306
1281
  } value;
1307
1282
 
1308
1283
  /* Cached values for virtual methods to save us one switch.  */
1313
1288
    Used when this item is used in a temporary table.
1314
1289
    This is NOT placeholder metadata sent to client, as this value
1315
1290
    is assigned after sending metadata (in setup_one_conversion_function).
1316
 
    For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
 
1291
    For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
1317
1292
    in result set and placeholders metadata, no matter what type you will
1318
1293
    supply for this placeholder in mysql_stmt_execute.
1319
1294
  */
1322
1297
    Offset of placeholder inside statement text. Used to create
1323
1298
    no-placeholders version of this statement for the binary log.
1324
1299
  */
1325
 
  uint32_t pos_in_query;
 
1300
  uint pos_in_query;
1326
1301
 
1327
 
  Item_param(uint32_t pos_in_query_arg);
 
1302
  Item_param(uint pos_in_query_arg);
1328
1303
 
1329
1304
  enum Item_result result_type () const { return item_result_type; }
1330
1305
  enum Type type() const { return item_type; }
1331
1306
  enum_field_types field_type() const { return param_type; }
1332
1307
 
1333
1308
  double val_real();
1334
 
  int64_t val_int();
 
1309
  longlong val_int();
1335
1310
  my_decimal *val_decimal(my_decimal*);
1336
1311
  String *val_str(String*);
1337
 
  bool get_time(DRIZZLE_TIME *tm);
1338
 
  bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
 
1312
  bool get_time(MYSQL_TIME *tm);
 
1313
  bool get_date(MYSQL_TIME *tm, uint fuzzydate);
1339
1314
  int  save_in_field(Field *field, bool no_conversions);
1340
1315
 
1341
1316
  void set_null();
1342
 
  void set_int(int64_t i, uint32_t max_length_arg);
 
1317
  void set_int(longlong i, uint32 max_length_arg);
1343
1318
  void set_double(double i);
1344
 
  void set_decimal(char *str, ulong length);
 
1319
  void set_decimal(const char *str, ulong length);
1345
1320
  bool set_str(const char *str, ulong length);
1346
1321
  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);
 
1322
  void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
1349
1323
  bool set_from_user_var(THD *thd, const user_var_entry *entry);
1350
1324
  void reset();
1351
1325
  /*
1354
1328
    don't need to check that packet is not broken there). See
1355
1329
    sql_prepare.cc for details.
1356
1330
  */
1357
 
  void (*set_param_func)(Item_param *param, unsigned char **pos, ulong len);
 
1331
  void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
1358
1332
 
1359
1333
  const String *query_val_str(String *str) const;
1360
1334
 
1379
1353
    words, avoid pointing at one item from two different nodes of the tree.
1380
1354
    Return a new basic constant item if parameter value is a basic
1381
1355
    constant, assert otherwise. This method is called only if
1382
 
    basic_const_item returned true.
 
1356
    basic_const_item returned TRUE.
1383
1357
  */
1384
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
1358
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1385
1359
  Item *clone_item();
1386
1360
  /*
1387
1361
    Implement by-value equality evaluation if parameter value
1388
1362
    is set and is a basic constant (integer, real or string).
1389
 
    Otherwise return false.
 
1363
    Otherwise return FALSE.
1390
1364
  */
1391
1365
  bool eq(const Item *item, bool binary_cmp) const;
1392
1366
  /** Item is a argument to a limit clause. */
1397
1371
class Item_int :public Item_num
1398
1372
{
1399
1373
public:
1400
 
  int64_t value;
1401
 
  Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS)
1402
 
    :value((int64_t) i)
 
1374
  longlong value;
 
1375
  Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
 
1376
    :value((longlong) i)
1403
1377
    { max_length=length; fixed= 1; }
1404
 
  Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
 
1378
  Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1405
1379
    :value(i)
1406
1380
    { max_length=length; fixed= 1; }
1407
 
  Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1408
 
    :value((int64_t)i)
 
1381
  Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
 
1382
    :value((longlong)i)
1409
1383
    { max_length=length; fixed= 1; unsigned_flag= 1; }
1410
 
  Item_int(const char *str_arg,int64_t i,uint32_t length) :value(i)
 
1384
  Item_int(const char *str_arg,longlong i,uint length) :value(i)
1411
1385
    { max_length=length; name=(char*) str_arg; fixed= 1; }
1412
 
  Item_int(const char *str_arg, uint32_t length=64);
 
1386
  Item_int(const char *str_arg, uint length=64);
1413
1387
  enum Type type() const { return INT_ITEM; }
1414
1388
  enum Item_result result_type () const { return INT_RESULT; }
1415
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
1416
 
  int64_t val_int() { assert(fixed == 1); return value; }
 
1389
  enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
 
1390
  longlong val_int() { assert(fixed == 1); return value; }
1417
1391
  double val_real() { assert(fixed == 1); return (double) value; }
1418
1392
  my_decimal *val_decimal(my_decimal *);
1419
1393
  String *val_str(String*);
1422
1396
  Item *clone_item() { return new Item_int(name,value,max_length); }
1423
1397
  virtual void print(String *str, enum_query_type query_type);
1424
1398
  Item_num *neg() { value= -value; return this; }
1425
 
  uint32_t decimal_precision() const
 
1399
  uint decimal_precision() const
1426
1400
  { return (uint)(max_length - test(value < 0)); }
1427
1401
  bool eq(const Item *, bool binary_cmp) const;
1428
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1429
 
  { return false; }
1430
1402
};
1431
1403
 
1432
1404
 
1433
1405
class Item_uint :public Item_int
1434
1406
{
1435
1407
public:
1436
 
  Item_uint(const char *str_arg, uint32_t length);
1437
 
  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, uint length);
 
1409
  Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {}
 
1410
  Item_uint(const char *str_arg, longlong i, uint length);
1439
1411
  double val_real()
1440
 
    { assert(fixed == 1); return uint64_t2double((uint64_t)value); }
 
1412
    { assert(fixed == 1); return ulonglong2double((ulonglong)value); }
1441
1413
  String *val_str(String*);
1442
1414
  Item *clone_item() { return new Item_uint(name, value, max_length); }
1443
1415
  int save_in_field(Field *field, bool no_conversions);
1444
1416
  virtual void print(String *str, enum_query_type query_type);
1445
1417
  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; }
 
1418
  uint decimal_precision() const { return max_length; }
1449
1419
};
1450
1420
 
1451
1421
 
1455
1425
protected:
1456
1426
  my_decimal decimal_value;
1457
1427
public:
1458
 
  Item_decimal(const char *str_arg, uint32_t length, const CHARSET_INFO * const charset);
 
1428
  Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset);
1459
1429
  Item_decimal(const char *str, const my_decimal *val_arg,
1460
 
               uint32_t decimal_par, uint32_t length);
 
1430
               uint decimal_par, uint length);
1461
1431
  Item_decimal(my_decimal *value_par);
1462
 
  Item_decimal(int64_t val, bool unsig);
 
1432
  Item_decimal(longlong val, bool unsig);
1463
1433
  Item_decimal(double val, int precision, int scale);
1464
 
  Item_decimal(const unsigned char *bin, int precision, int scale);
 
1434
  Item_decimal(const uchar *bin, int precision, int scale);
1465
1435
 
1466
1436
  enum Type type() const { return DECIMAL_ITEM; }
1467
1437
  enum Item_result result_type () const { return DECIMAL_RESULT; }
1468
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDECIMAL; }
1469
 
  int64_t val_int();
 
1438
  enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
 
1439
  longlong val_int();
1470
1440
  double val_real();
1471
1441
  String *val_str(String*);
1472
 
  my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
 
1442
  my_decimal *val_decimal(my_decimal *val __attribute__((__unused__)))
1473
1443
  { return &decimal_value; }
1474
1444
  int save_in_field(Field *field, bool no_conversions);
1475
1445
  bool basic_const_item() const { return 1; }
1484
1454
    unsigned_flag= !decimal_value.sign();
1485
1455
    return this;
1486
1456
  }
1487
 
  uint32_t decimal_precision() const { return decimal_value.precision(); }
 
1457
  uint decimal_precision() const { return decimal_value.precision(); }
1488
1458
  bool eq(const Item *, bool binary_cmp) const;
1489
1459
  void set_decimal_value(my_decimal *value_par);
1490
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1491
 
  { return false; }
1492
1460
};
1493
1461
 
1494
1462
 
1498
1466
public:
1499
1467
  double value;
1500
1468
  // 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)
 
1469
  Item_float(const char *str_arg, uint length);
 
1470
  Item_float(const char *str,double val_arg,uint decimal_par,uint length)
1503
1471
    :value(val_arg)
1504
1472
  {
1505
1473
    presentation= name=(char*) str;
1506
 
    decimals=(uint8_t) decimal_par;
 
1474
    decimals=(uint8) decimal_par;
1507
1475
    max_length=length;
1508
1476
    fixed= 1;
1509
1477
  }
1510
 
  Item_float(double value_par, uint32_t decimal_par) :presentation(0), value(value_par)
 
1478
  Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1511
1479
  {
1512
 
    decimals= (uint8_t) decimal_par;
 
1480
    decimals= (uint8) decimal_par;
1513
1481
    fixed= 1;
1514
1482
  }
1515
1483
  int save_in_field(Field *field, bool no_conversions);
1516
1484
  enum Type type() const { return REAL_ITEM; }
1517
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE; }
 
1485
  enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
1518
1486
  double val_real() { assert(fixed == 1); return value; }
1519
 
  int64_t val_int()
 
1487
  longlong val_int()
1520
1488
  {
1521
1489
    assert(fixed == 1);
1522
 
    if (value <= (double) INT64_MIN)
1523
 
    {
1524
 
       return INT64_MIN;
1525
 
    }
1526
 
    else if (value >= (double) (uint64_t) INT64_MAX)
1527
 
    {
1528
 
      return INT64_MAX;
1529
 
    }
1530
 
    return (int64_t) rint(value);
 
1490
    if (value <= (double) LONGLONG_MIN)
 
1491
    {
 
1492
       return LONGLONG_MIN;
 
1493
    }
 
1494
    else if (value >= (double) (ulonglong) LONGLONG_MAX)
 
1495
    {
 
1496
      return LONGLONG_MAX;
 
1497
    }
 
1498
    return (longlong) rint(value);
1531
1499
  }
1532
1500
  String *val_str(String*);
1533
1501
  my_decimal *val_decimal(my_decimal *);
1544
1512
{
1545
1513
  const char *func_name;
1546
1514
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)
 
1515
  Item_static_float_func(const char *str, double val_arg, uint decimal_par,
 
1516
                        uint length)
 
1517
    :Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1550
1518
  {}
1551
1519
 
1552
1520
  virtual inline void print(String *str,
1553
 
                            enum_query_type query_type __attribute__((unused)))
 
1521
                            enum_query_type query_type __attribute__((__unused__)))
1554
1522
  {
1555
1523
    str->append(func_name);
1556
1524
  }
1557
1525
 
1558
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1559
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1560
 
  { return false; }
 
1526
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1561
1527
};
1562
1528
 
1563
1529
 
1564
1530
class Item_string :public Item_basic_constant
1565
1531
{
1566
1532
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)
1570
 
    : m_cs_specified(false)
 
1533
  Item_string(const char *str,uint length,
 
1534
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
 
1535
              uint repertoire= MY_REPERTOIRE_UNICODE30)
 
1536
    : m_cs_specified(FALSE)
1571
1537
  {
1572
1538
    str_value.set_or_copy_aligned(str, length, cs);
1573
1539
    collation.set(cs, dv, repertoire);
1585
1551
    fixed= 1;
1586
1552
  }
1587
1553
  /* Just create an item and do not fill string representation */
1588
 
  Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
1589
 
    : m_cs_specified(false)
 
1554
  Item_string(CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
 
1555
    : m_cs_specified(FALSE)
1590
1556
  {
1591
1557
    collation.set(cs, dv);
1592
1558
    max_length= 0;
1594
1560
    decimals= NOT_FIXED_DEC;
1595
1561
    fixed= 1;
1596
1562
  }
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)
1600
 
    : m_cs_specified(false)
 
1563
  Item_string(const char *name_par, const char *str, uint length,
 
1564
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
 
1565
              uint repertoire= MY_REPERTOIRE_UNICODE30)
 
1566
    : m_cs_specified(FALSE)
1601
1567
  {
1602
1568
    str_value.set_or_copy_aligned(str, length, cs);
1603
1569
    collation.set(cs, dv, repertoire);
1611
1577
    This is used in stored procedures to avoid memory leaks and
1612
1578
    does a deep copy of its argument.
1613
1579
  */
1614
 
  void set_str_with_copy(const char *str_arg, uint32_t length_arg)
 
1580
  void set_str_with_copy(const char *str_arg, uint length_arg)
1615
1581
  {
1616
1582
    str_value.copy(str_arg, length_arg, collation.collation);
1617
1583
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
1624
1590
  }
1625
1591
  enum Type type() const { return STRING_ITEM; }
1626
1592
  double val_real();
1627
 
  int64_t val_int();
 
1593
  longlong val_int();
1628
1594
  String *val_str(String*)
1629
1595
  {
1630
1596
    assert(fixed == 1);
1633
1599
  my_decimal *val_decimal(my_decimal *);
1634
1600
  int save_in_field(Field *field, bool no_conversions);
1635
1601
  enum Item_result result_type () const { return STRING_RESULT; }
1636
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
 
1602
  enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1637
1603
  bool basic_const_item() const { return 1; }
1638
1604
  bool eq(const Item *item, bool binary_cmp) const;
1639
1605
  Item *clone_item() 
1641
1607
    return new Item_string(name, str_value.ptr(), 
1642
1608
                           str_value.length(), collation.collation);
1643
1609
  }
1644
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1645
 
  inline void append(char *str, uint32_t length)
 
1610
  Item *safe_charset_converter(CHARSET_INFO *tocs);
 
1611
  inline void append(char *str, uint length)
1646
1612
  {
1647
1613
    str_value.append(str, length);
1648
1614
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
1650
1616
  virtual void print(String *str, enum_query_type query_type);
1651
1617
 
1652
1618
  /**
1653
 
    Return true if character-set-introducer was explicitly specified in the
 
1619
    Return TRUE if character-set-introducer was explicitly specified in the
1654
1620
    original query for this item (text literal).
1655
1621
 
1656
1622
    This operation is to be called from Item_string::print(). The idea is
1664
1630
    one day when we start using original query as a view definition.
1665
1631
 
1666
1632
    @return This operation returns the value of m_cs_specified attribute.
1667
 
      @retval true if character set introducer was explicitly specified in
 
1633
      @retval TRUE if character set introducer was explicitly specified in
1668
1634
      the original query.
1669
 
      @retval false otherwise.
 
1635
      @retval FALSE otherwise.
1670
1636
  */
1671
1637
  inline bool is_cs_specified() const
1672
1638
  {
1687
1653
  {
1688
1654
    m_cs_specified= cs_specified;
1689
1655
  }
1690
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1691
 
  { return false; }
1692
1656
 
1693
1657
private:
1694
1658
  bool m_cs_specified;
1699
1663
{
1700
1664
  const char *func_name;
1701
1665
public:
1702
 
  Item_static_string_func(const char *name_par, const char *str, uint32_t length,
1703
 
                          const CHARSET_INFO * const cs,
 
1666
  Item_static_string_func(const char *name_par, const char *str, uint length,
 
1667
                          CHARSET_INFO *cs,
1704
1668
                          Derivation dv= DERIVATION_COERCIBLE)
1705
 
    :Item_string(NULL, str, length, cs, dv), func_name(name_par)
 
1669
    :Item_string(NullS, str, length, cs, dv), func_name(name_par)
1706
1670
  {}
1707
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
1671
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1708
1672
 
1709
1673
  virtual inline void print(String *str,
1710
 
                            enum_query_type query_type __attribute__((unused)))
 
1674
                            enum_query_type query_type __attribute__((__unused__)))
1711
1675
  {
1712
1676
    str->append(func_name);
1713
1677
  }
1714
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1715
 
  { return true; }
1716
1678
};
1717
1679
 
1718
1680
 
1732
1694
class Item_blob :public Item_string
1733
1695
{
1734
1696
public:
1735
 
  Item_blob(const char *name, uint32_t length) :
 
1697
  Item_blob(const char *name, uint length) :
1736
1698
    Item_string(name, length, &my_charset_bin)
1737
1699
  { max_length= length; }
1738
1700
  enum Type type() const { return TYPE_HOLDER; }
1739
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
 
1701
  enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
1740
1702
};
1741
1703
 
1742
1704
 
1749
1711
class Item_empty_string :public Item_string
1750
1712
{
1751
1713
public:
1752
 
  Item_empty_string(const char *header,uint32_t length, const CHARSET_INFO * cs= NULL) :
 
1714
  Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) :
1753
1715
    Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1754
1716
    { name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1755
1717
  void make_field(Send_field *field);
1760
1722
{
1761
1723
  enum_field_types int_field_type;
1762
1724
public:
1763
 
  Item_return_int(const char *name_arg, uint32_t length,
1764
 
                  enum_field_types field_type_arg, int64_t value= 0)
 
1725
  Item_return_int(const char *name_arg, uint length,
 
1726
                  enum_field_types field_type_arg, longlong value= 0)
1765
1727
    :Item_int(name_arg, value, length), int_field_type(field_type_arg)
1766
1728
  {
1767
1729
    unsigned_flag=1;
1774
1736
{
1775
1737
public:
1776
1738
  Item_hex_string() {}
1777
 
  Item_hex_string(const char *str,uint32_t str_length);
 
1739
  Item_hex_string(const char *str,uint str_length);
1778
1740
  enum Type type() const { return VARBIN_ITEM; }
1779
1741
  double val_real()
1780
1742
  { 
1781
1743
    assert(fixed == 1); 
1782
 
    return (double) (uint64_t) Item_hex_string::val_int();
 
1744
    return (double) (ulonglong) Item_hex_string::val_int();
1783
1745
  }
1784
 
  int64_t val_int();
 
1746
  longlong val_int();
1785
1747
  bool basic_const_item() const { return 1; }
1786
1748
  String *val_str(String*) { assert(fixed == 1); return &str_value; }
1787
1749
  my_decimal *val_decimal(my_decimal *);
1788
1750
  int save_in_field(Field *field, bool no_conversions);
1789
1751
  enum Item_result result_type () const { return STRING_RESULT; }
1790
1752
  enum Item_result cast_to_int_type() const { return INT_RESULT; }
1791
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
 
1753
  enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1792
1754
  virtual void print(String *str, enum_query_type query_type);
1793
1755
  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; }
 
1756
  virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
1797
1757
};
1798
1758
 
1799
1759
 
1800
1760
class Item_bin_string: public Item_hex_string
1801
1761
{
1802
1762
public:
1803
 
  Item_bin_string(const char *str,uint32_t str_length);
 
1763
  Item_bin_string(const char *str,uint str_length);
1804
1764
};
1805
1765
 
1806
1766
class Item_result_field :public Item    /* Item with result field */
1814
1774
  {}
1815
1775
  ~Item_result_field() {}                       /* Required with gcc 2.95 */
1816
1776
  Field *get_tmp_table_field() { return result_field; }
1817
 
  Field *tmp_table_field(Table *t_arg __attribute__((unused)))
 
1777
  Field *tmp_table_field(TABLE *t_arg __attribute__((__unused__)))
1818
1778
  { return result_field; }
1819
1779
  table_map used_tables() const { return 1; }
1820
1780
  virtual void fix_length_and_dec()=0;
1825
1785
    save_in_field(result_field, no_conversions);
1826
1786
  }
1827
1787
  void cleanup();
1828
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1829
 
  { return false; }
1830
1788
};
1831
1789
 
1832
1790
 
1859
1817
  */
1860
1818
  Item_ref(Name_resolution_context *context_arg, Item **item,
1861
1819
           const char *table_name_arg, const char *field_name_arg,
1862
 
           bool alias_name_used_arg= false);
 
1820
           bool alias_name_used_arg= FALSE);
1863
1821
 
1864
1822
  /* Constructor need to process subselect with temporary tables (see Item) */
1865
1823
  Item_ref(THD *thd, Item_ref *item)
1871
1829
    return ref && (*ref)->eq(it, binary_cmp);
1872
1830
  }
1873
1831
  double val_real();
1874
 
  int64_t val_int();
 
1832
  longlong val_int();
1875
1833
  my_decimal *val_decimal(my_decimal *);
1876
1834
  bool val_bool();
1877
1835
  String *val_str(String* tmp);
1878
1836
  bool is_null();
1879
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
1837
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1880
1838
  double val_result();
1881
 
  int64_t val_int_result();
 
1839
  longlong val_int_result();
1882
1840
  String *str_result(String* tmp);
1883
1841
  my_decimal *val_decimal_result(my_decimal *);
1884
1842
  bool val_bool_result();
1913
1871
  {
1914
1872
    return ref ? (*ref)->real_item() : this;
1915
1873
  }
1916
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
 
1874
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1917
1875
  { return (*ref)->walk(processor, walk_subquery, arg); }
1918
1876
  virtual void print(String *str, enum_query_type query_type);
1919
 
  bool result_as_int64_t()
 
1877
  bool result_as_longlong()
1920
1878
  {
1921
 
    return (*ref)->result_as_int64_t();
 
1879
    return (*ref)->result_as_longlong();
1922
1880
  }
1923
1881
  void cleanup();
1924
1882
  Item_field *filed_for_view_update()
1926
1884
  virtual Ref_Type ref_type() { return REF; }
1927
1885
 
1928
1886
  // Row emulation: forwarding of ROW-related calls to ref
1929
 
  uint32_t cols()
 
1887
  uint cols()
1930
1888
  {
1931
1889
    return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1932
1890
  }
1933
 
  Item* element_index(uint32_t i)
 
1891
  Item* element_index(uint i)
1934
1892
  {
1935
1893
    return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1936
1894
  }
1937
 
  Item** addr(uint32_t i)
 
1895
  Item** addr(uint i)
1938
1896
  {
1939
1897
    return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1940
1898
  }
1941
 
  bool check_cols(uint32_t c)
 
1899
  bool check_cols(uint c)
1942
1900
  {
1943
1901
    return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c) 
1944
1902
                                              : Item::check_cols(c);
1966
1924
  Item_direct_ref(Name_resolution_context *context_arg, Item **item,
1967
1925
                  const char *table_name_arg,
1968
1926
                  const char *field_name_arg,
1969
 
                  bool alias_name_used_arg= false)
 
1927
                  bool alias_name_used_arg= FALSE)
1970
1928
    :Item_ref(context_arg, item, table_name_arg,
1971
1929
              field_name_arg, alias_name_used_arg)
1972
1930
  {}
1974
1932
  Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
1975
1933
 
1976
1934
  double val_real();
1977
 
  int64_t val_int();
 
1935
  longlong val_int();
1978
1936
  String *val_str(String* tmp);
1979
1937
  my_decimal *val_decimal(my_decimal *);
1980
1938
  bool val_bool();
1981
1939
  bool is_null();
1982
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
1940
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1983
1941
  virtual Ref_Type ref_type() { return DIRECT_REF; }
1984
1942
};
1985
1943
 
2028
1986
  /* The aggregate function under which this outer ref is used, if any. */
2029
1987
  Item_sum *in_sum_func;
2030
1988
  /*
2031
 
    true <=> that the outer_ref is already present in the select list
 
1989
    TRUE <=> that the outer_ref is already present in the select list
2032
1990
    of the outer select.
2033
1991
  */
2034
1992
  bool found_in_select_list;
2050
2008
                     alias_name_used_arg),
2051
2009
    outer_ref(0), in_sum_func(0), found_in_select_list(1)
2052
2010
  {}
2053
 
  void save_in_result_field(bool no_conversions __attribute__((unused)))
 
2011
  void save_in_result_field(bool no_conversions __attribute__((__unused__)))
2054
2012
  {
2055
2013
    outer_ref->save_org_in_field(result_field);
2056
2014
  }
2070
2028
/*
2071
2029
  An object of this class:
2072
2030
   - Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
2073
 
   - Sets owner->was_null=true if it has returned a NULL value from any
 
2031
   - Sets owner->was_null=TRUE if it has returned a NULL value from any
2074
2032
     val_XXX() function. This allows to inject an Item_ref_null_helper
2075
2033
     object into subquery and then check if the subquery has produced a row
2076
2034
     with NULL value.
2087
2045
    :Item_ref(context_arg, item, table_name_arg, field_name_arg),
2088
2046
     owner(master) {}
2089
2047
  double val_real();
2090
 
  int64_t val_int();
 
2048
  longlong val_int();
2091
2049
  String* val_str(String* s);
2092
2050
  my_decimal *val_decimal(my_decimal *);
2093
2051
  bool val_bool();
2094
 
  bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
 
2052
  bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
2095
2053
  virtual void print(String *str, enum_query_type query_type);
2096
2054
  /*
2097
2055
    we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2117
2075
{
2118
2076
  Item *ref;
2119
2077
public:
2120
 
  Item_int_with_ref(int64_t i, Item *ref_arg, bool unsigned_arg) :
 
2078
  Item_int_with_ref(longlong i, Item *ref_arg, my_bool unsigned_arg) :
2121
2079
    Item_int(i), ref(ref_arg)
2122
2080
  {
2123
2081
    unsigned_flag= unsigned_arg;
2130
2088
  virtual Item *real_item() { return ref; }
2131
2089
};
2132
2090
 
2133
 
#ifdef DRIZZLE_SERVER
 
2091
#ifdef MYSQL_SERVER
2134
2092
#include "item_sum.h"
2135
2093
#include "item_func.h"
2136
2094
#include "item_row.h"
2147
2105
  Item *item;
2148
2106
  Item_copy_string(Item *i) :item(i)
2149
2107
  {
2150
 
    null_value= maybe_null= item->maybe_null;
 
2108
    null_value=maybe_null=item->maybe_null;
2151
2109
    decimals=item->decimals;
2152
2110
    max_length=item->max_length;
2153
2111
    name=item->name;
2161
2119
    int err_not_used;
2162
2120
    char *end_not_used;
2163
2121
    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));
 
2122
            my_strntod(str_value.charset(), (char*) str_value.ptr(),
 
2123
                       str_value.length(), &end_not_used, &err_not_used));
2166
2124
  }
2167
 
  int64_t val_int()
 
2125
  longlong val_int()
2168
2126
  {
2169
2127
    int err;
2170
 
    return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
2171
 
                                        str_value.length(),10, (char**) 0,
2172
 
                                        &err);
 
2128
    return null_value ? 0LL : my_strntoll(str_value.charset(),str_value.ptr(),
 
2129
                                            str_value.length(),10, (char**) 0,
 
2130
                                            &err); 
2173
2131
  }
2174
2132
  String *val_str(String*);
2175
2133
  my_decimal *val_decimal(my_decimal *);
2176
2134
  void make_field(Send_field *field) { item->make_field(field); }
2177
2135
  void copy();
2178
2136
  int save_in_field(Field *field,
2179
 
                    bool no_conversions __attribute__((unused)))
 
2137
                    bool no_conversions __attribute__((__unused__)))
2180
2138
  {
2181
2139
    return save_str_value_in_field(field, &str_value);
2182
2140
  }
2189
2147
class Cached_item :public Sql_alloc
2190
2148
{
2191
2149
public:
2192
 
  bool null_value;
 
2150
  my_bool null_value;
2193
2151
  Cached_item() :null_value(0) {}
2194
2152
  virtual bool cmp(void)=0;
2195
2153
  virtual ~Cached_item(); /*line -e1509 */
2218
2176
class Cached_item_int :public Cached_item
2219
2177
{
2220
2178
  Item *item;
2221
 
  int64_t value;
 
2179
  longlong value;
2222
2180
public:
2223
2181
  Cached_item_int(Item *item_par) :item(item_par),value(0) {}
2224
2182
  bool cmp(void);
2236
2194
 
2237
2195
class Cached_item_field :public Cached_item
2238
2196
{
2239
 
  unsigned char *buff;
 
2197
  uchar *buff;
2240
2198
  Field *field;
2241
 
  uint32_t length;
 
2199
  uint length;
2242
2200
 
2243
2201
public:
 
2202
  void dbug_print()
 
2203
  {
 
2204
    uchar *org_ptr;
 
2205
    org_ptr= field->ptr;
 
2206
    fprintf(DBUG_FILE, "new: ");
 
2207
    field->dbug_print();
 
2208
    field->ptr= buff;
 
2209
    fprintf(DBUG_FILE, ", old: ");
 
2210
    field->dbug_print();
 
2211
    field->ptr= org_ptr;
 
2212
    fprintf(DBUG_FILE, "\n");
 
2213
  }
2244
2214
  Cached_item_field(Field *arg_field) : field(arg_field)
2245
2215
  {
2246
2216
    field= arg_field;
2247
2217
    /* TODO: take the memory allocation below out of the constructor. */
2248
 
    buff= (unsigned char*) sql_calloc(length=field->pack_length());
 
2218
    buff= (uchar*) sql_calloc(length=field->pack_length());
2249
2219
  }
2250
2220
  bool cmp(void);
2251
2221
};
2269
2239
  int save_in_field(Field *field_arg, bool no_conversions);
2270
2240
  table_map used_tables() const { return (table_map)0L; }
2271
2241
 
2272
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
 
2242
  bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2273
2243
  {
2274
2244
    return arg->walk(processor, walk_subquery, args) ||
2275
2245
      (this->*processor)(args);
2276
2246
  }
2277
2247
 
2278
 
  Item *transform(Item_transformer transformer, unsigned char *args);
 
2248
  Item *transform(Item_transformer transformer, uchar *args);
2279
2249
};
2280
2250
 
2281
2251
/*
2309
2279
  */
2310
2280
  table_map used_tables() const { return RAND_TABLE_BIT; }
2311
2281
 
2312
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
 
2282
  bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2313
2283
  {
2314
2284
    return arg->walk(processor, walk_subquery, args) ||
2315
2285
            (this->*processor)(args);
2316
2286
  }
2317
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
2318
 
  { return true; }
2319
2287
};
2320
2288
 
2321
2289
 
2334
2302
  enum enum_field_types cached_field_type;
2335
2303
public:
2336
2304
  Item_cache(): 
2337
 
    example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR) 
 
2305
    example(0), used_table_map(0), cached_field(0), cached_field_type(MYSQL_TYPE_STRING) 
2338
2306
  {
2339
2307
    fixed= 1; 
2340
2308
    null_value= 1;
2348
2316
 
2349
2317
  void set_used_tables(table_map map) { used_table_map= map; }
2350
2318
 
2351
 
  virtual bool allocate(uint32_t i __attribute__((unused)))
 
2319
  virtual bool allocate(uint i __attribute__((__unused__)))
2352
2320
  { return 0; }
2353
2321
  virtual bool setup(Item *item)
2354
2322
  {
2370
2338
  virtual void print(String *str, enum_query_type query_type);
2371
2339
  bool eq_def(Field *field) 
2372
2340
  { 
2373
 
    return cached_field ? cached_field->eq_def (field) : false;
 
2341
    return cached_field ? cached_field->eq_def (field) : FALSE;
2374
2342
  }
2375
2343
  bool eq(const Item *item,
2376
 
          bool binary_cmp __attribute__((unused))) const
 
2344
          bool binary_cmp __attribute__((__unused__))) const
2377
2345
  {
2378
2346
    return this == item;
2379
2347
  }
2383
2351
class Item_cache_int: public Item_cache
2384
2352
{
2385
2353
protected:
2386
 
  int64_t value;
 
2354
  longlong value;
2387
2355
public:
2388
2356
  Item_cache_int(): Item_cache(), value(0) {}
2389
2357
  Item_cache_int(enum_field_types field_type_arg):
2390
2358
    Item_cache(field_type_arg), value(0) {}
2391
2359
 
2392
2360
  void store(Item *item);
2393
 
  void store(Item *item, int64_t val_arg);
 
2361
  void store(Item *item, longlong val_arg);
2394
2362
  double val_real() { assert(fixed == 1); return (double) value; }
2395
 
  int64_t val_int() { assert(fixed == 1); return value; }
 
2363
  longlong val_int() { assert(fixed == 1); return value; }
2396
2364
  String* val_str(String *str);
2397
2365
  my_decimal *val_decimal(my_decimal *);
2398
2366
  enum Item_result result_type() const { return INT_RESULT; }
2399
 
  bool result_as_int64_t() { return true; }
 
2367
  bool result_as_longlong() { return TRUE; }
2400
2368
};
2401
2369
 
2402
2370
 
2408
2376
 
2409
2377
  void store(Item *item);
2410
2378
  double val_real() { assert(fixed == 1); return value; }
2411
 
  int64_t val_int();
 
2379
  longlong val_int();
2412
2380
  String* val_str(String *str);
2413
2381
  my_decimal *val_decimal(my_decimal *);
2414
2382
  enum Item_result result_type() const { return REAL_RESULT; }
2424
2392
 
2425
2393
  void store(Item *item);
2426
2394
  double val_real();
2427
 
  int64_t val_int();
 
2395
  longlong val_int();
2428
2396
  String* val_str(String *str);
2429
2397
  my_decimal *val_decimal(my_decimal *);
2430
2398
  enum Item_result result_type() const { return DECIMAL_RESULT; }
2442
2410
    Item_cache(), value(0),
2443
2411
    is_varbinary(item->type() == FIELD_ITEM &&
2444
2412
                 ((const Item_field *) item)->field->type() ==
2445
 
                   DRIZZLE_TYPE_VARCHAR &&
 
2413
                   MYSQL_TYPE_VARCHAR &&
2446
2414
                 !((const Item_field *) item)->field->has_charset())
2447
2415
  {}
2448
2416
  void store(Item *item);
2449
2417
  double val_real();
2450
 
  int64_t val_int();
 
2418
  longlong val_int();
2451
2419
  String* val_str(String *) { assert(fixed == 1); return value; }
2452
2420
  my_decimal *val_decimal(my_decimal *);
2453
2421
  enum Item_result result_type() const { return STRING_RESULT; }
2454
 
  const CHARSET_INFO *charset() const { return value->charset(); };
 
2422
  CHARSET_INFO *charset() const { return value->charset(); };
2455
2423
  int save_in_field(Field *field, bool no_conversions);
2456
2424
};
2457
2425
 
2458
2426
class Item_cache_row: public Item_cache
2459
2427
{
2460
2428
  Item_cache  **values;
2461
 
  uint32_t item_count;
 
2429
  uint item_count;
2462
2430
  bool save_array;
2463
2431
public:
2464
2432
  Item_cache_row()
2468
2436
    'allocate' used only in row transformer, to preallocate space for row 
2469
2437
    cache.
2470
2438
  */
2471
 
  bool allocate(uint32_t num);
 
2439
  bool allocate(uint num);
2472
2440
  /*
2473
2441
    'setup' is needed only by row => it not called by simple row subselect
2474
2442
    (only by IN subselect (in subselect optimizer))
2485
2453
    illegal_method_call((const char*)"val");
2486
2454
    return 0;
2487
2455
  };
2488
 
  int64_t val_int()
 
2456
  longlong val_int()
2489
2457
  {
2490
2458
    illegal_method_call((const char*)"val_int");
2491
2459
    return 0;
2495
2463
    illegal_method_call((const char*)"val_str");
2496
2464
    return 0;
2497
2465
  };
2498
 
  my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
 
2466
  my_decimal *val_decimal(my_decimal *val __attribute__((__unused__)))
2499
2467
  {
2500
2468
    illegal_method_call((const char*)"val_decimal");
2501
2469
    return 0;
2503
2471
 
2504
2472
  enum Item_result result_type() const { return ROW_RESULT; }
2505
2473
  
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);
 
2474
  uint cols() { return item_count; }
 
2475
  Item *element_index(uint i) { return values[i]; }
 
2476
  Item **addr(uint i) { return (Item **) (values + i); }
 
2477
  bool check_cols(uint c);
2510
2478
  bool null_inside();
2511
2479
  void bring_value();
2512
2480
  void keep_array() { save_array= 1; }
2514
2482
  {
2515
2483
    Item_cache::cleanup();
2516
2484
    if (save_array)
2517
 
      memset(values, 0, item_count*sizeof(Item**));
 
2485
      bzero(values, item_count*sizeof(Item**));
2518
2486
    else
2519
2487
      values= 0;
2520
2488
    return;
2546
2514
  enum_field_types field_type() const { return fld_type; };
2547
2515
  enum Type type() const { return TYPE_HOLDER; }
2548
2516
  double val_real();
2549
 
  int64_t val_int();
 
2517
  longlong val_int();
2550
2518
  my_decimal *val_decimal(my_decimal *);
2551
2519
  String *val_str(String*);
2552
2520
  bool join_types(THD *thd, Item *);
2553
 
  Field *make_field_by_type(Table *table);
2554
 
  static uint32_t display_length(Item *item);
 
2521
  Field *make_field_by_type(TABLE *table);
 
2522
  static uint32 display_length(Item *item);
2555
2523
  static enum_field_types get_real_type(Item *);
2556
2524
};
2557
2525
 
2567
2535
                                    bool use_result_field);
2568
2536
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
2569
2537
extern bool field_is_equal_to_item(Field *field,Item *item);
2570
 
 
2571
 
#endif