~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_timefunc.h

Renamed strings to mystrings, for include/lib naming consistency.

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
69
69
  }
70
70
  enum_monotonicity_info get_monotonicity_info() const;
71
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; }
74
72
};
75
73
 
76
74
 
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
 
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
 
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
 
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
  }
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)
383
375
  {
384
376
    return tmp_table_field_from_field_type(table, 0);
385
377
  }
411
403
    decimals= DATETIME_DEC;
412
404
    max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
413
405
  }
414
 
  Field *tmp_table_field(Table *table)
 
406
  Field *tmp_table_field(TABLE *table)
415
407
  {
416
408
    return tmp_table_field_from_field_type(table, 0);
417
409
  }
435
427
{
436
428
  int64_t value;
437
429
  char buff[9*2+32];
438
 
  uint32_t buff_length;
 
430
  uint buff_length;
439
431
public:
440
432
  Item_func_curtime() :Item_str_timefunc() {}
441
433
  Item_func_curtime(Item *a) :Item_str_timefunc(a) {}
446
438
  /* 
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.
450
442
  */
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)))
454
 
  { return true; }
455
445
};
456
446
 
457
447
 
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);
465
455
};
466
456
 
467
457
 
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);
475
465
};
476
466
 
477
467
 
480
470
class Item_func_curdate :public Item_date
481
471
{
482
472
  int64_t value;
483
 
  DRIZZLE_TIME ltime;
 
473
  MYSQL_TIME ltime;
484
474
public:
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)))
492
 
  { return true; }
 
479
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
 
480
  virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
493
481
};
494
482
 
495
483
 
498
486
public:
499
487
  Item_func_curdate_local() :Item_func_curdate() {}
500
488
  const char *func_name() const { return "curdate"; }
501
 
  void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
489
  void store_now_in_TIME(MYSQL_TIME *now_time);
502
490
};
503
491
 
504
492
 
507
495
public:
508
496
  Item_func_curdate_utc() :Item_func_curdate() {}
509
497
  const char *func_name() const { return "utc_date"; }
510
 
  void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
498
  void store_now_in_TIME(MYSQL_TIME *now_time);
511
499
};
512
500
 
513
501
 
518
506
protected:
519
507
  int64_t value;
520
508
  char buff[20*2+32];   // +32 to make my_snprintf_{8bit|ucs2} happy
521
 
  uint32_t buff_length;
522
 
  DRIZZLE_TIME ltime;
 
509
  uint buff_length;
 
510
  MYSQL_TIME ltime;
523
511
public:
524
512
  Item_func_now() :Item_date_func() {}
525
513
  Item_func_now(Item *a) :Item_date_func(a) {}
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)))
534
 
  { return true; }
 
519
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
 
520
  virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
535
521
};
536
522
 
537
523
 
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; }
546
532
};
547
533
 
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);
556
542
};
557
543
 
558
544
 
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()
578
564
  {
579
565
    Item_func_now::update_used_tables();
587
573
public:
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)))
592
 
  { return false; }
 
576
  bool get_date(MYSQL_TIME *res, uint fuzzy_date);
593
577
};
594
578
 
595
579
 
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;
610
594
};
611
595
 
612
596
 
613
597
class Item_func_from_unixtime :public Item_date_func
614
598
{
615
 
  Session *session;
 
599
  THD *thd;
616
600
 public:
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);
623
607
};
624
608
 
625
609
 
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);
658
642
  void cleanup();
659
643
};
660
644
 
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);
702
686
};
758
742
class Item_char_typecast :public Item_typecast
759
743
{
760
744
  int cast_length;
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;
764
748
public:
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)
788
772
  {
789
773
    return tmp_table_field_from_field_type(table, 0);
790
774
  }  
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)
823
807
  {
824
808
    return tmp_table_field_from_field_type(table, 0);
825
809
  }
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)
851
835
  {
852
836
    return tmp_table_field_from_field_type(table, 0);
853
837
  }
903
887
  enum_field_types field_type() const { return cached_field_type; }
904
888
  void fix_length_and_dec();
905
889
 
906
 
  Field *tmp_table_field(Table *table)
 
890
  Field *tmp_table_field(TABLE *table)
907
891
  {
908
892
    return tmp_table_field_from_field_type(table, 0);
909
893
  }
994
978
class Item_func_get_format :public Item_str_func
995
979
{
996
980
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)
 
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)
1000
984
  {}
1001
985
  String *val_str(String *str);
1014
998
{
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;
1019
1003
public:
1020
1004
  Item_func_str_to_date(Item *a, Item *b)
1021
1005
    :Item_str_func(a, b), const_item(false)
1022
1006
  {}
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)
1029
1013
  {
1030
1014
    return tmp_table_field_from_field_type(table, 1);
1031
1015
  }
1037
1021
public:
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);
1041
1025
};