~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item.h

  • Committer: Monty Taylor
  • Date: 2008-07-05 17:07:46 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: monty@inaugust.com-20080705170746-8aq11u9fuwtfwy85
Removed my_alarm. Made my_lock only do the non-alarm version. Moved my_lock to MyISAM where it belongs.

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
  }
 
1149
#endif
 
1150
 
1199
1151
  friend class Item_default_value;
1200
1152
  friend class Item_insert_value;
1201
1153
  friend class st_select_lex_unit;
1206
1158
public:
1207
1159
  Item_null(char *name_par=0)
1208
1160
  {
1209
 
    maybe_null= null_value= true;
 
1161
    maybe_null= null_value= TRUE;
1210
1162
    max_length= 0;
1211
1163
    name= name_par ? name_par : (char*) "NULL";
1212
1164
    fixed= 1;
1215
1167
  enum Type type() const { return NULL_ITEM; }
1216
1168
  bool eq(const Item *item, bool binary_cmp) const;
1217
1169
  double val_real();
1218
 
  int64_t val_int();
 
1170
  longlong val_int();
1219
1171
  String *val_str(String *str);
1220
1172
  my_decimal *val_decimal(my_decimal *);
1221
1173
  int save_in_field(Field *field, bool no_conversions);
1222
1174
  int save_safe_in_field(Field *field);
1223
1175
  bool send(Protocol *protocol, String *str);
1224
1176
  enum Item_result result_type () const { return STRING_RESULT; }
1225
 
  enum_field_types field_type() const   { return DRIZZLE_TYPE_NULL; }
 
1177
  enum_field_types field_type() const   { return MYSQL_TYPE_NULL; }
1226
1178
  bool basic_const_item() const { return 1; }
1227
1179
  Item *clone_item() { return new Item_null(name); }
1228
1180
  bool is_null() { return 1; }
1229
1181
 
1230
 
  virtual inline void print(String *str,
1231
 
                            enum_query_type query_type __attribute__((unused)))
 
1182
  virtual inline void print(String *str, enum_query_type query_type)
1232
1183
  {
1233
1184
    str->append(STRING_WITH_LEN("NULL"));
1234
1185
  }
1235
1186
 
1236
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1237
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1238
 
  { return false; }
 
1187
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1239
1188
};
1240
1189
 
1241
1190
class Item_null_result :public Item_null
1248
1197
  {
1249
1198
    save_in_field(result_field, no_conversions);
1250
1199
  }
1251
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1252
 
  { return true; }
1253
1200
};  
1254
1201
 
1255
1202
/* Item represents one placeholder ('?') of prepared statement */
1282
1229
  my_decimal decimal_value;
1283
1230
  union
1284
1231
  {
1285
 
    int64_t integer;
 
1232
    longlong integer;
1286
1233
    double   real;
1287
1234
    /*
1288
1235
      Character sets conversion info for string values.
1292
1239
    */
1293
1240
    struct CONVERSION_INFO
1294
1241
    {
1295
 
      const CHARSET_INFO *character_set_client;
1296
 
      const CHARSET_INFO *character_set_of_placeholder;
 
1242
      CHARSET_INFO *character_set_client;
 
1243
      CHARSET_INFO *character_set_of_placeholder;
1297
1244
      /*
1298
1245
        This points at character set of connection if conversion
1299
1246
        to it is required (i. e. if placeholder typecode is not BLOB).
1300
1247
        Otherwise it's equal to character_set_client (to simplify
1301
1248
        check in convert_str_value()).
1302
1249
      */
1303
 
      const CHARSET_INFO *final_character_set_of_str_value;
 
1250
      CHARSET_INFO *final_character_set_of_str_value;
1304
1251
    } cs_info;
1305
 
    DRIZZLE_TIME     time;
 
1252
    MYSQL_TIME     time;
1306
1253
  } value;
1307
1254
 
1308
1255
  /* Cached values for virtual methods to save us one switch.  */
1313
1260
    Used when this item is used in a temporary table.
1314
1261
    This is NOT placeholder metadata sent to client, as this value
1315
1262
    is assigned after sending metadata (in setup_one_conversion_function).
1316
 
    For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
 
1263
    For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
1317
1264
    in result set and placeholders metadata, no matter what type you will
1318
1265
    supply for this placeholder in mysql_stmt_execute.
1319
1266
  */
1322
1269
    Offset of placeholder inside statement text. Used to create
1323
1270
    no-placeholders version of this statement for the binary log.
1324
1271
  */
1325
 
  uint32_t pos_in_query;
 
1272
  uint pos_in_query;
1326
1273
 
1327
 
  Item_param(uint32_t pos_in_query_arg);
 
1274
  Item_param(uint pos_in_query_arg);
1328
1275
 
1329
1276
  enum Item_result result_type () const { return item_result_type; }
1330
1277
  enum Type type() const { return item_type; }
1331
1278
  enum_field_types field_type() const { return param_type; }
1332
1279
 
1333
1280
  double val_real();
1334
 
  int64_t val_int();
 
1281
  longlong val_int();
1335
1282
  my_decimal *val_decimal(my_decimal*);
1336
1283
  String *val_str(String*);
1337
 
  bool get_time(DRIZZLE_TIME *tm);
1338
 
  bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
 
1284
  bool get_time(MYSQL_TIME *tm);
 
