~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item.h

  • Committer: Monty Taylor
  • Date: 2008-07-02 14:35:48 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: monty@inaugust.com-20080702143548-onj30ry0sugr01uw
Removed all references to THREAD.

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, bool unsigned_flag) const
 
169
  { return (longlong) rint(val->real); }
173
170
  virtual double val_real(Hybrid_type *val) const { return val->real; }
174
171
  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;
 
172
  virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
176
173
  static const Hybrid_type_traits *instance();
177
174
  Hybrid_type_traits() {}
178
175
  virtual ~Hybrid_type_traits() {}
189
186
  /* Hybrid_type operations. */
190
187
  virtual void set_zero(Hybrid_type *val) const;
191
188
  virtual void add(Hybrid_type *val, Field *f) const;
192
 
  virtual void div(Hybrid_type *val, uint64_t u) const;
 
189
  virtual void div(Hybrid_type *val, ulonglong u) const;
193
190
 
194
 
  virtual int64_t val_int(Hybrid_type *val, bool unsigned_flag) const;
 
191
  virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const;
195
192
  virtual double val_real(Hybrid_type *val) const;
196
 
  virtual my_decimal *val_decimal(Hybrid_type *val,
197
 
                                  my_decimal *buf __attribute__((unused))) const
 
193
  virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
198
194
  { return &val->dec_buf[val->used_dec_buf_no]; }
199
 
  virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
 
195
  virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
200
196
  static const Hybrid_type_traits_decimal *instance();
201
197
  Hybrid_type_traits_decimal() {};
202
198
};
214
210
  { val->integer= 0; }
215
211
  virtual void add(Hybrid_type *val, Field *f) const
216
212
  { val->integer+= f->val_int(); }
217
 
  virtual void div(Hybrid_type *val, uint64_t u) const
218
 
  { val->integer/= (int64_t) u; }
 
213
  virtual void div(Hybrid_type *val, ulonglong u) const
 
214
  { val->integer/= (longlong) u; }
219
215
 
220
 
  virtual int64_t val_int(Hybrid_type *val,
221
 
                           bool unsigned_flag __attribute__((unused))) const
 
216
  virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const
222
217
  { return val->integer; }
223
218
  virtual double val_real(Hybrid_type *val) const
224
219
  { return (double) val->integer; }
225
 
  virtual my_decimal *val_decimal(Hybrid_type *val,
226
 
                                  my_decimal *buf __attribute__((unused))) const
 
220
  virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
227
221
  {
228
222
    int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
229
223
    return &val->dec_buf[2];
230
224
  }
231
 
  virtual String *val_str(Hybrid_type *val, String *buf,
232
 
                          uint8_t decimals __attribute__((unused))) const
 
225
  virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const
233
226
  { buf->set(val->integer, &my_charset_bin); return buf;}
234
227
  static const Hybrid_type_traits_integer *instance();
235
228
  Hybrid_type_traits_integer() {};
271
264
    statements we have to change this member dynamically to ensure correct
272
265
    name resolution of different parts of the statement.
273
266
  */
274
 
  TableList *table_list;
 
267
  TABLE_LIST *table_list;
275
268
  /*
276
269
    In most cases the two table references below replace 'table_list' above
277
270
    for the purpose of name resolution. The first and last name resolution
279
272
    join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
280
273
    and JOIN ... ON. 
281
274
  */
282
 
  TableList *first_name_resolution_table;
 
275
  TABLE_LIST *first_name_resolution_table;
283
276
  /*
284
277
    Last table to search in the list of leaf table references that begins
285
278
    with first_name_resolution_table.
286
279
  */
287
 
  TableList *last_name_resolution_table;
 
280
  TABLE_LIST *last_name_resolution_table;
288
281
 
289
282
  /*
290
283
    SELECT_LEX item belong to, in case of merged VIEW it can differ from
302
295
  void *error_processor_data;
303
296
 
304
297
  /*
305
 
    When true items are resolved in this context both against the
306
 
    SELECT list and this->table_list. If false, items are resolved
 
298
    When TRUE items are resolved in this context both against the
 
299
    SELECT list and this->table_list. If FALSE, items are resolved
307
300
    only against this->table_list.
308
301
  */
309
302
  bool resolve_in_select_list;
322
315
 
323
316
  void init()
324
317
  {
325
 
    resolve_in_select_list= false;
 
318
    resolve_in_select_list= FALSE;
326
319
    error_processor= &dummy_error_processor;
327
320
    first_name_resolution_table= NULL;
328
321
    last_name_resolution_table= NULL;
329
322
  }
330
323
 
331
 
  void resolve_in_table_list_only(TableList *tables)
 
324
  void resolve_in_table_list_only(TABLE_LIST *tables)
332
325
  {
333
326
    table_list= first_name_resolution_table= tables;
334
 
    resolve_in_select_list= false;
 
327
    resolve_in_select_list= FALSE;
335
328
  }
336
329
 
337
330
  void process_error(THD *thd)
348
341
class Name_resolution_context_state
349
342
{
350
343
private:
351
 
  TableList *save_table_list;
352
 
  TableList *save_first_name_resolution_table;
353
 
  TableList *save_next_name_resolution_table;
 
344
  TABLE_LIST *save_table_list;
 
345
  TABLE_LIST *save_first_name_resolution_table;
 
346
  TABLE_LIST *save_next_name_resolution_table;
354
347
  bool        save_resolve_in_select_list;
355
 
  TableList *save_next_local;
 
348
  TABLE_LIST *save_next_local;
356
349
 
357
350
public:
358
351
  Name_resolution_context_state() {}          /* Remove gcc warning */
359
352
 
360
353
public:
361
354
  /* Save the state of a name resolution context. */
362
 
  void save_state(Name_resolution_context *context, TableList *table_list)
 
355
  void save_state(Name_resolution_context *context, TABLE_LIST *table_list)
363
356
  {
364
357
    save_table_list=                  context->table_list;
365
358
    save_first_name_resolution_table= context->first_name_resolution_table;
369
362
  }
370
363
 
371
364
  /* Restore a name resolution context from saved state. */
372
 
  void restore_state(Name_resolution_context *context, TableList *table_list)
 
365
  void restore_state(Name_resolution_context *context, TABLE_LIST *table_list)
373
366
  {
374
367
    table_list->next_local=                save_next_local;
375
368
    table_list->next_name_resolution_table= save_next_name_resolution_table;
378
371
    context->resolve_in_select_list=       save_resolve_in_select_list;
379
372
  }
380
373
 
381
 
  TableList *get_first_name_resolution_table()
 
374
  TABLE_LIST *get_first_name_resolution_table()
382
375
  {
383
376
    return save_first_name_resolution_table;
384
377
  }
393
386
  etc etc). An Item* tree is assumed to have the same monotonicity properties
394
387
  as its correspoinding function F:
395
388
 
396
 
  [signed] int64_t F(field1, field2, ...) {
 
389
  [signed] longlong F(field1, field2, ...) {
397
390
    put values of field_i into table record buffer;
398
391
    return item->val_int(); 
399
392
  }
414
407
} enum_monotonicity_info;
415
408
 
416
409
/*************************************************************************/
417
 
typedef bool (Item::*Item_processor) (unsigned char *arg);
 
410
typedef bool (Item::*Item_processor) (uchar *arg);
418
411
/*
419
412
  Analyzer function
420
413
    SYNOPSIS
422
415
                    OUT: Parameter to be passed to the transformer
423
416
 
424
417
    RETURN 
425
 
      true   Invoke the transformer
426
 
      false  Don't do it
 
418
      TRUE   Invoke the transformer
 
419
      FALSE  Don't do it
427
420
 
428
421
*/
429
 
typedef bool (Item::*Item_analyzer) (unsigned char **argp);
430
 
typedef Item* (Item::*Item_transformer) (unsigned char *arg);
 
422
typedef bool (Item::*Item_analyzer) (uchar **argp);
 
423
typedef Item* (Item::*Item_transformer) (uchar *arg);
431
424
typedef void (*Cond_traverser) (const Item *item, void *arg);
432
425
 
433
426
 
436
429
  Item(const Item &);                   /* Prevent use of these */
437
430
  void operator=(Item &);
438
431
  /* Cache of the result of is_expensive(). */
439
 
  int8_t is_expensive_cache;
440
 
  virtual bool is_expensive_processor(unsigned char *arg __attribute__((unused)))
441
 
  { return 0; }
 
432
  int8 is_expensive_cache;
 
433
  virtual bool is_expensive_processor(uchar *arg) { return 0; }
442
434
 
443
435
public:
444
436
  static void *operator new(size_t size)
445
437
  { return sql_alloc(size); }
446
438
  static void *operator new(size_t size, MEM_ROOT *mem_root)
447
439
  { return alloc_root(mem_root, size); }
448
 
  static void operator delete(void *ptr __attribute__((unused)),
449
 
                              size_t size __attribute__((unused)))
450
 
  { TRASH(ptr, size); }
451
 
  static void operator delete(void *ptr __attribute__((unused)),
452
 
                              MEM_ROOT *mem_root __attribute__((unused)))
453
 
  {}
 
440
  static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
 
