~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Stewart Smith
  • Date: 2009-06-16 00:44:35 UTC
  • mto: (1119.2.6 merge)
  • mto: This revision was merged to the branch mainline in revision 1124.
  • Revision ID: stewart@flamingspork.com-20090616004435-t1vust6erhco7edc
make comment_index test not leave tables behind after running

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 <mysys/drizzle_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"
33
 
 
34
 
namespace drizzled
35
 
{
36
 
 
37
 
class Field;
 
28
#include <drizzled/sql_alloc.h>
 
29
#include <drizzled/table.h>
 
30
 
 
31
class TableList;
 
32
class Item_field;
 
33
class Name_resolution_context;
 
34
class Select_Lex;
38
35
class Item_equal;
39
 
class Item_field;
40
 
class Item_ident;
 
36
class user_var_entry;
 
37
class Item_sum;
41
38
class Item_in_subselect;
42
 
class Item_sum;
43
 
class Select_Lex;
44
39
class SendField;
45
 
class Table;
46
 
class user_var_entry;
 
40
class Field;
47
41
 
48
 
namespace plugin { class Client; }
49
 
namespace type { class Time; }
50
 
namespace type { class Decimal; }
 
42
namespace drizzled
 
43
{
 
44
namespace plugin
 
45
{
 
46
class Protocol;
 
47
}
 
48
}
51
49
 
52
50
/**
53
51
  Dummy error processor used by default by Name_resolution_context.
74
72
typedef bool (Item::*Item_processor) (unsigned char *arg);
75
73
 
76
74
/**
77
 
 * The Item class is the base class for all items in the parsed
 
75
 * The Item class is the base class for all items in the parsed 
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 Sql_alloc
82
80
{
83
81
  /* Prevent use of these */
84
82
  Item(const Item &);
90
88
 
91
89
public:
92
90
 
93
 
  enum Type
 
91
  enum Type 
94
92
  {
95
93
    FIELD_ITEM= 0,
96
94
    FUNC_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
120
 
  {
 
117
  { 
121
118
    T_POSTFIX,
122
119
    T_PREFIX
123
120
  };
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
 
   * subselect. Computed by fix_fields.
 
155
   * subselect. Computed by fix_fields. 
172
156
   */
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
   *
180
163
   * @note
181
164
   *
182
 
   * Alloc & destruct is done as start of select using memory::sql_alloc
 
165
   * Alloc & destruct is done as start of select using sql_alloc
183
166
   */
184
167
  Item();
185
 
 
186
168
  /**
187
169
   * Constructor used by Item_field, Item_ref & aggregate (sum) functions.
188
 
   *
 
170
   * 
189
171
   * Used for duplicating lists in processing queries with temporary
190
172
   * tables.
191
 
   *
 
173
   * 
192
174
   * Also it used for Item_cond_and/Item_cond_or for creating
193
175
   * top AND/OR structure of WHERE clause to protect it of
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
 
 
205
 
  void set_name(const std::string &arg)
206
 
  {
207
 
    set_name(arg.c_str(), arg.length(), system_charset_info);
208
 
  }
209
 
 
210
 
  void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs= system_charset_info);
 
185
  void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs);
211
186
  /**
212
187
   * Renames item (used for views, cleanup() return original name).
213
188
   *
237
212
 
238
213
  /**
239
214
   * Should be used in case where we are sure that we do not need
240
 
   * complete fix_fields() procedure.
 
215
   * complete fix_fields() procedure.  
241
216
   */
242
217
  inline void quick_fix_field()
243
218
  {
244
219
    fixed= true;
245
220
  }
246
221
 
 
222
  /**
 
223
   * Save value in field, but don't give any warnings.
 
224
   *
 
225
   * @note
 
226
   *
 
227
   * This is used to temporary store and retrieve a value in a column,
 
228
   * for example in opt_range to adjust the key value to fit the column.
 
229
   * Return: Function returns 1 on overflow and -1 on fatal errors
 
230
   */
 
231
  int save_in_field_no_warnings(Field *field, bool no_conversions);
 
232
 
247
233
  virtual int save_in_field(Field *field, bool no_conversions);
248
234
  virtual void save_org_in_field(Field *field)
249
235
  {
256
242
  /**
257
243
   * This is only called from items that is not of type item_field.
258
244
   */
259
 
  virtual bool send(plugin::Client *client, String *str);
 
245
  virtual bool send(drizzled::plugin::Protocol *protocol, String *str);
260
246
  /**
261
 
    Compares this Item to another Item, returning true if Item's
 
247
    Compares this Item to another Item, returning true if Item's 
262
248
    are functionally equal.
263
249
 
264
250
    @details
297
283
   *
298
284
   * This function is defined only for unary monotonic functions. The caller
299
285
   * supplies the source half-interval
300
 
   *
 
286
   * 
301
287
   * x $CMP$ const
302
288
   *
303
289
   * The value of const is supplied implicitly as the value this item's
304
290
   * argument, the form of $CMP$ comparison is specified through the
305
291
   * function's arguments. The calle returns the result interval
306
 
   *
 
292
   * 
307
293
   * F(x) $CMP2$ F(const)
308
294
   *
309
295
   * passing back F(const) as the return value, and the form of $CMP2$
332
318
   * Returns integer representation of item.
333
319
   *
334
320
   * @retval
335
 
   *
 
321
   * 
336
322
   * In case of NULL value return 0 and set null_value flag to true.
337
323
   * If value is not null null_value flag will be reset to false.
338
324
   */
381
367
   *   If value is not null null_value flag will be reset to false.
382
368
   */
383
369
  virtual String *val_str(String *str)=0;
384
 
 
385
370
  /**
386
371
   * Return decimal representation of item with fixed point.
387
372
   *
395
380
   *
396
381
   * @retval
397
382
   *
398
 
   * Return pointer on type::Decimal (it can be other then passed via argument)
 
383
   * Return pointer on my_decimal (it can be other then passed via argument)
399
384
   * if value is not NULL (null_value flag will be reset to false).
400
385
   * In case of NULL value it return 0 pointer and set null_value flag
401
386
   * to true.
402
387
   */
403
 
  virtual type::Decimal *val_decimal(type::Decimal *decimal_buffer)= 0;
404
 
 
 
388
  virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
405
389
  /**
406
390
   * Return boolean value of item.
407
391
   *
411
395
   * true value is true (not equal to 0)
412
396
   */
413
397
  virtual bool val_bool();
414
 
 
415
398
  /* Helper functions, see item_sum.cc */
416
399
  String *val_string_from_real(String *str);
417
400
  String *val_string_from_int(String *str);
418
401
  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);
 
402
  my_decimal *val_decimal_from_real(my_decimal *decimal_value);
 
403
  my_decimal *val_decimal_from_int(my_decimal *decimal_value);
 
404
  my_decimal *val_decimal_from_string(my_decimal *decimal_value);
 
405
  my_decimal *val_decimal_from_date(my_decimal *decimal_value);
 
406
  my_decimal *val_decimal_from_time(my_decimal *decimal_value);
424
407
  int64_t val_int_from_decimal();
425
408
  double val_real_from_decimal();
426
409
 
427
 
  bool save_time_in_field(Field *field);
428
 
  bool save_date_in_field(Field *field);
429
 
 
 
410
  int save_time_in_field(Field *field);
 
411
  int save_date_in_field(Field *field);
430
412
  /**
431
413
   * Stores a string value in field directly
432
414
   *
434
416
   *
435
417
   * The method is used by Item_*::save_in_field implementations
436
418
   * when we don't need to calculate the value to store
437
 
   *
 
419
   * 
438
420
   * @see Item_string::save_in_field() implementation for example
439
421
   *
440
422
   * @param Pointer to field where to store
472
454
  {
473
455
    return val_str(tmp);
474
456
  }
475
 
  virtual type::Decimal *val_decimal_result(type::Decimal *val)
 
457
  virtual my_decimal *val_decimal_result(my_decimal *val)
476
458
  {
477
459
    return val_decimal(val);
478
460
  }
519
501
  {
520
502
    return COND_OK;
521
503
  }
522
 
  uint32_t float_length(uint32_t decimals_par) const;
 
504
  inline uint32_t float_length(uint32_t decimals_par) const
 
505
  {
 
506
    return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;
 
507
  }
523
508
  virtual uint32_t decimal_precision() const;
524
509
  int decimal_int_part() const;
525
510
 
549
534
 
550
535
    For more information about view definition query, INFORMATION_SCHEMA
551
536
    query and why they should be generated from the Item-tree, @see
552
 
    register_view().
 
537
    mysql_register_view().
553
538
  */
554
539
  virtual void print(String *str, enum_query_type query_type);
555
540
 
583
568
                      bool skip_registered);
584
569
 
585
570
  /**
586
 
    Get the value of the function as a type::Time structure.
 
571
    Get the value of the function as a DRIZZLE_TIME structure.
587
572
    As a extra convenience the time structure is reset on error!
588
573
  */
589
 
  virtual bool get_date(type::Time &ltime, uint32_t fuzzydate);
 
574
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
590
575
  /**
591
576
    Get time of first argument.
592
577
 
593
578
    As a extra convenience the time structure is reset on error!
594
579
  */
595
 
  virtual bool get_time(type::Time &ltime);
596
 
  virtual bool get_date_result(type::Time &ltime,uint32_t fuzzydate);
 
580
  virtual bool get_time(DRIZZLE_TIME *ltime);
 
581
  virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
597
582
 
598
583
  /**
599
584
    The method allows to determine nullness of a complex expression
695
680
  virtual bool collect_item_field_processor(unsigned char * arg);
696
681
  virtual bool find_item_in_field_list_processor(unsigned char *arg);
697
682
  virtual bool change_context_processor(unsigned char *context);
 
683
  virtual bool reset_query_id_processor(unsigned char *query_id_arg);
698
684
  virtual bool register_field_in_read_map(unsigned char *arg);
699
685
  virtual bool subst_argument_checker(unsigned char **arg);
700
686
 
701
 
  virtual bool cache_const_expr_analyzer(unsigned char **arg);
702
 
  virtual Item* cache_const_expr_transformer(unsigned char *arg);
703
 
 
704
687
  virtual Item *equal_fields_propagator(unsigned char * arg);
705
688
  virtual bool set_no_const_sub(unsigned char *arg);
706
689
  virtual Item *replace_equal_field(unsigned char * arg);
727
710
      \#    Created field
728
711
  */
729
712
  Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
 
713
  virtual Item_field *filed_for_view_update();
730
714
 
731
715
  virtual Item *neg_transformer(Session *session);
732
716
  virtual Item *update_value_transformer(unsigned char *select_arg);
754
738
   * cost Item::execution_cost(),
755
739
   * where 'cost' is either 'double' or some structure of various cost
756
740
   * 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
741
   */
763
742
  virtual bool is_expensive();
764
743
 
784
763
   *  false otherwise
785
764
   */
786
765
  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
766
};
810
767
 
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
 
} /* namespace drizzled */
818
 
 
819
 
