~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/timefunc.h

MergedĀ fromĀ Lee.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <drizzled/functions/time/date.h>
32
32
#include <drizzled/functions/time/curdate.h>
33
33
#include <drizzled/functions/time/curtime.h>
 
34
#include <drizzled/functions/time/date_add_interval.h>
34
35
#include <drizzled/functions/time/date_format.h>
35
36
#include <drizzled/functions/time/dayname.h>
36
37
#include <drizzled/functions/time/dayofmonth.h>
37
38
#include <drizzled/functions/time/dayofyear.h>
 
39
#include <drizzled/functions/time/extract.h>
38
40
#include <drizzled/functions/time/from_days.h>
39
41
#include <drizzled/functions/time/from_unixtime.h>
40
42
#include <drizzled/functions/time/get_format.h>
 
43
#include <drizzled/functions/time/get_interval_value.h>
41
44
#include <drizzled/functions/time/hour.h>
 
45
#include <drizzled/functions/time/last_day.h>
42
46
#include <drizzled/functions/time/makedate.h>
43
47
#include <drizzled/functions/time/make_datetime.h>
44
48
#include <drizzled/functions/time/make_datetime_with_warn.h>
53
57
#include <drizzled/functions/time/period_diff.h>
54
58
#include <drizzled/functions/time/sec_to_time.h>
55
59
#include <drizzled/functions/time/second.h>
 
60
#include <drizzled/functions/time/str_to_date.h>
56
61
#include <drizzled/functions/time/sysdate_local.h>
57
62
#include <drizzled/functions/time/timestamp_diff.h>
58
63
#include <drizzled/functions/time/time_to_sec.h>
59
64
#include <drizzled/functions/time/timediff.h>
60
65
#include <drizzled/functions/time/to_days.h>
 
66
#include <drizzled/functions/time/typecast.h>
61
67
#include <drizzled/functions/time/unix_timestamp.h>
62
68
#include <drizzled/functions/time/week.h>
63
69
#include <drizzled/functions/time/week_mode.h>
64
70
#include <drizzled/functions/time/year.h>
65
71
#include <drizzled/functions/time/yearweek.h>
66
72
 
67
 
bool get_interval_value(Item *args,interval_type int_type,
68
 
                               String *str_value, INTERVAL *interval);
69
 
 
70
 
class Item_date_add_interval :public Item_date_func
71
 
{
72
 
  String value;
73
 
  enum_field_types cached_field_type;
74
 
 
75
 
public:
76
 
  const interval_type int_type; // keep it public
77
 
  const bool date_sub_interval; // keep it public
78
 
  Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg)
79
 
    :Item_date_func(a,b),int_type(type_arg), date_sub_interval(neg_arg) {}
80
 
  String *val_str(String *);
81
 
  const char *func_name() const { return "date_add_interval"; }
82
 
  void fix_length_and_dec();
83
 
  enum_field_types field_type() const { return cached_field_type; }
84
 
  int64_t val_int();
85
 
  bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
86
 
  bool eq(const Item *item, bool binary_cmp) const;
87
 
  virtual void print(String *str, enum_query_type query_type);
88
 
};
89
 
 
90
 
 
91
 
class Item_extract :public Item_int_func
92
 
{
93
 
  String value;
94
 
  bool date_value;
95
 
 public:
96
 
  const interval_type int_type; // keep it public
97
 
  Item_extract(interval_type type_arg, Item *a)
98
 
    :Item_int_func(a), int_type(type_arg) {}
99
 
  int64_t val_int();
100
 
  enum Functype functype() const { return EXTRACT_FUNC; }
101
 
  const char *func_name() const { return "extract"; }
102
 
  void fix_length_and_dec();
103
 
  bool eq(const Item *item, bool binary_cmp) const;
104
 
  virtual void print(String *str, enum_query_type query_type);
105
 
};
106
 
 
107
 
 
108
 
class Item_typecast :public Item_str_func
109
 
{
110
 
public:
111
 
  Item_typecast(Item *a) :Item_str_func(a) {}
112
 
  String *val_str(String *a)
113
 
  {
114
 
    assert(fixed == 1);
115
 
    String *tmp=args[0]->val_str(a);
116
 
    null_value=args[0]->null_value;
117
 
    if (tmp)
118
 
      tmp->set_charset(collation.collation);
119
 
    return tmp;
120
 
  }
121
 
  void fix_length_and_dec()
122
 
  {
123
 
    collation.set(&my_charset_bin);
124
 
    max_length=args[0]->max_length;
125
 
  }
126
 
  virtual const char* cast_type() const= 0;
127
 
  virtual void print(String *str, enum_query_type query_type);
128
 
};
129
 
 
130
 
 
131
 
class Item_typecast_maybe_null :public Item_typecast
132
 
{
133
 
public:
134
 
  Item_typecast_maybe_null(Item *a) :Item_typecast(a) {}
135
 
  void fix_length_and_dec()
136
 
  {
137
 
    collation.set(&my_charset_bin);
138
 
    max_length=args[0]->max_length;
139
 
    maybe_null= 1;
140
 
  }
141
 
};
142
 
 
143
 
 
144
 
class Item_char_typecast :public Item_typecast
145
 