441
  static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
454
442
 
455
443
  enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
456
444
             INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
458
446
             PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
459
447
             FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
460
448
             SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
461
 
             PARAM_ITEM, DECIMAL_ITEM,
 
449
             PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
 
450
             XPATH_NODESET, XPATH_NODESET_CMP,
462
451
             VIEW_FIXER_ITEM};
463
452
 
464
453
  enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
466
455
  enum traverse_order { POSTFIX, PREFIX };
467
456
  
468
457
  /* Reuse size, only used by SP local variable assignment, otherwize 0 */
469
 
  uint32_t rsize;
 
458
  uint rsize;
470
459
 
471
460
  /*
472
461
    str_values's main purpose is to be used to cache the value in
477
466
  /* Original item name (if it was renamed)*/
478
467
  char * orig_name;
479
468
  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
 
469
  uint32 max_length;
 
470
  uint name_length;                     /* Length of name */
 
471
  int8 marker;
 
472
  uint8 decimals;
 
473
  my_bool maybe_null;                   /* If item may be null */
 
474
  my_bool null_value;                   /* if item is null */
 
475
  my_bool unsigned_flag;
 
476
  my_bool with_sum_func;
 
477
  my_bool fixed;                        /* If item fixed with fix_fields */
 
478
  my_bool is_autogenerated_name;        /* indicate was name of this Item
490
479
                                           autogenerated or set by user */
491
480
  DTCollation collation;
492
 
  bool with_subselect;               /* If this item is a subselect or some
 
481
  my_bool with_subselect;               /* If this item is a subselect or some
493
482
                                           of its arguments is or contains a
494
483
                                           subselect. Computed by fix_fields. */
495
484
  Item_result cmp_context;              /* Comparison context */
510
499
    name=0;
511
500
#endif
512
501
  }             /*lint -e1509 */
513
 
  void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs);
 
502
  void set_name(const char *str, uint length, CHARSET_INFO *cs);
514
503
  void rename(char *new_name);
515
504
  void init_make_field(Send_field *tmp_field,enum enum_field_types type);
516
505
  virtual void cleanup();
517
506
  virtual void make_field(Send_field *field);
518
 
  Field *make_string_field(Table *table);
 
507
  Field *make_string_field(TABLE *table);
519
508
  virtual bool fix_fields(THD *, Item **);
520
509
  /*
521
510
    Fix after some tables has been pulled out. Basically re-calculate all
522
511
    attributes that are dependent on the tables.
523
512
  */
524
 
  virtual void fix_after_pullout(st_select_lex *new_parent __attribute__((unused)),
525
 
                                 Item **ref __attribute__((unused))) {};
 
513
  virtual void fix_after_pullout(st_select_lex *new_parent, Item **ref) {};
526
514
 
527
515
  /*
528
516
    should be used in case where we are sure that we do not need
557
545
 
558
546
    SYNOPSIS
559
547
      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"
 
548
        left_endp  FALSE  <=> The interval is "x < const" or "x <= const"
 
549
                   TRUE   <=> The interval is "x > const" or "x >= const"
562
550
 
563
 
        incl_endp  IN   true <=> the comparison is '<' or '>'
564
 
                        false <=> the comparison is '<=' or '>='
 
551
        incl_endp  IN   TRUE <=> the comparison is '<' or '>'
 
552
                        FALSE <=> the comparison is '<=' or '>='
565
553
                   OUT  The same but for the "F(x) $CMP$ F(const)" comparison
566
554
 
567
555
    DESCRIPTION
582
570
 
583
571
    RETURN
584
572
      The output range bound, which equal to the value of val_int()
585
 
        - If the value of the function is NULL then the bound is the
586
 
          smallest possible value of INT64_MIN
 
573
        - If the value of the function is NULL then the bound is the 
 
574
          smallest possible value of LONGLONG_MIN 
587
575
  */
588
 
  virtual int64_t val_int_endpoint(bool left_endp __attribute__((unused)),
589
 
                                    bool *incl_endp __attribute__((unused)))
590
 
  { assert(0); return 0; }
 
576
  virtual longlong val_int_endpoint(bool left_endp, bool *incl_endp)
 
577
  { DBUG_ASSERT(0); return 0; }
591
578
 
592
579
 
593
580
  /* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
598
585
      val_real()
599
586
 
600
587
    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.
 
588
      In case of NULL value return 0.0 and set null_value flag to TRUE.
 
589
      If value is not null null_value flag will be reset to FALSE.
603
590
  */
604
591
  virtual double val_real()=0;
605
592
  /*
609
596
      val_int()
610
597
 
611
598
    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.
 
599
      In case of NULL value return 0 and set null_value flag to TRUE.
 
600
      If value is not null null_value flag will be reset to FALSE.
614
601
  */
615
 
  virtual int64_t val_int()=0;
 
602
  virtual longlong val_int()=0;
616
603
  /*
617
604
    This is just a shortcut to avoid the cast. You should still use
618
605
    unsigned_flag to check the sign of the item.
619
606
  */
620
 
  inline uint64_t val_uint() { return (uint64_t) val_int(); }
 
607
  inline ulonglong val_uint() { return (ulonglong) val_int(); }
621
608
  /*
622
609
    Return string representation of this item object.
623
610
 
649
636
 
650
637
    RETURN
651
638
      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.
 
639
      to TRUE.
 
640
      If value is not null null_value flag will be reset to FALSE.
654
641
  */
655
642
  virtual String *val_str(String *str)=0;
656
643
  /*
667
654
 
668
655
    RETURN
669
656
      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).
 
657
        if value is not NULL (null_value flag will be reset to FALSE).
671
658
      In case of NULL value it return 0 pointer and set null_value flag
672
 
        to true.
 
659
        to TRUE.
673
660
  */
674
661
  virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
675
662
  /*
676
663
    Return boolean value of item.
677
664
 
678
665
    RETURN
679
 
      false value is false or NULL
680
 
      true value is true (not equal to 0)
 
666
      FALSE value is false or NULL
 
667
      TRUE value is true (not equal to 0)
681
668
  */
682
669
  virtual bool val_bool();
683
670
  virtual String *val_nodeset(String*) { return 0; }
690
677
  my_decimal *val_decimal_from_string(my_decimal *decimal_value);
691
678
  my_decimal *val_decimal_from_date(my_decimal *decimal_value);
692
679
  my_decimal *val_decimal_from_time(my_decimal *decimal_value);
693
 
  int64_t val_int_from_decimal();
 
680
  longlong val_int_from_decimal();
694
681
  double val_real_from_decimal();
695
682
 
696
683
  int save_time_in_field(Field *field);
697
684
  int save_date_in_field(Field *field);
698
685
  int save_str_value_in_field(Field *field, String *result);
699
686
 
700
 
  virtual Field *get_tmp_table_field(void) { return 0; }
 
687
  virtual Field *get_tmp_table_field() { return 0; }
701
688
  /* This is also used to create fields in CREATE ... SELECT: */
702
 
  virtual Field *tmp_table_field(Table *t_arg __attribute__((unused)))
703
 
  { return 0; }
704
 
  virtual const char *full_name(void) const { return name ? name : "???"; }
 
689
  virtual Field *tmp_table_field(TABLE *t_arg) { return 0; }
 
690
  virtual const char *full_name() const { return name ? name : "???"; }
705
691
 
706
692
  /*
707
693
    *result* family of methods is analog of *val* family (see above) but
710
696
    way as *val* methods do it.
711
697
  */
712
698
  virtual double  val_result() { return val_real(); }
713
 
  virtual int64_t val_int_result() { return val_int(); }
 
699
  virtual longlong val_int_result() { return val_int(); }
714
700
  virtual String *str_result(String* tmp) { return val_str(tmp); }
715
701
  virtual my_decimal *val_decimal_result(my_decimal *val)
716
702
  { return val_decimal(val); }
738
724
  /* cloning of constant items (0 if it is not const) */
739
725
  virtual Item *clone_item() { return 0; }
740
726
  virtual cond_result eq_cmp_result() const { return COND_OK; }
741
 
  inline uint32_t float_length(uint32_t decimals_par) const
 
727
  inline uint float_length(uint decimals_par) const
742
728
  { return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;}
743
 
  virtual uint32_t decimal_precision() const;
 
729
  virtual uint decimal_precision() const;
744
730
  inline int decimal_int_part() const
745
731
  { return my_decimal_int_part(decimal_precision(), decimals); }
746
732
  /* 
766
752
    query and why they should be generated from the Item-tree, @see
767
753
    mysql_register_view().
768
754
  */
769
 
  virtual inline void print(String *str,
770
 
                            enum_query_type query_type __attribute__((unused)))
 
755
  virtual inline void print(String *str, enum_query_type query_type)
771
756
  {
772
757
    str->append(full_name());
773
758
  }
774
759
 
775
760
  void print_item_w_name(String *, enum_query_type query_type);
776
761
  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))) {}
 
762
  virtual void split_sum_func(THD *thd, Item **ref_pointer_array,
 
763
                              List<Item> &fields) {}
780
764
  /* Called for items that really have to be split */
781
765
  void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields,
782
766
                       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)
 
767
  virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
