~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_timefunc.h

  • Committer: Brian Aker
  • Date: 2008-07-14 16:24:25 UTC
  • Revision ID: brian@tangent.org-20080714162425-juw3vw221gs9kysh
Cleanup around intptr_t

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 */
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(); }
349
345
    decimals=0;
350
346
    max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
351
347
  }
352
 
  Field *tmp_table_field(Table *table)
 
348
  Field *tmp_table_field(TABLE *table)
353
349
  {
354
350
    return tmp_table_field_from_field_type(table, 0);
355
351
  }
360
356
    return  val_decimal_from_date(decimal_value);
361
357
  }
362
358
  int save_in_field(Field *field,
363
 
                    bool no_conversions __attribute__((unused)))
 
359
                    bool no_conversions __attribute__((__unused__)))
364
360
  {
365
361
    return save_date_in_field(field);
366
362
  }
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)
379
375
  {
380
376
    return tmp_table_field_from_field_type(table, 0);
381
377
  }
387
383
    return  val_decimal_from_date(decimal_value);
388
384
  }
389
385
  int save_in_field(Field *field,
390
 
                    bool no_conversions __attribute__((unused)))
 
386
                    bool no_conversions __attribute__((__unused__)))
391
387
  {
392
388
    return save_date_in_field(field);
393
389
  }
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()
406
402
  {
407
403
    decimals= DATETIME_DEC;
408
404
    max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
409
405
  }
410
 
  Field *tmp_table_field(Table *table)
 
406
  Field *tmp_table_field(TABLE *table)
411
407
  {
412
408
    return tmp_table_field_from_field_type(table, 0);
413
409
  }
418
414
    return  val_decimal_from_time(decimal_value);
419
415
  }
420
416
  int save_in_field(Field *field,
421
 
                    bool no_conversions __attribute__((unused)))
 
417
                    bool no_conversions __attribute__((__unused__)))
422
418
  {
423
419
    return save_time_in_field(field);
424
420
  }
431
427
{
432
428
  int64_t value;
433
429
  char buff[9*2+32];
434
 
  uint32_t buff_length;
 
430
  uint buff_length;
435
431
public:
436
432
  Item_func_curtime() :Item_str_timefunc() {}
437
433
  Item_func_curtime(Item *a) :Item_str_timefunc(a) {}
442
438
  /* 
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.
446
442
  */
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; }
449
445
};
450
446
 
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);
459
455
};
460
456
 
461
457
 
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);
469
465
};
470
466
 
471
467
 
474
470
class Item_func_curdate :public Item_date
475
471
{
476
472
  int64_t value;
477
 
  DRIZZLE_TIME ltime;
 
473
  MYSQL_TIME ltime;
478
474
public:
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;
485
481
};
486
482
 
487
483
 
490
486
public:
491
487
  Item_func_curdate_local() :Item_func_curdate() {}
492
488
  const char *func_name() const { return "curdate"; }
493
 
  void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
489
  void store_now_in_TIME(MYSQL_TIME *now_time);
494
490
};
495
491
 
496
492
 
499
495
public:
500
496
  Item_func_curdate_utc() :Item_func_curdate() {}
501
497
  const char *func_name() const { return "utc_date"; }
502
 
  void store_now_in_TIME(DRIZZLE_TIME *now_time);
 
498
  void store_now_in_TIME(MYSQL_TIME *now_time);
503
499
};
504
500
 
505
501
 
510
506
protected:
511
507
  int64_t value;
512
508
  char buff[20*2+32];   // +32 to make my_snprintf_{8bit|ucs2} happy
513
 
  uint32_t buff_length;
514
 
  DRIZZLE_TIME ltime;
 
509
  uint buff_length;
 
510
  MYSQL_TIME ltime;
515
511
public:
516
512
  Item_func_now() :Item_date_func() {}
517
513
  Item_func_now(Item *a) :Item_date_func(a) {}
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;
525
521
};
526
522
 
527
523
 
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; }
536
532
};
537
533
 
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);
546
542
};
547
543
 
548
544
 
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()
568
564
  {
569
565
    Item_func_now::update_used_tables();
577
573
public:
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);
581
577
};
582
578
 
583
579
 
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;
598
594
};
599
595
 
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);
611
607
};
612
608
 
613
609
 
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);
646
642
  void cleanup();
647
643
};
648
644
 
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);
690
686
};
746
742
class Item_char_typecast :public Item_typecast
747
743
{
748
744
  int cast_length;
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;
752
748
public:
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)
776
772
  {
777
773
    return tmp_table_field_from_field_type(table, 0);
778
774
  }  
791
787
    return  val_decimal_from_date(decimal_value);
792
788
  }
793
789
  int save_in_field(Field *field,
794
 
                    bool no_conversions __attribute__((unused)))
 
790
                    bool no_conversions __attribute__((__unused__)))
795
791
  {
796
792
    return save_date_in_field(field);
797
793
  }
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)
811
807
  {
812
808
    return tmp_table_field_from_field_type(table, 0);
813
809
  }
820
816
    return  val_decimal_from_time(decimal_value);
821
817
  }
822
818
  int save_in_field(Field *field,
823
 
                    bool no_conversions __attribute__((unused)))
 
819
                    bool no_conversions __attribute__((__unused__)))
824
820
  {
825
821
    return save_time_in_field(field);
826
822
  }
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)
839
835
  {
840
836
    return tmp_table_field_from_field_type(table, 0);
841
837
  }
856
852
    return  val_decimal_from_date(decimal_value);
857
853
  }
858
854
  int save_in_field(Field *field,
859
 
                    bool no_conversions __attribute__((unused)))
 
855
                    bool no_conversions __attribute__((__unused__)))
860
856
  {
861
857
    return save_date_in_field(field);
862
858
  }
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()
873
869
  { 
874
870
    decimals=0;
891
887
  enum_field_types field_type() const { return cached_field_type; }
892
888
  void fix_length_and_dec();
893
889
 
894
 
  Field *tmp_table_field(Table *table)
 
890
  Field *tmp_table_field(TABLE *table)
895
891
  {
896
892
    return tmp_table_field_from_field_type(table, 0);
897
893
  }
901
897
  my_decimal *val_decimal(my_decimal *decimal_value)
902
898
  {
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);
909
905
  }
910
906
  int save_in_field(Field *field, bool no_conversions)
911
907
  {
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);
917
913
  }
982
978
class Item_func_get_format :public Item_str_func
983
979
{
984
980
public:
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)
988
984
  {}
989
985
  String *val_str(String *str);
1002
998
{
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;
1007
1003
public:
1008
1004
  Item_func_str_to_date(Item *a, Item *b)
1009
1005
    :Item_str_func(a, b), const_item(false)
1010
1006
  {}
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)
1017
1013
  {
1018
1014
    return tmp_table_field_from_field_type(table, 1);
1019
1015
  }
1025
1021
public:
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);
1029
1025
};