~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/date.h

  • Committer: Jay Pipes
  • Date: 2009-01-30 04:01:12 UTC
  • mto: This revision was merged to the branch mainline in revision 830.
  • Revision ID: jpipes@serialcoder-20090130040112-svbn774guj98pwi4
To remain in compatibility with MySQL, added ability to interpret
decimal arguments as datetime strings for temporal functions.

Fixed YEAR(), MONTH(), DAYOFMONTH(), DAYOFYEAR(), HOUR(), MINUTE(), SECOND(), and MICROSECOND()
to accept decimal parameters and interpret them the same way as MySQL.

Fixed an issue with the TemporalFormat::matches() method which was 
incorrectly assuming all microsecond arguments were specified as 6 digits.
Added power of 10 multiplier to usecond calculation. This fixes issues with
failures in type_date and func_sapdb test cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#ifndef DRIZZLED_FUNCTION_TIME_DATE_H
21
21
#define DRIZZLED_FUNCTION_TIME_DATE_H
22
22
 
23
 
#include "drizzled/function/func.h"
24
 
#include "drizzled/function/str/strfunc.h"
25
 
#include <drizzled/temporal.h>
26
 
 
27
 
namespace drizzled
28
 
{
29
 
 
30
 
/* A function which evaluates to a Date */
 
23
#include <drizzled/function/func.h>
 
24
#include <drizzled/function/str/strfunc.h>
 
25
/*
 
26
  This can't be a Item_str_func, because the val_real() functions are special
 
27
*/
 
28
 
31
29
class Item_date :public Item_func
32
30
{
33
31
public:
34
 
  using Item_func::tmp_table_field;
35
 
 
36
32
  Item_date() :Item_func() {}
37
33
  Item_date(Item *a) :Item_func(a) {}
38
34
  enum Item_result result_type () const { return STRING_RESULT; }
45
41
  {
46
42
    collation.set(&my_charset_bin);
47
43
    decimals=0;
48
 
    max_length=Date::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
 
44
    max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
49
45
  }
50
 
  /**
51
 
   * All functions which inherit from Item_date must implement
52
 
   * their own get_temporal() method, which takes a supplied
53
 
   * Date reference and populates it with a correct
54
 
   * date based on the semantics of the function.
55
 
   *
56
 
   * Returns whether the function was able to correctly fill
57
 
   * the supplied date temporal with a proper date.
58
 
   *
59
 
   * @param Reference to a Date to populate
60
 
   */
61
 
  virtual bool get_temporal(Date &temporal)= 0;
62
46
  Field *tmp_table_field(Table *table)
63
47
  {
64
48
    return tmp_table_field_from_field_type(table, 0);
84
68
  Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
85
69
  Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
86
70
  enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
87
 
 
88
 
  using Item_func::tmp_table_field;
89
71
  Field *tmp_table_field(Table *table)
90
72
  {
91
73
    return tmp_table_field_from_field_type(table, 0);
104
86
  }
105
87
};
106
88
 
107
 
} /* namespace drizzled */
108
 
 
109
89
#endif /* DRIZZLED_FUNCTION_TIME_DATE_H */