1285
  bool get_date(MYSQL_TIME *tm, uint fuzzydate);
1339
1286
  int  save_in_field(Field *field, bool no_conversions);
1340
1287
 
1341
1288
  void set_null();
1342
 
  void set_int(int64_t i, uint32_t max_length_arg);
 
1289
  void set_int(longlong i, uint32 max_length_arg);
1343
1290
  void set_double(double i);
1344
 
  void set_decimal(char *str, ulong length);
 
1291
  void set_decimal(const char *str, ulong length);
1345
1292
  bool set_str(const char *str, ulong length);
1346
1293
  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);
 
1294
  void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
1349
1295
  bool set_from_user_var(THD *thd, const user_var_entry *entry);
1350
1296
  void reset();
1351
1297
  /*
1354
1300
    don't need to check that packet is not broken there). See
1355
1301
    sql_prepare.cc for details.
1356
1302
  */
1357
 
  void (*set_param_func)(Item_param *param, unsigned char **pos, ulong len);
 
1303
  void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
1358
1304
 
1359
1305
  const String *query_val_str(String *str) const;
1360
1306
 
1369
1315
  { return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
1370
1316
  virtual void print(String *str, enum_query_type query_type);
1371
1317
  bool is_null()
1372
 
  { assert(state != NO_VALUE); return state == NULL_VALUE; }
 
1318
  { DBUG_ASSERT(state != NO_VALUE); return state == NULL_VALUE; }
1373
1319
  bool basic_const_item() const;
1374
1320
  /*
1375
1321
    This method is used to make a copy of a basic constant item when
1379
1325
    words, avoid pointing at one item from two different nodes of the tree.
1380
1326
    Return a new basic constant item if parameter value is a basic
1381
1327
    constant, assert otherwise. This method is called only if
1382
 
    basic_const_item returned true.
 
1328
    basic_const_item returned TRUE.
1383
1329
  */
1384
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
1330
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1385
1331
  Item *clone_item();
1386
1332
  /*
1387
1333
    Implement by-value equality evaluation if parameter value
1388
1334
    is set and is a basic constant (integer, real or string).
1389
 
    Otherwise return false.
 
1335
    Otherwise return FALSE.
1390
1336
  */
1391
1337
  bool eq(const Item *item, bool binary_cmp) const;
1392
1338
  /** Item is a argument to a limit clause. */
1397
1343
class Item_int :public Item_num
1398
1344
{
1399
1345
public:
1400
 
  int64_t value;
1401
 
  Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS)
1402
 
    :value((int64_t) i)
 
1346
  longlong value;
 
1347
  Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
 
1348
    :value((longlong) i)
1403
1349
    { max_length=length; fixed= 1; }
1404
 
  Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
 
1350
  Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1405
1351
    :value(i)
1406
1352
    { max_length=length; fixed= 1; }
1407
 
  Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1408
 
    :value((int64_t)i)
 
1353
  Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
 
1354
    :value((longlong)i)
1409
1355
    { max_length=length; fixed= 1; unsigned_flag= 1; }
1410
 
  Item_int(const char *str_arg,int64_t i,uint32_t length) :value(i)
 
1356
  Item_int(const char *str_arg,longlong i,uint length) :value(i)
1411
1357
    { max_length=length; name=(char*) str_arg; fixed= 1; }
1412
 
  Item_int(const char *str_arg, uint32_t length=64);
 
1358
  Item_int(const char *str_arg, uint length=64);
1413
1359
  enum Type type() const { return INT_ITEM; }
1414
1360
  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; }
 
1361
  enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
 
1362
  longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
 
1363
  double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
1418
1364
  my_decimal *val_decimal(my_decimal *);
1419
1365
  String *val_str(String*);
1420
1366
  int save_in_field(Field *field, bool no_conversions);
1422
1368
  Item *clone_item() { return new Item_int(name,value,max_length); }
1423
1369
  virtual void print(String *str, enum_query_type query_type);
1424
1370
  Item_num *neg() { value= -value; return this; }
1425
 
  uint32_t decimal_precision() const
 
1371
  uint decimal_precision() const
1426
1372
  { return (uint)(max_length - test(value < 0)); }
1427
1373
  bool eq(const Item *, bool binary_cmp) const;
1428
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1429
 
  { return false; }
1430
1374
};
1431
1375
 
1432
1376
 
1433
1377
class Item_uint :public Item_int
1434
1378
{
1435
1379
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);
 
1380
  Item_uint(const char *str_arg, uint length);
 
1381
  Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {}
 
1382
  Item_uint(const char *str_arg, longlong i, uint length);
1439
1383
  double val_real()
1440
 
    { assert(fixed == 1); return uint64_t2double((uint64_t)value); }
 
1384
    { DBUG_ASSERT(fixed == 1); return ulonglong2double((ulonglong)value); }
1441
1385
  String *val_str(String*);
1442
1386
  Item *clone_item() { return new Item_uint(name, value, max_length); }
1443
1387
  int save_in_field(Field *field, bool no_conversions);
1444
1388
  virtual void print(String *str, enum_query_type query_type);
1445
1389
  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; }
 
1390
  uint decimal_precision() const { return max_length; }
1449
1391
};
1450
1392
 
1451
1393
 
1455
1397
protected:
1456
1398
  my_decimal decimal_value;