/** @TODO Why is this in the middle? */
820
768
#include <drizzled/item/ident.h>
821
769
 
822
 
namespace drizzled
823
 
{
824
 
 
825
770
/**
826
771
  Mark item and Select_Lexs as dependent if item was resolved in
827
772
  outer SELECT.
914
859
/**
915
860
  Create field for temporary table.
916
861
 
917
 
  @todo:
918
 
 
 
862
  @todo: 
 
863
  
919
864
   This is here for now because it needs the Item::Type. It should live
920
865
   in Field or Table once item.h is clean enough to actually include
921
866
 
945
890
    new_created field
946
891
*/
947
892
Field *create_tmp_field(Session *session,
948
 
                        Table *table,
 
893
                        Table *table, 
949
894
                        Item *item,
950
895
                        Item::Type type,
951
 
                        Item ***copy_func,
 
896
                        Item ***copy_func, 
952
897
                        Field **from_field,
953
898
                        Field **def_field,
954
 
                        bool group,
 
899
                        bool group, 
955
900
                        bool modify_item,
 
901
                        bool table_cant_handle_bit_fields,
956
902
                        bool make_copy_field,
957
903
                        uint32_t convert_blob_length);
958
904
 
959
 
} /* namespace drizzled */
960
 
 
961
905
#endif /* DRIZZLED_ITEM_H */