~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Barry.Leslie at PrimeBase
  • Date: 2011-01-22 03:22:44 UTC
  • mfrom: (2101 staging)
  • mto: (2228.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2230.
  • Revision ID: barry.leslie@primebase.com-20110122032244-ukbe3mlj7fs8xph6
Merged with lp:drizzle.

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
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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
21
21
#define DRIZZLED_ITEM_H
22
22
 
23
23
#include <drizzled/dtcollation.h>
24
 
#include <drizzled/drizzle_time.h>
25
 
#include <drizzled/decimal.h>
 
24
#include <drizzled/type/time.h>
 
25
#include <drizzled/type/decimal.h>
26
26
#include <drizzled/sql_list.h>
27
27
#include "drizzled/memory/sql_alloc.h"
28
28
#include <drizzled/table.h>
111
111
    ROW_ITEM, CACHE_ITEM,
112
112
    TYPE_HOLDER,
113
113
    PARAM_ITEM,
 
114
    BOOLEAN_ITEM,
114
115
    DECIMAL_ITEM
115
116
  };
116
117
  enum traverse_order
134
135
 
135
136
  /** Name from select */
136
137
  char *name;
 
138
 
137
139
  /** Length of name */
138
140
  uint32_t name_length;
139
141
 
148
150
  bool maybe_null; /**< True if item may be null */
149
151
  bool null_value; /**< True if item is null */
150
152
  bool unsigned_flag;
 
153
 
 
154
  bool is_unsigned() const
 
155
  {
 
156
    return unsigned_flag;
 
157
  }
 
158
 
 
159
  virtual bool negative() const
 
160
  {
 
161
    return false;
 
162
  }
 
163
 
151
164
  bool with_sum_func;
152
165
  bool is_autogenerated_name; /**< indicates whether name of this Item was autogenerated or set by user */
153
166
  /**
165
178
   * Alloc & destruct is done as start of select using memory::sql_alloc
166
179
   */
167
180
  Item();
 
181
 
168
182
  /**
169
183
   * Constructor used by Item_field, Item_ref & aggregate (sum) functions.
170
184
   *
179
193
  virtual ~Item()
180
194
  {
181
195
#ifdef EXTRA_DEBUG
182
 
    name=0;
 
196
    name= NULL;
183
197
#endif
184
198
  }
185
199
 
362
376
   *   If value is not null null_value flag will be reset to false.
363
377
   */
364
378
  virtual String *val_str(String *str)=0;
 
379
 
365
380
  /**
366
381
   * Return decimal representation of item with fixed point.
367
382
   *
375
390
   *
376
391
   * @retval
377
392
   *
378
 
   * Return pointer on my_decimal (it can be other then passed via argument)
 
393
   * Return pointer on type::Decimal (it can be other then passed via argument)
379
394
   * if value is not NULL (null_value flag will be reset to false).
380
395
   * In case of NULL value it return 0 pointer and set null_value flag
381
396
   * to true.
382
397
   */
383
 
  virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
 
398
  virtual type::Decimal *val_decimal(type::Decimal *decimal_buffer)= 0;
 
399
 
384
400
  /**
385
401
   * Return boolean value of item.
386
402
   *
390
406
   * true value is true (not equal to 0)
391
407
   */
392
408
  virtual bool val_bool();
 
409
 
393
410
  /* Helper functions, see item_sum.cc */
394
411
  String *val_string_from_real(String *str);
395
412
  String *val_string_from_int(String *str);
396
413
  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);
 
414
  type::Decimal *val_decimal_from_real(type::Decimal *decimal_value);
 
415
  type::Decimal *val_decimal_from_int(type::Decimal *decimal_value);
 
416
  type::Decimal *val_decimal_from_string(type::Decimal *decimal_value);
 
417
  type::Decimal *val_decimal_from_date(type::Decimal *decimal_value);
 