1457
1399
public:
1458
 
  Item_decimal(const char *str_arg, uint32_t length, const CHARSET_INFO * const charset);
 
1400
  Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset);
1459
1401
  Item_decimal(const char *str, const my_decimal *val_arg,
1460
 
               uint32_t decimal_par, uint32_t length);
 
1402
               uint decimal_par, uint length);
1461
1403
  Item_decimal(my_decimal *value_par);
1462
 
  Item_decimal(int64_t val, bool unsig);
 
1404
  Item_decimal(longlong val, bool unsig);
1463
1405
  Item_decimal(double val, int precision, int scale);
1464
 
  Item_decimal(const unsigned char *bin, int precision, int scale);
 
1406
  Item_decimal(const uchar *bin, int precision, int scale);
1465
1407
 
1466
1408
  enum Type type() const { return DECIMAL_ITEM; }
1467
1409
  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();
 
1410
  enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
 
1411
  longlong val_int();
1470
1412
  double val_real();
1471
1413
  String *val_str(String*);
1472
 
  my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
1473
 
  { return &decimal_value; }
 
1414
  my_decimal *val_decimal(my_decimal *val) { return &decimal_value; }
1474
1415
  int save_in_field(Field *field, bool no_conversions);
1475
1416
  bool basic_const_item() const { return 1; }
1476
1417
  Item *clone_item()
1484
1425
    unsigned_flag= !decimal_value.sign();
1485
1426
    return this;
1486
1427
  }
1487
 
  uint32_t decimal_precision() const { return decimal_value.precision(); }
 
1428
  uint decimal_precision() const { return decimal_value.precision(); }
1488
1429
  bool eq(const Item *, bool binary_cmp) const;
1489
1430
  void set_decimal_value(my_decimal *value_par);
1490
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1491
 
  { return false; }
1492
1431
};
1493
1432
 
1494
1433
 
1498
1437
public:
1499
1438
  double value;
1500
1439
  // 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)
 
1440
  Item_float(const char *str_arg, uint length);
 
1441
  Item_float(const char *str,double val_arg,uint decimal_par,uint length)
1503
1442
    :value(val_arg)
1504
1443
  {
1505
1444
    presentation= name=(char*) str;
1506
 
    decimals=(uint8_t) decimal_par;
 
1445
    decimals=(uint8) decimal_par;
1507
1446
    max_length=length;
1508
1447
    fixed= 1;
1509
1448
  }
1510
 
  Item_float(double value_par, uint32_t decimal_par) :presentation(0), value(value_par)
 
1449
  Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1511
1450
  {
1512
 
    decimals= (uint8_t) decimal_par;
 
1451
    decimals= (uint8) decimal_par;
1513
1452
    fixed= 1;
1514
1453
  }
1515
1454
  int save_in_field(Field *field, bool no_conversions);
1516
1455
  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()
 
1456
  enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
 
1457
  double val_real() { DBUG_ASSERT(fixed == 1); return value; }
 
1458
  longlong val_int()
1520
1459
  {
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);
 
1460
    DBUG_ASSERT(fixed == 1);
 
1461
    if (value <= (double) LONGLONG_MIN)
 
1462
    {
 
1463
       return LONGLONG_MIN;
 
1464
    }
 
1465
    else if (value >= (double) (ulonglong) LONGLONG_MAX)
 
1466
    {
 
1467
      return LONGLONG_MAX;
 
1468
    }
 
1469
    return (longlong) rint(value);
1531
1470
  }
1532
1471
  String *val_str(String*);
1533
1472
  my_decimal *val_decimal(my_decimal *);
1544
1483
{
1545
1484
  const char *func_name;
1546
1485
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)
 
1486
  Item_static_float_func(const char *str, double val_arg, uint decimal_par,
 
1487
                        uint length)
 
1488
    :Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1550
1489
  {}
1551
1490
 
1552
 
  virtual inline void print(String *str,
1553
 
                            enum_query_type query_type __attribute__((unused)))
 
1491
  virtual inline void print(String *str, enum_query_type query_type)
1554
1492
  {
1555
1493
    str->append(func_name);
1556
1494
  }
1557
1495
 
1558
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1559
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1560
 
  { return false; }
 
1496
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1561
1497
};
1562
1498
 
1563
1499
 
1564
1500
class Item_string :public Item_basic_constant
1565
1501
{
1566
1502
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)
 
1503
  Item_string(const char *str,uint length,
 
1504
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
 
1505
              uint repertoire= MY_REPERTOIRE_UNICODE30)
 
1506
    : m_cs_specified(FALSE)
1571
1507
  {
1572
1508
    str_value.set_or_copy_aligned(str, length, cs);
1573
1509
    collation.set(cs, dv, repertoire);
1585
1521
    fixed= 1;
1586
1522
  }
1587
1523
  /* 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)
 
1524
  Item_string(CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
 
1525
    : m_cs_specified(FALSE)
1590
1526
  {
1591
1527
    collation.set(cs, dv);
1592
1528
    max_length= 0;
1594
1530
    decimals= NOT_FIXED_DEC;
1595
1531
    fixed= 1;
1596
1532
  }
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)
 
1533
  Item_string(const char *name_par, const char *str, uint length,
 
1534
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
 
1535
              uint repertoire= MY_REPERTOIRE_UNICODE30)
 
1536
    : m_cs_specified(FALSE)
1601
1537
  {
1602
1538
    str_value.set_or_copy_aligned(str, length, cs);
1603
1539
    collation.set(cs, dv, repertoire);
1611
1547
    This is used in stored procedures to avoid memory leaks and
1612
1548
    does a deep copy of its argument.
1613
1549
  */