768
  virtual bool get_time(MYSQL_TIME *ltime);
 
769
  virtual bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
786
770
  { return get_date(ltime,fuzzydate); }
787
771
  /*
788
772
    The method allows to determine nullness of a complex expression 
800
784
 
801
785
  /*
802
786
    Inform the item that there will be no distinction between its result
803
 
    being false or NULL.
 
787
    being FALSE or NULL.
804
788
 
805
789
    NOTE
806
790
      This function will be called for eg. Items that are top-level AND-parts
808
792
      Item_cond_and and subquery-related item) enable special optimizations
809
793
      when they are "top level".
810
794
  */
811
 
  virtual void top_level_item(void) {}
 
795
  virtual void top_level_item() {}
812
796
  /*
813
797
    set field of temporary table for Item which can be switched on temporary
814
798
    table during query processing (grouping and so on)
815
799
  */
816
 
  virtual void set_result_field(Field *field __attribute__((unused))) {}
817
 
  virtual bool is_result_field(void) { return 0; }
818
 
  virtual bool is_bool_func(void) { return 0; }
819
 
  virtual void save_in_result_field(bool no_conversions __attribute__((unused)))
820
 
  {}
 
800
  virtual void set_result_field(Field *field) {}
 
801
  virtual bool is_result_field() { return 0; }
 
802
  virtual bool is_bool_func() { return 0; }
 
803
  virtual void save_in_result_field(bool no_conversions) {}
821
804
  /*
822
805
    set value of aggregate function in case of no rows for grouping were found
823
806
  */
824
 
  virtual void no_rows_in_result(void) {}
825
 
  virtual Item *copy_or_same(THD *thd __attribute__((unused)))
826
 
  { return this; }
827
 
  virtual Item *copy_andor_structure(THD *thd  __attribute__((unused)))
828
 
  { return this; }
829
 
  virtual Item *real_item(void) { return this; }
 
807
  virtual void no_rows_in_result() {}
 
808
  virtual Item *copy_or_same(THD *thd) { return this; }
 
809
  virtual Item *copy_andor_structure(THD *thd) { return this; }
 
810
  virtual Item *real_item() { return this; }
830
811
  virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
831
812
 
832
 
  static const CHARSET_INFO *default_charset();
833
 
  virtual const CHARSET_INFO *compare_collation() { return NULL; }
 
813
  static CHARSET_INFO *default_charset();
 
814
  virtual CHARSET_INFO *compare_collation() { return NULL; }
834
815
 
835
 
  virtual bool walk(Item_processor processor __attribute__((unused)),
836
 
                    bool walk_subquery __attribute__((unused)),
837
 
                    unsigned char *arg)
 
816
  virtual bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
838
817
  {
839
818
    return (this->*processor)(arg);
840
819
  }
841
820
 
842
 
  virtual Item* transform(Item_transformer transformer, unsigned char *arg);
 
821
  virtual Item* transform(Item_transformer transformer, uchar *arg);
843
822
 
844
823
  /*
845
824
    This function performs a generic "compilation" of the Item tree.
857
836
    i.e. analysis is performed top-down while transformation is done
858
837
    bottom-up.      
859
838
  */
860
 
  virtual Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
861
 
                        Item_transformer transformer, unsigned char *arg_t)
 
839
  virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
 
840
                        Item_transformer transformer, uchar *arg_t)
862
841
  {
863
842
    if ((this->*analyzer) (arg_p))
864
843
      return ((this->*transformer) (arg_t));
865
844
    return 0;
866
845
  }
867
846
 
868
 
   virtual void traverse_cond(Cond_traverser traverser __attribute__((unused)),
869
 
                              void *arg,
870
 
                              traverse_order order __attribute__((unused)))
 
847
   virtual void traverse_cond(Cond_traverser traverser,
 
848
                              void *arg, traverse_order order)
871
849
   {
872
850
     (*traverser)(this, arg);
873
851
   }
874
852
 
875
 
  virtual bool remove_dependence_processor(unsigned char * arg __attribute__((unused)))
876
 
  { return 0; }
877
 
  virtual bool remove_fixed(unsigned char * arg __attribute__((unused)))
878
 
  {
879
 
    fixed= 0;
880
 
    return 0;
881
 
  }
882
 
  virtual bool cleanup_processor(unsigned char *arg __attribute__((unused)));
883
 
  virtual bool collect_item_field_processor(unsigned char * arg __attribute__((unused)))
884
 
  { return 0; }
885
 
  virtual bool find_item_in_field_list_processor(unsigned char *arg __attribute__((unused)))
886
 
 { 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)
900
 
  {
 
853
  virtual bool remove_dependence_processor(uchar * arg) { return 0; }
 
854
  virtual bool remove_fixed(uchar * arg) { fixed= 0; return 0; }
 
855
  virtual bool cleanup_processor(uchar *arg);
 
856
  virtual bool collect_item_field_processor(uchar * arg) { return 0; }
 
857
  virtual bool find_item_in_field_list_processor(uchar *arg) { return 0; }
 
858
  virtual bool change_context_processor(uchar *context) { return 0; }
 
859
  virtual bool reset_query_id_processor(uchar *query_id_arg) { return 0; }
 
860
  virtual bool register_field_in_read_map(uchar *arg) { return 0; }
 
861
  virtual bool subst_argument_checker(uchar **arg)
 
862
  { 
901
863
    if (*arg)
902
 
      *arg= NULL;
903
 
    return true;
 
864
      *arg= NULL; 
 
865
    return TRUE;     
904
866
  }
905
867
 
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
 
 
 
868
  virtual Item *equal_fields_propagator(uchar * arg) { return this; }
 
869
  virtual bool set_no_const_sub(uchar *arg) { return FALSE; }
 
870
  virtual Item *replace_equal_field(uchar * arg) { return this; }
922
871
 
923
872
  /*
924
873
    For SP local variable returns pointer to Item representing its
925
874
    current value and pointer to current Item otherwise.
926
875
  */
927
 
  virtual Item *this_item(void) { return this; }
928
 
  virtual const Item *this_item(void) const { return this; }
 
876
  virtual Item *this_item() { return this; }
 
877
  virtual const Item *this_item() const { return this; }
929
878
 
930
879
  /*
931
880
    For SP local variable returns address of pointer to Item representing its
932
881
    current value and pointer passed via parameter otherwise.
933
882
  */
934
 
  virtual Item **this_item_addr(THD *thd __attribute__((unused)), Item **addr_arg) { return addr_arg; }
 
883
  virtual Item **this_item_addr(THD *thd, Item **addr_arg) { return addr_arg; }
935
884
 
936
885
  // 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);
 
886
  virtual uint cols() { return 1; }
 
887
  virtual Item* element_index(uint i) { return this; }
 
888
  virtual Item** addr(uint i) { return 0; }
 
889
  virtual bool check_cols(uint c);
941
890
  // It is not row => null inside is impossible
942
891
  virtual bool null_inside() { return 0; }
943
892
  // used in row subselects to get value of elements
944
893
  virtual void bring_value() {}
945
894
 
946
 
  Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
 
895
  Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length);
947
896
  virtual Item_field *filed_for_view_update() { return 0; }
948
897
 
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);
 
898
  virtual Item *neg_transformer(THD *thd) { return NULL; }
 
899
  virtual Item *update_value_transformer(uchar *select_arg) { return this; }
 
900
  virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
952
901
  void delete_self()
953
902
  {
954
903
    cleanup();
956
905
  }
957
906
 
958
907
  /*
959
 
    result_as_int64_t() must return true for Items representing DATE/TIME
 
908
    result_as_longlong() must return TRUE for Items representing DATE/TIME
960
909
    functions and DATE/TIME table fields.
961
910
    Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
962
911
    their values should be compared as integers (because the integer
963
912
    representation is more precise than the string one).
964
913
  */
965
 
  virtual bool result_as_int64_t() { return false; }
 
914
  virtual bool result_as_longlong() { return FALSE; }
966
915
  bool is_datetime();
967
916
 
968
917
  /*
979
928
  virtual bool is_expensive()
980
929
  {
981
930
    if (is_expensive_cache < 0)
982
 
      is_expensive_cache= walk(&Item::is_expensive_processor, 0, (unsigned char*)0);
 
931
      is_expensive_cache= walk(&Item::is_expensive_processor, 0, (uchar*)0);
983
932
    return test(is_expensive_cache);
984
933
  }
985
934
  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); 
 
935
  bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs); 
987
936
};
988
937
 
989
938
 
1004
953
};
1005
954
 
1006
955
bool agg_item_collations(DTCollation &c, const char *name,
1007
 
                         Item **items, uint32_t nitems, uint32_t flags, int item_sep);
 
956
                         Item **items, uint nitems, uint flags, int item_sep);
1008
957
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
1009
 
                                        Item **items, uint32_t nitems, uint32_t flags);
 
958
                                        Item **items, uint nitems, uint flags);
1010
959
bool agg_item_charsets(DTCollation &c, const char *name,
1011
 
                       Item **items, uint32_t nitems, uint32_t flags, int item_sep);
 
960
                       Item **items, uint nitems, uint flags, int item_sep);
1012
961
 
1013
962
 
1014
963
class Item_num: public Item_basic_constant
1016
965
public:
1017
966
  Item_num() {}                               /* Remove gcc warning */
