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 */
19
#ifdef USE_PRAGMA_INTERFACE
20
#pragma interface /* gcc class implementation */
23
23
enum date_time_format_types
25
25
TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
354
346
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
356
Field *tmp_table_field(Table *table)
348
Field *tmp_table_field(TABLE *table)
358
350
return tmp_table_field_from_field_type(table, 0);
379
371
Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
380
372
Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
381
373
enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
382
Field *tmp_table_field(Table *table)
374
Field *tmp_table_field(TABLE *table)
384
376
return tmp_table_field_from_field_type(table, 0);
411
403
decimals= DATETIME_DEC;
412
404
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
414
Field *tmp_table_field(Table *table)
406
Field *tmp_table_field(TABLE *table)
416
408
return tmp_table_field_from_field_type(table, 0);
447
439
Abstract method that defines which time zone is used for conversion.
448
440
Converts time current time in my_time_t representation to broken-down
449
DRIZZLE_TIME representation using UTC-SYSTEM or per-thread time zone.
441
MYSQL_TIME representation using UTC-SYSTEM or per-thread time zone.
451
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
443
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
452
444
bool result_as_int64_t() { return true; }
453
bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
461
451
Item_func_curtime_local() :Item_func_curtime() {}
462
452
Item_func_curtime_local(Item *a) :Item_func_curtime(a) {}
463
453
const char *func_name() const { return "curtime"; }
464
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
454
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
471
461
Item_func_curtime_utc() :Item_func_curtime() {}
472
462
Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {}
473
463
const char *func_name() const { return "utc_time"; }
474
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
464
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
480
470
class Item_func_curdate :public Item_date
485
475
Item_func_curdate() :Item_date() {}
486
476
int64_t val_int() { assert(fixed == 1); return (value) ; }
487
477
String *val_str(String *str);
488
478
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)))
479
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
480
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
528
516
int save_in_field(Field *to, bool no_conversions);
529
517
String *val_str(String *str);
530
518
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)))
519
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
520
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
541
527
Item_func_now_local() :Item_func_now() {}
542
528
Item_func_now_local(Item *a) :Item_func_now(a) {}
543
529
const char *func_name() const { return "now"; }
544
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
530
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
545
531
virtual enum Functype functype() const { return NOW_FUNC; }
552
538
Item_func_now_utc() :Item_func_now() {}
553
539
Item_func_now_utc(Item *a) :Item_func_now(a) {}
554
540
const char *func_name() const { return "utc_timestamp"; }
555
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
541
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
567
553
Item_func_sysdate_local(Item *a) :Item_func_now(a) {}
568
554
bool const_item() const { return 0; }
569
555
const char *func_name() const { return "sysdate"; }
570
void store_now_in_TIME(DRIZZLE_TIME *now_time);
556
void store_now_in_TIME(MYSQL_TIME *now_time);
571
557
double val_real();
572
558
int64_t val_int();
573
559
int save_in_field(Field *to, bool no_conversions);
574
560
String *val_str(String *str);
575
561
void fix_length_and_dec();
576
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
562
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
577
563
void update_used_tables()
579
565
Item_func_now::update_used_tables();
588
574
Item_func_from_days(Item *a) :Item_date(a) {}
589
575
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)))
576
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
605
589
const char *func_name() const
606
590
{ return is_time_format ? "time_format" : "date_format"; }
607
591
void fix_length_and_dec();
608
uint32_t format_length(const String *format);
592
uint format_length(const String *format);
609
593
bool eq(const Item *item, bool binary_cmp) const;
613
597
class Item_func_from_unixtime :public Item_date_func
617
601
Item_func_from_unixtime(Item *a) :Item_date_func(a) {}
618
602
int64_t val_int();
619
603
String *val_str(String *str);
620
604
const char *func_name() const { return "from_unixtime"; }
621
605
void fix_length_and_dec();
622
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
606
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
654
638
String *val_str(String *str);
655
639
const char *func_name() const { return "convert_tz"; }
656
640
void fix_length_and_dec();
657
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
641
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
696
680
void fix_length_and_dec();
697
681
enum_field_types field_type() const { return cached_field_type; }
698
682
int64_t val_int();
699
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
683
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
700
684
bool eq(const Item *item, bool binary_cmp) const;
701
685
virtual void print(String *str, enum_query_type query_type);
758
742
class Item_char_typecast :public Item_typecast
761
const CHARSET_INFO *cast_cs, *from_cs;
745
CHARSET_INFO *cast_cs, *from_cs;
762
746
bool charset_conversion;
763
747
String tmp_value;
765
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)
766
750
:Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
767
751
enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
768
752
bool eq(const Item *item, bool binary_cmp) const;
780
764
Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
781
765
const char *func_name() const { return "cast_as_date"; }
782
766
String *val_str(String *str);
783
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
784
bool get_time(DRIZZLE_TIME *ltime);
767
bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
768
bool get_time(MYSQL_TIME *ltime);
785
769
const char *cast_type() const { return "date"; }
786
770
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
787
Field *tmp_table_field(Table *table)
771
Field *tmp_table_field(TABLE *table)
789
773
return tmp_table_field_from_field_type(table, 0);
816
800
Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
817
801
const char *func_name() const { return "cast_as_time"; }
818
802
String *val_str(String *str);
819
bool get_time(DRIZZLE_TIME *ltime);
803
bool get_time(MYSQL_TIME *ltime);
820
804
const char *cast_type() const { return "time"; }
821
805
enum_field_types field_type() const { return DRIZZLE_TYPE_TIME; }
822
Field *tmp_table_field(Table *table)
806
Field *tmp_table_field(TABLE *table)
824
808
return tmp_table_field_from_field_type(table, 0);
847
831
String *val_str(String *str);
848
832
const char *cast_type() const { return "datetime"; }
849
833
enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
850
Field *tmp_table_field(Table *table)
834
Field *tmp_table_field(TABLE *table)
852
836
return tmp_table_field_from_field_type(table, 0);
903
887
enum_field_types field_type() const { return cached_field_type; }
904
888
void fix_length_and_dec();
906
Field *tmp_table_field(Table *table)
890
Field *tmp_table_field(TABLE *table)
908
892
return tmp_table_field_from_field_type(table, 0);
994
978
class Item_func_get_format :public Item_str_func
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)
981
const timestamp_type type; // keep it public
982
Item_func_get_format(timestamp_type type_arg, Item *a)
999
983
:Item_str_func(a), type(type_arg)
1001
985
String *val_str(String *str);
1015
999
enum_field_types cached_field_type;
1016
1000
date_time_format_types cached_format_type;
1017
enum enum_drizzle_timestamp_type cached_timestamp_type;
1001
timestamp_type cached_timestamp_type;
1018
1002
bool const_item;
1020
1004
Item_func_str_to_date(Item *a, Item *b)
1021
1005
:Item_str_func(a, b), const_item(false)
1023
1007
String *val_str(String *str);
1024
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
1008
bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
1025
1009
const char *func_name() const { return "str_to_date"; }
1026
1010
enum_field_types field_type() const { return cached_field_type; }
1027
1011
void fix_length_and_dec();
1028
Field *tmp_table_field(Table *table)
1012
Field *tmp_table_field(TABLE *table)
1030
1014
return tmp_table_field_from_field_type(table, 1);
1038
1022
Item_func_last_day(Item *a) :Item_date(a) {}
1039
1023
const char *func_name() const { return "last_day"; }
1040
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
1024
bool get_date(MYSQL_TIME *res, uint fuzzy_date);