1614
 
  void set_str_with_copy(const char *str_arg, uint32_t length_arg)
 
1550
  void set_str_with_copy(const char *str_arg, uint length_arg)
1615
1551
  {
1616
1552
    str_value.copy(str_arg, length_arg, collation.collation);
1617
1553
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
1624
1560
  }
1625
1561
  enum Type type() const { return STRING_ITEM; }
1626
1562
  double val_real();
1627
 
  int64_t val_int();
 
1563
  longlong val_int();
1628
1564
  String *val_str(String*)
1629
1565
  {
1630
 
    assert(fixed == 1);
 
1566
    DBUG_ASSERT(fixed == 1);
1631
1567
    return (String*) &str_value;
1632
1568
  }
1633
1569
  my_decimal *val_decimal(my_decimal *);
1634
1570
  int save_in_field(Field *field, bool no_conversions);
1635
1571
  enum Item_result result_type () const { return STRING_RESULT; }
1636
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
 
1572
  enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1637
1573
  bool basic_const_item() const { return 1; }
1638
1574
  bool eq(const Item *item, bool binary_cmp) const;
1639
1575
  Item *clone_item() 
1641
1577
    return new Item_string(name, str_value.ptr(), 
1642
1578
                           str_value.length(), collation.collation);
1643
1579
  }
1644
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1645
 
  inline void append(char *str, uint32_t length)
 
1580
  Item *safe_charset_converter(CHARSET_INFO *tocs);
 
1581
  inline void append(char *str, uint length)
1646
1582
  {
1647
1583
    str_value.append(str, length);
1648
1584
    max_length= str_value.numchars() * collation.collation->mbmaxlen;
1650
1586
  virtual void print(String *str, enum_query_type query_type);
1651
1587
 
1652
1588
  /**
1653
 
    Return true if character-set-introducer was explicitly specified in the
 
1589
    Return TRUE if character-set-introducer was explicitly specified in the
1654
1590
    original query for this item (text literal).
1655
1591
 
1656
1592
    This operation is to be called from Item_string::print(). The idea is
1664
1600
    one day when we start using original query as a view definition.
1665
1601
 
1666
1602
    @return This operation returns the value of m_cs_specified attribute.
1667
 
      @retval true if character set introducer was explicitly specified in
 
1603
      @retval TRUE if character set introducer was explicitly specified in
1668
1604
      the original query.
1669
 
      @retval false otherwise.
 
1605
      @retval FALSE otherwise.
1670
1606
  */
1671
1607
  inline bool is_cs_specified() const
1672
1608
  {
1687
1623
  {
1688
1624
    m_cs_specified= cs_specified;
1689
1625
  }
1690
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1691
 
  { return false; }
1692
1626
 
1693
1627
private:
1694
1628
  bool m_cs_specified;
1699
1633
{
1700
1634
  const char *func_name;
1701
1635
public:
1702
 
  Item_static_string_func(const char *name_par, const char *str, uint32_t length,
1703
 
                          const CHARSET_INFO * const cs,
 
1636
  Item_static_string_func(const char *name_par, const char *str, uint length,
 
1637
                          CHARSET_INFO *cs,
1704
1638
                          Derivation dv= DERIVATION_COERCIBLE)
1705
 
    :Item_string(NULL, str, length, cs, dv), func_name(name_par)
 
1639
    :Item_string(NullS, str, length, cs, dv), func_name(name_par)
1706
1640
  {}
1707
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
1641
  Item *safe_charset_converter(CHARSET_INFO *tocs);
1708
1642
 
1709
 
  virtual inline void print(String *str,
1710
 
                            enum_query_type query_type __attribute__((unused)))
 
1643
  virtual inline void print(String *str, enum_query_type query_type)
1711
1644
  {
1712
1645
    str->append(func_name);
1713
1646
  }
1714
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1715
 
  { return true; }
1716
1647
};
1717
1648
 
1718
1649
 
1732
1663
class Item_blob :public Item_string
1733
1664
{
1734
1665
public:
1735
 
  Item_blob(const char *name, uint32_t length) :
 
1666
  Item_blob(const char *name, uint length) :
1736
1667
    Item_string(name, length, &my_charset_bin)
1737
1668
  { max_length= length; }
1738
1669
  enum Type type() const { return TYPE_HOLDER; }
1739
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
 
1670
  enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
1740
1671
};
1741
1672
 
1742
1673
 
1749
1680
class Item_empty_string :public Item_string
1750
1681
{
1751
1682
public:
1752
 
  Item_empty_string(const char *header,uint32_t length, const CHARSET_INFO * cs= NULL) :
 
1683
  Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) :
1753
1684
    Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1754
1685
    { name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1755
1686
  void make_field(Send_field *field);
1760
1691
{
1761
1692
  enum_field_types int_field_type;
1762
1693
public:
1763
 
  Item_return_int(const char *name_arg, uint32_t length,
1764
 
                  enum_field_types field_type_arg, int64_t value= 0)
 
1694
  Item_return_int(const char *name_arg, uint length,
 
1695
                  enum_field_types field_type_arg, longlong value= 0)
1765
1696
    :Item_int(name_arg, value, length), int_field_type(field_type_arg)
1766
1697
  {
1767
1698
    unsigned_flag=1;
1774
1705
{
1775
1706
public:
1776
1707
  Item_hex_string() {}
1777
 
  Item_hex_string(const char *str,uint32_t str_length);
 
1708
  Item_hex_string(const char *str,uint str_length);
1778
1709
  enum Type type() const { return VARBIN_ITEM; }
1779
1710
  double val_real()
1780
1711
  { 
1781
 
    assert(fixed == 1); 
1782
 
    return (double) (uint64_t) Item_hex_string::val_int();
 
1712
    DBUG_ASSERT(fixed == 1); 
 
1713
    return (double) (ulonglong) Item_hex_string::val_int();
1783
1714
  }
1784
 
  int64_t val_int();
 
1715
  longlong val_int();
1785
1716
  bool basic_const_item() const { return 1; }
1786
 
  String *val_str(String*) { assert(fixed == 1); return &str_value; }
 
1717
  String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; }
1787
1718
  my_decimal *val_decimal(my_decimal *);
1788
1719
  int save_in_field(Field *field, bool no_conversions);
1789
1720
  enum Item_result result_type () const { return STRING_RESULT; }
1790
1721
  enum Item_result cast_to_int_type() const { return INT_RESULT; }
1791
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
 
1722
  enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1792
1723
  virtual void print(String *str, enum_query_type query_type);
1793
1724
  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; }
 
1725
  virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
1797
1726
};
1798
1727
 
1799
1728
 
1800
1729
class Item_bin_string: public Item_hex_string
1801
1730
{
1802
1731
public:
1803
 
  Item_bin_string(const char *str,uint32_t str_length);
 
1732
  Item_bin_string(const char *str,uint str_length);
1804
1733
};
1805
1734
 
1806
1735
class Item_result_field :public Item    /* Item with result field */
1814
1743
  {}
1815
1744
  ~Item_result_field() {}                       /* Required with gcc 2.95 */
1816
1745
  Field *get_tmp_table_field() { return result_field; }
1817
 
  Field *tmp_table_field(Table *t_arg __attribute__((unused)))
1818
 
  { return result_field; }
 
1746
  Field *tmp_table_field(TABLE *t_arg) { return result_field; }
1819
1747
  table_map used_tables() const { return 1; }
1820
1748
  virtual void fix_length_and_dec()=0;
1821
1749
  void set_result_field(Field *field) { result_field= field; }
1825
1753
    save_in_field(result_field, no_conversions);
1826
1754
  }
1827
1755
  void cleanup();
1828
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1829
 
  { return false; }
1830
1756
};
1831
1757
 
1832
1758
 
1859
1785
  */
1860
1786
  Item_ref(Name_resolution_context *context_arg, Item **item,
1861
1787
           const char *table_name_arg, const char *field_name_arg,
1862
 
           bool alias_name_used_arg= false);
 
1788
           bool alias_name_used_arg= FALSE);
1863
1789
 
1864
1790
  /* Constructor need to process subselect with temporary tables (see Item) */
1865
1791
  Item_ref(THD *thd, Item_ref *item)
1871
1797
    return ref && (*ref)->eq(it, binary_cmp);
1872
1798
  }