418
  type::Decimal *val_decimal_from_time(type::Decimal *decimal_value);
402
419
  int64_t val_int_from_decimal();
403
420
  double val_real_from_decimal();
404
421
 
449
466
  {
450
467
    return val_str(tmp);
451
468
  }
452
 
  virtual my_decimal *val_decimal_result(my_decimal *val)
 
469
  virtual type::Decimal *val_decimal_result(type::Decimal *val)
453
470
  {
454
471
    return val_decimal(val);
455
472
  }
526
543
 
527
544
    For more information about view definition query, INFORMATION_SCHEMA
528
545
    query and why they should be generated from the Item-tree, @see
529
 
    mysql_register_view().
 
546
    register_view().
530
547
  */
531
548
  virtual void print(String *str, enum_query_type query_type);
532
549
 
560
577
                      bool skip_registered);
561
578
 
562
579
  /**
563
 
    Get the value of the function as a DRIZZLE_TIME structure.
 
580
    Get the value of the function as a type::Time structure.
564
581
    As a extra convenience the time structure is reset on error!
565
582
  */
566
 
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
583
  virtual bool get_date(type::Time *ltime,uint32_t fuzzydate);
567
584
  /**
568
585
    Get time of first argument.
569
586
 
570
587
    As a extra convenience the time structure is reset on error!
571
588
  */
572
 
  virtual bool get_time(DRIZZLE_TIME *ltime);
573
 
  virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
589
  virtual bool get_time(type::Time *ltime);
 
590
  virtual bool get_date_result(type::Time *ltime,uint32_t fuzzydate);
574
591
 
575
592
  /**
576
593
    The method allows to determine nullness of a complex expression
761
778
   *  false otherwise
762
779
   */
763
780
  bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs);
 
781
 
 
782
  inline uint32_t char_to_byte_length_safe(uint32_t char_length_arg, uint32_t mbmaxlen_arg)
 
783
  { 
 
784
    uint64_t tmp= ((uint64_t) char_length_arg) * mbmaxlen_arg;
 
785
    return (tmp > UINT32_MAX) ? (uint32_t) UINT32_MAX : (uint32_t) tmp;
 
786
  } 
 
787
 
 
788
  uint32_t max_char_length() const
 
789
  {
 
790
    return max_length / collation.collation->mbmaxlen;
 
791
  }
 
792
 
 
793
  void fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs)
 
794
  { 
 
795
    max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen);
 
796
    collation.collation= cs;
 
797
  }
 
798
 
 
799
  void fix_char_length(uint32_t max_char_length_arg)
 
800
  { 
 
801
    max_length= char_to_byte_length_safe(max_char_length_arg,
 
802
                                         collation.collation->mbmaxlen);
 
803
  }
 
804
 
 
805
  void fix_char_length_uint64_t(uint64_t max_char_length_arg)
 
806
  { 
 
807
    uint64_t max_result_length= max_char_length_arg *
 
808
      collation.collation->mbmaxlen;
 
809
 
 
810
    if (max_result_length >= MAX_BLOB_WIDTH)
 
811
    { 
 
812
      max_length= MAX_BLOB_WIDTH;
 
813
      maybe_null= false;
 
814
    }
 
815
    else
 
816
    {
 
817
      max_length= max_result_length;
 
818
    }
 
819
  }
 
820
 
 
821
  void fix_length_and_charset_datetime(uint32_t max_char_length_arg)
 
822
  { 
 
823
    collation.set(&my_charset_bin);
 
824
    fix_char_length(max_char_length_arg);
 
825
  }
764
826
};
765
827
 
 
828
namespace display {
 
829
const std::string &type(Item::Type type);
 
830
} /* namespace display */
 
831
 
 
832
std::ostream& operator<<(std::ostream& output, const Item &item);
 
833
 
766
834
} /* namespace drizzled */
767
835
 
768
836
/** @TODO Why is this in the middle? */