~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_timefunc.cc

  • Committer: Jay Pipes
  • Date: 2008-07-17 17:54:00 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: jay@mysql.com-20080717175400-xm2aazihjra8mdzq
Removal of DBUG from libdrizzle/ - Round 2

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) - 
769
776
      case 'U':
770
777
      case 'u':
771
778
      {
772
 
        uint32_t year;
773
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
779
        uint year;
 
780
        if (type == MYSQL_TIMESTAMP_TIME)
774
781
          return 1;
775
782
        length= int10_to_str(calc_week(l_time,
776
783
                                       (*ptr) == 'U' ?
783
790
      case 'v':
784
791
      case 'V':
785
792
      {
786
 
        uint32_t year;
787
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
793
        uint year;
 
794
        if (type == MYSQL_TIMESTAMP_TIME)
788
795
          return 1;
789
796
        length= int10_to_str(calc_week(l_time,
790
797
                                       ((*ptr) == 'V' ?
798
805
      case 'x':
799
806
      case 'X':
800
807
      {
801
 
        uint32_t year;
802
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
808
        uint year;
 
809
        if (type == MYSQL_TIMESTAMP_TIME)
803
810
          return 1;
804
811
        (void) calc_week(l_time,
805
812
                         ((*ptr) == 'X' ?
811
818
      }
812
819
      break;
813
820
      case 'w':
814
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
821
        if (type == MYSQL_TIMESTAMP_TIME)
815
822
          return 1;
816
823
        weekday=calc_weekday(calc_daynr(l_time->year,l_time->month,
817
824
                                        l_time->day),1);
848
855
                         For example, '1.1' -> '1.100000'
849
856
*/
850
857
 
851
 
static bool get_interval_info(const char *str,uint32_t length, const CHARSET_INFO * const cs,
852
 
                              uint32_t count, uint64_t *values,
 
858
static bool get_interval_info(const char *str,uint length,CHARSET_INFO *cs,
 
859
                              uint count, uint64_t *values,
853
860
                              bool transform_msec)
854
861
{
855
862
  const char *end=str+length;
856
 
  uint32_t i;
 
863
  uint i;
857
864
  while (str != end && !my_isdigit(cs,*str))
858
865
    str++;
859
866
 
862
869
    int64_t value;
863
870
    const char *start= str;
864
871
    for (value=0; str != end && my_isdigit(cs,*str) ; str++)
865
 
      value= value * 10L + (int64_t) (*str - '0');
 
872
      value= value * 10LL + (int64_t) (*str - '0');
866
873
    if (transform_msec && i == count - 1) // microseconds always last
867
874
    {
868
875
      long msec_length= 6 - (str - start);
876
883
    {
877
884
      i++;
878
885
      /* Change values[0...i-1] -> values[0...count-1] */
879
 
      bmove_upp((unsigned char*) (values+count), (unsigned char*) (values+i),
 
886
      bmove_upp((uchar*) (values+count), (uchar*) (values+i),
880
887
                sizeof(*values)*i);
881
 
      memset(values, 0, sizeof(*values)*(count-i));
 
888
      bzero((uchar*) values, sizeof(*values)*(count-i));
882
889
      break;
883
890
    }
884
891
  }
918
925
int64_t Item_func_to_days::val_int()
919
926
{
920
927
  assert(fixed == 1);
921
 
  DRIZZLE_TIME ltime;
 
928
  MYSQL_TIME ltime;
922
929
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
923
930
    return 0;
924
931
  return (int64_t) calc_daynr(ltime.year,ltime.month,ltime.day);
943
950
{
944
951
  if (args[0]->type() == Item::FIELD_ITEM)
945
952
  {
946
 
    if (args[0]->field_type() == DRIZZLE_TYPE_NEWDATE)
 
953
    if (args[0]->field_type() == MYSQL_TYPE_NEWDATE)
947
954
      return MONOTONIC_STRICT_INCREASING;
948
 
    if (args[0]->field_type() == DRIZZLE_TYPE_DATETIME)
 
955
    if (args[0]->field_type() == MYSQL_TYPE_DATETIME)
949
956
      return MONOTONIC_INCREASING;
950
957
  }
951
958
  return NON_MONOTONIC;
955
962
int64_t Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp)
956
963
{
957
964
  assert(fixed == 1);
958
 
  DRIZZLE_TIME ltime;
 
965
  MYSQL_TIME ltime;
959
966
  int64_t res;
960
967
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
961
968
  {
964
971
  }
965
972
  res=(int64_t) calc_daynr(ltime.year,ltime.month,ltime.day);
966
973
  
967
 
  if (args[0]->field_type() == DRIZZLE_TYPE_NEWDATE)
 
974
  if (args[0]->field_type() == MYSQL_TYPE_NEWDATE)
968
975
  {
969
976
    // TO_DAYS() is strictly monotonic for dates, leave incl_endp intact
970
977
    return res;
993
1000
int64_t Item_func_dayofyear::val_int()
994
1001
{
995
1002
  assert(fixed == 1);
996
 
  DRIZZLE_TIME ltime;
 
1003
  MYSQL_TIME ltime;
997
1004
  if (get_arg0_date(&ltime,TIME_NO_ZERO_DATE))
998
1005
    return 0;
999
1006
  return (int64_t) calc_daynr(ltime.year,ltime.month,ltime.day) -
1003
1010
int64_t Item_func_dayofmonth::val_int()
1004
1011
{
1005
1012
  assert(fixed == 1);
1006
 
  DRIZZLE_TIME ltime;
 
1013
  MYSQL_TIME ltime;
1007
1014
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1008
1015
  return (int64_t) ltime.day;
1009
1016
}
1011
1018
int64_t Item_func_month::val_int()
1012
1019
{
1013
1020
  assert(fixed == 1);
1014
 
  DRIZZLE_TIME ltime;
 
1021
  MYSQL_TIME ltime;
1015
1022
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1016
1023
  return (int64_t) ltime.month;
1017
1024
}
1021
1028
{
1022
1029
  assert(fixed == 1);
1023
1030
  const char *month_name;
1024
 
  uint32_t   month= (uint) val_int();
 
1031
  uint   month= (uint) val_int();
1025
1032
  THD *thd= current_thd;
1026
1033
 
1027
1034
  if (null_value || !month)
1043
1050
int64_t Item_func_quarter::val_int()
1044
1051
{
1045
1052
  assert(fixed == 1);
1046
 
  DRIZZLE_TIME ltime;
 
1053
  MYSQL_TIME ltime;
1047
1054
  if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
1048
1055
    return 0;
1049
1056
  return (int64_t) ((ltime.month+2)/3);
1052
1059
int64_t Item_func_hour::val_int()
1053
1060
{
1054
1061
  assert(fixed == 1);
1055
 
  DRIZZLE_TIME ltime;
 
1062
  MYSQL_TIME ltime;
1056
1063
  (void) get_arg0_time(&ltime);
1057
1064
  return ltime.hour;
1058
1065
}
1060
1067
int64_t Item_func_minute::val_int()
1061
1068
{
1062
1069
  assert(fixed == 1);
1063
 
  DRIZZLE_TIME ltime;
 
1070
  MYSQL_TIME ltime;
1064
1071
  (void) get_arg0_time(&ltime);
1065
1072
  return ltime.minute;
1066
1073
}
1071
1078
int64_t Item_func_second::val_int()
1072
1079
{
1073
1080
  assert(fixed == 1);
1074
 
  DRIZZLE_TIME ltime;
 
1081
  MYSQL_TIME ltime;
1075
1082
  (void) get_arg0_time(&ltime);
1076
1083
  return ltime.second;
1077
1084
}
1078
1085
 
1079
1086
 
1080
 
uint32_t week_mode(uint32_t mode)
 
1087
uint week_mode(uint mode)
1081
1088
{
1082
 
  uint32_t week_format= (mode & 7);
 
1089
  uint week_format= (mode & 7);
1083
1090
  if (!(week_format & WEEK_MONDAY_FIRST))
1084
1091
    week_format^= WEEK_FIRST_WEEKDAY;
1085
1092
  return week_format;
1119
1126
int64_t Item_func_week::val_int()
1120
1127
{
1121
1128
  assert(fixed == 1);
1122
 
  uint32_t year;
1123
 
  DRIZZLE_TIME ltime;
 
1129
  uint year;
 
1130
  MYSQL_TIME ltime;
1124
1131
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1125
1132
    return 0;
1126
1133
  return (int64_t) calc_week(&ltime,
1132
1139
int64_t Item_func_yearweek::val_int()
1133
1140
{
1134
1141
  assert(fixed == 1);
1135
 
  uint32_t year,week;
1136
 
  DRIZZLE_TIME ltime;
 
1142
  uint year,week;
 
1143
  MYSQL_TIME ltime;
1137
1144
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1138
1145
    return 0;
1139
1146
  week= calc_week(&ltime, 
1146
1153
int64_t Item_func_weekday::val_int()
1147
1154
{
1148
1155
  assert(fixed == 1);
1149
 
  DRIZZLE_TIME ltime;
 
1156
  MYSQL_TIME ltime;
1150
1157
  
1151
1158
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1152
1159
    return 0;
1160
1167
String* Item_func_dayname::val_str(String* str)
1161
1168
{
1162
1169
  assert(fixed == 1);
1163
 
  uint32_t weekday=(uint) val_int();            // Always Item_func_daynr()
 
1170
  uint weekday=(uint) val_int();                // Always Item_func_daynr()
1164
1171
  const char *day_name;
1165
1172
  THD *thd= current_thd;
1166
1173
 
1176
1183
int64_t Item_func_year::val_int()
1177
1184
{
1178
1185
  assert(fixed == 1);
1179
 
  DRIZZLE_TIME ltime;
 
1186
  MYSQL_TIME ltime;
1180
1187
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1181
1188
  return (int64_t) ltime.year;
1182
1189
}
1199
1206
enum_monotonicity_info Item_func_year::get_monotonicity_info() const
1200
1207
{
1201
1208
  if (args[0]->type() == Item::FIELD_ITEM &&
1202
 
      (args[0]->field_type() == DRIZZLE_TYPE_NEWDATE ||
1203
 
       args[0]->field_type() == DRIZZLE_TYPE_DATETIME))
 
1209
      (args[0]->field_type() == MYSQL_TYPE_NEWDATE ||
 
1210
       args[0]->field_type() == MYSQL_TYPE_DATETIME))
1204
1211
    return MONOTONIC_INCREASING;
1205
1212
  return NON_MONOTONIC;
1206
1213
}
1209
1216
int64_t Item_func_year::val_int_endpoint(bool left_endp, bool *incl_endp)
1210
1217
{
1211
1218
  assert(fixed == 1);
1212
 
  DRIZZLE_TIME ltime;
 
1219
  MYSQL_TIME ltime;
1213
1220
  if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
1214
1221
  {
1215
1222
    /* got NULL, leave the incl_endp intact */
1238
1245
 
1239
1246
int64_t Item_func_unix_timestamp::val_int()
1240
1247
{
1241
 
  DRIZZLE_TIME ltime;
 
1248
  MYSQL_TIME ltime;
1242
1249
  bool not_used;
1243
1250
  
1244
1251
  assert(fixed == 1);
1247
1254
  if (args[0]->type() == FIELD_ITEM)
1248
1255
  {                                             // Optimize timestamp field
1249
1256
    Field *field=((Item_field*) args[0])->field;
1250
 
    if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
 
1257
    if (field->type() == MYSQL_TYPE_TIMESTAMP)
1251
1258
      return ((Field_timestamp*) field)->get_timestamp(&null_value);
1252
1259
  }
1253
1260
  
1269
1276
int64_t Item_func_time_to_sec::val_int()
1270
1277
{
1271
1278
  assert(fixed == 1);
1272
 
  DRIZZLE_TIME ltime;
 
1279
  MYSQL_TIME ltime;
1273
1280
  int64_t seconds;
1274
1281
  (void) get_arg0_time(&ltime);
1275
1282
  seconds=ltime.hour*3600L+ltime.minute*60+ltime.second;
1290
1297
  int64_t value= 0;
1291
1298
  const char *str= NULL;
1292
1299
  size_t length= 0;
1293
 
  const CHARSET_INFO * const cs= str_value->charset();
 
1300
  CHARSET_INFO *cs=str_value->charset();
1294
1301
 
1295
 
  memset(interval, 0, sizeof(*interval));
 
1302
  bzero((char*) interval,sizeof(*interval));
1296
1303
  if ((int) int_type <= INTERVAL_MICROSECOND)
1297
1304
  {
1298
1305
    value= args->val_int();
1438
1445
String *Item_date::val_str(String *str)
1439
1446
{
1440
1447
  assert(fixed == 1);
1441
 
  DRIZZLE_TIME ltime;
 
1448
  MYSQL_TIME ltime;
1442
1449
  if (get_date(&ltime, TIME_FUZZY_DATE))
1443
1450
    return (String *) 0;
1444
1451
  if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
1454
1461
int64_t Item_date::val_int()
1455
1462
{
1456
1463
  assert(fixed == 1);
1457
 
  DRIZZLE_TIME ltime;
 
1464
  MYSQL_TIME ltime;
1458
1465
  if (get_date(&ltime, TIME_FUZZY_DATE))
1459
1466
    return 0;
1460
1467
  return (int64_t) (ltime.year*10000L+ltime.month*100+ltime.day);
1461
1468
}
1462
1469
 
1463
1470
 
1464
 
bool Item_func_from_days::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
1471
bool Item_func_from_days::get_date(MYSQL_TIME *ltime, uint fuzzy_date __attribute__((__unused__)))
1465
1472
{
1466
1473
  int64_t value=args[0]->val_int();
1467
1474
  if ((null_value=args[0]->null_value))
1468
1475
    return 1;
1469
 
  memset(ltime, 0, sizeof(DRIZZLE_TIME));
 
1476
  bzero(ltime, sizeof(MYSQL_TIME));
1470
1477
  get_date_from_daynr((long) value, &ltime->year, &ltime->month, &ltime->day);
1471
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
1478
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
1472
1479
  return 0;
1473
1480
}
1474
1481
 
1483
1490
  
1484
1491
  /* We don't need to set second_part and neg because they already 0 */
1485
1492
  ltime.hour= ltime.minute= ltime.second= 0;
1486
 
  ltime.time_type= DRIZZLE_TIMESTAMP_DATE;
 
1493
  ltime.time_type= MYSQL_TIMESTAMP_DATE;
1487
1494
  value= (int64_t) TIME_to_uint64_t_date(&ltime);
1488
1495
}
1489
1496
 
1500
1507
}
1501
1508
 
1502
1509
/**
1503
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1510
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1504
1511
    time zone. Defines time zone (local) used for whole CURDATE function.
1505
1512
*/
1506
 
void Item_func_curdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1513
void Item_func_curdate_local::store_now_in_TIME(MYSQL_TIME *now_time)
1507
1514
{
1508
1515
  THD *thd= current_thd;
1509
1516
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1513
1520
 
1514
1521
 
1515
1522
/**
1516
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
1523
    Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
1517
1524
    time zone. Defines time zone (UTC) used for whole UTC_DATE function.
1518
1525
*/
1519
 
void Item_func_curdate_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1526
void Item_func_curdate_utc::store_now_in_TIME(MYSQL_TIME *now_time)
1520
1527
{
1521
1528
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1522
1529
                             (my_time_t)(current_thd->query_start()));
1527
1534
}
1528
1535
 
1529
1536
 
1530
 
bool Item_func_curdate::get_date(DRIZZLE_TIME *res,
1531
 
                                 uint32_t fuzzy_date __attribute__((unused)))
 
1537
bool Item_func_curdate::get_date(MYSQL_TIME *res,
 
1538
                                 uint fuzzy_date __attribute__((unused)))
1532
1539
{
1533
1540
  *res=ltime;
1534
1541
  return 0;
1535
1542
}
1536
1543
 
1537
1544
 
1538
 
String *Item_func_curtime::val_str(String *str __attribute__((unused)))
 
1545
String *Item_func_curtime::val_str(String *str __attribute__((__unused__)))
1539
1546
{
1540
1547
  assert(fixed == 1);
1541
1548
  str_value.set(buff, buff_length, &my_charset_bin);
1545
1552
 
1546
1553
void Item_func_curtime::fix_length_and_dec()
1547
1554
{
1548
 
  DRIZZLE_TIME ltime;
 
1555
  MYSQL_TIME ltime;
1549
1556
 
1550
1557
  decimals= DATETIME_DEC;
1551
1558
  collation.set(&my_charset_bin);
1557
1564
 
1558
1565
 
1559
1566
/**
1560
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1567
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1561
1568
    time zone. Defines time zone (local) used for whole CURTIME function.
1562
1569
*/
1563
 
void Item_func_curtime_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1570
void Item_func_curtime_local::store_now_in_TIME(MYSQL_TIME *now_time)
1564
1571
{
1565
1572
  THD *thd= current_thd;
1566
1573
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1570
1577
 
1571
1578
 
1572
1579
/**
1573
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
1580
    Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
1574
1581
    time zone. Defines time zone (UTC) used for whole UTC_TIME function.
1575
1582
*/
1576
 
void Item_func_curtime_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1583
void Item_func_curtime_utc::store_now_in_TIME(MYSQL_TIME *now_time)
1577
1584
{
1578
1585
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1579
1586
                             (my_time_t)(current_thd->query_start()));
1584
1591
}
1585
1592
 
1586
1593
 
1587
 
String *Item_func_now::val_str(String *str __attribute__((unused)))
 
1594
String *Item_func_now::val_str(String *str __attribute__((__unused__)))
1588
1595
{
1589
1596
  assert(fixed == 1);
1590
1597
  str_value.set(buff,buff_length, &my_charset_bin);
1606
1613
 
1607
1614
 
1608
1615
/**
1609
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1616
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1610
1617
    time zone. Defines time zone (local) used for whole NOW function.
1611
1618
*/
1612
 
void Item_func_now_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1619
void Item_func_now_local::store_now_in_TIME(MYSQL_TIME *now_time)
1613
1620
{
1614
1621
  THD *thd= current_thd;
1615
1622
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1619
1626
 
1620
1627
 
1621
1628
/**
1622
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
1629
    Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
1623
1630
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
1624
1631
*/
1625
 
void Item_func_now_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1632
void Item_func_now_utc::store_now_in_TIME(MYSQL_TIME *now_time)
1626
1633
{
1627
1634
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1628
1635
                             (my_time_t)(current_thd->query_start()));
1633
1640
}
1634
1641
 
1635
1642
 
1636
 
bool Item_func_now::get_date(DRIZZLE_TIME *res,
1637
 
                             uint32_t fuzzy_date __attribute__((unused)))
 
1643
bool Item_func_now::get_date(MYSQL_TIME *res,
 
1644
                             uint fuzzy_date __attribute__((unused)))
1638
1645
{
1639
1646
  *res= ltime;
1640
1647
  return 0;
1641
1648
}
1642
1649
 
1643
1650
 
1644
 
int Item_func_now::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
 
1651
int Item_func_now::save_in_field(Field *to, bool no_conversions __attribute__((__unused__)))
1645
1652
{
1646
1653
  to->set_notnull();
1647
 
  return to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
1654
  return to->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
1648
1655
}
1649
1656
 
1650
1657
 
1651
1658
/**
1652
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1659
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1653
1660
    time zone. Defines time zone (local) used for whole SYSDATE function.
1654
1661
*/
1655
 
void Item_func_sysdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1662
void Item_func_sysdate_local::store_now_in_TIME(MYSQL_TIME *now_time)
1656
1663
{
1657
1664
  THD *thd= current_thd;
1658
1665
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, (my_time_t) my_time(0));
1660
1667
}
1661
1668
 
1662
1669
 
1663
 
String *Item_func_sysdate_local::val_str(String *str __attribute__((unused)))
 
1670
String *Item_func_sysdate_local::val_str(String *str __attribute__((__unused__)))
1664
1671
{
1665
1672
  assert(fixed == 1);
1666
1673
  store_now_in_TIME(&ltime);
1694
1701
}
1695
1702
 
1696
1703
 
1697
 
bool Item_func_sysdate_local::get_date(DRIZZLE_TIME *res,
1698
 
                                       uint32_t fuzzy_date __attribute__((unused)))
 
1704
bool Item_func_sysdate_local::get_date(MYSQL_TIME *res,
 
1705
                                       uint fuzzy_date __attribute__((unused)))
1699
1706
{
1700
1707
  store_now_in_TIME(&ltime);
1701
1708
  *res= ltime;
1703
1710
}
1704
1711
 
1705
1712
 
1706
 
int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
 
1713
int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions __attribute__((__unused__)))
1707
1714
{
1708
1715
  store_now_in_TIME(&ltime);
1709
1716
  to->set_notnull();
1710
 
  to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
1717
  to->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
1711
1718
  return 0;
1712
1719
}
1713
1720
 
1715
1722
String *Item_func_sec_to_time::val_str(String *str)
1716
1723
{
1717
1724
  assert(fixed == 1);
1718
 
  DRIZZLE_TIME ltime;
 
1725
  MYSQL_TIME ltime;
1719
1726
  int64_t arg_val= args[0]->val_int(); 
1720
1727
 
1721
1728
  if ((null_value=args[0]->null_value) ||
1735
1742
int64_t Item_func_sec_to_time::val_int()
1736
1743
{
1737
1744
  assert(fixed == 1);
1738
 
  DRIZZLE_TIME ltime;
 
1745
  MYSQL_TIME ltime;
1739
1746
  int64_t arg_val= args[0]->val_int(); 
1740
1747
  
1741
1748
  if ((null_value=args[0]->null_value))
1758
1765
  Item *arg1= args[1]->this_item();
1759
1766
 
1760
1767
  decimals=0;
1761
 
  const CHARSET_INFO * const cs= thd->variables.collation_connection;
1762
 
  uint32_t repertoire= arg1->collation.repertoire;
 
1768
  CHARSET_INFO *cs= thd->variables.collation_connection;
 
1769
  uint32 repertoire= arg1->collation.repertoire;
1763
1770
  if (!thd->variables.lc_time_names->is_ascii)
1764
1771
    repertoire|= MY_REPERTOIRE_EXTENDED;
1765
1772
  collation.set(cs, arg1->collation.derivation, repertoire);
1772
1779
  else
1773
1780
  {
1774
1781
    fixed_length=0;
1775
 
    max_length=cmin(arg1->max_length,(uint32_t) MAX_BLOB_WIDTH) * 10 *
 
1782
    max_length=min(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
1776
1783
                   collation.collation->mbmaxlen;
1777
1784
    set_if_smaller(max_length,MAX_BLOB_WIDTH);
1778
1785
  }
1805
1812
 
1806
1813
 
1807
1814
 
1808
 
uint32_t Item_func_date_format::format_length(const String *format)
 
1815
uint Item_func_date_format::format_length(const String *format)
1809
1816
{
1810
 
  uint32_t size=0;
 
1817
  uint size=0;
1811
1818
  const char *ptr=format->ptr();
1812
1819
  const char *end=ptr+format->length();
1813
1820
 
1881
1888
String *Item_func_date_format::val_str(String *str)
1882
1889
{
1883
1890
  String *format;
1884
 
  DRIZZLE_TIME l_time;
1885
 
  uint32_t size;
 
1891
  MYSQL_TIME l_time;
 
1892
  uint size;
1886
1893
  assert(fixed == 1);
1887
1894
 
1888
1895
  if (!is_time_format)
1924
1931
  /* Create the result string */
1925
1932
  str->set_charset(collation.collation);
1926
1933
  if (!make_date_time(&date_time_format, &l_time,
1927
 
                      is_time_format ? DRIZZLE_TIMESTAMP_TIME :
1928
 
                                       DRIZZLE_TIMESTAMP_DATE,
 
1934
                      is_time_format ? MYSQL_TIMESTAMP_TIME :
 
1935
                                       MYSQL_TIMESTAMP_DATE,
1929
1936
                      str))
1930
1937
    return str;
1931
1938
 
1948
1955
 
1949
1956
String *Item_func_from_unixtime::val_str(String *str)
1950
1957
{
1951
 
  DRIZZLE_TIME time_tmp;
 
1958
  MYSQL_TIME time_tmp;
1952
1959
 
1953
1960
  assert(fixed == 1);
1954
1961
 
1969
1976
 
1970
1977
int64_t Item_func_from_unixtime::val_int()
1971
1978
{
1972
 
  DRIZZLE_TIME time_tmp;
 
1979
  MYSQL_TIME time_tmp;
1973
1980
 
1974
1981
  assert(fixed == 1);
1975
1982
 
1979
1986
  return (int64_t) TIME_to_uint64_t_datetime(&time_tmp);
1980
1987
}
1981
1988
 
1982
 
bool Item_func_from_unixtime::get_date(DRIZZLE_TIME *ltime,
1983
 
                                       uint32_t fuzzy_date __attribute__((unused)))
 
1989
bool Item_func_from_unixtime::get_date(MYSQL_TIME *ltime,
 
1990
                                       uint fuzzy_date __attribute__((unused)))
1984
1991
{
1985
1992
  uint64_t tmp= (uint64_t)(args[0]->val_int());
1986
1993
  /*
2009
2016
    The field type for the result of an Item_date function is defined as
2010
2017
    follows:
2011
2018
 
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
 
2019
    - If first arg is a MYSQL_TYPE_DATETIME result is MYSQL_TYPE_DATETIME
 
2020
    - If first arg is a MYSQL_TYPE_NEWDATE and the interval type uses hours,
 
2021
      minutes or seconds then type is MYSQL_TYPE_DATETIME.
 
2022
    - Otherwise the result is MYSQL_TYPE_STRING
 
2023
      (This is because you can't know if the string contains a DATE, MYSQL_TIME or
2017
2024
      DATETIME argument)
2018
2025
  */
2019
 
  cached_field_type= DRIZZLE_TYPE_VARCHAR;
 
2026
  cached_field_type= MYSQL_TYPE_STRING;
2020
2027
  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)
 
2028
  if (arg0_field_type == MYSQL_TYPE_DATETIME ||
 
2029
      arg0_field_type == MYSQL_TYPE_TIMESTAMP)
 
2030
    cached_field_type= MYSQL_TYPE_DATETIME;
 
2031
  else if (arg0_field_type == MYSQL_TYPE_NEWDATE)
2025
2032
  {
2026
2033
    if (int_type <= INTERVAL_DAY || int_type == INTERVAL_YEAR_MONTH)
2027
2034
      cached_field_type= arg0_field_type;
2028
2035
    else
2029
 
      cached_field_type= DRIZZLE_TYPE_DATETIME;
 
2036
      cached_field_type= MYSQL_TYPE_DATETIME;
2030
2037
  }
2031
2038
}
2032
2039
 
2033
2040
 
2034
2041
/* Here arg[1] is a Item_interval object */
2035
2042
 
2036
 
bool Item_date_add_interval::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
2043
bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, uint fuzzy_date __attribute__((__unused__)))
2037
2044
{
2038
2045
  INTERVAL interval;
2039
2046
 
2053
2060
String *Item_date_add_interval::val_str(String *str)
2054
2061
{
2055
2062
  assert(fixed == 1);
2056
 
  DRIZZLE_TIME ltime;
 
2063
  MYSQL_TIME ltime;
2057
2064
  enum date_time_format_types format;
2058
2065
 
2059
2066
  if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
2060
2067
    return 0;
2061
2068
 
2062
 
  if (ltime.time_type == DRIZZLE_TIMESTAMP_DATE)
 
2069
  if (ltime.time_type == MYSQL_TIMESTAMP_DATE)
2063
2070
    format= DATE_ONLY;
2064
2071
  else if (ltime.second_part)
2065
2072
    format= DATE_TIME_MICROSECOND;
2077
2084
int64_t Item_date_add_interval::val_int()
2078
2085
{
2079
2086
  assert(fixed == 1);
2080
 
  DRIZZLE_TIME ltime;
 
2087
  MYSQL_TIME ltime;
2081
2088
  int64_t date;
2082
2089
  if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
2083
2090
    return (int64_t) 0;
2084
2091
  date = (ltime.year*100L + ltime.month)*100L + ltime.day;
2085
 
  return ltime.time_type == DRIZZLE_TIMESTAMP_DATE ? date :
 
2092
  return ltime.time_type == MYSQL_TIMESTAMP_DATE ? date :
2086
2093
    ((date*100L + ltime.hour)*100L+ ltime.minute)*100L + ltime.second;
2087
2094
}
2088
2095
 
2167
2174
int64_t Item_extract::val_int()
2168
2175
{
2169
2176
  assert(fixed == 1);
2170
 
  DRIZZLE_TIME ltime;
2171
 
  uint32_t year;
 
2177
  MYSQL_TIME ltime;
 
2178
  uint year;
2172
2179
  ulong week_format;
2173
2180
  long neg;
2174
2181
  if (date_value)
2307
2314
{
2308
2315
  assert(fixed == 1);
2309
2316
  String *res;
2310
 
  uint32_t length;
 
2317
  uint32 length;
2311
2318
 
2312
2319
  if (!charset_conversion)
2313
2320
  {
2320
2327
  else
2321
2328
  {
2322
2329
    // Convert character set if differ
2323
 
    uint32_t dummy_errors;
 
2330
    uint dummy_errors;
2324
2331
    if (!(res= args[0]->val_str(&tmp_value)) ||
2325
2332
        str->copy(res->ptr(), res->length(), from_cs,
2326
2333
        cast_cs, &dummy_errors))
2340
2347
  */
2341
2348
  if (cast_length >= 0)
2342
2349
  {
2343
 
    if (res->length() > (length= (uint32_t) res->charpos(cast_length)))
 
2350
    if (res->length() > (length= (uint32) res->charpos(cast_length)))
2344
2351
    {                                           // Safe even if const arg
2345
2352
      char char_type[40];
2346
2353
      snprintf(char_type, sizeof(char_type), "%s(%lu)",
2352
2359
        str_value= *res;                        // Not malloced string
2353
2360
        res= &str_value;
2354
2361
      }
2355
 
      push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2362
      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2356
2363
                          ER_TRUNCATED_WRONG_VALUE,
2357
2364
                          ER(ER_TRUNCATED_WRONG_VALUE), char_type,
2358
2365
                          res->c_ptr_safe());
2366
2373
        str->copy(*res);
2367
2374
        res= str;
2368
2375
      }
2369
 
      memset(res->ptr() + res->length(), 0,
2370
 
             (uint) cast_length - res->length());
 
2376
      bzero((char*) res->ptr() + res->length(),
 
2377
            (uint) cast_length - res->length());
2371
2378
      res->length(cast_length);
2372
2379
    }
2373
2380
  }
2378
2385
 
2379
2386
void Item_char_typecast::fix_length_and_dec()
2380
2387
{
2381
 
  uint32_t char_length;
 
2388
  uint32 char_length;
2382
2389
  /* 
2383
2390
     We always force character set conversion if cast_cs
2384
2391
     is a multi-byte character set. It garantees that the
2404
2411
  from_cs= (args[0]->result_type() == INT_RESULT || 
2405
2412
            args[0]->result_type() == DECIMAL_RESULT ||
2406
2413
            args[0]->result_type() == REAL_RESULT) ?
2407
 
           (cast_cs->mbminlen == 1 ? cast_cs : &my_charset_utf8_general_ci) :
 
2414
           (cast_cs->mbminlen == 1 ? cast_cs : &my_charset_latin1) :
2408
2415
           args[0]->collation.collation;
2409
2416
  charset_conversion= (cast_cs->mbmaxlen > 1) ||
2410
2417
                      (!my_charset_same(from_cs, cast_cs) && from_cs != &my_charset_bin && cast_cs != &my_charset_bin);
2418
2425
String *Item_datetime_typecast::val_str(String *str)
2419
2426
{
2420
2427
  assert(fixed == 1);
2421
 
  DRIZZLE_TIME ltime;
 
2428
  MYSQL_TIME ltime;
2422
2429
 
2423
2430
  if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
2424
2431
      !make_datetime(ltime.second_part ? DATE_TIME_MICROSECOND : DATE_TIME, 
2433
2440
int64_t Item_datetime_typecast::val_int()
2434
2441
{
2435
2442
  assert(fixed == 1);
2436
 
  DRIZZLE_TIME ltime;
 
2443
  MYSQL_TIME ltime;
2437
2444
  if (get_arg0_date(&ltime,1))
2438
2445
  {
2439
2446
    null_value= 1;
2444
2451
}
2445
2452
 
2446
2453
 
2447
 
bool Item_time_typecast::get_time(DRIZZLE_TIME *ltime)
 
2454
bool Item_time_typecast::get_time(MYSQL_TIME *ltime)
2448
2455
{
2449
2456
  bool res= get_arg0_time(ltime);
2450
2457
  /*
2451
 
    For DRIZZLE_TIMESTAMP_TIME value we can have non-zero day part,
 
2458
    For MYSQL_TIMESTAMP_TIME value we can have non-zero day part,
2452
2459
    which we should not lose.
2453
2460
  */
2454
 
  if (ltime->time_type == DRIZZLE_TIMESTAMP_DATETIME)
 
2461
  if (ltime->time_type == MYSQL_TIMESTAMP_DATETIME)
2455
2462
    ltime->year= ltime->month= ltime->day= 0;
2456
 
  ltime->time_type= DRIZZLE_TIMESTAMP_TIME;
 
2463
  ltime->time_type= MYSQL_TIMESTAMP_TIME;
2457
2464
  return res;
2458
2465
}
2459
2466
 
2460
2467
 
2461
2468
int64_t Item_time_typecast::val_int()
2462
2469
{
2463
 
  DRIZZLE_TIME ltime;
 
2470
  MYSQL_TIME ltime;
2464
2471
  if (get_time(&ltime))
2465
2472
  {
2466
2473
    null_value= 1;
2472
2479
String *Item_time_typecast::val_str(String *str)
2473
2480
{
2474
2481
  assert(fixed == 1);
2475
 
  DRIZZLE_TIME ltime;
 
2482
  MYSQL_TIME ltime;
2476
2483
 
2477
2484
  if (!get_arg0_time(&ltime) &&
2478
2485
      !make_datetime(ltime.second_part ? TIME_MICROSECOND : TIME_ONLY,
2484
2491
}
2485
2492
 
2486
2493
 
2487
 
bool Item_date_typecast::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
2494
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date __attribute__((__unused__)))
2488
2495
{
2489
2496
  bool res= get_arg0_date(ltime, TIME_FUZZY_DATE);
2490
2497
  ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
2491
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
2498
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
2492
2499
  return res;
2493
2500
}
2494
2501
 
2495
2502
 
2496
 
bool Item_date_typecast::get_time(DRIZZLE_TIME *ltime)
 
2503
bool Item_date_typecast::get_time(MYSQL_TIME *ltime)
2497
2504
{
2498
 
  memset(ltime, 0, sizeof(DRIZZLE_TIME));
 
2505
  bzero((char *)ltime, sizeof(MYSQL_TIME));
2499
2506
  return args[0]->null_value;
2500
2507
}
2501
2508
 
2503
2510
String *Item_date_typecast::val_str(String *str)
2504
2511
{
2505
2512
  assert(fixed == 1);
2506
 
  DRIZZLE_TIME ltime;
 
2513
  MYSQL_TIME ltime;
2507
2514
 
2508
2515
  if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
2509
2516
      !str->alloc(MAX_DATE_STRING_REP_LENGTH))
2519
2526
int64_t Item_date_typecast::val_int()
2520
2527
{
2521
2528
  assert(fixed == 1);
2522
 
  DRIZZLE_TIME ltime;
 
2529
  MYSQL_TIME ltime;
2523
2530
  if ((null_value= args[0]->get_date(&ltime, TIME_FUZZY_DATE)))
2524
2531
    return 0;
2525
2532
  return (int64_t) (ltime.year * 10000L + ltime.month * 100 + ltime.day);
2538
2545
String *Item_func_makedate::val_str(String *str)
2539
2546
{
2540
2547
  assert(fixed == 1);
2541
 
  DRIZZLE_TIME l_time;
 
2548
  MYSQL_TIME l_time;
2542
2549
  long daynr=  (long) args[1]->val_int();
2543
2550
  long year= (long) args[0]->val_int();
2544
2551
  long days;
2581
2588
int64_t Item_func_makedate::val_int()
2582
2589
{
2583
2590
  assert(fixed == 1);
2584
 
  DRIZZLE_TIME l_time;
 
2591
  MYSQL_TIME l_time;
2585
2592
  long daynr=  (long) args[1]->val_int();
2586
2593
  long year= (long) args[0]->val_int();
2587
2594
  long days;
2619
2626
    The field type for the result of an Item_func_add_time function is defined
2620
2627
    as follows:
2621
2628
 
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
 
2629
    - If first arg is a MYSQL_TYPE_DATETIME or MYSQL_TYPE_TIMESTAMP 
 
2630
      result is MYSQL_TYPE_DATETIME
 
2631
    - If first arg is a MYSQL_TYPE_TIME result is MYSQL_TYPE_TIME
 
2632
    - Otherwise the result is MYSQL_TYPE_STRING
2626
2633
  */
2627
2634
 
2628
 
  cached_field_type= DRIZZLE_TYPE_VARCHAR;
 
2635
  cached_field_type= MYSQL_TYPE_STRING;
2629
2636
  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;
 
2637
  if (arg0_field_type == MYSQL_TYPE_NEWDATE ||
 
2638
      arg0_field_type == MYSQL_TYPE_DATETIME ||
 
2639
      arg0_field_type == MYSQL_TYPE_TIMESTAMP)
 
2640
    cached_field_type= MYSQL_TYPE_DATETIME;
 
2641
  else if (arg0_field_type == MYSQL_TYPE_TIME)
 
2642
    cached_field_type= MYSQL_TYPE_TIME;
2636
2643
}
2637
2644
 
2638
2645
/**
2648
2655
String *Item_func_add_time::val_str(String *str)
2649
2656
{
2650
2657
  assert(fixed == 1);
2651
 
  DRIZZLE_TIME l_time1, l_time2, l_time3;
 
2658
  MYSQL_TIME l_time1, l_time2, l_time3;
2652
2659
  bool is_time= 0;
2653
2660
  long days, microseconds;
2654
2661
  int64_t seconds;
2659
2666
  {
2660
2667
    if (get_arg0_date(&l_time1, TIME_FUZZY_DATE) || 
2661
2668
        args[1]->get_time(&l_time2) ||
2662
 
        l_time1.time_type == DRIZZLE_TIMESTAMP_TIME || 
2663
 
        l_time2.time_type != DRIZZLE_TIMESTAMP_TIME)
 
2669
        l_time1.time_type == MYSQL_TIMESTAMP_TIME || 
 
2670
        l_time2.time_type != MYSQL_TIMESTAMP_TIME)
2664
2671
      goto null_date;
2665
2672
  }
2666
2673
  else                                // ADDTIME function
2667
2674
  {
2668
2675
    if (args[0]->get_time(&l_time1) || 
2669
2676
        args[1]->get_time(&l_time2) ||
2670
 
        l_time2.time_type == DRIZZLE_TIMESTAMP_DATETIME)
 
2677
        l_time2.time_type == MYSQL_TIMESTAMP_DATETIME)
2671
2678
      goto null_date;
2672
 
    is_time= (l_time1.time_type == DRIZZLE_TIMESTAMP_TIME);
 
2679
    is_time= (l_time1.time_type == MYSQL_TIMESTAMP_TIME);
2673
2680
  }
2674
2681
  if (l_time1.neg != l_time2.neg)
2675
2682
    l_sign= -l_sign;
2676
2683
  
2677
 
  memset(&l_time3, 0, sizeof(l_time3));
 
2684
  bzero((char *)&l_time3, sizeof(l_time3));
2678
2685
  
2679
2686
  l_time3.neg= calc_time_diff(&l_time1, &l_time2, -l_sign,
2680
2687
                              &seconds, &microseconds);
2751
2758
  int64_t seconds;
2752
2759
  long microseconds;
2753
2760
  int l_sign= 1;
2754
 
  DRIZZLE_TIME l_time1 ,l_time2, l_time3;
 
2761
  MYSQL_TIME l_time1 ,l_time2, l_time3;
2755
2762
 
2756
2763
  null_value= 0;  
2757
2764
  if (args[0]->get_time(&l_time1) ||
2762
2769
  if (l_time1.neg != l_time2.neg)
2763
2770
    l_sign= -l_sign;
2764
2771
 
2765
 
  memset(&l_time3, 0, sizeof(l_time3));
 
2772
  bzero((char *)&l_time3, sizeof(l_time3));
2766
2773
  
2767
2774
  l_time3.neg= calc_time_diff(&l_time1, &l_time2, l_sign,
2768
2775
                              &seconds, &microseconds);
2769
2776
 
2770
2777
  /*
2771
 
    For DRIZZLE_TIMESTAMP_TIME only:
 
2778
    For MYSQL_TIMESTAMP_TIME only:
2772
2779
      If first argument was negative and diff between arguments
2773
2780
      is non-zero we need to swap sign to get proper result.
2774
2781
  */
2796
2803
String *Item_func_maketime::val_str(String *str)
2797
2804
{
2798
2805
  assert(fixed == 1);
2799
 
  DRIZZLE_TIME ltime;
 
2806
  MYSQL_TIME ltime;
2800
2807
  bool overflow= 0;
2801
2808
 
2802
2809
  int64_t hour=   args[0]->val_int();
2811
2818
                   str->alloc(MAX_DATE_STRING_REP_LENGTH))))
2812
2819
    return 0;
2813
2820
 
2814
 
  memset(&ltime, 0, sizeof(ltime));
 
2821
  bzero((char *)&ltime, sizeof(ltime));
2815
2822
  ltime.neg= 0;
2816
2823
 
2817
2824
  /* Check for integer overflows */
2818
2825
  if (hour < 0)
2819
 
    ltime.neg= 1;
2820
 
 
 
2826
  {
 
2827
    if (args[0]->unsigned_flag)
 
2828
      overflow= 1;
 
2829
    else
 
2830
      ltime.neg= 1;
 
2831
  }
2821
2832
  if (-hour > UINT_MAX || hour > UINT_MAX)
2822
2833
    overflow= 1;
2823
2834
 
2836
2847
    char *ptr= int64_t10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
2837
2848
    int len = (int)(ptr - buf) +
2838
2849
      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);
 
2850
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
2851
                                 buf, len, MYSQL_TIMESTAMP_TIME,
 
2852
                                 NullS);
2842
2853
  }
2843
2854
  
2844
2855
  if (make_time_with_warn((DATE_TIME_FORMAT *) 0, &ltime, str))
2861
2872
int64_t Item_func_microsecond::val_int()
2862
2873
{
2863
2874
  assert(fixed == 1);
2864
 
  DRIZZLE_TIME ltime;
 
2875
  MYSQL_TIME ltime;
2865
2876
  if (!get_arg0_time(&ltime))
2866
2877
    return ltime.second_part;
2867
2878
  return 0;
2870
2881
 
2871
2882
int64_t Item_func_timestamp_diff::val_int()
2872
2883
{
2873
 
  DRIZZLE_TIME ltime1, ltime2;
 
2884
  MYSQL_TIME ltime1, ltime2;
2874
2885
  int64_t seconds;
2875
2886
  long microseconds;
2876
2887
  long months= 0;
2889
2900
      int_type == INTERVAL_QUARTER ||
2890
2901
      int_type == INTERVAL_MONTH)
2891
2902
  {
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;
 
2903
    uint year_beg, year_end, month_beg, month_end, day_beg, day_end;
 
2904
    uint years= 0;
 
2905
    uint second_beg, second_end, microsecond_beg, microsecond_end;
2895
2906
 
2896
2907
    if (neg == -1)
2897
2908
    {
3010
3021
    break;
3011
3022
  }
3012
3023
 
3013
 
  for (uint32_t i=0 ; i < 2 ; i++)
 
3024
  for (uint i=0 ; i < 2 ; i++)
3014
3025
  {
3015
3026
    str->append(',');
3016
3027
    args[i]->print(str, query_type);
3035
3046
       (format_name= format->format_name);
3036
3047
       format++)
3037
3048
  {
3038
 
    uint32_t format_name_len;
 
3049
    uint format_name_len;
3039
3050
    format_name_len= strlen(format_name);
3040
3051
    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))
 
3052
        !my_strnncoll(&my_charset_latin1, 
 
3053
                      (const uchar *) val->ptr(), val_len, 
 
3054
                      (const uchar *) format_name, val_len))
3044
3055
    {
3045
3056
      const char *format_str= get_date_time_format_str(format, type);
3046
3057
      str->set(format_str, strlen(format_str), &my_charset_bin);
3059
3070
  str->append('(');
3060
3071
 
3061
3072
  switch (type) {
3062
 
  case DRIZZLE_TIMESTAMP_DATE:
 
3073
  case MYSQL_TIMESTAMP_DATE:
3063
3074
    str->append(STRING_WITH_LEN("DATE, "));
3064
3075
    break;
3065
 
  case DRIZZLE_TIMESTAMP_DATETIME:
 
3076
  case MYSQL_TIMESTAMP_DATETIME:
3066
3077
    str->append(STRING_WITH_LEN("DATETIME, "));
3067
3078
    break;
3068
 
  case DRIZZLE_TIMESTAMP_TIME:
 
3079
  case MYSQL_TIMESTAMP_TIME:
3069
3080
    str->append(STRING_WITH_LEN("TIME, "));
3070
3081
    break;
3071
3082
  default:
3101
3112
*/
3102
3113
 
3103
3114
static date_time_format_types
3104
 
get_date_time_result_type(const char *format, uint32_t length)
 
3115
get_date_time_result_type(const char *format, uint length)
3105
3116
{
3106
3117
  const char *time_part_frms= "HISThiklrs";
3107
3118
  const char *date_part_frms= "MVUXYWabcjmvuxyw";
3149
3160
{
3150
3161
  maybe_null= 1;
3151
3162
  decimals=0;
3152
 
  cached_field_type= DRIZZLE_TYPE_DATETIME;
 
3163
  cached_field_type= MYSQL_TYPE_DATETIME;
3153
3164
  max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
3154
 
  cached_timestamp_type= DRIZZLE_TIMESTAMP_NONE;
 
3165
  cached_timestamp_type= MYSQL_TIMESTAMP_NONE;
3155
3166
  if ((const_item= args[1]->const_item()))
3156
3167
  {
3157
3168
    char format_buff[64];
3163
3174
                                                    format->length());
3164
3175
      switch (cached_format_type) {
3165
3176
      case DATE_ONLY:
3166
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_DATE;
3167
 
        cached_field_type= DRIZZLE_TYPE_NEWDATE; 
 
3177
        cached_timestamp_type= MYSQL_TIMESTAMP_DATE;
 
3178
        cached_field_type= MYSQL_TYPE_NEWDATE; 
3168
3179
        max_length= MAX_DATE_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
3169
3180
        break;
3170
3181
      case TIME_ONLY:
3171
3182
      case TIME_MICROSECOND:
3172
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_TIME;
3173
 
        cached_field_type= DRIZZLE_TYPE_TIME; 
 
3183
        cached_timestamp_type= MYSQL_TIMESTAMP_TIME;
 
3184
        cached_field_type= MYSQL_TYPE_TIME; 
3174
3185
        max_length= MAX_TIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
3175
3186
        break;
3176
3187
      default:
3177
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_DATETIME;
3178
 
        cached_field_type= DRIZZLE_TYPE_DATETIME; 
 
3188
        cached_timestamp_type= MYSQL_TIMESTAMP_DATETIME;
 
3189
        cached_field_type= MYSQL_TYPE_DATETIME; 
3179
3190
        break;
3180
3191
      }
3181
3192
    }
3183
3194
}
3184
3195
 
3185
3196
 
3186
 
bool Item_func_str_to_date::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
 
3197
bool Item_func_str_to_date::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
3187
3198
{
3188
3199
  DATE_TIME_FORMAT date_time_format;
3189
3200
  char val_buff[64], format_buff[64];
3196
3207
    goto null_date;
3197
3208
 
3198
3209
  null_value= 0;
3199
 
  memset(ltime, 0, sizeof(*ltime));
 
3210
  bzero((char*) ltime, sizeof(*ltime));
3200
3211
  date_time_format.format.str=    (char*) format->ptr();
3201
3212
  date_time_format.format.length= format->length();
3202
3213
  if (extract_date_time(&date_time_format, val->ptr(), val->length(),
3204
3215
      ((fuzzy_date & TIME_NO_ZERO_DATE) &&
3205
3216
       (ltime->year == 0 || ltime->month == 0 || ltime->day == 0)))
3206
3217
    goto null_date;
3207
 
  if (cached_timestamp_type == DRIZZLE_TIMESTAMP_TIME && ltime->day)
 
3218
  if (cached_timestamp_type == MYSQL_TIMESTAMP_TIME && ltime->day)
3208
3219
  {
3209
3220
    /*
3210
3221
      Day part for time type can be nonzero value and so 
3224
3235
String *Item_func_str_to_date::val_str(String *str)
3225
3236
{
3226
3237
  assert(fixed == 1);
3227
 
  DRIZZLE_TIME ltime;
 
3238
  MYSQL_TIME ltime;
3228
3239
 
3229
3240
  if (Item_func_str_to_date::get_date(&ltime, TIME_FUZZY_DATE))
3230
3241
    return 0;
3237
3248
}
3238
3249
 
3239
3250
 
3240
 
bool Item_func_last_day::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
 
3251
bool Item_func_last_day::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
3241
3252
{
3242
3253
  if (get_arg0_date(ltime, fuzzy_date & ~TIME_FUZZY_DATE) ||
3243
3254
      (ltime->month == 0))
3246
3257
    return 1;
3247
3258
  }
3248
3259
  null_value= 0;
3249
 
  uint32_t month_idx= ltime->month-1;
 
3260
  uint month_idx= ltime->month-1;
3250
3261
  ltime->day= days_in_month[month_idx];
3251
3262
  if ( month_idx == 1 && calc_days_in_year(ltime->year) == 366)
3252
3263
    ltime->day= 29;
3253
3264
  ltime->hour= ltime->minute= ltime->second= 0;
3254
3265
  ltime->second_part= 0;
3255
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
3266
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
3256
3267
  return 0;
3257
3268
}