1873
1799
  double val_real();
1874
 
  int64_t val_int();
 
1800
  longlong val_int();
1875
1801
  my_decimal *val_decimal(my_decimal *);
1876
1802
  bool val_bool();
1877
1803
  String *val_str(String* tmp);
1878
1804
  bool is_null();
1879
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
1805
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1880
1806
  double val_result();
1881
 
  int64_t val_int_result();
 
1807
  longlong val_int_result();
1882
1808
  String *str_result(String* tmp);
1883
1809
  my_decimal *val_decimal_result(my_decimal *);
1884
1810
  bool val_bool_result();
1913
1839
  {
1914
1840
    return ref ? (*ref)->real_item() : this;
1915
1841
  }
1916
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
 
1842
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1917
1843
  { return (*ref)->walk(processor, walk_subquery, arg); }
1918
1844
  virtual void print(String *str, enum_query_type query_type);
1919
 
  bool result_as_int64_t()
 
1845
  bool result_as_longlong()
1920
1846
  {
1921
 
    return (*ref)->result_as_int64_t();
 
1847
    return (*ref)->result_as_longlong();
1922
1848
  }
1923
1849
  void cleanup();
1924
1850
  Item_field *filed_for_view_update()
1926
1852
  virtual Ref_Type ref_type() { return REF; }
1927
1853
 
1928
1854
  // Row emulation: forwarding of ROW-related calls to ref
1929
 
  uint32_t cols()
 
1855
  uint cols()
1930
1856
  {
1931
1857
    return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1932
1858
  }
1933
 
  Item* element_index(uint32_t i)
 
1859
  Item* element_index(uint i)
1934
1860
  {
1935
1861
    return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1936
1862
  }
1937
 
  Item** addr(uint32_t i)
 
1863
  Item** addr(uint i)
1938
1864
  {
1939
1865
    return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1940
1866
  }
1941
 
  bool check_cols(uint32_t c)
 
1867
  bool check_cols(uint c)
