~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Monty Taylor
  • Date: 2010-12-26 03:00:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101226030037-2qcfxg5ryamekd56
Cleaned through ha0ha.

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