~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_timefunc.cc

  • Committer: Monty Taylor
  • Date: 2008-07-15 21:40:58 UTC
  • mfrom: (77.1.113 codestyle32)
  • mto: This revision was merged to the branch mainline in revision 176.
  • Revision ID: mordred@camelot-20080715214058-rm3phulldos9xehv
Merged from codestyle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  @todo
24
24
    Move month and days to language files
25
25
*/
26
 
#include <drizzled/server_includes.h>
 
26
 
 
27
#ifdef USE_PRAGMA_IMPLEMENTATION
 
28
#pragma implementation                          // gcc: Class implementation
 
29
#endif
 
30
 
 
31
#include "mysql_priv.h"
 
32
#include <m_ctype.h>
27
33
#include <time.h>
28
 
#include <drizzled/drizzled_error_messages.h>
29
34
 
30
35
/** Day number for Dec 31st, 9999. */
31
36
#define MAX_DAY_NUMBER 3652424L
48
53
  the microseconds twice.
49
54
*/
50
55
 
51
 
static bool make_datetime(date_time_format_types format, DRIZZLE_TIME *ltime,
 
56
static bool make_datetime(date_time_format_types format, MYSQL_TIME *ltime,
52
57
                          String *str)
53
58
{
54
59
  char *buff;
55
 
  const CHARSET_INFO * const cs= &my_charset_bin;
56
 
  uint32_t length= MAX_DATE_STRING_REP_LENGTH;
 
60
  CHARSET_INFO *cs= &my_charset_bin;
 
61
  uint length= MAX_DATE_STRING_REP_LENGTH;
57
62
 
58
63
  if (str->alloc(length))
59
64
    return 1;
97
102
 
98
103
 
99
104
/*
100
 
  Wrapper over make_datetime() with validation of the input DRIZZLE_TIME value
 
105
  Wrapper over make_datetime() with validation of the input MYSQL_TIME value
101
106
 
102
107
  NOTE
103
108
    see make_datetime() for more information
107
112
    0    otherwise
108
113
*/
109
114
 
110
 
static bool make_datetime_with_warn(date_time_format_types format, DRIZZLE_TIME *ltime,
 
115
static bool make_datetime_with_warn(date_time_format_types format, MYSQL_TIME *ltime,
111
116
                                    String *str)
112
117
{
113
118
  int warning= 0;
119
124
  if (!warning)
120
125
    return 0;
121
126
 
122
 
  make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
127
  make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
123
128
                               str->ptr(), str->length(),
124
 
                               DRIZZLE_TIMESTAMP_TIME, NULL);
 
129
                               MYSQL_TIMESTAMP_TIME, NullS);
125
130
  return make_datetime(format, ltime, str);
126
131
}
127
132
 
128
133
 
129
134
/*
130
 
  Wrapper over make_time() with validation of the input DRIZZLE_TIME value
 
135
  Wrapper over make_time() with validation of the input MYSQL_TIME value
131
136
 
132
137
  NOTE
133
138
    see make_time() for more info
138
143
*/
139
144
 
140
145
static bool make_time_with_warn(const DATE_TIME_FORMAT *format,
141
 
                                DRIZZLE_TIME *l_time, String *str)
 
146
                                MYSQL_TIME *l_time, String *str)
142
147
{
143
148
  int warning= 0;
144
149
  make_time(format, l_time, str);
146
151
    return 1;
147
152
  if (warning)
148
153
  {
149
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
154
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
150
155
                                 str->ptr(), str->length(),
151
 
                                 DRIZZLE_TIMESTAMP_TIME, NULL);
 
156
                                 MYSQL_TIMESTAMP_TIME, NullS);
152
157
    make_time(format, l_time, str);
153
158
  }
154
159
 
157
162
 
158
163
 
159
164
/*
160
 
  Convert seconds to DRIZZLE_TIME value with overflow checking
 
165
  Convert seconds to MYSQL_TIME value with overflow checking
161
166
 
162
167
  SYNOPSIS:
163
168
    sec_to_time()
164
169
    seconds          number of seconds
165
170
    unsigned_flag    1, if 'seconds' is unsigned, 0, otherwise
166
 
    ltime            output DRIZZLE_TIME value
 
171
    ltime            output MYSQL_TIME value
167
172
 
168
173
  DESCRIPTION
169
 
    If the 'seconds' argument is inside DRIZZLE_TIME data range, convert it to a
 
174
    If the 'seconds' argument is inside MYSQL_TIME data range, convert it to a
170
175
    corresponding value.
171
176
    Otherwise, truncate the resulting value to the nearest endpoint, and
172
177
    produce a warning message.
176
181
    0                otherwise
177
182
*/
178
183
  
179
 
static bool sec_to_time(int64_t seconds, bool unsigned_flag, DRIZZLE_TIME *ltime)
 
184
static bool sec_to_time(int64_t seconds, bool unsigned_flag, MYSQL_TIME *ltime)
180
185
{
181
 
  uint32_t sec;
 
186
  uint sec;
182
187
 
183
 
  memset(ltime, 0, sizeof(*ltime));
 
188
  bzero((char *)ltime, sizeof(*ltime));
184
189
  
185
190
  if (seconds < 0)
186
191
  {
 
192
    if (unsigned_flag)
 
193
      goto overflow;
187
194
    ltime->neg= 1;
188
195
    if (seconds < -3020399)
189
196
      goto overflow;
207
214
  char buf[22];
208
215
  int len= (int)(int64_t10_to_str(seconds, buf, unsigned_flag ? 10 : -10)
209
216
                 - buf);
210
 
  make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
211
 
                               buf, len, DRIZZLE_TIMESTAMP_TIME,
212
 
                               NULL);
 
217
  make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
218
                               buf, len, MYSQL_TIMESTAMP_TIME,
 
219
                               NullS);
213
220
  
214
221
  return 1;
215
222
}
227
234
                                            {(char *)"%H:%i:%S", 8}};
228
235
 
229
236
/**
230
 
  Extract datetime value to DRIZZLE_TIME struct from string value
 
237
  Extract datetime value to MYSQL_TIME struct from string value
231
238
  according to format string.
232
239
 
233
240
  @param format         date/time format specification
260
267
*/
261
268
 
262
269
static bool extract_date_time(DATE_TIME_FORMAT *format,
263
 
                              const char *val, uint32_t length, DRIZZLE_TIME *l_time,
264
 
                              enum enum_drizzle_timestamp_type cached_timestamp_type,
 
270
                              const char *val, uint length, MYSQL_TIME *l_time,
 
271
                              timestamp_type cached_timestamp_type,
265
272
                              const char **sub_pattern_end,
266
273
                              const char *date_time_type)
