~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Stewart Smith
  • Date: 2011-03-29 01:30:47 UTC
  • mto: (2257.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: stewart@flamingspork.com-20110329013047-5ujzfx6pahmwuko2
have CachedDirectory print out a warning if we can't stat() something in a directory. We should always have access to at least stat() things in directories Drizzle is running in (otherwise there is likely a problem)

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