~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

Merge Stewart.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
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/my_time.h>
 
25
#include <drizzled/my_decimal.h>
 
26
#include <drizzled/sql_bitmap.h>
27
27
#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"
 
28
#include "drizzled/memory/sql_alloc.h"
 
29
#include <drizzled/table.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;
47
 
 
48
 
namespace plugin { class Client; }
49
 
namespace type { class Time; }
50
 
namespace type { class Decimal; }
 
43
class Field;
 
44
 
 
45
namespace plugin
 
46
{
 
47
class Client;
 
48
}
 
49
 
51
50
 
52
51
/**
53
52
  Dummy error processor used by default by Name_resolution_context.
78
77
 * statement "tree" or Lex.  Each item represents something in the
79
78
 * execution plan.
80
79
 */
81
 
class DRIZZLED_API Item : public memory::SqlAlloc
 
80
class Item: public memory::SqlAlloc
82
81
{
83
82
  /* Prevent use of these */
84
83
  Item(const Item &);
113
112
    ROW_ITEM, CACHE_ITEM,
114
113
    TYPE_HOLDER,
115
114
    PARAM_ITEM,
116
 
    BOOLEAN_ITEM,
117
115
    DECIMAL_ITEM
118
116
  };
119
117
  enum traverse_order
137
135
 
138
136
  /** Name from select */
139
137
  char *name;
140
 
 
141
138
  /** Length of name */
142
139
  uint32_t name_length;
143
140
 
152
149
  bool maybe_null; /**< True if item may be null */
153
150
  bool null_value; /**< True if item is null */
154
151
  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
152
  bool with_sum_func;
167
153
  bool is_autogenerated_name; /**< indicates whether name of this Item was autogenerated or set by user */
168
 
 
169
154
  /**
170
155
   * If this item is a subselect or some of its arguments is or contains a
171
156
   * subselect. Computed by fix_fields.
173
158
  bool with_subselect;
174
159
  DTCollation collation;
175
160
  Item_result cmp_context; /**< Comparison context */
176
 
 
177
161
  /**
178
162
   * Constructor
179
163
   *
182
166
   * Alloc & destruct is done as start of select using memory::sql_alloc
183
167
   */
184
168
  Item();
185
 
 
186
169
  /**
187
170
   * Constructor used by Item_field, Item_ref & aggregate (sum) functions.
188
171
   *
194
177
   * optimisation changes in prepared statements
195
178
   */
196
179
  Item(Session *session, Item *item);
197
 
 
198
180
  virtual ~Item()
199
181
  {
200
182
#ifdef EXTRA_DEBUG
201
 
    name= NULL;
 
183
    name=0;
202
184
#endif
203
185
  }
204
186
 
381
363
   *   If value is not null null_value flag will be reset to false.
382
364
   */
383
365
  virtual String *val_str(String *str)=0;
384
 
 
385
366
  /**
386
367
   * Return decimal representation of item with fixed point.
387
368
   *
395
376
   *
396
377
   * @retval
397
378
   *
398
 
   * Return pointer on type::Decimal (it can be other then passed via argument)
 
379
   * Return pointer on my_decimal (it can be other then passed via argument)
399
380
   * if value is not NULL (null_value flag will be reset to false).
400
381
   * In case of NULL value it return 0 pointer and set null_value flag
401
382
   * to true.
402
383
   */
403
 
  virtual type::Decimal *val_decimal(type::Decimal *decimal_buffer)= 0;
404
 
 
 
384
  virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
405
385
  /**
406
386
   * Return boolean value of item.
407
387
   *
411
391
   * true value is true (not equal to 0)
412
392
   */
413
393
  virtual bool val_bool();
414
 
 
415
394
  /* Helper functions, see item_sum.cc */
416
395
  String *val_string_from_real(String *str);
417
396
  String *val_string_from_int(String *str);
418
397
  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);
 
398
  my_decimal *val_decimal_from_real(my_decimal *decimal_value);
 
399
  my_decimal *val_decimal_from_int(my_decimal *decimal_value);
 
400
  my_decimal *val_decimal_from_string(my_decimal *decimal_value);
 
401
  my_decimal *val_decimal_from_date(my_decimal *decimal_value);
 
402
  my_decimal *val_decimal_from_time(my_decimal *decimal_value);
424
403
  int64_t val_int_from_decimal();
425
404
  double val_real_from_decimal();
426
405
 
427
 
  bool save_time_in_field(Field *field);
428
 
  bool save_date_in_field(Field *field);
429
 
 
 
406
  int save_time_in_field(Field *field);
 
407
  int save_date_in_field(Field *field);
430
408
  /**
431
409
   * Stores a string value in field directly
432
410
   *
472
450
  {
473
451
    return val_str(tmp);
474
452
  }
475
 
  virtual type::Decimal *val_decimal_result(type::Decimal *val)
 
453
  virtual my_decimal *val_decimal_result(my_decimal *val)
476
454
  {
477
455
    return val_decimal(val);
478
456
  }
549
527
 
550
528
    For more information about view definition query, INFORMATION_SCHEMA
551
529
    query and why they should be generated from the Item-tree, @see
552
 
    register_view().
 
530
    mysql_register_view().
553
531
  */
554
532
  virtual void print(String *str, enum_query_type query_type);
555
533
 
583
561
                      bool skip_registered);
584
562
 
585
563
  /**
586
 
    Get the value of the function as a type::Time structure.
 
564
    Get the value of the function as a DRIZZLE_TIME structure.
587
565
    As a extra convenience the time structure is reset on error!
588
566
  */
589
 
  virtual bool get_date(type::Time &ltime, uint32_t fuzzydate);
 
567
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
590
568
  /**
591
569
    Get time of first argument.
592
570
 
593
571
    As a extra convenience the time structure is reset on error!
594
572
  */
595
 
  virtual bool get_time(type::Time &ltime);
596
 
  virtual bool get_date_result(type::Time &ltime,uint32_t fuzzydate);
 
573
  virtual bool get_time(DRIZZLE_TIME *ltime);
 
574
  virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
597
575
 
598
576
  /**
599
577
    The method allows to determine nullness of a complex expression
754
732
   * cost Item::execution_cost(),
755
733
   * where 'cost' is either 'double' or some structure of various cost
756
734
   * parameters.
757
 
   *
758
 
   *NOTE
759
 
   *   This function is now used to prevent evaluation of materialized IN
760
 
   *   subquery predicates before it is allowed. grep for
761
 
   *   DontEvaluateMaterializedSubqueryTooEarly to see the uses.
762
735
   */
763
736
  virtual bool is_expensive();
764
737
 
784
757
   *  false otherwise
785
758
   */
786
759
  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
760
};
810
761
 
811
 
namespace display {
812
 
const std::string &type(Item::Type type);
813
 
} /* namespace display */
814
 
 
815
 
std::ostream& operator<<(std::ostream& output, const Item &item);
816
 
 
817
762
} /* namespace drizzled */
818
763
 
819
764
/** @TODO Why is this in the middle? */