1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
1
/* Copyright (C) 2000-2006 MySQL AB
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.
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.
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 */
21
17
/* Function items used by mysql */
338
334
Item_date() :Item_func() {}
339
335
Item_date(Item *a) :Item_func(a) {}
340
336
enum Item_result result_type () const { return STRING_RESULT; }
341
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
337
enum_field_types field_type() const { return MYSQL_TYPE_NEWDATE; }
342
338
String *val_str(String *str);
343
339
int64_t val_int();
344
340
double val_real() { return val_real_from_decimal(); }
350
346
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
352
Field *tmp_table_field(Table *table)
348
Field *tmp_table_field(TABLE *table)
354
350
return tmp_table_field_from_field_type(table, 0);
360
356
return val_decimal_from_date(decimal_value);
362
358
int save_in_field(Field *field,
363
bool no_conversions __attribute__((unused)))
359
bool no_conversions __attribute__((__unused__)))
365
361
return save_date_in_field(field);
374
370
Item_date_func(Item *a) :Item_str_func(a) {}
375
371
Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
376
372
Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
377
enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
378
Field *tmp_table_field(Table *table)
373
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
374
Field *tmp_table_field(TABLE *table)
380
376
return tmp_table_field_from_field_type(table, 0);
387
383
return val_decimal_from_date(decimal_value);
389
385
int save_in_field(Field *field,
390
bool no_conversions __attribute__((unused)))
386
bool no_conversions __attribute__((__unused__)))
392
388
return save_date_in_field(field);
401
397
Item_str_timefunc(Item *a) :Item_str_func(a) {}
402
398
Item_str_timefunc(Item *a,Item *b) :Item_str_func(a,b) {}
403
399
Item_str_timefunc(Item *a, Item *b, Item *c) :Item_str_func(a, b ,c) {}
404
enum_field_types field_type() const { return DRIZZLE_TYPE_TIME; }
400
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
405
401
void fix_length_and_dec()
407
403
decimals= DATETIME_DEC;
408
404
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
410
Field *tmp_table_field(Table *table)
406
Field *tmp_table_field(TABLE *table)
412
408
return tmp_table_field_from_field_type(table, 0);
418
414
return val_decimal_from_time(decimal_value);
420
416
int save_in_field(Field *field,
421
bool no_conversions __attribute__((unused)))
417
bool no_conversions __attribute__((__unused__)))
423
419
return save_time_in_field(field);
443
439
Abstract method that defines which time zone is used for conversion.
444
440
Converts time current time in my_time_t representation to broken-down
445
DRIZZLE_TIME representation using UTC-SYSTEM or per-thread time zone.
441
MYSQL_TIME representation using UTC-SYSTEM or per-thread time zone.
447
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
443
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
448
444
bool result_as_int64_t() { return true; }
455
451
Item_func_curtime_local() :Item_func_curtime() {}
456
452
Item_func_curtime_local(Item *a) :Item_func_curtime(a) {}
457
453
const char *func_name() const { return "curtime"; }
458
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
454
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
465
461
Item_func_curtime_utc() :Item_func_curtime() {}
466
462
Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {}
467
463
const char *func_name() const { return "utc_time"; }
468
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
464
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
474
470
class Item_func_curdate :public Item_date
479
475
Item_func_curdate() :Item_date() {}
480
476
int64_t val_int() { assert(fixed == 1); return (value) ; }
481
477
String *val_str(String *str);
482
478
void fix_length_and_dec();
483
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
484
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
479
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
480
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
520
516
int save_in_field(Field *to, bool no_conversions);
521
517
String *val_str(String *str);
522
518
void fix_length_and_dec();
523
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
524
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
519
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
520
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
531
527
Item_func_now_local() :Item_func_now() {}
532
528
Item_func_now_local(Item *a) :Item_func_now(a) {}
533
529
const char *func_name() const { return "now"; }
534
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
530
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
535
531
virtual enum Functype functype() const { return NOW_FUNC; }
542
538
Item_func_now_utc() :Item_func_now() {}
543
539
Item_func_now_utc(Item *a) :Item_func_now(a) {}
544
540
const char *func_name() const { return "utc_timestamp"; }
545
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
541
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
557
553
Item_func_sysdate_local(Item *a) :Item_func_now(a) {}
558
554
bool const_item() const { return 0; }
559
555
const char *func_name() const { return "sysdate"; }
560
void store_now_in_TIME(DRIZZLE_TIME *now_time);
556
void store_now_in_TIME(MYSQL_TIME *now_time);
561
557
double val_real();
562
558
int64_t val_int();
563
559
int save_in_field(Field *to, bool no_conversions);
564
560
String *val_str(String *str);
565
561
void fix_length_and_dec();
566
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
562
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
567
563
void update_used_tables()
569
565
Item_func_now::update_used_tables();
578
574
Item_func_from_days(Item *a) :Item_date(a) {}
579
575
const char *func_name() const { return "from_days"; }
580
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
576
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
593
589
const char *func_name() const
594
590
{ return is_time_format ? "time_format" : "date_format"; }
595
591
void fix_length_and_dec();
596
uint32_t format_length(const String *format);
592
uint format_length(const String *format);
597
593
bool eq(const Item *item, bool binary_cmp) const;
607
603
String *val_str(String *str);
608
604
const char *func_name() const { return "from_unixtime"; }
609
605
void fix_length_and_dec();
610
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
606
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
642
638
String *val_str(String *str);
643
639
const char *func_name() const { return "convert_tz"; }
644
640
void fix_length_and_dec();
645
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
641
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
684
680
void fix_length_and_dec();
685
681
enum_field_types field_type() const { return cached_field_type; }
686
682
int64_t val_int();
687
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
683
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
688
684
bool eq(const Item *item, bool binary_cmp) const;
689
685
virtual void print(String *str, enum_query_type query_type);
746
742
class Item_char_typecast :public Item_typecast
749
const CHARSET_INFO *cast_cs, *from_cs;
745
CHARSET_INFO *cast_cs, *from_cs;
750
746
bool charset_conversion;
751
747
String tmp_value;
753
Item_char_typecast(Item *a, int length_arg, const CHARSET_INFO * const cs_arg)
749
Item_char_typecast(Item *a, int length_arg, CHARSET_INFO *cs_arg)
754
750
:Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
755
751
enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
756
752
bool eq(const Item *item, bool binary_cmp) const;
768
764
Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
769
765
const char *func_name() const { return "cast_as_date"; }
770
766
String *val_str(String *str);
771
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
772
bool get_time(DRIZZLE_TIME *ltime);
767
bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
768
bool get_time(MYSQL_TIME *ltime);
773
769
const char *cast_type() const { return "date"; }
774
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
775
Field *tmp_table_field(Table *table)
770
enum_field_types field_type() const { return MYSQL_TYPE_NEWDATE; }
771
Field *tmp_table_field(TABLE *table)
777
773
return tmp_table_field_from_field_type(table, 0);
791
787
return val_decimal_from_date(decimal_value);
793
789
int save_in_field(Field *field,
794
bool no_conversions __attribute__((unused)))
790
bool no_conversions __attribute__((__unused__)))
796
792
return save_date_in_field(field);
804
800
Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
805
801
const char *func_name() const { return "cast_as_time"; }
806
802
String *val_str(String *str);
807
bool get_time(DRIZZLE_TIME *ltime);
803
bool get_time(MYSQL_TIME *ltime);
808
804
const char *cast_type() const { return "time"; }
809
enum_field_types field_type() const { return DRIZZLE_TYPE_TIME; }
810
Field *tmp_table_field(Table *table)
805
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
806
Field *tmp_table_field(TABLE *table)
812
808
return tmp_table_field_from_field_type(table, 0);
820
816
return val_decimal_from_time(decimal_value);
822
818
int save_in_field(Field *field,
823
bool no_conversions __attribute__((unused)))
819
bool no_conversions __attribute__((__unused__)))
825
821
return save_time_in_field(field);
834
830
const char *func_name() const { return "cast_as_datetime"; }
835
831
String *val_str(String *str);
836
832
const char *cast_type() const { return "datetime"; }
837
enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
838
Field *tmp_table_field(Table *table)
833
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
834
Field *tmp_table_field(TABLE *table)
840
836
return tmp_table_field_from_field_type(table, 0);
856
852
return val_decimal_from_date(decimal_value);
858
854
int save_in_field(Field *field,
859
bool no_conversions __attribute__((unused)))
855
bool no_conversions __attribute__((__unused__)))
861
857
return save_date_in_field(field);
868
864
Item_func_makedate(Item *a,Item *b) :Item_date_func(a,b) {}
869
865
String *val_str(String *str);
870
866
const char *func_name() const { return "makedate"; }
871
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
867
enum_field_types field_type() const { return MYSQL_TYPE_NEWDATE; }
872
868
void fix_length_and_dec()
891
887
enum_field_types field_type() const { return cached_field_type; }
892
888
void fix_length_and_dec();
894
Field *tmp_table_field(Table *table)
890
Field *tmp_table_field(TABLE *table)
896
892
return tmp_table_field_from_field_type(table, 0);
901
897
my_decimal *val_decimal(my_decimal *decimal_value)
903
899
assert(fixed == 1);
904
if (cached_field_type == DRIZZLE_TYPE_TIME)
900
if (cached_field_type == MYSQL_TYPE_TIME)
905
901
return val_decimal_from_time(decimal_value);
906
if (cached_field_type == DRIZZLE_TYPE_DATETIME)
902
if (cached_field_type == MYSQL_TYPE_DATETIME)
907
903
return val_decimal_from_date(decimal_value);
908
904
return Item_str_func::val_decimal(decimal_value);
910
906
int save_in_field(Field *field, bool no_conversions)
912
if (cached_field_type == DRIZZLE_TYPE_TIME)
908
if (cached_field_type == MYSQL_TYPE_TIME)
913
909
return save_time_in_field(field);
914
if (cached_field_type == DRIZZLE_TYPE_DATETIME)
910
if (cached_field_type == MYSQL_TYPE_DATETIME)
915
911
return save_date_in_field(field);
916
912
return Item_str_func::save_in_field(field, no_conversions);
982
978
class Item_func_get_format :public Item_str_func
985
const enum enum_drizzle_timestamp_type type; // keep it public
986
Item_func_get_format(enum enum_drizzle_timestamp_type type_arg, Item *a)
981
const timestamp_type type; // keep it public
982
Item_func_get_format(timestamp_type type_arg, Item *a)
987
983
:Item_str_func(a), type(type_arg)
989
985
String *val_str(String *str);
1003
999
enum_field_types cached_field_type;
1004
1000
date_time_format_types cached_format_type;
1005
enum enum_drizzle_timestamp_type cached_timestamp_type;
1001
timestamp_type cached_timestamp_type;
1006
1002
bool const_item;
1008
1004
Item_func_str_to_date(Item *a, Item *b)
1009
1005
:Item_str_func(a, b), const_item(false)
1011
1007
String *val_str(String *str);
1012
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
1008
bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
1013
1009
const char *func_name() const { return "str_to_date"; }
1014
1010
enum_field_types field_type() const { return cached_field_type; }
1015
1011
void fix_length_and_dec();
1016
Field *tmp_table_field(Table *table)
1012
Field *tmp_table_field(TABLE *table)
1018
1014
return tmp_table_field_from_field_type(table, 1);
1026
1022
Item_func_last_day(Item *a) :Item_date(a) {}
1027
1023
const char *func_name() const { return "last_day"; }
1028
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
1024
bool get_date(MYSQL_TIME *res, uint fuzzy_date);