~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Monty Taylor
  • Date: 2011-03-10 18:09:05 UTC
  • mfrom: (2225.2.2 refactor)
  • mto: This revision was merged to the branch mainline in revision 2228.
  • Revision ID: mordred@inaugust.com-20110310180905-ttx05t7q7ff6nl7c
Merge Olad: Refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
 
20
 
 
21
 
20
22
#ifndef DRIZZLED_ITEM_H
21
23
#define DRIZZLED_ITEM_H
22
24
 
23
25
#include <drizzled/dtcollation.h>
24
 
#include <drizzled/drizzle_time.h>
25
 
#include <drizzled/decimal.h>
 
26
#include <drizzled/global_charset_info.h>
 
27
#include <drizzled/item_result.h>
 
28
#include <drizzled/memory/sql_alloc.h>
26
29
#include <drizzled/sql_list.h>
27
 
#include "drizzled/memory/sql_alloc.h"
28
 
#include <drizzled/table.h>
29
 
#include "drizzled/item_result.h"
 
30
#include <drizzled/sql_string.h>
 
31
 
 
32
#include <drizzled/visibility.h>
30
33
 
31
34
namespace drizzled
32
35
{
33
36
 
34
 
class TableList;
 
37
class Field;
 
38
class Item_equal;
35
39
class Item_field;
36
 
class Name_resolution_context;
 
40
class Item_ident;
 
41
class Item_in_subselect;
 
42
class Item_sum;
37
43
class Select_Lex;
38
 
class Item_equal;
 
44
class SendField;
 
45
class Table;
39
46
class user_var_entry;
40
 
class Item_sum;
41
 
class Item_in_subselect;
42
 
class SendField;
43
 
class Field;
44
47
 
45
 
namespace plugin
46
 
{
47
 
class Client;
48
 
}
 
48
namespace plugin { class Client; }
 
49
namespace type { class Time; }
 
50
namespace type { class Decimal; }
49
51
 
50
52
/**
51
53
  Dummy error processor used by default by Name_resolution_context.
76
78
 * statement "tree" or Lex.  Each item represents something in the
77
79
 * execution plan.
78
80
 */
79
 
class Item: public memory::SqlAlloc
 
81
class DRIZZLED_API Item : public memory::SqlAlloc
80
82
{
81
83
  /* Prevent use of these */
82
84
  Item(const Item &);
111
113
    ROW_ITEM, CACHE_ITEM,
112
114
    TYPE_HOLDER,
113
115
    PARAM_ITEM,
 
116
    BOOLEAN_ITEM,
114
117
    DECIMAL_ITEM
115
118
  };
116
119
  enum traverse_order
134
137
 
135
138
  /** Name from select */
136
139
  char *name;
 
140
 
137
141
  /** Length of name */
138
142
  uint32_t name_length;
139
143
 
148
152
  bool maybe_null; /**< True if item may be null */
149
153
  bool null_value; /**< True if item is null */
150
154
  bool unsigned_flag;
 
155
 
 
156
  bool is_unsigned() const
 
157
  {
 
158
    return unsigned_flag;
 
159
  }
 
160
 
 
161
  virtual bool negative() const
 
162
  {
 
163
    return false;
 
164
  }
 
165
 
151
166
  bool with_sum_func;
152
167
  bool is_autogenerated_name; /**< indicates whether name of this Item was autogenerated or set by user */
 
168
 
153
169
  /**
154
170
   * If this item is a subselect or some of its arguments is or contains a
155
171
   * subselect. Computed by fix_fields.
157
173
  bool with_subselect;
158
174
  DTCollation collation;
159
175
  Item_result cmp_context; /**< Comparison context */
 
176
 
160
177
  /**
161
178
   * Constructor
162
179
   *
165
182
   * Alloc & destruct is done as start of select using memory::sql_alloc
166
183
   */
167
184
  Item();
 
185
 
168
186
  /**
169
187
   * Constructor used by Item_field, Item_ref & aggregate (sum) functions.
170
188
   *
176
194
   * optimisation changes in prepared statements
177
195
   */
178
196
  Item(Session *session, Item *item);
 
197
 
179
198
  virtual ~Item()
180
199
  {
181
200
#ifdef EXTRA_DEBUG
182
 
    name=0;
 
201
    name= NULL;
183
202
#endif
184
203
  }
185
204
 
362
381
   *   If value is not null null_value flag will be reset to false.
363
382
   */
364
383
  virtual String *val_str(String *str)=0;
 
384
 
365
385
  /**
366
386
   * Return decimal representation of item with fixed point.
367
387
   *
375
395
   *
376
396
   * @retval
377
397
   *
378
 
   * Return pointer on my_decimal (it can be other then passed via argument)
 
398
   * Return pointer on type::Decimal (it can be other then passed via argument)
379
399
   * if value is not NULL (null_value flag will be reset to false).
380
400
   * In case of NULL value it return 0 pointer and set null_value flag
381
401
   * to true.
382
402
   */
383
 
  virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
 
403
  virtual type::Decimal *val_decimal(type::Decimal *decimal_buffer)= 0;
 
404
 
384
405
  /**
385
406
   * Return boolean value of item.
386
407
   *
390
411
   * true value is true (not equal to 0)
391
412
   */
392
413
  virtual bool val_bool();
 
414
 
393
415
  /* Helper functions, see item_sum.cc */
394
416
  String *val_string_from_real(String *str);
395
417
  String *val_string_from_int(String *str);
396
418
  String *val_string_from_decimal(String *str);
397
 
  my_decimal *val_decimal_from_real(my_decimal *decimal_value);
398
 
  my_decimal *val_decimal_from_int(my_decimal *decimal_value);
399
 
  my_decimal *val_decimal_from_string(my_decimal *decimal_value);
400
 
  my_decimal *val_decimal_from_date(my_decimal *decimal_value);
401
 
  my_decimal *val_decimal_from_time(my_decimal *decimal_value);
 
419
  type::Decimal *val_decimal_from_real(type::Decimal *decimal_value);
 
420
  type::Decimal *val_decimal_from_int(type::Decimal *decimal_value);
 
421
  type::Decimal *val_decimal_from_string(type::Decimal *decimal_value);
 
422
  type::Decimal *val_decimal_from_date(type::Decimal *decimal_value);
 
423
  type::Decimal *val_decimal_from_time(type::Decimal *decimal_value);
402
424
  int64_t val_int_from_decimal();
403
425
  double val_real_from_decimal();
404
426
 
405
 
  int save_time_in_field(Field *field);
406
 
  int save_date_in_field(Field *field);
 
427
  bool save_time_in_field(Field *field);
 
428
  bool save_date_in_field(Field *field);
 
429
 
407
430
  /**
408
431
   * Stores a string value in field directly
409
432
   *
449
472
  {
450
473
    return val_str(tmp);
451
474
  }
452
 
  virtual my_decimal *val_decimal_result(my_decimal *val)
 
475
  virtual type::Decimal *val_decimal_result(type::Decimal *val)
453
476
  {
454
477
    return val_decimal(val);
455
478
  }
526
549
 
527
550
    For more information about view definition query, INFORMATION_SCHEMA
528
551
    query and why they should be generated from the Item-tree, @see
529
 
    mysql_register_view().
 
552
    register_view().
530
553
  */
531
 
  virtual void print(String *str, enum_query_type query_type);
 
554
  virtual void print(String *str);
532
555
 
533
 
  void print_item_w_name(String *, enum_query_type query_type);
 
556
  void print_item_w_name(String *);
534
557
  virtual void update_used_tables() {}
535
558
  virtual void split_sum_func(Session *session, 
536
559
                              Item **ref_pointer_array,
560
583
                      bool skip_registered);
561
584
 
562
585
  /**
563
 
    Get the value of the function as a DRIZZLE_TIME structure.
 
586
    Get the value of the function as a type::Time structure.
564
587
    As a extra convenience the time structure is reset on error!
565
588
  */
566
 
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
589
  virtual bool get_date(type::Time &ltime, uint32_t fuzzydate);
567
590
  /**
568
591
    Get time of first argument.
569
592
 
570
593
    As a extra convenience the time structure is reset on error!
571
594
  */
572
 
  virtual bool get_time(DRIZZLE_TIME *ltime);
573
 
  virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
595
  virtual bool get_time(type::Time &ltime);
 
596
  virtual bool get_date_result(type::Time &ltime,uint32_t fuzzydate);
574
597
 
575
598
  /**
576
599
    The method allows to determine nullness of a complex expression
761
784
   *  false otherwise
762
785
   */
763
786
  bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs);
 
787
 
 
788
  inline uint32_t char_to_byte_length_safe(uint32_t char_length_arg, uint32_t mbmaxlen_arg)
 
789
  { 
 
790
    uint64_t tmp= ((uint64_t) char_length_arg) * mbmaxlen_arg;
 
791
    return (tmp > UINT32_MAX) ? (uint32_t) UINT32_MAX : (uint32_t) tmp;
 
792
  } 
 
793
 
 
794
  uint32_t max_char_length() const;
 
795
 
 
796
  void fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs);
 
797
  void fix_char_length(uint32_t max_char_length_arg);
 
798
  void fix_char_length_uint64_t(uint64_t max_char_length_arg);
 
799
  void fix_length_and_charset_datetime(uint32_t max_char_length_arg);
 
800
 
 
801
protected:
 
802
  Session &getSession()
 
803
  {
 
804
    return _session;
 
805
  }
 
806
 
 
807
private:
 
808
  Session &_session;
764
809
};
765
810
 
766
811
namespace display {