1018
967
  virtual Item_num *neg()= 0;
1019
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
968
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1020
969
};
1021
970
 
1022
971
#define NO_CACHED_FIELD_INDEX ((uint)(-1))
1046
995
    stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX 
1047
996
    if index value is not known.
1048
997
  */
1049
 
  uint32_t cached_field_index;
 
998
  uint cached_field_index;
1050
999
  /*
1051
1000
    Cached pointer to table which contains this field, used for the same reason
1052
1001
    by prep. stmt. too in case then we have not-fully qualified field.
1053
1002
    0 - means no cached value.
1054
1003
  */
1055
 
  TableList *cached_table;
 
1004
  TABLE_LIST *cached_table;
1056
1005
  st_select_lex *depended_from;
1057
1006
  Item_ident(Name_resolution_context *context_arg,
1058
1007
             const char *db_name_arg, const char *table_name_arg,
1060
1009
  Item_ident(THD *thd, Item_ident *item);
1061
1010
  const char *full_name() const;
1062
1011
  void cleanup();
1063
 
  bool remove_dependence_processor(unsigned char * arg);
 
1012
  bool remove_dependence_processor(uchar * arg);
1064
1013
  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; }
 
1014
  virtual bool change_context_processor(uchar *cntx)
 
1015
    { context= (Name_resolution_context *)cntx; return FALSE; }
1067
1016
  friend bool insert_fields(THD *thd, Name_resolution_context *context,
1068
1017
                            const char *db_name,
1069
1018
                            const char *table_name, List_iterator<Item> *it,
1085
1034
 
1086
1035
  enum Type type() const { return FIELD_ITEM; }
1087
1036
  double val_real() { return field->val_real(); }
1088
 
  int64_t val_int() { return field->val_int(); }
 
1037
  longlong val_int() { return field->val_int(); }
1089
1038
  String *val_str(String *str) { return field->val_str(str); }
1090
1039
  my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); }
1091
1040
  void make_field(Send_field *tmp_field);
1104
1053
  Item_equal *item_equal;
1105
1054
  bool no_const_subst;
1106
1055
  /*
1107
 
    if any_privileges set to true then here real effective privileges will
 
1056
    if any_privileges set to TRUE then here real effective privileges will
1108
1057
    be stored
1109
1058
  */
1110
 
  uint32_t have_privileges;
 
1059
  uint have_privileges;
1111
1060
  /* field need any privileges (for VIEW creation) */
1112
1061
  bool any_privileges;
1113
1062
  Item_field(Name_resolution_context *context_arg,
1132
1081
  enum Type type() const { return FIELD_ITEM; }
1133
1082
  bool eq(const Item *item, bool binary_cmp) const;
1134
1083
  double val_real();
1135
 
  int64_t val_int();
 
1084
  longlong val_int();
1136
1085
  my_decimal *val_decimal(my_decimal *);
1137
1086
  String *val_str(String*);
1138
1087
  double val_result();
1139
 
  int64_t val_int_result();
 
1088
  longlong val_int_result();
1140
1089
  String *str_result(String* tmp);
1141
1090
  my_decimal *val_decimal_result(my_decimal *);
1142
1091
  bool val_bool_result();
1164
1113
  {
1165
1114
    return MONOTONIC_STRICT_INCREASING;
1166
1115
  }
1167
 
  int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
 
1116
  longlong val_int_endpoint(bool left_endp, bool *incl_endp);
1168
1117
  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);
 
1118
  Field *tmp_table_field(TABLE *t_arg) { return result_field; }
 
1119
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
1120
  bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate);
 
1121
  bool get_time(MYSQL_TIME *ltime);
1173
1122
  bool is_null() { return field->is_null(); }
1174
1123
  void update_null_value();
1175
1124
  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; }
 
1125
  bool collect_item_field_processor(uchar * arg);
 
1126
  bool find_item_in_field_list_processor(uchar *arg);
 
1127
  bool register_field_in_read_map(uchar *arg);
1182
1128
  void cleanup();
1183
 
  bool result_as_int64_t()
 
1129
  bool result_as_longlong()
1184
1130
  {
1185
 
    return field->can_be_compared_as_int64_t();
 
1131
    return field->can_be_compared_as_longlong();
1186
1132
  }
1187
1133
  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(); }
 
1134
  bool subst_argument_checker(uchar **arg);
 
1135
  Item *equal_fields_propagator(uchar *arg);
 
1136
  bool set_no_const_sub(uchar *arg);
 
1137
  Item *replace_equal_field(uchar *arg);
 
1138
  inline uint32 max_disp_length() { return field->max_display_length(); }
1193
1139
  Item_field *filed_for_view_update() { return this; }
1194
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
1140
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1195
1141
  int fix_outer_field(THD *thd, Field **field, Item **reference);
1196
 
  virtual Item *update_value_transformer(unsigned char *select_arg);
 
1142
  virtual Item *update_value_transformer(uchar *select_arg);
1197
1143
  virtual void print(String *str, enum_query_type query_type);
1198
1144
 
 
1145
#ifndef DBUG_OFF
 
1146
  void dbug_print()
 
1147
  {
 
1148
    fprintf(DBUG_FILE, "<field ");
 
1149
    if (field)
 
1150
    {
 
1151
      fprintf(DBUG_FILE, "'%s.%s': ", field->table->alias, field->field_name);
 
1152
      field->dbug_print();
 
1153
    }
 
1154
    else
 
1155
      fprintf(DBUG_FILE, "NULL");
 
1156
 
 
1157
    fprintf(DBUG_FILE, ", result_field: ");
 
1158
    if (result_field)
 
1159
    {
 
1160
      fprintf(DBUG_FILE, "'%s.%s': ",
 
1161
              result_field->table->alias, result_field->field_name);
 
1162
      result_field->dbug_print();
 
1163
    }
 
1164
    else
 
1165
      fprintf(DBUG_FILE, "NULL");
 
1166
    fprintf(DBUG_FILE, ">\n");
 
1167
  }
 
1168
#endif
 
1169
 
1199
1170
  friend class Item_default_value;
1200
1171
  friend class Item_insert_value;
1201
1172
  friend class st_select_lex_unit;
1206
1177
public:
1207
1178
  Item_null(char *name_par=0)
1208
1179
  {
1209
 
    maybe_null= null_value= true;
 
1180
    maybe_null= null_value= TRUE;
1210
1181
    max_length= 0;
1211
1182
    name= name_par ? name_par : (char*) "NULL";
1212
1183
    fixed= 1;
1215
1186
  enum Type type() const { return NULL_ITEM; }
1216
1187
  bool eq(const Item *item, bool binary_cmp) const;
1217
1188
  double val_real();
1218
 
  int64_t val_int();
 
1189
  longlong val_int();
1219
1190
  String *val_str(String *str);
1220
1191
  my_decimal *val_decimal(my_decimal *);
1221
1192
  int save_in_field(Field *field, bool no_conversions);
1222
1193
  int save_safe_in_field(Field *field);
1223
1194
  bool send(Protocol *protocol, String *str);
1224
1195
  enum Item_result result_type () const { return STRING_RESULT; }
1225
 
  enum_field_types field_type() const   { return DRIZZLE_TYPE_NULL; }
 
1196
  enum_field_types field_type() const   { return MYSQL_TYPE_NULL; }
1226
1197
  bool basic_const_item() const { return 1; }
1227
1198
  Item *clone_item() { return new Item_null(name); }
1228
1199
  bool is_null() { return 1; }
1229
1200
 
1230
 
  virtual inline void print(String *str,
1231
 
                            enum_query_type query_type __attribute__((unused)))
 
1201
  virtual inline void print(String *str, enum_query_type query_type)
1232
1202
  {
1233
1203
    str->append(STRING_WITH_LEN("NULL"));
1234
1204
  }
1235
1205
 
1236
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1237
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1238
 
  { return false; }
 
1206
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1239
1207
};
1240
1208
 
1241
1209
class Item_null_result :public Item_null
1248
1216
  {
1249
1217
    save_in_field(result_field, no_conversions);
1250
1218
  }
1251
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1252
 
  { return true; }
1253
1219
};  
1254
1220
 
1255
1221
/* Item represents one placeholder ('?') of prepared statement */
1282
1248
  my_decimal decimal_value;
1283
1249
  union
1284
1250
  {
1285
 
    int64_t integer;
 
1251
    longlong integer;
1286
1252
    double   real;
1287
1253
    /*
1288
1254
      Character sets conversion info for string values.
1292
1258
    */
1293
1259
    struct CONVERSION_INFO
1294
1260
    {
1295
 
      const CHARSET_INFO *character_set_client;
1296
 
      const CHARSET_INFO *character_set_of_placeholder;
 
1261
      CHARSET_INFO *character_set_client;
 
1262
      CHARSET_INFO *character_set_of_placeholder;
1297
1263
      /*
1298
1264
        This points at character set of connection if conversion
1299
1265
        to it is required (i. e. if placeholder typecode is not BLOB).
1300
1266
        Otherwise it's equal to character_set_client (to simplify
1301
1267
        check in convert_str_value()).
1302
1268
      */
1303
 
      const CHARSET_INFO *final_character_set_of_str_value;
 
1269
      CHARSET_INFO *final_character_set_of_str_value;
1304
1270
    } cs_info;
1305
 
    DRIZZLE_TIME     time;
 
1271
    MYSQL_TIME     time;
1306
1272
  } value;