{
146
 
  int cast_length;
147
 
  const CHARSET_INFO *cast_cs, *from_cs;
148
 
  bool charset_conversion;
149
 
  String tmp_value;
150
 
public:
151
 
  Item_char_typecast(Item *a, int length_arg, const CHARSET_INFO * const cs_arg)
152
 
    :Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
153
 
  enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
154
 
  bool eq(const Item *item, bool binary_cmp) const;
155
 
  const char *func_name() const { return "cast_as_char"; }
156
 
  const char* cast_type() const { return "char"; };
157
 
  String *val_str(String *a);
158
 
  void fix_length_and_dec();
159
 
  virtual void print(String *str, enum_query_type query_type);
160
 
};
161
 
 
162
 
 
163
 
class Item_date_typecast :public Item_typecast_maybe_null
164
 
{
165
 
public:
166
 
  Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
167
 
  const char *func_name() const { return "cast_as_date"; }
168
 
  String *val_str(String *str);
169
 
  bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
170
 
  bool get_time(DRIZZLE_TIME *ltime);
171
 
  const char *cast_type() const { return "date"; }
172
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_DATE; }
173
 
  Field *tmp_table_field(Table *table)
174
 
  {
175
 
    return tmp_table_field_from_field_type(table, 0);
176
 
  }  
177
 
  void fix_length_and_dec()
178
 
  {
179
 
    collation.set(&my_charset_bin);
180
 
    max_length= 10;
181
 
    maybe_null= 1;
182
 
  }
183
 
  bool result_as_int64_t() { return true; }
184
 
  int64_t val_int();
185
 
  double val_real() { return (double) val_int(); }
186
 
  my_decimal *val_decimal(my_decimal *decimal_value)
187
 
  {
188
 
    assert(fixed == 1);
189
 
    return  val_decimal_from_date(decimal_value);
190
 
  }
191
 
  int save_in_field(Field *field,
192
 
                    bool no_conversions __attribute__((unused)))
193
 
  {
194
 
    return save_date_in_field(field);
195
 
  }
196
 
};
197
 
 
198
 
 
199
 
class Item_time_typecast :public Item_typecast_maybe_null
200
 
{
201
 
public:
202
 
  Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
203
 
  const char *func_name() const { return "cast_as_time"; }
204
 
  String *val_str(String *str);
205
 
  bool get_time(DRIZZLE_TIME *ltime);
206
 
  const char *cast_type() const { return "time"; }
207
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_TIME; }
208
 
  Field *tmp_table_field(Table *table)
209
 
  {
210
 
    return tmp_table_field_from_field_type(table, 0);
211
 
  }
212
 
  bool result_as_int64_t() { return true; }
213
 
  int64_t val_int();
214
 
  double val_real() { return val_real_from_decimal(); }
215
 
  my_decimal *val_decimal(my_decimal *decimal_value)
216
 
  {
217
 
    assert(fixed == 1);
218
 
    return  val_decimal_from_time(decimal_value);
219
 
  }
220
 
  int save_in_field(Field *field,
221
 
                    bool no_conversions __attribute__((unused)))
222
 
  {
223
 
    return save_time_in_field(field);
224
 
  }
225
 
};
226
 
 
227
 
 
228
 
class Item_datetime_typecast :public Item_typecast_maybe_null
229
 
{
230
 
public:
231
 
  Item_datetime_typecast(Item *a) :Item_typecast_maybe_null(a) {}
232
 
  const char *func_name() const { return "cast_as_datetime"; }
233
 
  String *val_str(String *str);
234
 
  const char *cast_type() const { return "datetime"; }
235
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
236
 
  Field *tmp_table_field(Table *table)
237
 
  {
238
 
    return tmp_table_field_from_field_type(table, 0);
239
 
  }
240
 
  void fix_length_and_dec()
241
 
  {
242
 
    collation.set(&my_charset_bin);
243
 
    maybe_null= 1;
244
 
    max_length= MAX_DATETIME_FULL_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
245
 
    decimals= DATETIME_DEC;
246
 
  }
247
 
  bool result_as_int64_t() { return true; }
248
 
  int64_t val_int();
249
 
  double val_real() { return val_real_from_decimal(); }
250
 
  double val() { return (double) val_int(); }
251
 
  my_decimal *val_decimal(my_decimal *decimal_value)
252
 
  {
253
 
    assert(fixed == 1);
254
 
    return  val_decimal_from_date(decimal_value);
255
 
  }
256
 
  int save_in_field(Field *field,
257
 
                    bool no_conversions __attribute__((unused)))
258
 
  {
259
 
    return save_date_in_field(field);
260
 
  }
261
 
};
262
 
 
263
 
 
264
 
class Item_func_str_to_date :public Item_str_func
265
 
{
266
 
  enum_field_types cached_field_type;
267
 
  date_time_format_types cached_format_type;
268
 
  enum enum_drizzle_timestamp_type cached_timestamp_type;
269
 
  bool const_item;
270
 
public:
271
 
  Item_func_str_to_date(Item *a, Item *b)
272
 
    :Item_str_func(a, b), const_item(false)
273
 
  {}
274
 
  String *val_str(String *str);
275
 
  bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
276
 
  const char *func_name() const { return "str_to_date"; }
277
 
  enum_field_types field_type() const { return cached_field_type; }
278
 
  void fix_length_and_dec();
279
 
  Field *tmp_table_field(Table *table)
280
 
  {
281
 
    return tmp_table_field_from_field_type(table, 1);
282
 
  }
283
 
};
284
 
 
285
 
 
286
 
class Item_func_last_day :public Item_date
287
 
{
288
 
public:
289
 
  Item_func_last_day(Item *a) :Item_date(a) {}
290
 
  const char *func_name() const { return "last_day"; }
291
 
  bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
292
 
};
293
 
 
294
73
#endif /* DRIZZLED_ITEM_TIMEFUNC_H */