1942
1868
  {
1943
1869
    return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c) 
1944
1870
                                              : Item::check_cols(c);
1966
1892
  Item_direct_ref(Name_resolution_context *context_arg, Item **item,
1967
1893
                  const char *table_name_arg,
1968
1894
                  const char *field_name_arg,
1969
 
                  bool alias_name_used_arg= false)
 
1895
                  bool alias_name_used_arg= FALSE)
1970
1896
    :Item_ref(context_arg, item, table_name_arg,
1971
1897
              field_name_arg, alias_name_used_arg)
1972
1898
  {}
1974
1900
  Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
1975
1901
 
1976
1902
  double val_real();
1977
 
  int64_t val_int();
 
1903
  longlong val_int();
1978
1904
  String *val_str(String* tmp);
1979
1905
  my_decimal *val_decimal(my_decimal *);
1980
1906
  bool val_bool();
1981
1907
  bool is_null();
1982
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
1908
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1983
1909
  virtual Ref_Type ref_type() { return DIRECT_REF; }
1984
1910
};
1985
1911
 
2028
1954
  /* The aggregate function under which this outer ref is used, if any. */
2029
1955
  Item_sum *in_sum_func;
2030
1956
  /*
2031
 
    true <=> that the outer_ref is already present in the select list
 
1957
    TRUE <=> that the outer_ref is already present in the select list
2032
1958
    of the outer select.
2033
1959
  */
2034
1960
  bool found_in_select_list;
2050
1976
                     alias_name_used_arg),
2051
1977
    outer_ref(0), in_sum_func(0), found_in_select_list(1)
2052
1978
  {}
2053
 
  void save_in_result_field(bool no_conversions __attribute__((unused)))
 
1979
  void save_in_result_field(bool no_conversions)
2054
1980
  {
2055
1981
    outer_ref->save_org_in_field(result_field);
2056
1982
  }
2070
1996
/*
2071
1997
  An object of this class:
2072
1998
   - 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
 
1999
   - Sets owner->was_null=TRUE if it has returned a NULL value from any
2074
2000
     val_XXX() function. This allows to inject an Item_ref_null_helper
2075
2001
     object into subquery and then check if the subquery has produced a row
2076
2002
     with NULL value.
2087
2013
    :Item_ref(context_arg, item, table_name_arg, field_name_arg),
2088
2014
     owner(master) {}
2089
2015
  double val_real();
2090
 
  int64_t val_int();
 
2016
  longlong val_int();
2091
2017
  String* val_str(String* s);
2092
2018
  my_decimal *val_decimal(my_decimal *);
2093
2019
  bool val_bool();
2094
 
  bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
 
2020
  bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
2095
2021
  virtual void print(String *str, enum_query_type query_type);
2096
2022
  /*
2097
2023
    we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2117
2043
{
2118
2044
  Item *ref;
2119
2045
public:
2120
 
  Item_int_with_ref(int64_t i, Item *ref_arg, bool unsigned_arg) :
 
2046
  Item_int_with_ref(longlong i, Item *ref_arg, my_bool unsigned_arg) :
2121
2047
    Item_int(i), ref(ref_arg)
2122
2048
  {
2123
2049
    unsigned_flag= unsigned_arg;
2130
2056
  virtual Item *real_item() { return ref; }
2131
2057
};
2132
2058
 
2133
 
#ifdef DRIZZLE_SERVER
 
2059
#ifdef MYSQL_SERVER
2134
2060
#include "item_sum.h"
2135
2061
#include "item_func.h"
2136
2062
#include "item_row.h"
2147
2073
  Item *item;
2148
2074
  Item_copy_string(Item *i) :item(i)
2149
2075
  {
2150
 
    null_value= maybe_null= item->maybe_null;
 
2076
    null_value=maybe_null=item->maybe_null;
2151
2077
    decimals=item->decimals;
2152
2078
    max_length=item->max_length;
2153
2079
    name=item->name;
2161
2087
    int err_not_used;
2162
2088
    char *end_not_used;
2163
2089
    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));
 
2090
            my_strntod(str_value.charset(), (char*) str_value.ptr(),
 
2091
                       str_value.length(), &end_not_used, &err_not_used));
2166
2092
  }
2167
 
  int64_t val_int()
 
2093
  longlong val_int()
2168
2094
  {
2169
2095
    int err;
2170
 
    return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
2171
 
                                        str_value.length(),10, (char**) 0,
2172
 
                                        &err);
 
2096
    return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
 
2097
                                            str_value.length(),10, (char**) 0,
 
2098
                                            &err); 
2173
2099
  }
2174
2100
  String *val_str(String*);
2175
2101
  my_decimal *val_decimal(my_decimal *);
2176
2102
  void make_field(Send_field *field) { item->make_field(field); }
2177
2103
  void copy();
2178
 
  int save_in_field(Field *field,
2179
 
                    bool no_conversions __attribute__((unused)))
 
2104
  int save_in_field(Field *field, bool no_conversions)
2180
2105
  {
2181
2106
    return save_str_value_in_field(field, &str_value);
2182
2107
  }
2189
2114
class Cached_item :public Sql_alloc
2190
2115
{
2191
2116
public:
2192
 
  bool null_value;
 
2117
  my_bool null_value;
2193
2118
  Cached_item() :null_value(0) {}
2194
2119
  virtual bool cmp(void)=0;
2195
2120
  virtual ~Cached_item(); /*line -e1509 */