1307
1273
 
1308
1274
  /* Cached values for virtual methods to save us one switch.  */
1313
1279
    Used when this item is used in a temporary table.
1314
1280
    This is NOT placeholder metadata sent to client, as this value
1315
1281
    is assigned after sending metadata (in setup_one_conversion_function).
1316
 
    For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
 
1282
    For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
1317
1283
    in result set and placeholders metadata, no matter what type you will
1318
1284
    supply for this placeholder in mysql_stmt_execute.
1319
1285
  */
1322
1288
    Offset of placeholder inside statement text. Used to create
1323
1289
    no-placeholders version of this statement for the binary log.
1324
1290
  */
1325
 
  uint32_t pos_in_query;
 
1291
  uint pos_in_query;
1326
1292
 
1327
 
  Item_param(uint32_t pos_in_query_arg);
 
1293
  Item_param(uint pos_in_query_arg);
1328
1294
 
1329
1295
  enum Item_result result_type () const { return item_result_type; }
1330
1296
  enum Type type() const { return item_type; }
1331
1297
  enum_field_types field_type() const { return param_type; }
1332
1298
 
1333
1299
  double val_real();
1334
 
  int64_t val_int();
 
1300
  longlong val_int();
1335
1301
  my_decimal *val_decimal(my_decimal*);
1336
1302
  String *val_str(String*);
1337
 
  bool get_time(DRIZZLE_TIME *tm);
1338
 
  bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
 
1303
  bool get_time(MYSQL_TIME *tm);
 
1304
  bool get_date(MYSQL_TIME *tm, uint fuzzydate);
1339
1305
  int  save_in_field(Field *field, bool no_conversions);
1340
1306
 
1341
1307
  void set_null();
1342
 
  void set_int(int64_t i, uint32_t max_length_arg);
 
1308
  void set_int(longlong i, uint32 max_length_arg);
1343
1309
  void set_double(double i);
1344
 
  void set_decimal(char *str, ulong length);
 
1310
  void set_decimal(const char *str, ulong length);
1345
1311
  bool set_str(const char *str, ulong length);
1346
1312
  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);
 
1313
  void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
1349
1314
  bool set_from_user_var(THD *thd, const user_var_entry *entry);
1350
1315
  void reset();
1351
1316
  /*
1354
1319
    don't need to check that packet is not broken there). See
1355
1320
    sql_prepare.cc for details.
1356
1321
  */
1357
 
  void (*set_param_func)(Item_param *param, unsigned char **pos, ulong len);
 
1322
  void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
1358
1323
 
1359
1324
  const String *query_val_str(String *str) const;
1360
1325
 
1369
1334
  { return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
1370
1335
  virtual void print(String *str, enum_query_type query_type);
1371
1336
  bool is_null()
1372
 
  { assert(state != NO_VALUE); return state == NULL_VALUE; }
 
1337
  { DBUG_ASSERT(state != NO_VALUE); return state == NULL_VALUE; }
1373
1338
  bool basic_const_item() const;
1374
1339
  /*
1375
1340
    This method is used to make a copy of a basic constant item when
1379
1344
    words, avoid pointing at one item from two different nodes of the tree.
1380
1345
    Return a new basic constant item if parameter value is a basic
1381
1346
    constant, assert otherwise. This method is called only if
1382
 
    basic_const_item returned true.
 
1347
    basic_const_item returned TRUE.
1383
1348
  */
1384
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
1349
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1385
1350
  Item *clone_item();
1386
1351
  /*
1387
1352
    Implement by-value equality evaluation if parameter value
1388
1353
    is set and is a basic constant (integer, real or string).
1389
 
    Otherwise return false.
 
1354
    Otherwise return FALSE.
1390
1355
  */
1391
1356
  bool eq(const Item *item, bool binary_cmp) const;
1392
1357
  /** Item is a argument to a limit clause. */
1397
1362
class Item_int :public Item_num
1398
1363
{
1399
1364
public:
1400
 
  int64_t value;
1401
 
  Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS)
1402
 
    :value((int64_t) i)
 
1365
  longlong value;
 
1366
  Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
 
1367
    :value((longlong) i)
1403
1368
    { max_length=length; fixed= 1; }
1404
 
  Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
 
1369
  Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1405
1370
    :value(i)
1406
1371
    { max_length=length; fixed= 1; }
1407
 
  Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1408
 
    :value((int64_t)i)
 
1372
  Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
 
1373
    :value((longlong)i)
1409
1374
    { max_length=length; fixed= 1; unsigned_flag= 1; }
1410
 
  Item_int(const char *str_arg,int64_t i,uint32_t length) :value(i)
 
1375
  Item_int(const char *str_arg,longlong i,uint length) :value(i)
1411
1376
    { max_length=length; name=(char*) str_arg; fixed= 1; }
1412
 
  Item_int(const char *str_arg, uint32_t length=64);
 
1377
  Item_int(const char *str_arg, uint length=64);
1413
1378
  enum Type type() const { return INT_ITEM; }
1414
1379
  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; }
1417
 
  double val_real() { assert(fixed == 1); return (double) value; }
 
1380
  enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
 
1381
  longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
 
1382
  double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
1418
1383
  my_decimal *val_decimal(my_decimal *);
1419
1384
  String *val_str(String*);
1420
1385
  int save_in_field(Field *field, bool no_conversions);
1422
1387
  Item *clone_item() { return new Item_int(name,value,max_length); }
1423
1388
  virtual void print(String *str, enum_query_type query_type);
1424
1389
  Item_num *neg() { value= -value; return this; }
1425
 
  uint32_t decimal_precision() const
 
1390
  uint decimal_precision() const
1426
1391
  { return (uint)(max_length - test(value < 0)); }
1427
1392
  bool eq(const Item *, bool binary_cmp) const;
1428
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1429
 
  { return false; }
1430
1393
};
1431
1394
 
1432
1395
 
1433
1396
class Item_uint :public Item_int
1434
1397
{
1435
1398
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);
 
1399
  Item_uint(const char *str_arg, uint length);
 
1400
  Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {}
 
1401
  Item_uint(const char *str_arg, longlong i, uint length);
1439
1402
  double val_real()
1440
 
    { assert(fixed == 1); return uint64_t2double((uint64_t)value); }
 
1403
    { DBUG_ASSERT(fixed == 1); return ulonglong2double((ulonglong)value); }
1441
1404
  String *val_str(String*);
1442
1405
  Item *clone_item() { return new Item_uint(name, value, max_length); }
1443
1406
  int save_in_field(Field *field, bool no_conversions);
1444
1407
  virtual void print(String *str, enum_query_type query_type);
1445
1408
  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; }
 
1409
  uint decimal_precision() const { return max_length; }
1449
1410
};
1450
1411
 
1451
1412
 
1455
1416
protected:
1456
1417
  my_decimal decimal_value;
1457
1418
public:
1458
 
  Item_decimal(const char *str_arg, uint32_t length, const CHARSET_INFO * const charset);
 
1419
  Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset);
1459
1420
  Item_decimal(const char *str, const my_decimal *val_arg,
1460
 
               uint32_t decimal_par, uint32_t length);
 
1421
               uint decimal_par, uint length);
1461
1422
  Item_decimal(my_decimal *value_par);
1462
 
  Item_decimal(int64_t val, bool unsig);
 
1423
  Item_decimal(longlong val, bool unsig);
1463
1424
  Item_decimal(double val, int precision, int scale);
1464
 
  Item_decimal(const unsigned char *bin, int precision, int scale);
 
1425
  Item_decimal(const uchar *bin, int precision, int scale);
1465
1426
 
1466
1427
  enum Type type() const { return DECIMAL_ITEM; }
1467
1428
  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();
 
1429
  enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
 
1430
  longlong val_int();
1470
1431
  double val_real();
1471
1432
  String *val_str(String*);
1472
 
  my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
1473
 
  { return &decimal_value; }
 
1433
  my_decimal *val_decimal(my_decimal *val) { return &decimal_value; }
1474
1434
  int save_in_field(Field *field, bool no_conversions);
1475
1435
  bool basic_const_item() const { return 1; }
1476
1436
  Item *clone_item()
1484
1444
    unsigned_flag= !decimal_value.sign();
1485
1445
    return this;
1486
1446
  }
1487
 
  uint32_t decimal_precision() const { return decimal_value.precision(); }
 
1447
  uint decimal_precision() const { return decimal_value.precision(); }
1488
1448
  bool eq(const Item *, bool binary_cmp) const;
1489
1449
  void set_decimal_value(my_decimal *value_par);
1490
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1491
 
  { return false; }
1492
1450
};
1493
1451
 
1494
1452
 
1498
1456
public:
1499
1457
  double value;
1500
1458
  // 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)
 
1459
  Item_float(const char *str_arg, uint length);
 
