~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_timefunc.h

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705112018-fr12kkmgphtu7m29
Changes so that removal of duplicate curr_dir from my_sys.h work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
 
21
17
/* Function items used by mysql */
22
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
 
22
 
23
23
enum date_time_format_types 
24
24
25
25
  TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
32
32
{
33
33
public:
34
34
  Item_func_period_add(Item *a,Item *b) :Item_int_func(a,b) {}
35
 
  int64_t val_int();
 
35
  longlong val_int();
36
36
  const char *func_name() const { return "period_add"; }
37
37
  void fix_length_and_dec() 
38
38
  { 
45
45
{
46
46
public:
47
47
  Item_func_period_diff(Item *a,Item *b) :Item_int_func(a,b) {}
48
 
  int64_t val_int();
 
48
  longlong val_int();
49
49
  const char *func_name() const { return "period_diff"; }
50
50
  void fix_length_and_dec()
51
51
  { 
59
59
{
60
60
public:
61
61
  Item_func_to_days(Item *a) :Item_int_func(a) {}
62
 
  int64_t val_int();
 
62
  longlong val_int();
63
63
  const char *func_name() const { return "to_days"; }
64
64
  void fix_length_and_dec() 
65
65
  { 
68
68
    maybe_null=1; 
69
69
  }
70
70
  enum_monotonicity_info get_monotonicity_info() const;
71
 
  int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
72
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
73
 
  { return false; }
 
71
  longlong val_int_endpoint(bool left_endp, bool *incl_endp);
74
72
};
75
73
 
76
74
 
78
76
{
79
77
public:
80
78
  Item_func_dayofmonth(Item *a) :Item_int_func(a) {}
81
 
  int64_t val_int();
 
79
  longlong val_int();
82
80
  const char *func_name() const { return "dayofmonth"; }
83
81
  void fix_length_and_dec() 
84
82
  { 
86
84
    max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
87
85
    maybe_null=1; 
88
86
  }
89
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
90
 
  { return false; }
91
87
};
92
88
 
93
89
 
95
91
{
96
92
public:
97
93
  Item_func_month(Item *a) :Item_func(a) {}
98
 
  int64_t val_int();
 
94
  longlong val_int();
99
95
  double val_real()
100
 
  { assert(fixed == 1); return (double) Item_func_month::val_int(); }
 
96
  { DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); }
101
97
  String *val_str(String *str) 
102
98
  {
103
99
    str->set(val_int(), &my_charset_bin);
112
108
    max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
113
109
    maybe_null=1; 
114
110
  }
115
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
116
 
  { return false; }
117
111
};
118
112
 
119
113
 
138
132
{
139
133
public:
140
134
  Item_func_dayofyear(Item *a) :Item_int_func(a) {}
141
 
  int64_t val_int();
 
135
  longlong val_int();
142
136
  const char *func_name() const { return "dayofyear"; }
143
137
  void fix_length_and_dec() 
144
138
  { 
153
147
{
154
148
public:
155
149
  Item_func_hour(Item *a) :Item_int_func(a) {}
156
 
  int64_t val_int();
 
150
  longlong val_int();
157
151
  const char *func_name() const { return "hour"; }
158
152
  void fix_length_and_dec()
159
153
  {
168
162
{
169
163
public:
170
164
  Item_func_minute(Item *a) :Item_int_func(a) {}
171
 
  int64_t val_int();
 
165
  longlong val_int();
172
166
  const char *func_name() const { return "minute"; }
173
167
  void fix_length_and_dec()
174
168
  {
183
177
{
184
178
public:
185
179
  Item_func_quarter(Item *a) :Item_int_func(a) {}
186
 
  int64_t val_int();
 
180
  longlong val_int();
187
181
  const char *func_name() const { return "quarter"; }
188
182
  void fix_length_and_dec()
189
183
  { 
198
192
{
199
193
public:
200
194
  Item_func_second(Item *a) :Item_int_func(a) {}
201
 
  int64_t val_int();
 
195
  longlong val_int();
202
196
  const char *func_name() const { return "second"; }
203
197
  void fix_length_and_dec() 
204
198
  { 
213
207
{
214
208
public:
215
209
  Item_func_week(Item *a,Item *b) :Item_int_func(a,b) {}
216
 
  int64_t val_int();
 
210
  longlong val_int();
217
211
  const char *func_name() const { return "week"; }
218
212
  void fix_length_and_dec()
219
213
  { 
227
221
{
228
222
public:
229
223
  Item_func_yearweek(Item *a,Item *b) :Item_int_func(a,b) {}
230
 
  int64_t val_int();
 
224
  longlong val_int();
231
225
  const char *func_name() const { return "yearweek"; }
232
226
  void fix_length_and_dec()
233
227
  { 
242
236
{
243
237
public:
244
238
  Item_func_year(Item *a) :Item_int_func(a) {}
245
 
  int64_t val_int();
 
239
  longlong val_int();
246
240
  const char *func_name() const { return "year"; }
247
241
  enum_monotonicity_info get_monotonicity_info() const;
248
 
  int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
 
242
  longlong val_int_endpoint(bool left_endp, bool *incl_endp);
249
243
  void fix_length_and_dec()
250
244
  { 
251
245
    decimals=0;
261
255
public:
262
256
  Item_func_weekday(Item *a,bool type_arg)
263
257
    :Item_func(a), odbc_type(type_arg) {}
264
 
  int64_t val_int();
265
 
  double val_real() { assert(fixed == 1); return (double) val_int(); }
 
258
  longlong val_int();
 
259
  double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
266
260
  String *val_str(String *str)
267
261
  {
268
 
    assert(fixed == 1);
 
262
    DBUG_ASSERT(fixed == 1);
269
263
    str->set(val_int(), &my_charset_bin);
270
264
    return null_value ? 0 : str;
271
265
  }
306
300
public:
307
301
  Item_func_unix_timestamp() :Item_int_func() {}
308
302
  Item_func_unix_timestamp(Item *a) :Item_int_func(a) {}
309
 
  int64_t val_int();
 
303
  longlong val_int();
310
304
  const char *func_name() const { return "unix_timestamp"; }
311
305
  void fix_length_and_dec()
312
306
  {
313
307
    decimals=0;
314
308
    max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
315
309
  }
316
 
  bool check_vcol_func_processor(unsigned char *int_arg  __attribute__((unused)))
317
 
  { return true; }
318
310
};
319
311
 
320
312
 
322
314
{
323
315
public:
324
316
  Item_func_time_to_sec(Item *item) :Item_int_func(item) {}
325
 
  int64_t val_int();
 
317
  longlong val_int();
326
318
  const char *func_name() const { return "time_to_sec"; }
327
319
  void fix_length_and_dec()
328
320
  {
342
334
  Item_date() :Item_func() {}
343
335
  Item_date(Item *a) :Item_func(a) {}
344
336
  enum Item_result result_type () const { return STRING_RESULT; }
345
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
 
337
  enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
346
338
  String *val_str(String *str);
347
 
  int64_t val_int();
 
339
  longlong val_int();
348
340
  double val_real() { return val_real_from_decimal(); }
349
341
  const char *func_name() const { return "date"; }
350
342
  void fix_length_and_dec()
353
345
    decimals=0;
354
346
    max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
355
347
  }
356
 
  Field *tmp_table_field(Table *table)
 
348
  Field *tmp_table_field(TABLE *table)
357
349
  {
358
350
    return tmp_table_field_from_field_type(table, 0);
359
351
  }
360
 
  bool result_as_int64_t() { return true; }
 
352
  bool result_as_longlong() { return TRUE; }
361
353
  my_decimal *val_decimal(my_decimal *decimal_value)
362
354
  {
363
 
    assert(fixed == 1);
 
355
    DBUG_ASSERT(fixed == 1);
364
356
    return  val_decimal_from_date(decimal_value);
365
357
  }
366
 
  int save_in_field(Field *field,
367
 
                    bool no_conversions __attribute__((unused)))
 
358
  int save_in_field(Field *field, bool no_conversions)
368
359
  {
369
360
    return save_date_in_field(field);
370
361
  }
378
369
  Item_date_func(Item *a) :Item_str_func(a) {}
379
370
  Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
380
371
  Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
381
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
382
 
  Field *tmp_table_field(Table *table)
 
372
  enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
 
373
  Field *tmp_table_field(TABLE *table)
383
374
  {
384
375
    return tmp_table_field_from_field_type(table, 0);
385
376
  }
386
 
  bool result_as_int64_t() { return true; }
 
377
  bool result_as_longlong() { return TRUE; }
387
378
  double val_real() { return (double) val_int(); }
388
379
  my_decimal *val_decimal(my_decimal *decimal_value)
389
380
  {
390
 
    assert(fixed == 1);
 
381
    DBUG_ASSERT(fixed == 1);
391
382
    return  val_decimal_from_date(decimal_value);
392
383
  }
393
 
  int save_in_field(Field *field,
394
 
                    bool no_conversions __attribute__((unused)))
 
384
  int save_in_field(Field *field, bool no_conversions)
395
385
  {
396
386
    return save_date_in_field(field);
397
387
  }
405
395
  Item_str_timefunc(Item *a) :Item_str_func(a) {}
406
396
  Item_str_timefunc(Item *a,Item *b) :Item_str_func(a,b) {}
407
397
  Item_str_timefunc(Item *a, Item *b, Item *c) :Item_str_func(a, b ,c) {}
408
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_TIME; }
 
398
  enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
409
399
  void fix_length_and_dec()
410
400
  {
411
401
    decimals= DATETIME_DEC;
412
402
    max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
413
403
  }
414
 
  Field *tmp_table_field(Table *table)
 
404
  Field *tmp_table_field(TABLE *table)
415
405
  {
416
406
    return tmp_table_field_from_field_type(table, 0);
417
407
  }
418
408
  double val_real() { return val_real_from_decimal(); }
419
409
  my_decimal *val_decimal(my_decimal *decimal_value)
420
410
  {
421
 
    assert(fixed == 1);
 
411
    DBUG_ASSERT(fixed == 1);
422
412
    return  val_decimal_from_time(decimal_value);
423
413
  }
424
 
  int save_in_field(Field *field,
425
 
                    bool no_conversions __attribute__((unused)))
 
414
  int save_in_field(Field *field, bool no_conversions)
426
415
  {
427
416
    return save_time_in_field(field);
428
417
  }
433
422
 
434
423
class Item_func_curtime :public Item_str_timefunc
435
424
{
436
 
  int64_t value;
 
425
  longlong value;
437
426
  char buff[9*2+32];
438
 
  uint32_t buff_length;
 
427
  uint buff_length;
439
428
public:
440
429
  Item_func_curtime() :Item_str_timefunc() {}
441
430
  Item_func_curtime(Item *a) :Item_str_timefunc(a) {}
442
 
  double val_real() { assert(fixed == 1); return (double) value; }
443
 
  int64_t val_int() { assert(fixed == 1); return value; }
 
431
  double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
 
432
  longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
444
433
  String *val_str(String *str);
445
434
  void fix_length_and_dec();
446
435
  /* 
447
436
    Abstract method that defines which time zone is used for conversion.
448
437
    Converts time current time in my_time_t representation to broken-down
449
 
    DRIZZLE_TIME representation using UTC-SYSTEM or per-thread time zone.
 
438
    MYSQL_TIME representation using UTC-SYSTEM or per-thread time zone.
450
439
  */
451
 
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
452
 
  bool result_as_int64_t() { return true; }
453
 
  bool check_vcol_func_processor(unsigned char *int_arg  __attribute__((unused)))
454
 
  { return true; }
 
440
  virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
 
441
  bool result_as_longlong() { return TRUE; }
455
442
};
456
443
 
457
444
 
461
448
  Item_func_curtime_local() :Item_func_curtime() {}
462
449
  Item_func_curtime_local(Item *a) :Item_func_curtime(a) {}
463
450
  const char *func_name() const { return "curtime"; }
464
 
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
451
  virtual void store_now_in_TIME(MYSQL_TIME *now_time);
465
452
};
466
453
 
467
454
 
471
458
  Item_func_curtime_utc() :Item_func_curtime() {}
472
459
  Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {}
473
460
  const char *func_name() const { return "utc_time"; }
474
 
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
461
  virtual void store_now_in_TIME(MYSQL_TIME *now_time);
475
462
};
476
463
 
477
464
 
479
466
 
480
467
class Item_func_curdate :public Item_date
481
468
{
482
 
  int64_t value;
483
 
  DRIZZLE_TIME ltime;
 
469
  longlong value;
 
470
  MYSQL_TIME ltime;
484
471
public:
485
472
  Item_func_curdate() :Item_date() {}
486
 
  int64_t val_int() { assert(fixed == 1); return (value) ; }
 
473
  longlong val_int() { DBUG_ASSERT(fixed == 1); return (value) ; }
487
474
  String *val_str(String *str);
488
475
  void fix_length_and_dec();
489
 
  bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
490
 
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
491
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
492
 
  { return true; }
 
476
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
 
477
  virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
493
478
};
494
479
 
495
480
 
498
483
public:
499
484
  Item_func_curdate_local() :Item_func_curdate() {}
500
485
  const char *func_name() const { return "curdate"; }
501
 
  void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
486
  void store_now_in_TIME(MYSQL_TIME *now_time);
502
487
};
503
488
 
504
489
 
507
492
public:
508
493
  Item_func_curdate_utc() :Item_func_curdate() {}
509
494
  const char *func_name() const { return "utc_date"; }
510
 
  void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
495
  void store_now_in_TIME(MYSQL_TIME *now_time);
511
496
};
512
497
 
513
498
 
516
501
class Item_func_now :public Item_date_func
517
502
{
518
503
protected:
519
 
  int64_t value;
 
504
  longlong value;
520
505
  char buff[20*2+32];   // +32 to make my_snprintf_{8bit|ucs2} happy
521
 
  uint32_t buff_length;
522
 
  DRIZZLE_TIME ltime;
 
506
  uint buff_length;
 
507
  MYSQL_TIME ltime;
523
508
public:
524
509
  Item_func_now() :Item_date_func() {}
525
510
  Item_func_now(Item *a) :Item_date_func(a) {}
526
511
  enum Item_result result_type () const { return STRING_RESULT; }
527
 
  int64_t val_int() { assert(fixed == 1); return value; }
 
512
  longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
528
513
  int save_in_field(Field *to, bool no_conversions);
529
514
  String *val_str(String *str);
530
515
  void fix_length_and_dec();
531
 
  bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
532
 
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
533
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
534
 
  { return true; }
 
516
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
 
517
  virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
535
518
};
536
519
 
537
520
 
541
524
  Item_func_now_local() :Item_func_now() {}
542
525
  Item_func_now_local(Item *a) :Item_func_now(a) {}
543
526
  const char *func_name() const { return "now"; }
544
 
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
527
  virtual void store_now_in_TIME(MYSQL_TIME *now_time);
545
528
  virtual enum Functype functype() const { return NOW_FUNC; }
546
529
};
547
530
 
552
535
  Item_func_now_utc() :Item_func_now() {}
553
536
  Item_func_now_utc(Item *a) :Item_func_now(a) {}
554
537
  const char *func_name() const { return "utc_timestamp"; }
555
 
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
538
  virtual void store_now_in_TIME(MYSQL_TIME *now_time);
556
539
};
557
540
 
558
541
 
567
550
  Item_func_sysdate_local(Item *a) :Item_func_now(a) {}
568
551
  bool const_item() const { return 0; }
569
552
  const char *func_name() const { return "sysdate"; }
570
 
  void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
553
  void store_now_in_TIME(MYSQL_TIME *now_time);
571
554
  double val_real();
572
 
  int64_t val_int();
 
555
  longlong val_int();
573
556
  int save_in_field(Field *to, bool no_conversions);
574
557
  String *val_str(String *str);
575
558
  void fix_length_and_dec();
576
 
  bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
 
559
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
577
560
  void update_used_tables()
578
561
  {
579
562
    Item_func_now::update_used_tables();
587
570
public:
588
571
  Item_func_from_days(Item *a) :Item_date(a) {}
589
572
  const char *func_name() const { return "from_days"; }
590
 
  bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
591
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
592
 
  { return false; }
 
573
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
593
574
};
594
575
 
595
576
 
605
586
  const char *func_name() const
606
587
    { return is_time_format ? "time_format" : "date_format"; }
607
588
  void fix_length_and_dec();
608
 
  uint32_t format_length(const String *format);
 
589
  uint format_length(const String *format);
609
590
  bool eq(const Item *item, bool binary_cmp) const;
610
591
};
611
592
 
615
596
  THD *thd;
616
597
 public:
617
598
  Item_func_from_unixtime(Item *a) :Item_date_func(a) {}
618
 
  int64_t val_int();
 
599
  longlong val_int();
619
600
  String *val_str(String *str);
620
601
  const char *func_name() const { return "from_unixtime"; }
621
602
  void fix_length_and_dec();
622
 
  bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
 
603
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
623
604
};
624
605
 
625
606
 
650
631
 public:
651
632
  Item_func_convert_tz(Item *a, Item *b, Item *c):
652
633
    Item_date_func(a, b, c), from_tz_cached(0), to_tz_cached(0) {}
653
 
  int64_t val_int();
 
634
  longlong val_int();
654
635
  String *val_str(String *str);
655
636
  const char *func_name() const { return "convert_tz"; }
656
637
  void fix_length_and_dec();
657
 
  bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
 
638
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
658
639
  void cleanup();
659
640
};
660
641
 
665
646
  Item_func_sec_to_time(Item *item) :Item_str_timefunc(item) {}
666
647
  double val_real()
667
648
  {
668
 
    assert(fixed == 1);
 
649
    DBUG_ASSERT(fixed == 1);
669
650
    return (double) Item_func_sec_to_time::val_int();
670
651
  }
671
 
  int64_t val_int();
 
652
  longlong val_int();
672
653
  String *val_str(String *);
673
654
  void fix_length_and_dec()
674
655
  { 
677
658
    maybe_null=1;
678
659
  }
679
660
  const char *func_name() const { return "sec_to_time"; }
680
 
  bool result_as_int64_t() { return true; }
 
661
  bool result_as_longlong() { return TRUE; }
681
662
};
682
663
 
683
664
 
695
676
  const char *func_name() const { return "date_add_interval"; }
696
677
  void fix_length_and_dec();
697
678
  enum_field_types field_type() const { return cached_field_type; }
698
 
  int64_t val_int();
699
 
  bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
 
679
  longlong val_int();
 
680
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
700
681
  bool eq(const Item *item, bool binary_cmp) const;
701
682
  virtual void print(String *str, enum_query_type query_type);
702
683
};
710
691
  const interval_type int_type; // keep it public
711
692
  Item_extract(interval_type type_arg, Item *a)
712
693
    :Item_int_func(a), int_type(type_arg) {}
713
 
  int64_t val_int();
 
694
  longlong val_int();
714
695
  enum Functype functype() const { return EXTRACT_FUNC; }
715
696
  const char *func_name() const { return "extract"; }
716
697
  void fix_length_and_dec();
725
706
  Item_typecast(Item *a) :Item_str_func(a) {}
726
707
  String *val_str(String *a)
727
708
  {
728
 
    assert(fixed == 1);
 
709
    DBUG_ASSERT(fixed == 1);
729
710
    String *tmp=args[0]->val_str(a);
730
711
    null_value=args[0]->null_value;
731
712
    if (tmp)
758
739
class Item_char_typecast :public Item_typecast
759
740
{
760
741
  int cast_length;
761
 
  const CHARSET_INFO *cast_cs, *from_cs;
 
742
  CHARSET_INFO *cast_cs, *from_cs;
762
743
  bool charset_conversion;
763
744
  String tmp_value;
764
745
public:
765
 
  Item_char_typecast(Item *a, int length_arg, const CHARSET_INFO * const cs_arg)
 
746
  Item_char_typecast(Item *a, int length_arg, CHARSET_INFO *cs_arg)
766
747
    :Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
767
748
  enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
768
749
  bool eq(const Item *item, bool binary_cmp) const;
780
761
  Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
781
762
  const char *func_name() const { return "cast_as_date"; }
782
763
  String *val_str(String *str);
783
 
  bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
784
 
  bool get_time(DRIZZLE_TIME *ltime);
 
764
  bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
 
765
  bool get_time(MYSQL_TIME *ltime);
785
766
  const char *cast_type() const { return "date"; }
786
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
787
 
  Field *tmp_table_field(Table *table)
 
767
  enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
 
768
  Field *tmp_table_field(TABLE *table)
788
769
  {
789
770
    return tmp_table_field_from_field_type(table, 0);
790
771
  }  
794
775
    max_length= 10;
795
776
    maybe_null= 1;
796
777
  }
797
 
  bool result_as_int64_t() { return true; }
798
 
  int64_t val_int();
 
778
  bool result_as_longlong() { return TRUE; }
 
779
  longlong val_int();
799
780
  double val_real() { return (double) val_int(); }
800
781
  my_decimal *val_decimal(my_decimal *decimal_value)
801
782
  {
802
 
    assert(fixed == 1);
 
783
    DBUG_ASSERT(fixed == 1);
803
784
    return  val_decimal_from_date(decimal_value);
804
785
  }
805
 
  int save_in_field(Field *field,
806
 
                    bool no_conversions __attribute__((unused)))
 
786
  int save_in_field(Field *field, bool no_conversions)
807
787
  {
808
788
    return save_date_in_field(field);
809
789
  }
816
796
  Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
817
797
  const char *func_name() const { return "cast_as_time"; }
818
798
  String *val_str(String *str);
819
 
  bool get_time(DRIZZLE_TIME *ltime);
 
799
  bool get_time(MYSQL_TIME *ltime);
820
800
  const char *cast_type() const { return "time"; }
821
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_TIME; }
822
 
  Field *tmp_table_field(Table *table)
 
801
  enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
 
802
  Field *tmp_table_field(TABLE *table)
823
803
  {
824
804
    return tmp_table_field_from_field_type(table, 0);
825
805
  }
826
 
  bool result_as_int64_t() { return true; }
827
 
  int64_t val_int();
 
806
  bool result_as_longlong() { return TRUE; }
 
807
  longlong val_int();
828
808
  double val_real() { return val_real_from_decimal(); }
829
809
  my_decimal *val_decimal(my_decimal *decimal_value)
830
810
  {
831
 
    assert(fixed == 1);
 
811
    DBUG_ASSERT(fixed == 1);
832
812
    return  val_decimal_from_time(decimal_value);
833
813
  }
834
 
  int save_in_field(Field *field,
835
 
                    bool no_conversions __attribute__((unused)))
 
814
  int save_in_field(Field *field, bool no_conversions)
836
815
  {
837
816
    return save_time_in_field(field);
838
817
  }
846
825
  const char *func_name() const { return "cast_as_datetime"; }
847
826
  String *val_str(String *str);
848
827
  const char *cast_type() const { return "datetime"; }
849
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
850
 
  Field *tmp_table_field(Table *table)
 
828
  enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
 
829
  Field *tmp_table_field(TABLE *table)
851
830
  {
852
831
    return tmp_table_field_from_field_type(table, 0);
853
832
  }
858
837
    max_length= MAX_DATETIME_FULL_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
859
838
    decimals= DATETIME_DEC;
860
839
  }
861
 
  bool result_as_int64_t() { return true; }
862
 
  int64_t val_int();
 
840
  bool result_as_longlong() { return TRUE; }
 
841
  longlong val_int();
863
842
  double val_real() { return val_real_from_decimal(); }
864
843
  double val() { return (double) val_int(); }
865
844
  my_decimal *val_decimal(my_decimal *decimal_value)
866
845
  {
867
 
    assert(fixed == 1);
 
846
    DBUG_ASSERT(fixed == 1);
868
847
    return  val_decimal_from_date(decimal_value);
869
848
  }
870
 
  int save_in_field(Field *field,
871
 
                    bool no_conversions __attribute__((unused)))
 
849
  int save_in_field(Field *field, bool no_conversions)
872
850
  {
873
851
    return save_date_in_field(field);
874
852
  }
880
858
  Item_func_makedate(Item *a,Item *b) :Item_date_func(a,b) {}
881
859
  String *val_str(String *str);
882
860
  const char *func_name() const { return "makedate"; }
883
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
 
861
  enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
884
862
  void fix_length_and_dec()
885
863
  { 
886
864
    decimals=0;
887
865
    max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
888
866
  }
889
 
  int64_t val_int();
 
867
  longlong val_int();
890
868
};
891
869
 
892
870
 
903
881
  enum_field_types field_type() const { return cached_field_type; }
904
882
  void fix_length_and_dec();
905
883
 
906
 
  Field *tmp_table_field(Table *table)
 
884
  Field *tmp_table_field(TABLE *table)
907
885
  {
908
886
    return tmp_table_field_from_field_type(table, 0);
909
887
  }
912
890
  double val_real() { return val_real_from_decimal(); }
913
891
  my_decimal *val_decimal(my_decimal *decimal_value)
914
892
  {
915
 
    assert(fixed == 1);
916
 
    if (cached_field_type == DRIZZLE_TYPE_TIME)
 
893
    DBUG_ASSERT(fixed == 1);
 
894
    if (cached_field_type == MYSQL_TYPE_TIME)
917
895
      return  val_decimal_from_time(decimal_value);
918
 
    if (cached_field_type == DRIZZLE_TYPE_DATETIME)
 
896
    if (cached_field_type == MYSQL_TYPE_DATETIME)
919
897
      return  val_decimal_from_date(decimal_value);
920
898
    return Item_str_func::val_decimal(decimal_value);
921
899
  }
922
900
  int save_in_field(Field *field, bool no_conversions)
923
901
  {
924
 
    if (cached_field_type == DRIZZLE_TYPE_TIME)
 
902
    if (cached_field_type == MYSQL_TYPE_TIME)
925
903
      return save_time_in_field(field);
926
 
    if (cached_field_type == DRIZZLE_TYPE_DATETIME)
 
904
    if (cached_field_type == MYSQL_TYPE_DATETIME)
927
905
      return save_date_in_field(field);
928
906
    return Item_str_func::save_in_field(field, no_conversions);
929
907
  }
949
927
  Item_func_maketime(Item *a, Item *b, Item *c)
950
928
    :Item_str_timefunc(a, b, c) 
951
929
  {
952
 
    maybe_null= true;
 
930
    maybe_null= TRUE;
953
931
  }
954
932
  String *val_str(String *str);
955
933
  const char *func_name() const { return "maketime"; }
959
937
{
960
938
public:
961
939
  Item_func_microsecond(Item *a) :Item_int_func(a) {}
962
 
  int64_t val_int();
 
940
  longlong val_int();
963
941
  const char *func_name() const { return "microsecond"; }
964
942
  void fix_length_and_dec() 
965
943
  { 
976
954
  Item_func_timestamp_diff(Item *a,Item *b,interval_type type_arg)
977
955
    :Item_int_func(a,b), int_type(type_arg) {}
978
956
  const char *func_name() const { return "timestampdiff"; }
979
 
  int64_t val_int();
 
957
  longlong val_int();
980
958
  void fix_length_and_dec()
981
959
  {
982
960
    decimals=0;
994
972
class Item_func_get_format :public Item_str_func
995
973
{
996
974
public:
997
 
  const enum enum_drizzle_timestamp_type type; // keep it public
998
 
  Item_func_get_format(enum enum_drizzle_timestamp_type type_arg, Item *a)
 
975
  const timestamp_type type; // keep it public
 
976
  Item_func_get_format(timestamp_type type_arg, Item *a)
999
977
    :Item_str_func(a), type(type_arg)
1000
978
  {}
1001
979
  String *val_str(String *str);
1014
992
{
1015
993
  enum_field_types cached_field_type;
1016
994
  date_time_format_types cached_format_type;
1017
 
  enum enum_drizzle_timestamp_type cached_timestamp_type;
 
995
  timestamp_type cached_timestamp_type;
1018
996
  bool const_item;
1019
997
public:
1020
998
  Item_func_str_to_date(Item *a, Item *b)
1021
999
    :Item_str_func(a, b), const_item(false)
1022
1000
  {}
1023
1001
  String *val_str(String *str);
1024
 
  bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
 
1002
  bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
1025
1003
  const char *func_name() const { return "str_to_date"; }
1026
1004
  enum_field_types field_type() const { return cached_field_type; }
1027
1005
  void fix_length_and_dec();
1028
 
  Field *tmp_table_field(Table *table)
 
1006
  Field *tmp_table_field(TABLE *table)
1029
1007
  {
1030
1008
    return tmp_table_field_from_field_type(table, 1);
1031
1009
  }
1037
1015
public:
1038
1016
  Item_func_last_day(Item *a) :Item_date(a) {}
1039
1017
  const char *func_name() const { return "last_day"; }
1040
 
  bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
 
1018
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
1041
1019
};