2218
2143
class Cached_item_int :public Cached_item
2219
2144
{
2220
2145
  Item *item;
2221
 
  int64_t value;
 
2146
  longlong value;
2222
2147
public:
2223
2148
  Cached_item_int(Item *item_par) :item(item_par),value(0) {}
2224
2149
  bool cmp(void);
2236
2161
 
2237
2162
class Cached_item_field :public Cached_item
2238
2163
{
2239
 
  unsigned char *buff;
 
2164
  uchar *buff;
2240
2165
  Field *field;
2241
 
  uint32_t length;
 
2166
  uint length;
2242
2167
 
2243
2168
public:
 
2169
#ifndef DBUG_OFF
 
2170
  void dbug_print()
 
2171
  {
 
2172
    uchar *org_ptr;
 
2173
    org_ptr= field->ptr;
 
2174
    fprintf(DBUG_FILE, "new: ");
 
2175
    field->dbug_print();
 
2176
    field->ptr= buff;
 
2177
    fprintf(DBUG_FILE, ", old: ");
 
2178
    field->dbug_print();
 
2179
    field->ptr= org_ptr;
 
2180
    fprintf(DBUG_FILE, "\n");
 
2181
  }
 
2182
#endif
2244
2183
  Cached_item_field(Field *arg_field) : field(arg_field)
2245
2184
  {
2246
2185
    field= arg_field;
2247
2186
    /* TODO: take the memory allocation below out of the constructor. */
2248
 
    buff= (unsigned char*) sql_calloc(length=field->pack_length());
 
2187
    buff= (uchar*) sql_calloc(length=field->pack_length());
2249
2188
  }
2250
2189
  bool cmp(void);
2251
2190
};
2269
2208
  int save_in_field(Field *field_arg, bool no_conversions);
2270
2209
  table_map used_tables() const { return (table_map)0L; }
2271
2210
 
2272
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
 
2211
  bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2273
2212
  {
2274
2213
    return arg->walk(processor, walk_subquery, args) ||
2275
2214
      (this->*processor)(args);
2276
2215
  }
2277
2216
 
2278
 
  Item *transform(Item_transformer transformer, unsigned char *args);
 
2217
  Item *transform(Item_transformer transformer, uchar *args);
2279
2218
};
2280
2219
 
2281
2220
/*
2309
2248
  */
2310
2249
  table_map used_tables() const { return RAND_TABLE_BIT; }
2311
2250
 
2312
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
 
2251
  bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2313
2252
  {
2314
2253
    return arg->walk(processor, walk_subquery, args) ||
2315
2254
            (this->*processor)(args);
2316
2255
  }
2317
 
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
2318
 
  { return true; }
2319
2256
};
2320
2257
 
2321
2258
 
2334
2271
  enum enum_field_types cached_field_type;
2335
2272
public:
2336
2273
  Item_cache(): 
2337
 
    example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR) 
 
2274
    example(0), used_table_map(0), cached_field(0), cached_field_type(MYSQL_TYPE_STRING) 
2338
2275
  {
2339
2276
    fixed= 1; 
2340
2277
    null_value= 1;
2348
2285
 
2349
2286
  void set_used_tables(table_map map) { used_table_map= map; }
2350
2287
 
2351
 
  virtual bool allocate(uint32_t i __attribute__((unused)))
2352
 
  { return 0; }
 
2288
  virtual bool allocate(uint i) { return 0; }
2353
2289
  virtual bool setup(Item *item)
2354
2290
  {
2355
2291
    example= item;
2370
2306
  virtual void print(String *str, enum_query_type query_type);
2371
2307
  bool eq_def(Field *field) 
2372
2308
  { 
2373
 
    return cached_field ? cached_field->eq_def (field) : false;
 
2309
    return cached_field ? cached_field->eq_def (field) : FALSE;
2374
2310
  }
2375
 
  bool eq(const Item *item,
2376
 
          bool binary_cmp __attribute__((unused))) const
 
2311
  bool eq(const Item *item, bool binary_cmp) const
2377
2312
  {
2378
2313
    return this == item;
2379
2314
  }
2383
2318
class Item_cache_int: public Item_cache
2384
2319
{
2385
2320
protected:
2386
 
  int64_t value;
 
2321
  longlong value;
2387
2322
public:
2388
2323
  Item_cache_int(): Item_cache(), value(0) {}
2389
2324
  Item_cache_int(enum_field_types field_type_arg):
2390
2325
    Item_cache(field_type_arg), value(0) {}
2391
2326
 
2392
2327
  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; }
 
2328
  void store(Item *item, longlong val_arg);
 
2329
  double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
 
2330
  longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
2396
2331
  String* val_str(String *str);
2397
2332
  my_decimal *val_decimal(my_decimal *);
2398
2333
  enum Item_result result_type() const { return INT_RESULT; }
2399
 
  bool result_as_int64_t() { return true; }
 
2334
  bool result_as_longlong() { return TRUE; }
2400
2335
};
2401
2336
 
2402
2337
 
2407
2342
  Item_cache_real(): Item_cache(), value(0) {}
2408
2343
 
2409
2344
  void store(Item *item);
2410
 
  double val_real() { assert(fixed == 1); return value; }
2411
 
  int64_t val_int();
 
2345
  double val_real() { DBUG_ASSERT(fixed == 1); return value; }
 
2346
  longlong val_int();
2412
2347
  String* val_str(String *str);
2413
2348
  my_decimal *val_decimal(my_decimal *);
2414
2349
  enum Item_result result_type() const { return REAL_RESULT; }
2424
2359
 
2425
2360
  void store(Item *item);
2426
2361
  double val_real();
2427
 
  int64_t val_int();
 
2362
  longlong val_int();
2428
2363
  String* val_str(String *str);
2429
2364
  my_decimal *val_decimal(my_decimal *);
2430
2365
  enum Item_result result_type() const { return DECIMAL_RESULT; }
2442
2377
    Item_cache(), value(0),
2443
2378
    is_varbinary(item->type() == FIELD_ITEM &&
2444
2379
                 ((const Item_field *) item)->field->type() ==
2445
 
                   DRIZZLE_TYPE_VARCHAR &&
 
2380
                   MYSQL_TYPE_VARCHAR &&
2446
2381
                 !((const Item_field *) item)->field->has_charset())
2447
2382
  {}
2448
2383
  void store(Item *item);
2449
2384
  double val_real();
2450
 
  int64_t val_int();
2451
 
  String* val_str(String *) { assert(fixed == 1); return value; }
 
2385
  longlong val_int();
 
2386
  String* val_str(String *) { DBUG_ASSERT(fixed == 1); return value; }
2452
2387
  my_decimal *val_decimal(my_decimal *);
2453
2388
  enum Item_result result_type() const { return STRING_RESULT; }
2454
 
  const CHARSET_INFO *charset() const { return value->charset(); };
 
2389
  CHARSET_INFO *charset() const { return value->charset(); };
2455
2390
  int save_in_field(Field *field, bool no_conversions);
2456
2391
};
2457
2392
 