1460
  Item_float(const char *str,double val_arg,uint decimal_par,uint length)
1503
1461
    :value(val_arg)
1504
1462
  {
1505
1463
    presentation= name=(char*) str;
1506
 
    decimals=(uint8_t) decimal_par;
 
1464
    decimals=(uint8) decimal_par;
1507
1465
    max_length=length;
1508
1466
    fixed= 1;
1509
1467
  }
1510
 
  Item_float(double value_par, uint32_t decimal_par) :presentation(0), value(value_par)
 
1468
  Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1511
1469
  {
1512
 
    decimals= (uint8_t) decimal_par;
 
1470
    decimals= (uint8) decimal_par;
1513
1471
    fixed= 1;
1514
1472
  }
1515
1473
  int save_in_field(Field *field, bool no_conversions);
1516
1474
  enum Type type() const { return REAL_ITEM; }
1517
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE; }
1518
 
  double val_real() { assert(fixed == 1); return value; }
1519
 
  int64_t val_int()
 
1475
  enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
 
1476
  double val_real() { DBUG_ASSERT(fixed == 1); return value; }
 
1477
  longlong val_int()
1520
1478
  {
1521
 
    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);
 
1479
    DBUG_ASSERT(fixed == 1);
 
1480
    if (value <= (double) LONGLONG_MIN)
 
1481
    {
 
1482
       return LONGLONG_MIN;
 
1483
    }
 
1484
    else if (value >= (double) (ulonglong) LONGLONG_MAX)
 
1485
    {
 
1486
      return LONGLONG_MAX;
 
1487
    }
 
1488
    return (longlong) rint(value);
1531
1489
  }
1532
1490
  String *val_str(String*);
1533
1491
  my_decimal *val_decimal(my_decimal *);
1544
1502
{
1545
1503
  const char *func_name;
1546
1504
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)
 
1505
  Item_static_float_func(const char *str, double val_arg, uint decimal_par,
 
1506
                        uint length)
 
1507
    :Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1550
1508
  {}
1551
1509
 
1552
 
  virtual inline void print(String *str,
1553
 
                            enum_query_type query_type __attribute__((unused)))
 
1510
  virtual inline void print(String *str, enum_query_type query_type)
1554
1511
  {
1555
1512
    str->append(func_name);
1556
1513
  }
1557
1514
 
1558
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1559
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1560
 
  { return false; }
 
1515
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1561
1516
};
1562
1517
 
1563
1518
 
1564
1519
class Item_string :public Item_basic_constant
1565
1520
{
1566
1521
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)
 
1522
  Item_string(const char *str,uint length,
 
1523
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
 
1524
              uint repertoire= MY_REPERTOIRE_UNICODE30)
 
1525
    : m_cs_specified(FALSE)
1571
1526
  {
1572
1527
    str_value.set_or_copy_aligned(str, length, cs);
1573
1528
    collation.set(cs, dv, repertoire);
1585
1540
    fixed= 1;
1586
1541
  }
1587
1542
  /* 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)
 
1543
  Item_string(CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
 
1544
    : m_cs_specified(FALSE)
1590
1545
  {
1591
1546
    collation.set(cs, dv);
1592
1547
    max_length= 0;
1594
1549
    decimals= NOT_FIXED_DEC;
1595
1550
    fixed= 1;
1596
1551
  }
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)
 
1552
  Item_string(const char *name_par, const char *str, uint length,
 
1553
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
 
1554
              uint repertoire= MY_REPERTOIRE_UNICODE30)
 
1555
    : m_cs_specified(FALSE)
1601
1556
  {
1602
1557
    str_value.set_or_copy_aligned(str, length, cs);
1603
1558
    collation.set(cs, dv, repertoire);
1611
1566
    This is used in stored procedures to avoid memory leaks and
1612
1567
    does a deep copy of its argument.
1613
1568
  */
1614
 
  void set_str_with_copy(const char *str_arg, uint32_t length_arg)
 
1569
  void set_str_with_copy(const char *str_arg, uint length_arg)
1615
1570
  {
1616
1571
    str_value.copy(str_arg, length_arg, collation.collation);
1617
1572
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
1624
1579
  }
1625
1580
  enum Type type() const { return STRING_ITEM; }
1626
1581
  double val_real();
1627
 
  int64_t val_int();
 
1582
  longlong val_int();
1628
1583
  String *val_str(String*)
1629
1584
  {
1630
 
    assert(fixed == 1);
 
1585
    DBUG_ASSERT(fixed == 1);
1631
1586
    return (String*) &str_value;
1632
1587
  }
1633
1588
  my_decimal *val_decimal(my_decimal *);
1634
1589
  int save_in_field(Field *field, bool no_conversions);
1635
1590
  enum Item_result result_type () const { return STRING_RESULT; }
1636
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
 
1591
  enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1637
1592
  bool basic_const_item() const { return 1; }
1638
1593
  bool eq(const Item *item, bool binary_cmp) const;
1639
1594
  Item *clone_item() 
1641
1596
    return new Item_string(name, str_value.ptr(), 
1642
1597
                           str_value.length(), collation.collation);
1643
1598
  }
1644
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1645
 
  inline void append(char *str, uint32_t length)
 
1599
  Item *safe_charset_converter(CHARSET_INFO *tocs);
 
1600
  inline void append(char *str, uint length)
1646
1601
  {
1647
1602
    str_value.append(str, length);
1648
1603
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
1650
1605
  virtual void print(String *str, enum_query_type query_type);
1651
1606
 
1652
1607
  /**
1653
 
    Return true if character-set-introducer was explicitly specified in the
 
1608
    Return TRUE if character-set-introducer was explicitly specified in the
1654
1609
    original query for this item (text literal).
1655
1610
 
1656
1611
    This operation is to be called from Item_string::print(). The idea is
1664
1619
    one day when we start using original query as a view definition.
1665
1620
 
1666
1621
    @return This operation returns the value of m_cs_specified attribute.
1667
 
      @retval true if character set introducer was explicitly specified in
 
1622
      @retval TRUE if character set introducer was explicitly specified in
1668
1623
      the original query.
1669
 
      @retval false otherwise.
 
1624
      @retval FALSE otherwise.
1670
1625
  */
1671
1626
  inline bool is_cs_specified() const
1672
1627
  {
1687
1642
  {
1688
1643
    m_cs_specified= cs_specified;
1689
1644
  }
1690
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1691
 
  { return false; }
1692
1645
 
1693
1646
private:
1694
1647
  bool m_cs_specified;
1699
1652
{
1700
1653
  const char *func_name;
1701
1654
public:
1702
 
  Item_static_string_func(const char *name_par, const char *str, uint32_t length,
1703
 
                          const CHARSET_INFO * const cs,
 
1655
  Item_static_string_func(const char *name_par, const char *str, uint length,
 
1656
                          CHARSET_INFO *cs,
1704
1657
                          Derivation dv= DERIVATION_COERCIBLE)
1705
 
    :Item_string(NULL, str, length, cs, dv), func_name(name_par)
 
1658
    :Item_string(NullS, str, length, cs, dv), func_name(name_par)
1706
1659
  {}
1707
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
1660
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1708
1661
 
1709
 
  virtual inline void print(String *str,
1710
 
                            enum_query_type query_type __attribute__((unused)))
 
1662
  virtual inline void print(String *str, enum_query_type query_type)
1711
1663
  {
1712
1664
    str->append(func_name);
1713
1665
  }
1714
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1715
 
  { return true; }
1716
1666
};
1717
1667
 
1718
1668
 
1732
1682
class Item_blob :public Item_string
1733
1683
{
1734
1684
public:
1735
 
  Item_blob(const char *name, uint32_t length) :
 
1685
  Item_blob(const char *name, uint length) :
1736
1686
    Item_string(name, length, &my_charset_bin)
1737
1687
  { max_length= length; }
1738
1688
  enum Type type() const { return TYPE_HOLDER; }
1739
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
 
1689
  enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
1740
1690
};
1741
1691
 
1742
1692
 
1749
1699
class Item_empty_string :public Item_string
1750
1700
{
1751
1701
public:
1752
 
  Item_empty_string(const char *header,uint32_t length, const CHARSET_INFO * cs= NULL) :
 
1702
  Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) :
1753
1703
    Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1754
1704
    { name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1755
1705
  void make_field(Send_field *field);
1760
1710
{
1761
1711
  enum_field_types int_field_type;
1762
1712
public:
1763
 
  Item_return_int(const char *name_arg, uint32_t length,
1764
 
                  enum_field_types field_type_arg, int64_t value= 0)
 
1713
  Item_return_int(const char *name_arg, uint length,
 
1714
                  enum_field_types field_type_arg, longlong value= 0)
1765
1715
    :Item_int(name_arg, value, length), int_field_type(field_type_arg)
1766
1716
  {
1767
1717
    unsigned_flag=1;
1774
1724
{
1775
1725
public:
1776
1726
  Item_hex_string() {}
1777
 
  Item_hex_string(const char *str,uint32_t str_length);
 
1727
  Item_hex_string(const char *str,uint str_length);
1778
1728
  enum Type type() const { return VARBIN_ITEM; }
1779
1729
  double val_real()
1780
1730
  { 
1781
 
    assert(fixed == 1); 
1782
 
    return (double) (uint64_t) Item_hex_string::val_int();
 
1731
    DBUG_ASSERT(fixed == 1); 
 
1732
    return (double) (ulonglong) Item_hex_string::val_int();
1783
1733
  }
1784
 
  int64_t val_int();
 
1734
  longlong val_int();
1785
1735
  bool basic_const_item() const { return 1; }
1786
 
  String *val_str(String*) { assert(fixed == 1); return &str_value; }
 
1736
  String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; }
1787
1737
  my_decimal *val_decimal(my_decimal *);
1788
1738
  int save_in_field(Field *field, bool no_conversions);
1789
1739
  enum Item_result result_type () const { return STRING_RESULT; }
1790
1740
  enum Item_result cast_to_int_type() const { return INT_RESULT; }
1791
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
 
1741
  enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1792
1742
  virtual void print(String *str, enum_query_type query_type);
1793
1743
  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; }
 
1744
  virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
1797
1745
};
1798
1746
 
1799
1747
 
1800
1748
class Item_bin_string: public Item_hex_string
1801
1749
{
1802
1750
public:
1803
 
  Item_bin_string(const char *str,uint32_t str_length);
 
1751
  Item_bin_string(const char *str,uint str_length);
1804
1752
};
1805
1753
 
1806
1754
class Item_result_field :public Item    /* Item with result field */
1814
1762
  {}
1815
1763
  ~Item_result_field() {}                       /* Required with gcc 2.95 */
1816
1764
  Field *get_tmp_table_field() { return result_field; }
1817
 
  Field *tmp_table_field(Table *t_arg __attribute__((unused)))
1818
 
  { return result_field; }
 
1765
  Field *tmp_table_field(TABLE *t_arg) { return result_field; }
1819
1766
  table_map used_tables() const { return 1; }
1820
1767
  virtual void fix_length_and_dec()=0;
1821
1768
  void set_result_field(Field *field) { result_field= field; }
1825
1772
    save_in_field(result_field, no_conversions);
1826
1773
  }
1827
1774
  void cleanup();
1828
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1829
 
  { return false; }
1830
1775
};
1831
1776
 
1832
1777
 
1859
1804
  */
1860
1805
  Item_ref(Name_resolution_context *context_arg, Item **item,
1861
1806
           const char *table_name_arg, const char *field_name_arg,
1862
 
           bool alias_name_used_arg= false);
 
1807
           bool alias_name_used_arg= FALSE);
1863
1808
 
1864
1809
  /* Constructor need to process subselect with temporary tables (see Item) */
1865
1810
  Item_ref(THD *thd, Item_ref *item)
1871
1816
    return ref && (*ref)->eq(it, binary_cmp);
1872
1817
  }