267
274
{
278
285
  const char *val_end= val + length;
279
286
  const char *ptr= format->format.str;
280
287
  const char *end= ptr + format->format.length;
281
 
  const CHARSET_INFO * const cs= &my_charset_bin;
 
288
  CHARSET_INFO *cs= &my_charset_bin;
282
289
 
283
290
  if (!sub_pattern_end)
284
 
    memset(l_time, 0, sizeof(*l_time));
 
291
    bzero((char*) l_time, sizeof(*l_time));
285
292
 
286
293
  for (; ptr != end && val != val_end; ptr++)
287
294
  {
300
307
      switch (*++ptr) {
301
308
        /* Year */
302
309
      case 'Y':
303
 
        tmp= (char*) val + cmin(4, val_len);
 
310
        tmp= (char*) val + min(4, val_len);
304
311
        l_time->year= (int) my_strtoll10(val, &tmp, &error);
305
312
        if ((int) (tmp-val) <= 2)
306
313
          l_time->year= year_2000_handling(l_time->year);
307
314
        val= tmp;
308
315
        break;
309
316
      case 'y':
310
 
        tmp= (char*) val + cmin(2, val_len);
 
317
        tmp= (char*) val + min(2, val_len);
311
318
        l_time->year= (int) my_strtoll10(val, &tmp, &error);
312
319
        val= tmp;
313
320
        l_time->year= year_2000_handling(l_time->year);
316
323
        /* Month */
317
324
      case 'm':
318
325
      case 'c':
319
 
        tmp= (char*) val + cmin(2, val_len);
 
326
        tmp= (char*) val + min(2, val_len);
320
327
        l_time->month= (int) my_strtoll10(val, &tmp, &error);
321
328
        val= tmp;
322
329
        break;
333
340
        /* Day */
334
341
      case 'd':
335
342
      case 'e':
336
 
        tmp= (char*) val + cmin(2, val_len);
 
343
        tmp= (char*) val + min(2, val_len);
337
344
        l_time->day= (int) my_strtoll10(val, &tmp, &error);
338
345
        val= tmp;
339
346
        break;
340
347
      case 'D':
341
 
        tmp= (char*) val + cmin(2, val_len);
 
348
        tmp= (char*) val + min(2, val_len);
342
349
        l_time->day= (int) my_strtoll10(val, &tmp, &error);
343
350
        /* Skip 'st, 'nd, 'th .. */
344
 
        val= tmp + cmin((int) (val_end-tmp), 2);
 
351
        val= tmp + min((int) (val_end-tmp), 2);
345
352
        break;
346
353
 
347
354
        /* Hour */
352
359
        /* fall through */
353
360
      case 'k':
354
361
      case 'H':
355
 
        tmp= (char*) val + cmin(2, val_len);
 
362
        tmp= (char*) val + min(2, val_len);
356
363
        l_time->hour= (int) my_strtoll10(val, &tmp, &error);
357
364
        val= tmp;
358
365
        break;
359
366
 
360
367
        /* Minute */
361
368
      case 'i':
362
 
        tmp= (char*) val + cmin(2, val_len);
 
369
        tmp= (char*) val + min(2, val_len);
363
370
        l_time->minute= (int) my_strtoll10(val, &tmp, &error);
364
371
        val= tmp;
365
372
        break;
367
374
        /* Second */
368
375
      case 's':
369
376
      case 'S':
370
 
        tmp= (char*) val + cmin(2, val_len);
 
377
        tmp= (char*) val + min(2, val_len);
371
378
        l_time->second= (int) my_strtoll10(val, &tmp, &error);
372
379
        val= tmp;
373
380
        break;
388
395
      case 'p':
389
396
        if (val_len < 2 || ! usa_time)
390
397
          goto err;
391
 
        if (!my_strnncoll(&my_charset_utf8_general_ci,
392
 
                          (const unsigned char *) val, 2, 
393
 
                          (const unsigned char *) "PM", 2))
 
398
        if (!my_strnncoll(&my_charset_latin1,
 
399
                          (const uchar *) val, 2, 
 
400
                          (const uchar *) "PM", 2))
394
401
          daypart= 12;
395
 
        else if (my_strnncoll(&my_charset_utf8_general_ci,
396
 
                              (const unsigned char *) val, 2, 
397
 
                              (const unsigned char *) "AM", 2))
 
402
        else if (my_strnncoll(&my_charset_latin1,
 
403
                              (const uchar *) val, 2, 
 
404
                              (const uchar *) "AM", 2))
398
405
          goto err;
399
406
        val+= 2;
400
407
        break;
419
426
        val= tmp;
420
427
        break;
421
428
      case 'j':
422
 
        tmp= (char*) val + cmin(val_len, 3);
 
429
        tmp= (char*) val + min(val_len, 3);
423
430
        yearday= (int) my_strtoll10(val, &tmp, &error);
424
431
        val= tmp;
425
432
        break;
431
438
      case 'u':
432
439
        sunday_first_n_first_week_non_iso= (*ptr=='U' || *ptr== 'V');
433
440
        strict_week_number= (*ptr=='V' || *ptr=='v');
434
 
        tmp= (char*) val + cmin(val_len, 2);
 
441
        tmp= (char*) val + min(val_len, 2);
435
442
        if ((week_number= (int) my_strtoll10(val, &tmp, &error)) < 0 ||
436
443
            (strict_week_number && !week_number) ||
437
444
            week_number > 53)
443
450
      case 'X':
444
451
      case 'x':
445
452
        strict_week_number_year_type= (*ptr=='X');
446
 
        tmp= (char*) val + cmin(4, val_len);
 
453
        tmp= (char*) val + min(4, val_len);
447
454
        strict_week_number_year= (int) my_strtoll10(val, &tmp, &error);
448
455
        val= tmp;
449
456
        break;
513
520
 
514
521
  if (yearday > 0)
515
522
  {
516
 
    uint32_t days;
 
523
    uint days;
517
524
    days= calc_daynr(l_time->year,1,1) +  yearday - 1;
518
525
    if (days <= 0 || days > MAX_DAY_NUMBER)
519
526
      goto err;
523
530
  if (week_number >= 0 && weekday)
524
531
  {
525
532
    int days;
526
 
    uint32_t weekday_b;
 
533
    uint weekday_b;
527
534
 
528
535
    /*
529
536
      %V,%v require %X,%x resprectively,
573
580
  {
574
581
    do
575
582
    {
576
 
      if (!my_isspace(&my_charset_utf8_general_ci,*val))
 
583
      if (!my_isspace(&my_charset_latin1,*val))
577
584
      {
578
 
        make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
585
        make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
579
586
                                     val_begin, length,
580
 
                                     cached_timestamp_type, NULL);
 
587
                                     cached_timestamp_type, NullS);
581
588
        break;
582
589
      }
583
590
    } while (++val != val_end);
587
594
err:
588
595
  {
589
596
    char buff[128];
590
 
    strmake(buff, val_begin, cmin(length, (uint)sizeof(buff)-1));
591
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
597
    strmake(buff, val_begin, min(length, sizeof(buff)-1));
 
598
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
592
599
                        ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
593
600
                        date_time_type, buff, "str_to_date");
594
601
  }
600
607
  Create a formated date/time value in a string.
601
608
*/
602
609
 
603
 
bool make_date_time(DATE_TIME_FORMAT *format, DRIZZLE_TIME *l_time,
604
 
                    enum enum_drizzle_timestamp_type type, String *str)
 
610
bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
 
611
                    timestamp_type type, String *str)
605
612
{
606
613
  char intbuff[15];
607
 
  uint32_t hours_i;
608
 
  uint32_t weekday;
 
614
  uint hours_i;
 
615
  uint weekday;
609
616
  ulong length;
610
617
  const char *ptr, *end;
611
618
  THD *thd= current_thd;
639
646
                    system_charset_info);
640
647
        break;
641
648
      case 'W':
642
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
649
        if (type == MYSQL_TIMESTAMP_TIME)
643
650
          return 1;
644
651
        weekday= calc_weekday(calc_daynr(l_time->year,l_time->month,
645
652
                              l_time->day),0);
648
655
                    system_charset_info);
649
656
        break;
650
657
      case 'a':
651
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
658
        if (type == MYSQL_TIMESTAMP_TIME)
652
659
          return 1;
653
660
        weekday=calc_weekday(calc_daynr(l_time->year,l_time->month,
654
661
                             l_time->day),0);
657
664
                    system_charset_info);
658
665
        break;
659
666
      case 'D':
660
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
667
        if (type == MYSQL_TIMESTAMP_TIME)
661
668
          return 1;
662
669
        length= int10_to_str(l_time->day, intbuff, 10) - intbuff;
663
670
        str->append_with_prefill(intbuff, length, 1, '0');
724
731
        str->append_with_prefill(intbuff, length, 2, '0');
725
732
        break;
726
733
      case 'j':
727
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
734
        if (type == MYSQL_TIMESTAMP_TIME)
728
735
          return 1;
729
736
        length= int10_to_str(calc_daynr(l_time->year,l_time->month,
730
737
                                        l_time->day) - 
745
752
        str->append(hours_i < 12 ? "AM" : "PM",2);
746
753
        break;
747
754
      case 'r':
748
 
        length= sprintf(intbuff, 
 
755
        length= my_sprintf(intbuff, 
 
756
                   (intbuff, 
749
757
                    ((l_time->hour % 24) < 12) ?
750
758
                    "%02d:%02d:%02d AM" : "%02d:%02d:%02d PM",
751
759
                    (l_time->hour+11)%12+1,
752
760
                    l_time->minute,
753
 
                    l_time->second);
 
761
                    l_time->second));
754
762
        str->append(intbuff, length);
755
763
        break;
756
764
      case 'S':
759
767
        str->append_with_prefill(intbuff, length, 2, '0');
760
768
        break;
761
769
      case 'T':
762
 
        length= sprintf(intbuff, 
 
770
        length= my_sprintf(intbuff, 
 
771
                   (intbuff, 
763
772
                    "%02d:%02d:%02d", 
764
773
                    l_time->hour, 
765
774
                    l_time->minute,
766
 
                    l_time->second);
 
775
                    l_time->second));
767
776
        str->append(intbuff, length);
768
777
        break;
769
778
      case 'U':
770
779
      case 'u':
771
780
      {
772
 
        uint32_t year;
773
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
781
        uint year;
 
782
        if (type == MYSQL_TIMESTAMP_TIME)
774
783
          return 1;
775
784
        length= int10_to_str(calc_week(l_time,
776
785
                                       (*ptr) == 'U' ?
783
792
      case 'v':
784
793
      case 'V':
785
794
      {
786
 
        uint32_t year;
787
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
795
        uint year;
 
796
        if (type == MYSQL_TIMESTAMP_TIME)
788
797
          return 1;
789
798
        length= int10_to_str(calc_week(l_time,
790
799
                                       ((*ptr) == 'V' ?
798
807
      case 'x':
799
808
      case 'X':
800
809
      {
801
 
        uint32_t year;
802
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
810
        uint year;
 
811
        if (type == MYSQL_TIMESTAMP_TIME)
803
812
          return 1;
804
813
        (void) calc_week(l_time,
805
814
                         ((*ptr) == 'X' ?
811
820
      }
812
821
      break;
813
822
      case 'w':
814
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
823
        if (type == MYSQL_TIMESTAMP_TIME)
815
824
          return 1;
816
825
        weekday=calc_weekday(calc_daynr(l_time->year,l_time->month,
817
826
                                        l_time->day),1);
848
857
                         For example, '1.1' -> '1.100000'
849
858
*/
850
859
 
851
 
static bool get_interval_info(const char *str,uint32_t length, const CHARSET_INFO * const cs,
852
 
                              uint32_t count, uint64_t *values,
 
860
static bool get_interval_info(const char *str,uint length,CHARSET_INFO *cs,
 
861
                              uint count, uint64_t *values,
853
862
                              bool transform_msec)
854
863
{
855
864
  const char *end=str+length;
856
 
  uint32_t i;
 
865
  uint i;
857
866
  while (str != end && !my_isdigit(cs,*str))
858
867
    str++;
859
868
 
862
871
    int64_t value;
863
872
    const char *start= str;
864
873
    for (value=0; str != end && my_isdigit(cs,*str) ; str++)
865
 
      value= value * 10L + (int64_t) (*str - '0');
 
874
      value= value * 10LL + (int64_t) (*str - '0');
866
875
    if (transform_msec && i == count - 1) // microseconds always last
867
876
    {
868
877
      long msec_length= 6 - (str - start);
876
885
    {
877
886
      i++;
878
887
      /* Change values[0...i-1] -> values[0...count-1] */
879
 
      bmove_upp((unsigned char*) (values+count), (unsigned char*) (values+i),
 
888
      bmove_upp((uchar*) (values+count), (uchar*) (values+i),
880
889
                sizeof(*values)*i);
881
 
      memset(values, 0, sizeof(*values)*(count-i));
 
890
      bzero((uchar*) values, sizeof(*values)*(count-i));
882
891
      break;
883
892
    }
884
893
  }
918
927
int64_t Item_func_to_days::val_int()
919
928
{
920
929
  assert(fixed == 1);
921
 
  DRIZZLE_TIME ltime;
 
930
  MYSQL_TIME ltime;
922
931
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
923
932
    return 0;
924
933
  return (int64_t) calc_daynr(ltime.year,ltime.month,ltime.day);
943
952
{
944
953
  if (args[0]->type() == Item::FIELD_ITEM)
945
954
  {
946
 
    if (args[0]->field_type() == DRIZZLE_TYPE_NEWDATE)
 
955
    if (args[0]->field_type() == MYSQL_TYPE_NEWDATE)
947
956
      return MONOTONIC_STRICT_INCREASING;
948
 
    if (args[0]->field_type() == DRIZZLE_TYPE_DATETIME)
 
957
    if (args[0]->field_type() == MYSQL_TYPE_DATETIME)
949
958
      return MONOTONIC_INCREASING;
950
959
  }
951
960
  return NON_MONOTONIC;
955
964
int64_t Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp)
956
965
{
957
966
  assert(fixed == 1);
958
 
  DRIZZLE_TIME ltime;
 
967
  MYSQL_TIME ltime;
959
968
  int64_t res;
960
969
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
961
970
  {
964
973
  }
965
974
  res=(int64_t) calc_daynr(ltime.year,ltime.month,ltime.day);
966
975
  
967
 
  if (args[0]->field_type() == DRIZZLE_TYPE_NEWDATE)
 
976
  if (args[0]->field_type() == MYSQL_TYPE_NEWDATE)
968
977
  {
969
978
    // TO_DAYS() is strictly monotonic for dates, leave incl_endp intact
970
979
    return res;
993
1002
int64_t Item_func_dayofyear::val_int()
994
1003
{
995
1004
  assert(fixed == 1);
996
 
  DRIZZLE_TIME ltime;
 
1005
  MYSQL_TIME ltime;
997
1006
  if (get_arg0_date(&ltime,TIME_NO_ZERO_DATE))
998
1007
    return 0;
999
1008
  return (int64_t) calc_daynr(ltime.year,ltime.month,ltime.day) -
1003
1012
int64_t Item_func_dayofmonth::val_int()
1004
1013
{
1005
1014
  assert(fixed == 1);
1006
 
  DRIZZLE_TIME ltime;
 
1015
  MYSQL_TIME ltime;
1007
1016
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1008
1017
  return (int64_t) ltime.day;
1009
1018
}
1011
1020
int64_t Item_func_month::val_int()
1012
1021
{
1013
1022
  assert(fixed == 1);
1014
 
  DRIZZLE_TIME ltime;
 
1023
  MYSQL_TIME ltime;
1015
1024
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1016
1025
  return (int64_t) ltime.month;
1017
1026
}
1021
1030
{
1022
1031
  assert(fixed == 1);
1023
1032
  const char *month_name;
1024
 
  uint32_t   month= (uint) val_int();
 
1033
  uint   month= (uint) val_int();
1025
1034
  THD *thd= current_thd;
1026
1035
 
1027
1036
  if (null_value || !month)
1043
1052
int64_t Item_func_quarter::val_int()
1044
1053
{
1045
1054
  assert(fixed == 1);
1046
 
  DRIZZLE_TIME ltime;
 
1055
  MYSQL_TIME ltime;
1047
1056
  if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
1048
1057
    return 0;
1049
1058
  return (int64_t) ((ltime.month+2)/3);
1052
1061
int64_t Item_func_hour::val_int()
1053
1062
{
1054
1063
  assert(fixed == 1);
1055
 
  DRIZZLE_TIME ltime;
 
1064
  MYSQL_TIME ltime;
1056
1065
  (void) get_arg0_time(&ltime);
1057
1066
  return ltime.hour;
1058
1067
}
1060
1069
int64_t Item_func_minute::val_int()
1061
1070
{
1062
1071
  assert(fixed == 1);
1063
 
  DRIZZLE_TIME ltime;
 
1072
  MYSQL_TIME ltime;
1064
1073
  (void) get_arg0_time(&ltime);
1065
1074
  return ltime.minute;
1066
1075
}
1071
1080
int64_t Item_func_second::val_int()
1072
1081
{
1073
1082
  assert(fixed == 1);
1074
 
  DRIZZLE_TIME ltime;
 
1083
  MYSQL_TIME ltime;
1075
1084
  (void) get_arg0_time(&ltime);
1076
1085
  return ltime.second;
1077
1086
}
1078
1087
 
1079
1088
 
1080
 
uint32_t week_mode(uint32_t mode)
 
1089
uint week_mode(uint mode)
1081
1090
{
1082
 
  uint32_t week_format= (mode & 7);
 
1091
  uint week_format= (mode & 7);
1083
1092
  if (!(week_format & WEEK_MONDAY_FIRST))
1084
1093
    week_format^= WEEK_FIRST_WEEKDAY;
1085
1094
  return week_format;
1119
1128
int64_t Item_func_week::val_int()
1120
1129
{
1121
1130
  assert(fixed == 1);
1122
 
  uint32_t year;
1123
 
  DRIZZLE_TIME ltime;
 
1131
  uint year;
 
1132
  MYSQL_TIME ltime;
1124
1133
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1125
1134
    return 0;
1126
1135
  return (int64_t) calc_week(&ltime,
1132
1141
int64_t Item_func_yearweek::val_int()
1133
1142
{
1134
1143
  assert(fixed == 1);
1135
 
  uint32_t year,week;
1136
 
  DRIZZLE_TIME ltime;
 
1144
  uint year,week;
 
1145
  MYSQL_TIME ltime;
1137
1146
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1138
1147
    return 0;
1139
1148
  week= calc_week(&ltime, 
1146
1155
int64_t Item_func_weekday::val_int()
1147
1156
{
1148
1157
  assert(fixed == 1);
1149
 
  DRIZZLE_TIME ltime;
 
1158
  MYSQL_TIME ltime;
1150
1159
  
1151
1160
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1152
1161
    return 0;
1160
1169
String* Item_func_dayname::val_str(String* str)
1161
1170
{
1162
1171
  assert(fixed == 1);
1163
 
  uint32_t weekday=(uint) val_int();            // Always Item_func_daynr()
 
1172
  uint weekday=(uint) val_int();                // Always Item_func_daynr()
1164
1173
  const char *day_name;
1165
1174
  THD *thd= current_thd;
1166
1175
 
1176
1185
int64_t Item_func_year::val_int()
1177
1186
{
1178
1187
  assert(fixed == 1);
1179
 
  DRIZZLE_TIME ltime;
 
1188
  MYSQL_TIME ltime;
1180
1189
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1181
1190
  return (int64_t) ltime.year;
1182
1191
}
1199
1208
enum_monotonicity_info Item_func_year::get_monotonicity_info() const
1200
1209
{
1201
1210
  if (args[0]->type() == Item::FIELD_ITEM &&
1202
 
      (args[0]->field_type() == DRIZZLE_TYPE_NEWDATE ||
1203
 
       args[0]->field_type() == DRIZZLE_TYPE_DATETIME))
 
1211
      (args[0]->field_type() == MYSQL_TYPE_NEWDATE ||
 
1212
       args[0]->field_type() == MYSQL_TYPE_DATETIME))
1204
1213
    return MONOTONIC_INCREASING;
1205
1214
  return NON_MONOTONIC;
1206
1215
}
1209
1218
int64_t Item_func_year::val_int_endpoint(bool left_endp, bool *incl_endp)
1210
1219
{
1211
1220
  assert(fixed == 1);
1212
 
  DRIZZLE_TIME ltime;
 
1221
  MYSQL_TIME ltime;
1213
1222
  if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
1214
1223
  {
1215
1224
    /* got NULL, leave the incl_endp intact */
1238
1247
 
1239
1248
int64_t Item_func_unix_timestamp::val_int()
1240
1249
{
1241
 
  DRIZZLE_TIME ltime;
 
1250
  MYSQL_TIME ltime;
1242
1251
  bool not_used;
1243
1252
  
1244
1253
  assert(fixed == 1);
1247
1256
  if (args[0]->type() == FIELD_ITEM)
1248
1257
  {                                             // Optimize timestamp field
1249
1258
    Field *field=((Item_field*) args[0])->field;
1250
 
    if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
 
1259
    if (field->type() == MYSQL_TYPE_TIMESTAMP)
1251
1260
      return ((Field_timestamp*) field)->get_timestamp(&null_value);
1252
1261
  }
1253
1262
  
1269
1278
int64_t Item_func_time_to_sec::val_int()
1270
1279
{
1271
1280
  assert(fixed == 1);
1272
 
  DRIZZLE_TIME ltime;
 
1281
  MYSQL_TIME ltime;
1273
1282
  int64_t seconds;
1274
1283
  (void) get_arg0_time(&ltime);
1275
1284
  seconds=ltime.hour*3600L+ltime.minute*60+ltime.second;
1290
1299
  int64_t value= 0;
1291
1300
  const char *str= NULL;
1292
1301
  size_t length= 0;
1293
 
  const CHARSET_INFO * const cs= str_value->charset();
 
1302
  CHARSET_INFO *cs=str_value->charset();
1294
1303
 
1295
 
  memset(interval, 0, sizeof(*interval));
 
1304
  bzero((char*) interval,sizeof(*interval));
1296
1305
  if ((int) int_type <= INTERVAL_MICROSECOND)
1297
1306
  {
1298
1307
    value= args->val_int();
1438
1447
String *Item_date::val_str(String *str)
1439
1448
{
1440
1449
  assert(fixed == 1);
1441
 
  DRIZZLE_TIME ltime;
 
1450
  MYSQL_TIME ltime;
1442
1451
  if (get_date(&ltime, TIME_FUZZY_DATE))
1443
1452
    return (String *) 0;
1444
1453
  if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
1454
1463
int64_t Item_date::val_int()
1455
1464
{
1456
1465
  assert(fixed == 1);
1457
 
  DRIZZLE_TIME ltime;
 
1466
  MYSQL_TIME ltime;
1458
1467
  if (get_date(&ltime, TIME_FUZZY_DATE))
1459
1468
    return 0;
1460
1469
  return (int64_t) (ltime.year*10000L+ltime.month*100+ltime.day);
1461
1470
}
1462
1471
 
1463
1472
 
1464
 
bool Item_func_from_days::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
1473
bool Item_func_from_days::get_date(MYSQL_TIME *ltime, uint fuzzy_date __attribute__((__unused__)))
1465
1474
{
1466
1475
  int64_t value=args[0]->val_int();
1467
1476
  if ((null_value=args[0]->null_value))
1468
1477
    return 1;
1469
 
  memset(ltime, 0, sizeof(DRIZZLE_TIME));
 
1478
  bzero(ltime, sizeof(MYSQL_TIME));
1470
1479
  get_date_from_daynr((long) value, &ltime->year, &ltime->month, &ltime->day);
1471
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
1480
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
1472
1481
  return 0;
1473
1482
}
1474
1483
 
1483
1492
  
1484
1493
  /* We don't need to set second_part and neg because they already 0 */
1485
1494
  ltime.hour= ltime.minute= ltime.second= 0;
1486
 
  ltime.time_type= DRIZZLE_TIMESTAMP_DATE;
 
1495
  ltime.time_type= MYSQL_TIMESTAMP_DATE;
1487
1496
  value= (int64_t) TIME_to_uint64_t_date(&ltime);
1488
1497
}
1489
1498
 
1500
1509
}
1501
1510
 
1502
1511
/**
1503
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1512
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1504
1513
    time zone. Defines time zone (local) used for whole CURDATE function.
1505
1514
*/
1506
 
void Item_func_curdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1515
void Item_func_curdate_local::store_now_in_TIME(MYSQL_TIME *now_time)
1507
1516
{
1508
1517
  THD *thd= current_thd;
1509
1518
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1513
1522
 
1514
1523
 
1515
1524
/**
1516
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
1525
    Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
1517
1526
    time zone. Defines time zone (UTC) used for whole UTC_DATE function.
1518
1527
*/
1519
 
void Item_func_curdate_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1528
void Item_func_curdate_utc::store_now_in_TIME(MYSQL_TIME *now_time)
1520
1529
{
1521
1530
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1522
1531
                             (my_time_t)(current_thd->query_start()));
1527
1536
}
1528
1537
 
1529
1538
 
1530
 
bool Item_func_curdate::get_date(DRIZZLE_TIME *res,
1531
 
                                 uint32_t fuzzy_date __attribute__((unused)))
 
1539
bool Item_func_curdate::get_date(MYSQL_TIME *res,
 
1540
                                 uint fuzzy_date __attribute__((unused)))
1532
1541
{
1533
1542
  *res=ltime;
1534
1543
  return 0;
1535
1544
}
1536
1545
 
1537
1546
 
1538
 
String *Item_func_curtime::val_str(String *str __attribute__((unused)))
 
1547
String *Item_func_curtime::val_str(String *str __attribute__((__unused__)))
1539
1548
{
1540
1549
  assert(fixed == 1);
1541
1550
  str_value.set(buff, buff_length, &my_charset_bin);
1545
1554
 
1546
1555
void Item_func_curtime::fix_length_and_dec()
1547
1556
{
1548
 
  DRIZZLE_TIME ltime;
 
1557
  MYSQL_TIME ltime;
1549
1558
 
1550
1559
  decimals= DATETIME_DEC;
1551
1560
  collation.set(&my_charset_bin);
1557
1566
 
1558
1567
 
1559
1568
/**
1560
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1569
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1561
1570
    time zone. Defines time zone (local) used for whole CURTIME function.
1562
1571
*/
1563
 
void Item_func_curtime_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1572
void Item_func_curtime_local::store_now_in_TIME(MYSQL_TIME *now_time)
1564
1573
{
1565
1574
  THD *thd= current_thd;
1566
1575
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1570
1579
 
1571
1580
 
1572
1581
/**
1573
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
1582
    Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
1574
1583
    time zone. Defines time zone (UTC) used for whole UTC_TIME function.
1575
1584
*/
1576
 
void Item_func_curtime_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1585
void Item_func_curtime_utc::store_now_in_TIME(MYSQL_TIME *now_time)
1577
1586
{
1578
1587
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1579
1588
                             (my_time_t)(current_thd->query_start()));
1584
1593
}
1585
1594
 
1586
1595
 
1587
 
String *Item_func_now::val_str(String *str __attribute__((unused)))
 
1596
String *Item_func_now::val_str(String *str __attribute__((__unused__)))
1588
1597
{
1589
1598
  assert(fixed == 1);
1590
1599
  str_value.set(buff,buff_length, &my_charset_bin);
1606
1615
 
1607
1616
 
1608
1617
/**
1609
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1618
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1610
1619
    time zone. Defines time zone (local) used for whole NOW function.
1611
1620
*/
1612
 
void Item_func_now_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1621
void Item_func_now_local::store_now_in_TIME(MYSQL_TIME *now_time)
1613
1622
{
1614
1623
  THD *thd= current_thd;
1615
1624
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1619
1628
 
1620
1629
 
1621
1630
/**
1622
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
1631
    Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
1623
1632
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
1624
1633
*/
1625
 
void Item_func_now_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1634
void Item_func_now_utc::store_now_in_TIME(MYSQL_TIME *now_time)
1626
1635
{
1627
1636
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1628
1637
                             (my_time_t)(current_thd->query_start()));
1633
1642
}
1634
1643
 
1635
1644
 
1636
 
bool Item_func_now::get_date(DRIZZLE_TIME *res,
1637
 
                             uint32_t fuzzy_date __attribute__((unused)))
 
1645
bool Item_func_now::get_date(MYSQL_TIME *res,
 
1646
                             uint fuzzy_date __attribute__((unused)))
1638
1647
{
1639
1648
  *res= ltime;
1640
1649
  return 0;
1641
1650
}
1642
1651
 
1643
1652
 
1644
 
int Item_func_now::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
 
1653
int Item_func_now::save_in_field(Field *to, bool no_conversions __attribute__((__unused__)))
1645
1654
{
1646
1655
  to->set_notnull();
1647
 
  return to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
1656
  return to->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
1648
1657
}
1649
1658
 
1650
1659
 
1651
1660
/**
1652
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1661
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1653
1662
    time zone. Defines time zone (local) used for whole SYSDATE function.
1654
1663
*/
1655
 
void Item_func_sysdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1664
void Item_func_sysdate_local::store_now_in_TIME(MYSQL_TIME *now_time)
1656
1665
{
1657
1666
  THD *thd= current_thd;
1658
1667
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, (my_time_t) my_time(0));
1660
1669
}
1661
1670
 
1662
1671
 
1663
 
String *Item_func_sysdate_local::val_str(String *str __attribute__((unused)))
 
1672
String *Item_func_sysdate_local::val_str(String *str __attribute__((__unused__)))
1664
1673
{
1665
1674
  assert(fixed == 1);
1666
1675
  store_now_in_TIME(&ltime);
1694
1703
}
1695
1704
 
1696
1705
 
1697
 
bool Item_func_sysdate_local::get_date(DRIZZLE_TIME *res,
1698
 
                                       uint32_t fuzzy_date __attribute__((unused)))
 
1706
bool Item_func_sysdate_local::get_date(MYSQL_TIME *res,
 
1707
                                       uint fuzzy_date __attribute__((unused)))
1699
1708
{
1700
1709
  store_now_in_TIME(&ltime);
1701
1710
  *res= ltime;
1703
1712
}
1704
1713
 
1705
1714
 
1706
 
int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
 
1715
int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions __attribute__((__unused__)))
1707
1716
{
1708
1717
  store_now_in_TIME(&ltime);
1709
1718
  to->set_notnull();
1710
 
  to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
1719
  to->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
1711
1720
  return 0;
1712
1721
}
1713
1722
 
1715
1724
String *Item_func_sec_to_time::val_str(String *str)
1716
1725
{
1717
1726
  assert(fixed == 1);
1718
 
  DRIZZLE_TIME ltime;
 
1727
  MYSQL_TIME ltime;
1719
1728
  int64_t arg_val= args[0]->val_int(); 
1720
1729
 
1721
1730
  if ((null_value=args[0]->null_value) ||
1735
1744
int64_t Item_func_sec_to_time::val_int()
1736
1745
{
1737
1746
  assert(fixed == 1);
1738
 
  DRIZZLE_TIME ltime;
 
1747
  MYSQL_TIME ltime;
1739
1748
  int64_t arg_val= args[0]->val_int(); 
1740
1749
  
1741
1750
  if ((null_value=args[0]->null_value))
1758
1767
  Item *arg1= args[1]->this_item();
1759
1768
 
1760
1769
  decimals=0;
1761
 
  const CHARSET_INFO * const cs= thd->variables.collation_connection;
1762
 
  uint32_t repertoire= arg1->collation.repertoire;
 
1770
  CHARSET_INFO *cs= thd->variables.collation_connection;
 
1771
  uint32 repertoire= arg1->collation.repertoire;
1763
1772
  if (!thd->variables.lc_time_names->is_ascii)
1764
1773
    repertoire|= MY_REPERTOIRE_EXTENDED;
1765
1774
  collation.set(cs, arg1->collation.derivation, repertoire);
1772
1781
  else
1773
1782
  {
1774
1783
    fixed_length=0;
1775
 
    max_length=cmin(arg1->max_length,(uint32_t) MAX_BLOB_WIDTH) * 10 *
 
1784
    max_length=min(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
1776
1785
                   collation.collation->mbmaxlen;
1777
1786
    set_if_smaller(max_length,MAX_BLOB_WIDTH);
1778
1787
  }
1805
1814
 
1806
1815
 
1807
1816
 
1808
 
uint32_t Item_func_date_format::format_length(const String *format)
 
1817
uint Item_func_date_format::format_length(const String *format)
1809
1818
{
1810
 
  uint32_t size=0;
 
1819
  uint size=0;
1811
1820
  const char *ptr=format->ptr();
1812
1821
  const char *end=ptr+format->length();
1813
1822
 
1881
1890
String *Item_func_date_format::val_str(String *str)
1882
1891
{
1883
1892
  String *format;
1884
 
  DRIZZLE_TIME l_time;
1885
 
  uint32_t size;
 
1893
  MYSQL_TIME l_time;
 
1894
  uint size;
1886
1895
  assert(fixed == 1);
1887
1896
 
1888
1897
  if (!is_time_format)
1924
1933
  /* Create the result string */
1925
1934
  str->set_charset(collation.collation);
1926
1935
  if (!make_date_time(&date_time_format, &l_time,
1927
 
                      is_time_format ? DRIZZLE_TIMESTAMP_TIME :
1928
 
                                       DRIZZLE_TIMESTAMP_DATE,
 
1936
                      is_time_format ? MYSQL_TIMESTAMP_TIME :
 
1937
                                       MYSQL_TIMESTAMP_DATE,
1929
1938
                      str))
1930
1939
    return str;
1931
1940
 
1948
1957
 
1949
1958
String *Item_func_from_unixtime::val_str(String *str)
1950
1959
{
1951
 
  DRIZZLE_TIME time_tmp;
 
1960
  MYSQL_TIME time_tmp;
1952
1961
 
1953
1962
  assert(fixed == 1);
1954
1963
 
1969
1978
 
1970
1979
int64_t Item_func_from_unixtime::val_int()
1971
1980
{
1972
 
  DRIZZLE_TIME time_tmp;
 
1981
  MYSQL_TIME time_tmp;
1973
1982
 
1974
1983
  assert(fixed == 1);
1975
1984
 
1979
1988
  return (int64_t) TIME_to_uint64_t_datetime(&time_tmp);
1980
1989
}
1981
1990
 
1982
 
bool Item_func_from_unixtime::get_date(DRIZZLE_TIME *ltime,
1983
 
                                       uint32_t fuzzy_date __attribute__((unused)))
 
1991
bool Item_func_from_unixtime::get_date(MYSQL_TIME *ltime,
 
1992
                                       uint fuzzy_date __attribute__((unused)))
1984
1993
{
1985
1994
  uint64_t tmp= (uint64_t)(args[0]->val_int());
1986
1995
  /*
2009
2018
    The field type for the result of an Item_date function is defined as
2010
2019
    follows:
2011
2020
 
2012
 
    - If first arg is a DRIZZLE_TYPE_DATETIME result is DRIZZLE_TYPE_DATETIME
2013
 
    - If first arg is a DRIZZLE_TYPE_NEWDATE and the interval type uses hours,
2014
 
      minutes or seconds then type is DRIZZLE_TYPE_DATETIME.
2015
 
    - Otherwise the result is DRIZZLE_TYPE_VARCHAR
2016
 
      (This is because you can't know if the string contains a DATE, DRIZZLE_TIME or
 
2021
    - If first arg is a MYSQL_TYPE_DATETIME result is MYSQL_TYPE_DATETIME
 
2022
    - If first arg is a MYSQL_TYPE_NEWDATE and the interval type uses hours,
 
2023
      minutes or seconds then type is MYSQL_TYPE_DATETIME.
 
2024
    - Otherwise the result is MYSQL_TYPE_STRING
 
2025
      (This is because you can't know if the string contains a DATE, MYSQL_TIME or
2017
2026
      DATETIME argument)
2018
2027
  */
2019
 
  cached_field_type= DRIZZLE_TYPE_VARCHAR;
 
2028
  cached_field_type= MYSQL_TYPE_STRING;
2020
2029
  arg0_field_type= args[0]->field_type();
2021
 
  if (arg0_field_type == DRIZZLE_TYPE_DATETIME ||
2022
 
      arg0_field_type == DRIZZLE_TYPE_TIMESTAMP)
2023
 
    cached_field_type= DRIZZLE_TYPE_DATETIME;
2024
 
  else if (arg0_field_type == DRIZZLE_TYPE_NEWDATE)
 
2030
  if (arg0_field_type == MYSQL_TYPE_DATETIME ||
 
2031
      arg0_field_type == MYSQL_TYPE_TIMESTAMP)
 
2032
    cached_field_type= MYSQL_TYPE_DATETIME;
 
2033
  else if (arg0_field_type == MYSQL_TYPE_NEWDATE)
2025
2034
  {
2026
2035
    if (int_type <= INTERVAL_DAY || int_type == INTERVAL_YEAR_MONTH)
2027
2036
      cached_field_type= arg0_field_type;
2028
2037
    else
2029
 
      cached_field_type= DRIZZLE_TYPE_DATETIME;
 
2038
      cached_field_type= MYSQL_TYPE_DATETIME;
2030
2039
  }
2031
2040
}
2032
2041
 
2033
2042
 
2034
2043
/* Here arg[1] is a Item_interval object */
2035
2044
 
2036
 
bool Item_date_add_interval::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
2045
bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, uint fuzzy_date __attribute__((__unused__)))
2037
2046
{
2038
2047
  INTERVAL interval;
2039
2048
 
2053
2062
String *Item_date_add_interval::val_str(String *str)
2054
2063
{
2055
2064
  assert(fixed == 1);
2056
 
  DRIZZLE_TIME ltime;
 
2065
  MYSQL_TIME ltime;
2057
2066
  enum date_time_format_types format;
2058
2067
 
2059
2068
  if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
2060
2069
    return 0;
2061
2070
 
2062
 
  if (ltime.time_type == DRIZZLE_TIMESTAMP_DATE)
 
2071
  if (ltime.time_type == MYSQL_TIMESTAMP_DATE)
2063
2072
    format= DATE_ONLY;
2064
2073
  else if (ltime.second_part)
2065
2074
    format= DATE_TIME_MICROSECOND;
2077
2086
int64_t Item_date_add_interval::val_int()
2078
2087
{
2079
2088
  assert(fixed == 1);
2080
 
  DRIZZLE_TIME ltime;
 
2089
  MYSQL_TIME ltime;
2081
2090
  int64_t date;
2082
2091
  if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
2083
2092
    return (int64_t) 0;
2084
2093
  date = (ltime.year*100L + ltime.month)*100L + ltime.day;
2085
 
  return ltime.time_type == DRIZZLE_TIMESTAMP_DATE ? date :
 
2094
  return ltime.time_type == MYSQL_TIMESTAMP_DATE ? date :
2086
2095
    ((date*100L + ltime.hour)*100L+ ltime.minute)*100L + ltime.second;
2087
2096
}
2088
2097
 
2167
2176
int64_t Item_extract::val_int()
2168
2177
{
2169
2178
  assert(fixed == 1);
2170
 
  DRIZZLE_TIME ltime;
2171
 
  uint32_t year;
 
2179
  MYSQL_TIME ltime;
 
2180
  uint year;
2172
2181
  ulong week_format;
2173
2182
  long neg;
2174
2183
  if (date_value)
2307
2316
{
2308
2317
  assert(fixed == 1);
2309
2318
  String *res;
2310
 
  uint32_t length;
 
2319
  uint32 length;
2311
2320
 
2312
2321
  if (!charset_conversion)
2313
2322
  {
2320
2329
  else
2321
2330
  {
2322
2331
    // Convert character set if differ
2323
 
    uint32_t dummy_errors;
 
2332
    uint dummy_errors;
2324
2333
    if (!(res= args[0]->val_str(&tmp_value)) ||
2325
2334
        str->copy(res->ptr(), res->length(), from_cs,
2326
2335
        cast_cs, &dummy_errors))
2340
2349
  */
2341
2350
  if (cast_length >= 0)
2342
2351
  {
2343
 
    if (res->length() > (length= (uint32_t) res->charpos(cast_length)))
 
2352
    if (res->length() > (length= (uint32) res->charpos(cast_length)))
2344
2353
    {                                           // Safe even if const arg
2345
2354
      char char_type[40];
2346
2355
      snprintf(char_type, sizeof(char_type), "%s(%lu)",
2352
2361
        str_value= *res;                        // Not malloced string
2353
2362
        res= &str_value;
2354
2363
      }
2355
 
      push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2364
      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2356
2365
                          ER_TRUNCATED_WRONG_VALUE,
2357
2366
                          ER(ER_TRUNCATED_WRONG_VALUE), char_type,
2358
2367
                          res->c_ptr_safe());
2366
2375
        str->copy(*res);
2367
2376
        res= str;
2368
2377
      }
2369
 
      memset(res->ptr() + res->length(), 0,
2370
 
             (uint) cast_length - res->length());
 
2378
      bzero((char*) res->ptr() + res->length(),
 
2379
            (uint) cast_length - res->length());
2371
2380
      res->length(cast_length);
2372
2381
    }
2373
2382
  }
2378
2387
 
2379
2388
void Item_char_typecast::fix_length_and_dec()
2380
2389
{
2381
 
  uint32_t char_length;
 
2390
  uint32 char_length;
2382
2391
  /* 
2383
2392
     We always force character set conversion if cast_cs
2384
2393
     is a multi-byte character set. It garantees that the
2404
2413
  from_cs= (args[0]->result_type() == INT_RESULT || 
2405
2414
            args[0]->result_type() == DECIMAL_RESULT ||
2406
2415
            args[0]->result_type() == REAL_RESULT) ?
2407
 
           (cast_cs->mbminlen == 1 ? cast_cs : &my_charset_utf8_general_ci) :
 
2416
           (cast_cs->mbminlen == 1 ? cast_cs : &my_charset_latin1) :
2408
2417
           args[0]->collation.collation;
2409
2418
  charset_conversion= (cast_cs->mbmaxlen > 1) ||
2410
2419
                      (!my_charset_same(from_cs, cast_cs) && from_cs != &my_charset_bin && cast_cs != &my_charset_bin);
2418
2427
String *Item_datetime_typecast::val_str(String *str)
2419
2428
{
2420
2429
  assert(fixed == 1);
2421
 
  DRIZZLE_TIME ltime;
 
2430
  MYSQL_TIME ltime;
2422
2431
 
2423
2432
  if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
2424
2433
      !make_datetime(ltime.second_part ? DATE_TIME_MICROSECOND : DATE_TIME, 
2433
2442
int64_t Item_datetime_typecast::val_int()
2434
2443
{
2435
2444
  assert(fixed == 1);
2436
 
  DRIZZLE_TIME ltime;
 
2445
  MYSQL_TIME ltime;
2437
2446
  if (get_arg0_date(&ltime,1))
2438
2447
  {
2439
2448
    null_value= 1;
2444
2453
}
2445
2454
 
2446
2455
 
2447
 
bool Item_time_typecast::get_time(DRIZZLE_TIME *ltime)
 
2456
bool Item_time_typecast::get_time(MYSQL_TIME *ltime)
2448
2457
{
2449
2458
  bool res= get_arg0_time(ltime);
2450
2459
  /*
2451
 
    For DRIZZLE_TIMESTAMP_TIME value we can have non-zero day part,
 
2460
    For MYSQL_TIMESTAMP_TIME value we can have non-zero day part,
2452
2461
    which we should not lose.
2453
2462
  */
2454
 
  if (ltime->time_type == DRIZZLE_TIMESTAMP_DATETIME)
 
2463
  if (ltime->time_type == MYSQL_TIMESTAMP_DATETIME)
2455
2464
    ltime->year= ltime->month= ltime->day= 0;
2456
 
  ltime->time_type= DRIZZLE_TIMESTAMP_TIME;
 
2465
  ltime->time_type= MYSQL_TIMESTAMP_TIME;
2457
2466
  return res;
2458
2467
}
2459
2468
 
2460
2469
 
2461
2470
int64_t Item_time_typecast::val_int()
2462
2471
{
2463
 
  DRIZZLE_TIME ltime;
 
2472
  MYSQL_TIME ltime;
2464
2473
  if (get_time(&ltime))
2465
2474
  {
2466
2475
    null_value= 1;
2472
2481
String *Item_time_typecast::val_str(String *str)
2473
2482
{
2474
2483
  assert(fixed == 1);
2475
 
  DRIZZLE_TIME ltime;
 
2484
  MYSQL_TIME ltime;
2476
2485
 
2477
2486
  if (!get_arg0_time(&ltime) &&
2478
2487
      !make_datetime(ltime.second_part ? TIME_MICROSECOND : TIME_ONLY,
2484
2493
}
2485
2494
 
2486
2495
 
2487
 
bool Item_date_typecast::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
2496
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date __attribute__((__unused__)))
2488
2497
{
2489
2498
  bool res= get_arg0_date(ltime, TIME_FUZZY_DATE);
2490
2499
  ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
2491
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
2500
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
2492
2501
  return res;
2493
2502
}
2494
2503
 
2495
2504
 
2496
 
bool Item_date_typecast::get_time(DRIZZLE_TIME *ltime)
 
2505
bool Item_date_typecast::get_time(MYSQL_TIME *ltime)
2497
2506
{
2498
 
  memset(ltime, 0, sizeof(DRIZZLE_TIME));
 
2507
  bzero((char *)ltime, sizeof(MYSQL_TIME));
2499
2508
  return args[0]->null_value;
2500
2509
}
2501
2510
 
2503
2512
String *Item_date_typecast::val_str(String *str)
2504
2513
{
2505
2514
  assert(fixed == 1);
2506
 
  DRIZZLE_TIME ltime;
 
2515
  MYSQL_TIME ltime;
2507
2516
 
2508
2517
  if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
2509
2518
      !str->alloc(MAX_DATE_STRING_REP_LENGTH))
2519
2528
int64_t Item_date_typecast::val_int()
2520
2529
{
2521
2530
  assert(fixed == 1);
2522
 
  DRIZZLE_TIME ltime;
 
2531
  MYSQL_TIME ltime;
2523
2532
  if ((null_value= args[0]->get_date(&ltime, TIME_FUZZY_DATE)))
2524
2533
    return 0;
2525
2534
  return (int64_t) (ltime.year * 10000L + ltime.month * 100 + ltime.day);
2538
2547
String *Item_func_makedate::val_str(String *str)
2539
2548
{
2540
2549
  assert(fixed == 1);
2541
 
  DRIZZLE_TIME l_time;
 
2550
  MYSQL_TIME l_time;
2542
2551
  long daynr=  (long) args[1]->val_int();
2543
2552
  long year= (long) args[0]->val_int();
2544
2553
  long days;
2581
2590
int64_t Item_func_makedate::val_int()
2582
2591
{
2583
2592
  assert(fixed == 1);
2584
 
  DRIZZLE_TIME l_time;
 
2593
  MYSQL_TIME l_time;
2585
2594
  long daynr=  (long) args[1]->val_int();
2586
2595
  long year= (long) args[0]->val_int();
2587
2596
  long days;
2619
2628
    The field type for the result of an Item_func_add_time function is defined
2620
2629
    as follows:
2621
2630
 
2622
 
    - If first arg is a DRIZZLE_TYPE_DATETIME or DRIZZLE_TYPE_TIMESTAMP 
2623
 
      result is DRIZZLE_TYPE_DATETIME
2624
 
    - If first arg is a DRIZZLE_TYPE_TIME result is DRIZZLE_TYPE_TIME
2625
 
    - Otherwise the result is DRIZZLE_TYPE_VARCHAR
 
2631
    - If first arg is a MYSQL_TYPE_DATETIME or MYSQL_TYPE_TIMESTAMP 
 
2632
      result is MYSQL_TYPE_DATETIME
 
2633
    - If first arg is a MYSQL_TYPE_TIME result is MYSQL_TYPE_TIME
 
2634
    - Otherwise the result is MYSQL_TYPE_STRING
2626
2635
  */
2627
2636
 
2628
 
  cached_field_type= DRIZZLE_TYPE_VARCHAR;
 
2637
  cached_field_type= MYSQL_TYPE_STRING;
2629
2638
  arg0_field_type= args[0]->field_type();
2630
 
  if (arg0_field_type == DRIZZLE_TYPE_NEWDATE ||
2631
 
      arg0_field_type == DRIZZLE_TYPE_DATETIME ||
2632
 
      arg0_field_type == DRIZZLE_TYPE_TIMESTAMP)
2633
 
    cached_field_type= DRIZZLE_TYPE_DATETIME;
2634
 
  else if (arg0_field_type == DRIZZLE_TYPE_TIME)
2635
 
    cached_field_type= DRIZZLE_TYPE_TIME;
 
2639
  if (arg0_field_type == MYSQL_TYPE_NEWDATE ||
 
2640
      arg0_field_type == MYSQL_TYPE_DATETIME ||
 
2641
      arg0_field_type == MYSQL_TYPE_TIMESTAMP)
 
2642
    cached_field_type= MYSQL_TYPE_DATETIME;
 
2643
  else if (arg0_field_type == MYSQL_TYPE_TIME)
 
2644
    cached_field_type= MYSQL_TYPE_TIME;
2636
2645
}
2637
2646
 
2638
2647
/**
2648
2657
String *Item_func_add_time::val_str(String *str)
2649
2658
{
2650
2659
  assert(fixed == 1);
2651
 
  DRIZZLE_TIME l_time1, l_time2, l_time3;
 
2660
  MYSQL_TIME l_time1, l_time2, l_time3;
2652
2661
  bool is_time= 0;
2653
2662
  long days, microseconds;
2654
2663
  int64_t seconds;
2659
2668
  {
2660
2669
    if (get_arg0_date(&l_time1, TIME_FUZZY_DATE) || 
2661
2670
        args[1]->get_time(&l_time2) ||
2662
 
        l_time1.time_type == DRIZZLE_TIMESTAMP_TIME || 
2663
 
        l_time2.time_type != DRIZZLE_TIMESTAMP_TIME)
 
2671
        l_time1.time_type == MYSQL_TIMESTAMP_TIME || 
 
2672
        l_time2.time_type != MYSQL_TIMESTAMP_TIME)
2664
2673
      goto null_date;
2665
2674
  }
2666
2675
  else                                // ADDTIME function
2667
2676
  {
2668
2677
    if (args[0]->get_time(&l_time1) || 
2669
2678
        args[1]->get_time(&l_time2) ||
2670
 
        l_time2.time_type == DRIZZLE_TIMESTAMP_DATETIME)
 
2679
        l_time2.time_type == MYSQL_TIMESTAMP_DATETIME)
2671
2680
      goto null_date;
2672
 
    is_time= (l_time1.time_type == DRIZZLE_TIMESTAMP_TIME);
 
2681
    is_time= (l_time1.time_type == MYSQL_TIMESTAMP_TIME);
2673
2682
  }
2674
2683
  if (l_time1.neg != l_time2.neg)
2675
2684
    l_sign= -l_sign;
2676
2685
  
2677
 
  memset(&l_time3, 0, sizeof(l_time3));
 
2686
  bzero((char *)&l_time3, sizeof(l_time3));
2678
2687
  
2679
2688
  l_time3.neg= calc_time_diff(&l_time1, &l_time2, -l_sign,
2680
2689
                              &seconds, &microseconds);
2751
2760
  int64_t seconds;
2752
2761
  long microseconds;
2753
2762
  int l_sign= 1;
2754
 
  DRIZZLE_TIME l_time1 ,l_time2, l_time3;
 
2763
  MYSQL_TIME l_time1 ,l_time2, l_time3;
2755
2764
 
2756
2765
  null_value= 0;  
2757
2766
  if (args[0]->get_time(&l_time1) ||
2762
2771
  if (l_time1.neg != l_time2.neg)
2763
2772
    l_sign= -l_sign;
2764
2773
 
2765
 
  memset(&l_time3, 0, sizeof(l_time3));
 
2774
  bzero((char *)&l_time3, sizeof(l_time3));
2766
2775
  
2767
2776
  l_time3.neg= calc_time_diff(&l_time1, &l_time2, l_sign,
2768
2777
                              &seconds, &microseconds);
2769
2778
 
2770
2779
  /*
2771
 
    For DRIZZLE_TIMESTAMP_TIME only:
 
2780
    For MYSQL_TIMESTAMP_TIME only:
2772
2781
      If first argument was negative and diff between arguments
2773
2782
      is non-zero we need to swap sign to get proper result.
2774
2783
  */
2796
2805
String *Item_func_maketime::val_str(String *str)
2797
2806
{
2798
2807
  assert(fixed == 1);
2799
 
  DRIZZLE_TIME ltime;
 
2808
  MYSQL_TIME ltime;
2800
2809
  bool overflow= 0;
2801
2810
 
2802
2811
  int64_t hour=   args[0]->val_int();
2811
2820
                   str->alloc(MAX_DATE_STRING_REP_LENGTH))))
2812
2821
    return 0;
2813
2822
 
2814
 
  memset(&ltime, 0, sizeof(ltime));
 
2823
  bzero((char *)&ltime, sizeof(ltime));
2815
2824
  ltime.neg= 0;
2816
2825
 
2817
2826
  /* Check for integer overflows */
2818
2827
  if (hour < 0)
2819
 
    ltime.neg= 1;
2820
 
 
 
2828
  {
 
2829
    if (args[0]->unsigned_flag)
 
2830
      overflow= 1;
 
2831
    else
 
2832
      ltime.neg= 1;
 
2833
  }
2821
2834
  if (-hour > UINT_MAX || hour > UINT_MAX)
2822
2835
    overflow= 1;
2823
2836
 
2835
2848
    char buf[28];
2836
2849
    char *ptr= int64_t10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
2837
2850
    int len = (int)(ptr - buf) +
2838
 
      sprintf(ptr, ":%02u:%02u", (uint)minute, (uint)second);
2839
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2840
 
                                 buf, len, DRIZZLE_TIMESTAMP_TIME,
2841
 
                                 NULL);
 
2851
      my_sprintf(ptr, (ptr, ":%02u:%02u", (uint)minute, (uint)second));
 
2852
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
2853
                                 buf, len, MYSQL_TIMESTAMP_TIME,
 
2854
                                 NullS);
2842
2855
  }
2843
2856
  
2844
2857
  if (make_time_with_warn((DATE_TIME_FORMAT *) 0, &ltime, str))
2861
2874
int64_t Item_func_microsecond::val_int()
2862
2875
{
2863
2876
  assert(fixed == 1);
2864
 
  DRIZZLE_TIME ltime;
 
2877
  MYSQL_TIME ltime;
2865
2878
  if (!get_arg0_time(&ltime))
2866
2879
    return ltime.second_part;
2867
2880
  return 0;
2870
2883
 
2871
2884
int64_t Item_func_timestamp_diff::val_int()
2872
2885
{
2873
 
  DRIZZLE_TIME ltime1, ltime2;
 
2886
  MYSQL_TIME ltime1, ltime2;
2874
2887
  int64_t seconds;
2875
2888
  long microseconds;
2876
2889
  long months= 0;
2889
2902
      int_type == INTERVAL_QUARTER ||
2890
2903
      int_type == INTERVAL_MONTH)
2891
2904
  {
2892
 
    uint32_t year_beg, year_end, month_beg, month_end, day_beg, day_end;
2893
 
    uint32_t years= 0;
2894
 
    uint32_t second_beg, second_end, microsecond_beg, microsecond_end;
 
2905
    uint year_beg, year_end, month_beg, month_end, day_beg, day_end;
 
2906
    uint years= 0;
 
2907
    uint second_beg, second_end, microsecond_beg, microsecond_end;
2895
2908
 
2896
2909
    if (neg == -1)
2897
2910
    {
3010
3023
    break;
3011
3024
  }
3012
3025
 
3013
 
  for (uint32_t i=0 ; i < 2 ; i++)
 
3026
  for (uint i=0 ; i < 2 ; i++)
3014
3027
  {
3015
3028
    str->append(',');
3016
3029
    args[i]->print(str, query_type);
3035
3048
       (format_name= format->format_name);
3036
3049
       format++)
3037
3050
  {
3038
 
    uint32_t format_name_len;
 
3051
    uint format_name_len;
3039
3052
    format_name_len= strlen(format_name);
3040
3053
    if (val_len == format_name_len &&
3041
 
        !my_strnncoll(&my_charset_utf8_general_ci, 
3042
 
                      (const unsigned char *) val->ptr(), val_len, 
3043
 
                      (const unsigned char *) format_name, val_len))
 
3054
        !my_strnncoll(&my_charset_latin1, 
 
3055
                      (const uchar *) val->ptr(), val_len, 
 
3056
                      (const uchar *) format_name, val_len))
3044
3057
    {
3045
3058
      const char *format_str= get_date_time_format_str(format, type);
3046
3059
      str->set(format_str, strlen(format_str), &my_charset_bin);
3059
3072
  str->append('(');
3060
3073
 
3061
3074
  switch (type) {
3062
 
  case DRIZZLE_TIMESTAMP_DATE:
 
3075
  case MYSQL_TIMESTAMP_DATE:
3063
3076
    str->append(STRING_WITH_LEN("DATE, "));
3064
3077
    break;
3065
 
  case DRIZZLE_TIMESTAMP_DATETIME:
 
3078
  case MYSQL_TIMESTAMP_DATETIME:
3066
3079
    str->append(STRING_WITH_LEN("DATETIME, "));
3067
3080
    break;
3068
 
  case DRIZZLE_TIMESTAMP_TIME:
 
3081
  case MYSQL_TIMESTAMP_TIME:
3069
3082
    str->append(STRING_WITH_LEN("TIME, "));
3070
3083
    break;
3071
3084
  default:
3101
3114
*/
3102
3115
 
3103
3116
static date_time_format_types
3104
 
get_date_time_result_type(const char *format, uint32_t length)
 
3117
get_date_time_result_type(const char *format, uint length)
3105
3118
{
3106
3119
  const char *time_part_frms= "HISThiklrs";
3107
3120
  const char *date_part_frms= "MVUXYWabcjmvuxyw";
3149
3162
{
3150
3163
  maybe_null= 1;
3151
3164
  decimals=0;
3152
 
  cached_field_type= DRIZZLE_TYPE_DATETIME;
 
3165
  cached_field_type= MYSQL_TYPE_DATETIME;
3153
3166
  max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
3154
 
  cached_timestamp_type= DRIZZLE_TIMESTAMP_NONE;
 
3167
  cached_timestamp_type= MYSQL_TIMESTAMP_NONE;
3155
3168
  if ((const_item= args[1]->const_item()))
3156
3169
  {
3157
3170
    char format_buff[64];
3163
3176
                                                    format->length());
3164
3177
      switch (cached_format_type) {
3165
3178
      case DATE_ONLY:
3166
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_DATE;
3167
 
        cached_field_type= DRIZZLE_TYPE_NEWDATE; 
 
3179
        cached_timestamp_type= MYSQL_TIMESTAMP_DATE;
 
3180
        cached_field_type= MYSQL_TYPE_NEWDATE; 
3168
3181
        max_length= MAX_DATE_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
3169
3182
        break;
3170
3183
      case TIME_ONLY:
3171
3184
      case TIME_MICROSECOND:
3172
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_TIME;
3173
 
        cached_field_type= DRIZZLE_TYPE_TIME; 
 
3185
        cached_timestamp_type= MYSQL_TIMESTAMP_TIME;
 
3186
        cached_field_type= MYSQL_TYPE_TIME; 
3174
3187
        max_length= MAX_TIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
3175
3188
        break;
3176
3189
      default:
3177
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_DATETIME;
3178
 
        cached_field_type= DRIZZLE_TYPE_DATETIME; 
 
3190
        cached_timestamp_type= MYSQL_TIMESTAMP_DATETIME;
 
3191
        cached_field_type= MYSQL_TYPE_DATETIME; 
3179
3192
        break;
3180
3193
      }
3181
3194
    }
3183
3196
}
3184
3197
 
3185
3198
 
3186
 
bool Item_func_str_to_date::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
 
3199
bool Item_func_str_to_date::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
3187
3200
{
3188
3201
  DATE_TIME_FORMAT date_time_format;
3189
3202
  char val_buff[64], format_buff[64];
3196
3209
    goto null_date;
3197
3210
 
3198
3211
  null_value= 0;
3199
 
  memset(ltime, 0, sizeof(*ltime));
 
3212
  bzero((char*) ltime, sizeof(*ltime));
3200
3213
  date_time_format.format.str=    (char*) format->ptr();
3201
3214
  date_time_format.format.length= format->length();
3202
3215
  if (extract_date_time(&date_time_format, val->ptr(), val->length(),
3204
3217
      ((fuzzy_date & TIME_NO_ZERO_DATE) &&
3205
3218
       (ltime->year == 0 || ltime->month == 0 || ltime->day == 0)))
3206
3219
    goto null_date;
3207
 
  if (cached_timestamp_type == DRIZZLE_TIMESTAMP_TIME && ltime->day)
 
3220
  if (cached_timestamp_type == MYSQL_TIMESTAMP_TIME && ltime->day)
3208
3221
  {
3209
3222
    /*
3210
3223
      Day part for time type can be nonzero value and so 
3224
3237
String *Item_func_str_to_date::val_str(String *str)
3225
3238
{
3226
3239
  assert(fixed == 1);
3227
 
  DRIZZLE_TIME ltime;
 
3240
  MYSQL_TIME ltime;
3228
3241
 
3229
3242
  if (Item_func_str_to_date::get_date(&ltime, TIME_FUZZY_DATE))
3230
3243
    return 0;
3237
3250
}
3238
3251
 
3239
3252
 
3240
 
bool Item_func_last_day::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
 
3253
bool Item_func_last_day::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
3241
3254
{
3242
3255
  if (get_arg0_date(ltime, fuzzy_date & ~TIME_FUZZY_DATE) ||
3243
3256
      (ltime->month == 0))
3246
3259
    return 1;
3247
3260
  }
3248
3261
  null_value= 0;
3249
 
  uint32_t month_idx= ltime->month-1;
 
3262
  uint month_idx= ltime->month-1;
3250
3263
  ltime->day= days_in_month[month_idx];
3251
3264
  if ( month_idx == 1 && calc_days_in_year(ltime->year) == 366)
3252
3265
    ltime->day= 29;
3253
3266
  ltime->hour= ltime->minute= ltime->second= 0;
3254
3267
  ltime->second_part= 0;
3255
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
3268
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
3256
3269
  return 0;
3257
3270
}