2458
2393
class Item_cache_row: public Item_cache
2459
2394
{
2460
2395
  Item_cache  **values;
2461
 
  uint32_t item_count;
 
2396
  uint item_count;
2462
2397
  bool save_array;
2463
2398
public:
2464
2399
  Item_cache_row()
2468
2403
    'allocate' used only in row transformer, to preallocate space for row 
2469
2404
    cache.
2470
2405
  */
2471
 
  bool allocate(uint32_t num);
 
2406
  bool allocate(uint num);
2472
2407
  /*
2473
2408
    'setup' is needed only by row => it not called by simple row subselect
2474
2409
    (only by IN subselect (in subselect optimizer))
2485
2420
    illegal_method_call((const char*)"val");
2486
2421
    return 0;
2487
2422
  };
2488
 
  int64_t val_int()
 
2423
  longlong val_int()
2489
2424
  {
2490
2425
    illegal_method_call((const char*)"val_int");
2491
2426
    return 0;
2495
2430
    illegal_method_call((const char*)"val_str");
2496
2431
    return 0;
2497
2432
  };
2498
 
  my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
 
2433
  my_decimal *val_decimal(my_decimal *val)
2499
2434
  {
2500
2435
    illegal_method_call((const char*)"val_decimal");
2501
2436
    return 0;
2503
2438
 
2504
2439
  enum Item_result result_type() const { return ROW_RESULT; }
2505
2440
  
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);
 
2441
  uint cols() { return item_count; }
 
2442
  Item *element_index(uint i) { return values[i]; }
 
2443
  Item **addr(uint i) { return (Item **) (values + i); }
 
2444
  bool check_cols(uint c);
2510
2445
  bool null_inside();
2511
2446
  void bring_value();
2512
2447
  void keep_array() { save_array= 1; }
2513
2448
  void cleanup()
2514
2449
  {
 
2450
    DBUG_ENTER("Item_cache_row::cleanup");
2515
2451
    Item_cache::cleanup();
2516
2452
    if (save_array)
2517
 
      memset(values, 0, item_count*sizeof(Item**));
 
2453
      bzero(values, item_count*sizeof(Item**));
2518
2454
    else
2519
2455
      values= 0;
2520
 
    return;
 
2456
    DBUG_VOID_RETURN;
2521
2457
  }
2522
2458
};
2523
2459
 
2546
2482
  enum_field_types field_type() const { return fld_type; };
2547
2483
  enum Type type() const { return TYPE_HOLDER; }
2548
2484
  double val_real();
2549
 
  int64_t val_int();
 
2485
  longlong val_int();
2550
2486
  my_decimal *val_decimal(my_decimal *);
2551
2487
  String *val_str(String*);
2552
2488
  bool join_types(THD *thd, Item *);
2553
 
  Field *make_field_by_type(Table *table);
2554
 
  static uint32_t display_length(Item *item);
 
2489
  Field *make_field_by_type(TABLE *table);
 
2490
  static uint32 display_length(Item *item);
2555
2491
  static enum_field_types get_real_type(Item *);
2556
2492
};
2557
2493
 
2565
2501
 
2566
2502
extern Cached_item *new_Cached_item(THD *thd, Item *item,
2567
2503
                                    bool use_result_field);
 
2504
extern Item_result item_cmp_type(Item_result a,Item_result b);
2568
2505
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
2569
2506
extern bool field_is_equal_to_item(Field *field,Item *item);
2570
 
 
2571
 
#endif