1873
1818
  double val_real();
1874
 
  int64_t val_int();
 
1819
  longlong val_int();
1875
1820
  my_decimal *val_decimal(my_decimal *);
1876
1821
  bool val_bool();
1877
1822
  String *val_str(String* tmp);
1878
1823
  bool is_null();
1879
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
1824
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1880
1825
  double val_result();
1881
 
  int64_t val_int_result();
 
1826
  longlong val_int_result();
1882
1827
  String *str_result(String* tmp);
1883
1828
  my_decimal *val_decimal_result(my_decimal *);
1884
1829
  bool val_bool_result();
1913
1858
  {
1914
1859
    return ref ? (*ref)->real_item() : this;
1915
1860
  }
1916
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
 
1861
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1917
1862
  { return (*ref)->walk(processor, walk_subquery, arg); }
1918
1863
  virtual void print(String *str, enum_query_type query_type);
1919
 
  bool result_as_int64_t()
 
1864
  bool result_as_longlong()
1920
1865
  {
1921
 
    return (*ref)->result_as_int64_t();
 
1866
    return (*ref)->result_as_longlong();
1922
1867
  }
1923
1868
  void cleanup();
1924
1869
  Item_field *filed_for_view_update()
1926
1871
  virtual Ref_Type ref_type() { return REF; }
1927
1872
 
1928
1873
  // Row emulation: forwarding of ROW-related calls to ref
1929
 
  uint32_t cols()
 
1874
  uint cols()
1930
1875
  {
1931
1876
    return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1932
1877
  }
1933
 
  Item* element_index(uint32_t i)
 
1878
  Item* element_index(uint i)
1934
1879
  {
1935
1880
    return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1936
1881
  }
1937
 
  Item** addr(uint32_t i)
 
1882
  Item** addr(uint i)
1938
1883
  {
1939
1884
    return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1940
1885
  }
1941
 
  bool check_cols(uint32_t c)
 
1886
  bool check_cols(uint c)
1942
1887
  {
1943
1888
    return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c) 
1944
1889
                                              : Item::check_cols(c);
1966
1911
  Item_direct_ref(Name_resolution_context *context_arg, Item **item,
1967
1912
                  const char *table_name_arg,
1968
1913
                  const char *field_name_arg,
1969
 
                  bool alias_name_used_arg= false)
 
1914
                  bool alias_name_used_arg= FALSE)
1970
1915
    :Item_ref(context_arg, item, table_name_arg,
1971
1916
              field_name_arg, alias_name_used_arg)
1972
1917
  {}
1974
1919
  Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
1975
1920
 
1976
1921
  double val_real();
1977
 
  int64_t val_int();
 
1922
  longlong val_int();
1978
1923
  String *val_str(String* tmp);
1979
1924
  my_decimal *val_decimal(my_decimal *);
1980
1925
  bool val_bool();
1981
1926
  bool is_null();
1982
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
1927
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1983
1928
  virtual Ref_Type ref_type() { return DIRECT_REF; }
1984
1929
};
1985
1930
 
2028
1973
  /* The aggregate function under which this outer ref is used, if any. */
2029
1974
  Item_sum *in_sum_func;
2030
1975
  /*
2031
 
    true <=> that the outer_ref is already present in the select list
 
1976
    TRUE <=> that the outer_ref is already present in the select list
2032
1977
    of the outer select.
2033
1978
  */
2034
1979
  bool found_in_select_list;
2050
1995
                     alias_name_used_arg),
2051
1996
    outer_ref(0), in_sum_func(0), found_in_select_list(1)
2052
1997
  {}
2053
 
  void save_in_result_field(bool no_conversions __attribute__((unused)))
 
1998
  void save_in_result_field(bool no_conversions)
2054
1999
  {
2055
2000
    outer_ref->save_org_in_field(result_field);
2056
2001
  }
2070
2015
/*
2071
2016
  An object of this class:
2072
2017
   - 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
 
2018
   - Sets owner->was_null=TRUE if it has returned a NULL value from any
2074
2019
     val_XXX() function. This allows to inject an Item_ref_null_helper
2075
2020
     object into subquery and then check if the subquery has produced a row
2076
2021
     with NULL value.
2087
2032
    :Item_ref(context_arg, item, table_name_arg, field_name_arg),
2088
2033
     owner(master) {}
2089
2034
  double val_real();
2090
 
  int64_t val_int();
 
2035
  longlong val_int();
2091
2036
  String* val_str(String* s);
2092
2037
  my_decimal *val_decimal(my_decimal *);
2093
2038
  bool val_bool();
2094
 
  bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
 
2039
  bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
2095
2040
  virtual void print(String *str, enum_query_type query_type);
2096
2041
  /*
2097
2042
    we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2117
2062
{
2118
2063
  Item *ref;
2119
2064
public:
2120
 
  Item_int_with_ref(int64_t i, Item *ref_arg, bool unsigned_arg) :
 
2065
  Item_int_with_ref(longlong i, Item *ref_arg, my_bool unsigned_arg) :
2121
2066
    Item_int(i), ref(ref_arg)
2122
2067
  {
2123
2068
    unsigned_flag= unsigned_arg;
2130
2075
  virtual Item *real_item() { return ref; }
2131
2076
};
2132
2077
 
2133
 
#ifdef DRIZZLE_SERVER
 
2078
#ifdef MYSQL_SERVER
2134
2079
#include "item_sum.h"
2135
2080
#include "item_func.h"
2136
2081
#include "item_row.h"
2147
2092
  Item *item;
2148
2093
  Item_copy_string(Item *i) :item(i)
2149
2094
  {
2150
 
    null_value= maybe_null= item->maybe_null;
 
2095
    null_value=maybe_null=item->maybe_null;
2151
2096
    decimals=item->decimals;
2152
2097
    max_length=item->max_length;
2153
2098
    name=item->name;
2161
2106
    int err_not_used;
2162
2107
    char *end_not_used;
2163
2108
    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));
 
2109
            my_strntod(str_value.charset(), (char*) str_value.ptr(),
 
2110
                       str_value.length(), &end_not_used, &err_not_used));
2166
2111
  }
2167
 
  int64_t val_int()
 
2112
  longlong val_int()
2168
2113
  {
2169
2114
    int err;
2170
 
    return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
2171
 
                                        str_value.length(),10, (char**) 0,
2172
 
                                        &err);
 
2115
    return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
 
2116
                                            str_value.length(),10, (char**) 0,
 
2117
                                            &err); 
2173
2118
  }
2174
2119
  String *val_str(String*);
2175
2120
  my_decimal *val_decimal(my_decimal *);
2176
2121
  void make_field(Send_field *field) { item->make_field(field); }
2177
2122
  void copy();
2178
 
  int save_in_field(Field *field,
2179
 
                    bool no_conversions __attribute__((unused)))
 
2123
  int save_in_field(Field *field, bool no_conversions)
2180
2124
  {
2181
2125
    return save_str_value_in_field(field, &str_value);
2182
2126
  }
2189
2133
class Cached_item :public Sql_alloc
2190
2134
{
2191
2135
public:
2192
 
  bool null_value;
 
2136
  my_bool null_value;
2193
2137
  Cached_item() :null_value(0) {}
2194
2138
  virtual bool cmp(void)=0;
2195
2139
  virtual ~Cached_item(); /*line -e1509 */
2218
2162
class Cached_item_int :public Cached_item
2219
2163
{
2220
2164
  Item *item;
2221
 
  int64_t value;
 
2165
  longlong value;
2222
2166
public:
2223
2167
  Cached_item_int(Item *item_par) :item(item_par),value(0) {}
2224
2168
  bool cmp(void);
2236
2180
 
2237
2181
class Cached_item_field :public Cached_item
2238
2182
{
2239
 
  unsigned char *buff;
 
2183
  uchar *buff;
2240
2184
  Field *field;
2241
 
  uint32_t length;
 
2185
  uint length;
2242
2186
 
2243
2187
public:
 
2188
#ifndef DBUG_OFF
 
2189
  void dbug_print()
 
2190
  {
 
2191
    uchar *org_ptr;
 
2192
    org_ptr= field->ptr;
 
2193
    fprintf(DBUG_FILE, "new: ");
 
2194
    field->dbug_print();
 
2195
    field->ptr= buff;
 
2196
    fprintf(DBUG_FILE, ", old: ");
 
2197
    field->dbug_print();
 
2198
    field->ptr= org_ptr;
 
2199
    fprintf(DBUG_FILE, "\n");
 
2200
  }
 
2201
#endif
2244
2202
  Cached_item_field(Field *arg_field) : field(arg_field)
2245
2203
  {
2246
2204
    field= arg_field;
2247
2205
    /* TODO: take the memory allocation below out of the constructor. */
2248
 
    buff= (unsigned char*) sql_calloc(length=field->pack_length());
 
2206
    buff= (uchar*) sql_calloc(length=field->pack_length());
2249
2207
  }
2250
2208
  bool cmp(void);
2251
2209
};
2269
2227
  int save_in_field(Field *field_arg, bool no_conversions);
2270
2228
  table_map used_tables() const { return (table_map)0L; }
2271
2229
 
2272
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
 
2230
  bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2273
2231
  {
2274
2232
    return arg->walk(processor, walk_subquery, args) ||
2275
2233
      (this->*processor)(args);
2276
2234
  }
2277
2235
 
2278
 
  Item *transform(Item_transformer transformer, unsigned char *args);
 
2236
  Item *transform(Item_transformer transformer, uchar *args);
2279
2237
};
2280
2238
 
2281
2239
/*
2309
2267
  */
2310
2268
  table_map used_tables() const { return RAND_TABLE_BIT; }
2311
2269
 
2312
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
 
2270
  bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2313
2271
  {
2314
2272
    return arg->walk(processor, walk_subquery, args) ||
2315
2273
            (this->*processor)(args);
2316
2274
  }
2317
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
2318
 
  { return true; }
2319
2275
};
2320
2276
 
2321
2277
 
2334
2290
  enum enum_field_types cached_field_type;
2335
2291
public:
2336
2292
  Item_cache(): 
2337
 
    example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR) 
 
2293
    example(0), used_table_map(0), cached_field(0), cached_field_type(MYSQL_TYPE_STRING) 
2338
2294
  {
2339
2295
    fixed= 1; 
2340
2296
    null_value= 1;
2348
2304
 
2349
2305
  void set_used_tables(table_map map) { used_table_map= map; }
2350
2306
 
2351
 
  virtual bool allocate(uint32_t i __attribute__((unused)))
2352
 
  { return 0; }
 
2307
  virtual bool allocate(uint i) { return 0; }
2353
2308
  virtual bool setup(Item *item)
2354
2309
  {
2355
2310
    example= item;
2370
2325
  virtual void print(String *str, enum_query_type query_type);
2371
2326
  bool eq_def(Field *field) 
2372
2327
  { 
2373
 
    return cached_field ? cached_field->eq_def (field) : false;
 
2328
    return cached_field ? cached_field->eq_def (field) : FALSE;
2374
2329
  }
2375
 
  bool eq(const Item *item,
2376
 
          bool binary_cmp __attribute__((unused))) const
 
2330
  bool eq(const Item *item, bool binary_cmp) const
2377
2331
  {
2378
2332
    return this == item;
2379
2333
  }
2383
2337
class Item_cache_int: public Item_cache
2384
2338
{
2385
2339
protected:
2386
 
  int64_t value;
 
2340
  longlong value;
2387
2341
public:
2388
2342
  Item_cache_int(): Item_cache(), value(0) {}
2389
2343
  Item_cache_int(enum_field_types field_type_arg):
2390
2344
    Item_cache(field_type_arg), value(0) {}
2391
2345
 
2392
2346
  void store(Item *item);
2393
 
  void store(Item *item, int64_t val_arg);
2394
 
  double val_real() { assert(fixed == 1); return (double) value; }
2395
 
  int64_t val_int() { assert(fixed == 1); return value; }
 
2347
  void store(Item *item, longlong val_arg);
 
2348
  double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
 
2349
  longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
2396
2350
  String* val_str(String *str);
2397
2351
  my_decimal *val_decimal(my_decimal *);
2398
2352
  enum Item_result result_type() const { return INT_RESULT; }
2399
 
  bool result_as_int64_t() { return true; }
 
2353
  bool result_as_longlong() { return TRUE; }
2400
2354
};
2401
2355
 
2402
2356
 
2407
2361
  Item_cache_real(): Item_cache(), value(0) {}
2408
2362
 
2409
2363
  void store(Item *item);
2410
 
  double val_real() { assert(fixed == 1); return value; }
2411
 
  int64_t val_int();
 
2364
  double val_real() { DBUG_ASSERT(fixed == 1); return value; }
 
2365
  longlong val_int();
2412
2366
  String* val_str(String *str);
2413
2367
  my_decimal *val_decimal(my_decimal *);
2414
2368
  enum Item_result result_type() const { return REAL_RESULT; }
2424
2378
 
2425
2379
  void store(Item *item);
2426
2380
  double val_real();
2427
 
  int64_t val_int();
 
2381
  longlong val_int();
2428
2382
  String* val_str(String *str);
2429
2383
  my_decimal *val_decimal(my_decimal *);
2430
2384
  enum Item_result result_type() const { return DECIMAL_RESULT; }
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);
2449
2403
  double val_real();
2450
 
  int64_t val_int();
2451
 
  String* val_str(String *) { assert(fixed == 1); return value; }
 
2404
  longlong val_int();
 
2405
  String* val_str(String *) { DBUG_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))
2485
2439
    illegal_method_call((const char*)"val");
2486
2440
    return 0;
2487
2441
  };
2488
 
  int64_t val_int()
 
2442
  longlong val_int()
2489
2443
  {
2490
2444
    illegal_method_call((const char*)"val_int");
2491
2445
    return 0;
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)
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; }
2513
2467
  void cleanup()
2514
2468
  {
 
2469
    DBUG_ENTER("Item_cache_row::cleanup");
2515
2470
    Item_cache::cleanup();
2516
2471
    if (save_array)
2517
 
      memset(values, 0, item_count*sizeof(Item**));
 
2472
      bzero(values, item_count*sizeof(Item**));
2518
2473
    else
2519
2474
      values= 0;
2520
 
    return;
 
2475
    DBUG_VOID_RETURN;
2521
2476
  }
2522
2477
};
2523
2478
 
2546
2501
  enum_field_types field_type() const { return fld_type; };
2547
2502
  enum Type type() const { return TYPE_HOLDER; }
2548
2503
  double val_real();
2549
 
  int64_t val_int();
 
2504
  longlong val_int();
2550
2505
  my_decimal *val_decimal(my_decimal *);
2551
2506
  String *val_str(String*);
2552
2507
  bool join_types(THD *thd, Item *);
2553
 
  Field *make_field_by_type(Table *table);
2554
 
  static uint32_t display_length(Item *item);
 
2508
  Field *make_field_by_type(TABLE *table);
 
2509
  static uint32 display_length(Item *item);
2555
2510
  static enum_field_types get_real_type(Item *);
2556
2511
};
2557
2512
 
2565
2520
 
2566
2521
extern Cached_item *new_Cached_item(THD *thd, Item *item,
2567
2522
                                    bool use_result_field);
 
2523
extern Item_result item_cmp_type(Item_result a,Item_result b);
2568
2524
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
2569
2525
extern bool field_is_equal_to_item(Field *field,Item *item);
2570
 
 
2571
 
#endif