~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_timefunc.cc

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705112018-fr12kkmgphtu7m29
Changes so that removal of duplicate curr_dir from my_sys.h work.

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(longlong 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;
192
199
  else if (seconds > 3020399)
193
200
    goto overflow;
194
201
  
195
 
  sec= (uint) ((uint64_t) seconds % 3600);
 
202
  sec= (uint) ((ulonglong) seconds % 3600);
196
203
  ltime->hour= (uint) (seconds/3600);
197
204
  ltime->minute= sec/60;
198
205
  ltime->second= sec % 60;
205
212
  ltime->second= TIME_MAX_SECOND;
206
213
 
207
214
  char buf[22];
208
 
  int len= (int)(int64_t10_to_str(seconds, buf, unsigned_flag ? 10 : -10)
 
215
  int len= (int)(longlong10_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;
 
289
  DBUG_ENTER("extract_date_time");
282
290
 
283
291
  if (!sub_pattern_end)
284
 
    memset(l_time, 0, sizeof(*l_time));
 
292
    bzero((char*) l_time, sizeof(*l_time));
285
293
 
286
294
  for (; ptr != end && val != val_end; ptr++)
287
295
  {
300
308
      switch (*++ptr) {
301
309
        /* Year */
302
310
      case 'Y':
303
 
        tmp= (char*) val + cmin(4, val_len);
 
311
        tmp= (char*) val + min(4, val_len);
304
312
        l_time->year= (int) my_strtoll10(val, &tmp, &error);
305
313
        if ((int) (tmp-val) <= 2)
306
314
          l_time->year= year_2000_handling(l_time->year);
307
315
        val= tmp;
308
316
        break;
309
317
      case 'y':
310
 
        tmp= (char*) val + cmin(2, val_len);
 
318
        tmp= (char*) val + min(2, val_len);
311
319
        l_time->year= (int) my_strtoll10(val, &tmp, &error);
312
320
        val= tmp;
313
321
        l_time->year= year_2000_handling(l_time->year);
316
324
        /* Month */
317
325
      case 'm':
318
326
      case 'c':
319
 
        tmp= (char*) val + cmin(2, val_len);
 
327
        tmp= (char*) val + min(2, val_len);
320
328
        l_time->month= (int) my_strtoll10(val, &tmp, &error);
321
329
        val= tmp;
322
330
        break;
333
341
        /* Day */
334
342
      case 'd':
335
343
      case 'e':
336
 
        tmp= (char*) val + cmin(2, val_len);
 
344
        tmp= (char*) val + min(2, val_len);
337
345
        l_time->day= (int) my_strtoll10(val, &tmp, &error);
338
346
        val= tmp;
339
347
        break;
340
348
      case 'D':
341
 
        tmp= (char*) val + cmin(2, val_len);
 
349
        tmp= (char*) val + min(2, val_len);
342
350
        l_time->day= (int) my_strtoll10(val, &tmp, &error);
343
351
        /* Skip 'st, 'nd, 'th .. */
344
 
        val= tmp + cmin((int) (val_end-tmp), 2);
 
352
        val= tmp + min((int) (val_end-tmp), 2);
345
353
        break;
346
354
 
347
355
        /* Hour */
352
360
        /* fall through */
353
361
      case 'k':
354
362
      case 'H':
355
 
        tmp= (char*) val + cmin(2, val_len);
 
363
        tmp= (char*) val + min(2, val_len);
356
364
        l_time->hour= (int) my_strtoll10(val, &tmp, &error);
357
365
        val= tmp;
358
366
        break;
359
367
 
360
368
        /* Minute */
361
369
      case 'i':
362
 
        tmp= (char*) val + cmin(2, val_len);
 
370
        tmp= (char*) val + min(2, val_len);
363
371
        l_time->minute= (int) my_strtoll10(val, &tmp, &error);
364
372
        val= tmp;
365
373
        break;
367
375
        /* Second */
368
376
      case 's':
369
377
      case 'S':
370
 
        tmp= (char*) val + cmin(2, val_len);
 
378
        tmp= (char*) val + min(2, val_len);
371
379
        l_time->second= (int) my_strtoll10(val, &tmp, &error);
372
380
        val= tmp;
373
381
        break;
388
396
      case 'p':
389
397
        if (val_len < 2 || ! usa_time)
390
398
          goto err;
391
 
        if (!my_strnncoll(&my_charset_utf8_general_ci,
392
 
                          (const unsigned char *) val, 2, 
393
 
                          (const unsigned char *) "PM", 2))
 
399
        if (!my_strnncoll(&my_charset_latin1,
 
400
                          (const uchar *) val, 2, 
 
401
                          (const uchar *) "PM", 2))
394
402
          daypart= 12;
395
 
        else if (my_strnncoll(&my_charset_utf8_general_ci,
396
 
                              (const unsigned char *) val, 2, 
397
 
                              (const unsigned char *) "AM", 2))
 
403
        else if (my_strnncoll(&my_charset_latin1,
 
404
                              (const uchar *) val, 2, 
 
405
                              (const uchar *) "AM", 2))
398
406
          goto err;
399
407
        val+= 2;
400
408
        break;
419
427
        val= tmp;
420
428
        break;
421
429
      case 'j':
422
 
        tmp= (char*) val + cmin(val_len, 3);
 
430
        tmp= (char*) val + min(val_len, 3);
423
431
        yearday= (int) my_strtoll10(val, &tmp, &error);
424
432
        val= tmp;
425
433
        break;
431
439
      case 'u':
432
440
        sunday_first_n_first_week_non_iso= (*ptr=='U' || *ptr== 'V');
433
441
        strict_week_number= (*ptr=='V' || *ptr=='v');
434
 
        tmp= (char*) val + cmin(val_len, 2);
 
442
        tmp= (char*) val + min(val_len, 2);
435
443
        if ((week_number= (int) my_strtoll10(val, &tmp, &error)) < 0 ||
436
444
            (strict_week_number && !week_number) ||
437
445
            week_number > 53)
443
451
      case 'X':
444
452
      case 'x':
445
453
        strict_week_number_year_type= (*ptr=='X');
446
 
        tmp= (char*) val + cmin(4, val_len);
 
454
        tmp= (char*) val + min(4, val_len);
447
455
        strict_week_number_year= (int) my_strtoll10(val, &tmp, &error);
448
456
        val= tmp;
449
457
        break;
457
465
        if (extract_date_time(&time_ampm_format, val,
458
466
                              (uint)(val_end - val), l_time,
459
467
                              cached_timestamp_type, &val, "time"))
460
 
          return(1);
 
468
          DBUG_RETURN(1);
461
469
        break;
462
470
 
463
471
        /* Time in 24-hour notation */
465
473
        if (extract_date_time(&time_24hrs_format, val,
466
474
                              (uint)(val_end - val), l_time,
467
475
                              cached_timestamp_type, &val, "time"))
468
 
          return(1);
 
476
          DBUG_RETURN(1);
469
477
        break;
470
478
 
471
479
        /* Conversion specifiers that match classes of characters */
508
516
  if (sub_pattern_end)
509
517
  {
510
518
    *sub_pattern_end= val;
511
 
    return(0);
 
519
    DBUG_RETURN(0);
512
520
  }
513
521
 
514
522
  if (yearday > 0)
515
523
  {
516
 
    uint32_t days;
 
524
    uint days;
517
525
    days= calc_daynr(l_time->year,1,1) +  yearday - 1;
518
526
    if (days <= 0 || days > MAX_DAY_NUMBER)
519
527
      goto err;
523
531
  if (week_number >= 0 && weekday)
524
532
  {
525
533
    int days;
526
 
    uint32_t weekday_b;
 
534
    uint weekday_b;
527
535
 
528
536
    /*
529
537
      %V,%v require %X,%x resprectively,
573
581
  {
574
582
    do
575
583
    {
576
 
      if (!my_isspace(&my_charset_utf8_general_ci,*val))
 
584
      if (!my_isspace(&my_charset_latin1,*val))
577
585
      {
578
 
        make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
586
        make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
579
587
                                     val_begin, length,
580
 
                                     cached_timestamp_type, NULL);
 
588
                                     cached_timestamp_type, NullS);
581
589
        break;
582
590
      }
583
591
    } while (++val != val_end);
584
592
  }
585
 
  return(0);
 
593
  DBUG_RETURN(0);
586
594
 
587
595
err:
588
596
  {
589
597
    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,
 
598
    strmake(buff, val_begin, min(length, sizeof(buff)-1));
 
599
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
592
600
                        ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
593
601
                        date_time_type, buff, "str_to_date");
594
602
  }
595
 
  return(1);
 
603
  DBUG_RETURN(1);
596
604
}
597
605
 
598
606
 
600
608
  Create a formated date/time value in a string.
601
609
*/
602
610
 
603
 
bool make_date_time(DATE_TIME_FORMAT *format, DRIZZLE_TIME *l_time,
604
 
                    enum enum_drizzle_timestamp_type type, String *str)
 
611
bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
 
612
                    timestamp_type type, String *str)
605
613
{
606
614
  char intbuff[15];
607
 
  uint32_t hours_i;
608
 
  uint32_t weekday;
 
615
  uint hours_i;
 
616
  uint weekday;
609
617
  ulong length;
610
618
  const char *ptr, *end;
611
619
  THD *thd= current_thd;
639
647
                    system_charset_info);
640
648
        break;
641
649
      case 'W':
642
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
650
        if (type == MYSQL_TIMESTAMP_TIME)
643
651
          return 1;
644
652
        weekday= calc_weekday(calc_daynr(l_time->year,l_time->month,
645
653
                              l_time->day),0);
648
656
                    system_charset_info);
649
657
        break;
650
658
      case 'a':
651
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
659
        if (type == MYSQL_TIMESTAMP_TIME)
652
660
          return 1;
653
661
        weekday=calc_weekday(calc_daynr(l_time->year,l_time->month,
654
662
                             l_time->day),0);
657
665
                    system_charset_info);
658
666
        break;
659
667
      case 'D':
660
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
668
        if (type == MYSQL_TIMESTAMP_TIME)
661
669
          return 1;
662
670
        length= int10_to_str(l_time->day, intbuff, 10) - intbuff;
663
671
        str->append_with_prefill(intbuff, length, 1, '0');
724
732
        str->append_with_prefill(intbuff, length, 2, '0');
725
733
        break;
726
734
      case 'j':
727
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
735
        if (type == MYSQL_TIMESTAMP_TIME)
728
736
          return 1;
729
737
        length= int10_to_str(calc_daynr(l_time->year,l_time->month,
730
738
                                        l_time->day) - 
745
753
        str->append(hours_i < 12 ? "AM" : "PM",2);
746
754
        break;
747
755
      case 'r':
748
 
        length= sprintf(intbuff, 
 
756
        length= my_sprintf(intbuff, 
 
757
                   (intbuff, 
749
758
                    ((l_time->hour % 24) < 12) ?
750
759
                    "%02d:%02d:%02d AM" : "%02d:%02d:%02d PM",
751
760
                    (l_time->hour+11)%12+1,
752
761
                    l_time->minute,
753
 
                    l_time->second);
 
762
                    l_time->second));
754
763
        str->append(intbuff, length);
755
764
        break;
756
765
      case 'S':
759
768
        str->append_with_prefill(intbuff, length, 2, '0');
760
769
        break;
761
770
      case 'T':
762
 
        length= sprintf(intbuff, 
 
771
        length= my_sprintf(intbuff, 
 
772
                   (intbuff, 
763
773
                    "%02d:%02d:%02d", 
764
774
                    l_time->hour, 
765
775
                    l_time->minute,
766
 
                    l_time->second);
 
776
                    l_time->second));
767
777
        str->append(intbuff, length);
768
778
        break;
769
779
      case 'U':
770
780
      case 'u':
771
781
      {
772
 
        uint32_t year;
773
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
782
        uint year;
 
783
        if (type == MYSQL_TIMESTAMP_TIME)
774
784
          return 1;
775
785
        length= int10_to_str(calc_week(l_time,
776
786
                                       (*ptr) == 'U' ?
783
793
      case 'v':
784
794
      case 'V':
785
795
      {
786
 
        uint32_t year;
787
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
796
        uint year;
 
797
        if (type == MYSQL_TIMESTAMP_TIME)
788
798
          return 1;
789
799
        length= int10_to_str(calc_week(l_time,
790
800
                                       ((*ptr) == 'V' ?
798
808
      case 'x':
799
809
      case 'X':
800
810
      {
801
 
        uint32_t year;
802
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
811
        uint year;
 
812
        if (type == MYSQL_TIMESTAMP_TIME)
803
813
          return 1;
804
814
        (void) calc_week(l_time,
805
815
                         ((*ptr) == 'X' ?
811
821
      }
812
822
      break;
813
823
      case 'w':
814
 
        if (type == DRIZZLE_TIMESTAMP_TIME)
 
824
        if (type == MYSQL_TIMESTAMP_TIME)
815
825
          return 1;
816
826
        weekday=calc_weekday(calc_daynr(l_time->year,l_time->month,
817
827
                                        l_time->day),1);
848
858
                         For example, '1.1' -> '1.100000'
849
859
*/
850
860
 
851
 
static bool get_interval_info(const char *str,uint32_t length, const CHARSET_INFO * const cs,
852
 
                              uint32_t count, uint64_t *values,
 
861
static bool get_interval_info(const char *str,uint length,CHARSET_INFO *cs,
 
862
                              uint count, ulonglong *values,
853
863
                              bool transform_msec)
854
864
{
855
865
  const char *end=str+length;
856
 
  uint32_t i;
 
866
  uint i;
857
867
  while (str != end && !my_isdigit(cs,*str))
858
868
    str++;
859
869
 
860
870
  for (i=0 ; i < count ; i++)
861
871
  {
862
 
    int64_t value;
 
872
    longlong value;
863
873
    const char *start= str;
864
874
    for (value=0; str != end && my_isdigit(cs,*str) ; str++)
865
 
      value= value * 10L + (int64_t) (*str - '0');
 
875
      value= value*LL(10) + (longlong) (*str - '0');
866
876
    if (transform_msec && i == count - 1) // microseconds always last
867
877
    {
868
878
      long msec_length= 6 - (str - start);
876
886
    {
877
887
      i++;
878
888
      /* Change values[0...i-1] -> values[0...count-1] */
879
 
      bmove_upp((unsigned char*) (values+count), (unsigned char*) (values+i),
 
889
      bmove_upp((uchar*) (values+count), (uchar*) (values+i),
880
890
                sizeof(*values)*i);
881
 
      memset(values, 0, sizeof(*values)*(count-i));
 
891
      bzero((uchar*) values, sizeof(*values)*(count-i));
882
892
      break;
883
893
    }
884
894
  }
886
896
}
887
897
 
888
898
 
889
 
int64_t Item_func_period_add::val_int()
 
899
longlong Item_func_period_add::val_int()
890
900
{
891
 
  assert(fixed == 1);
 
901
  DBUG_ASSERT(fixed == 1);
892
902
  ulong period=(ulong) args[0]->val_int();
893
903
  int months=(int) args[1]->val_int();
894
904
 
895
905
  if ((null_value=args[0]->null_value || args[1]->null_value) ||
896
906
      period == 0L)
897
907
    return 0; /* purecov: inspected */
898
 
  return (int64_t)
 
908
  return (longlong)
899
909
    convert_month_to_period((uint) ((int) convert_period_to_month(period)+
900
910
                                    months));
901
911
}
902
912
 
903
913
 
904
 
int64_t Item_func_period_diff::val_int()
 
914
longlong Item_func_period_diff::val_int()
905
915
{
906
 
  assert(fixed == 1);
 
916
  DBUG_ASSERT(fixed == 1);
907
917
  ulong period1=(ulong) args[0]->val_int();
908
918
  ulong period2=(ulong) args[1]->val_int();
909
919
 
910
920
  if ((null_value=args[0]->null_value || args[1]->null_value))
911
921
    return 0; /* purecov: inspected */
912
 
  return (int64_t) ((long) convert_period_to_month(period1)-
 
922
  return (longlong) ((long) convert_period_to_month(period1)-
913
923
                     (long) convert_period_to_month(period2));
914
924
}
915
925
 
916
926
 
917
927
 
918
 
int64_t Item_func_to_days::val_int()
 
928
longlong Item_func_to_days::val_int()
919
929
{
920
 
  assert(fixed == 1);
921
 
  DRIZZLE_TIME ltime;
 
930
  DBUG_ASSERT(fixed == 1);
 
931
  MYSQL_TIME ltime;
922
932
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
923
933
    return 0;
924
 
  return (int64_t) calc_daynr(ltime.year,ltime.month,ltime.day);
 
934
  return (longlong) calc_daynr(ltime.year,ltime.month,ltime.day);
925
935
}
926
936
 
927
937
 
943
953
{
944
954
  if (args[0]->type() == Item::FIELD_ITEM)
945
955
  {
946
 
    if (args[0]->field_type() == DRIZZLE_TYPE_NEWDATE)
 
956
    if (args[0]->field_type() == MYSQL_TYPE_DATE)
947
957
      return MONOTONIC_STRICT_INCREASING;
948
 
    if (args[0]->field_type() == DRIZZLE_TYPE_DATETIME)
 
958
    if (args[0]->field_type() == MYSQL_TYPE_DATETIME)
949
959
      return MONOTONIC_INCREASING;
950
960
  }
951
961
  return NON_MONOTONIC;
952
962
}
953
963
 
954
964
 
955
 
int64_t Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp)
 
965
longlong Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp)
956
966
{
957
 
  assert(fixed == 1);
958
 
  DRIZZLE_TIME ltime;
959
 
  int64_t res;
 
967
  DBUG_ASSERT(fixed == 1);
 
968
  MYSQL_TIME ltime;
 
969
  longlong res;
960
970
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
961
971
  {
962
972
    /* got NULL, leave the incl_endp intact */
963
 
    return INT64_MIN;
 
973
    return LONGLONG_MIN;
964
974
  }
965
 
  res=(int64_t) calc_daynr(ltime.year,ltime.month,ltime.day);
 
975
  res=(longlong) calc_daynr(ltime.year,ltime.month,ltime.day);
966
976
  
967
 
  if (args[0]->field_type() == DRIZZLE_TYPE_NEWDATE)
 
977
  if (args[0]->field_type() == MYSQL_TYPE_DATE)
968
978
  {
969
979
    // TO_DAYS() is strictly monotonic for dates, leave incl_endp intact
970
980
    return res;
985
995
                      ltime.second_part))
986
996
    ; /* do nothing */
987
997
  else
988
 
    *incl_endp= true;
 
998
    *incl_endp= TRUE;
989
999
  return res;
990
1000
}
991
1001
 
992
1002
 
993
 
int64_t Item_func_dayofyear::val_int()
 
1003
longlong Item_func_dayofyear::val_int()
994
1004
{
995
 
  assert(fixed == 1);
996
 
  DRIZZLE_TIME ltime;
 
1005
  DBUG_ASSERT(fixed == 1);
 
1006
  MYSQL_TIME ltime;
997
1007
  if (get_arg0_date(&ltime,TIME_NO_ZERO_DATE))
998
1008
    return 0;
999
 
  return (int64_t) calc_daynr(ltime.year,ltime.month,ltime.day) -
 
1009
  return (longlong) calc_daynr(ltime.year,ltime.month,ltime.day) -
1000
1010
    calc_daynr(ltime.year,1,1) + 1;
1001
1011
}
1002
1012
 
1003
 
int64_t Item_func_dayofmonth::val_int()
 
1013
longlong Item_func_dayofmonth::val_int()
1004
1014
{
1005
 
  assert(fixed == 1);
1006
 
  DRIZZLE_TIME ltime;
 
1015
  DBUG_ASSERT(fixed == 1);
 
1016
  MYSQL_TIME ltime;
1007
1017
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1008
 
  return (int64_t) ltime.day;
 
1018
  return (longlong) ltime.day;
1009
1019
}
1010
1020
 
1011
 
int64_t Item_func_month::val_int()
 
1021
longlong Item_func_month::val_int()
1012
1022
{
1013
 
  assert(fixed == 1);
1014
 
  DRIZZLE_TIME ltime;
 
1023
  DBUG_ASSERT(fixed == 1);
 
1024
  MYSQL_TIME ltime;
1015
1025
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1016
 
  return (int64_t) ltime.month;
 
1026
  return (longlong) ltime.month;
1017
1027
}
1018
1028
 
1019
1029
 
1020
1030
String* Item_func_monthname::val_str(String* str)
1021
1031
{
1022
 
  assert(fixed == 1);
 
1032
  DBUG_ASSERT(fixed == 1);
1023
1033
  const char *month_name;
1024
 
  uint32_t   month= (uint) val_int();
 
1034
  uint   month= (uint) val_int();
1025
1035
  THD *thd= current_thd;
1026
1036
 
1027
1037
  if (null_value || !month)
1040
1050
  Returns the quarter of the year.
1041
1051
*/
1042
1052
 
1043
 
int64_t Item_func_quarter::val_int()
 
1053
longlong Item_func_quarter::val_int()
1044
1054
{
1045
 
  assert(fixed == 1);
1046
 
  DRIZZLE_TIME ltime;
 
1055
  DBUG_ASSERT(fixed == 1);
 
1056
  MYSQL_TIME ltime;
1047
1057
  if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
1048
1058
    return 0;
1049
 
  return (int64_t) ((ltime.month+2)/3);
 
1059
  return (longlong) ((ltime.month+2)/3);
1050
1060
}
1051
1061
 
1052
 
int64_t Item_func_hour::val_int()
 
1062
longlong Item_func_hour::val_int()
1053
1063
{
1054
 
  assert(fixed == 1);
1055
 
  DRIZZLE_TIME ltime;
 
1064
  DBUG_ASSERT(fixed == 1);
 
1065
  MYSQL_TIME ltime;
1056
1066
  (void) get_arg0_time(&ltime);
1057
1067
  return ltime.hour;
1058
1068
}
1059
1069
 
1060
 
int64_t Item_func_minute::val_int()
 
1070
longlong Item_func_minute::val_int()
1061
1071
{
1062
 
  assert(fixed == 1);
1063
 
  DRIZZLE_TIME ltime;
 
1072
  DBUG_ASSERT(fixed == 1);
 
1073
  MYSQL_TIME ltime;
1064
1074
  (void) get_arg0_time(&ltime);
1065
1075
  return ltime.minute;
1066
1076
}
1068
1078
/**
1069
1079
  Returns the second in time_exp in the range of 0 - 59.
1070
1080
*/
1071
 
int64_t Item_func_second::val_int()
 
1081
longlong Item_func_second::val_int()
1072
1082
{
1073
 
  assert(fixed == 1);
1074
 
  DRIZZLE_TIME ltime;
 
1083
  DBUG_ASSERT(fixed == 1);
 
1084
  MYSQL_TIME ltime;
1075
1085
  (void) get_arg0_time(&ltime);
1076
1086
  return ltime.second;
1077
1087
}
1078
1088
 
1079
1089
 
1080
 
uint32_t week_mode(uint32_t mode)
 
1090
uint week_mode(uint mode)
1081
1091
{
1082
 
  uint32_t week_format= (mode & 7);
 
1092
  uint week_format= (mode & 7);
1083
1093
  if (!(week_format & WEEK_MONDAY_FIRST))
1084
1094
    week_format^= WEEK_FIRST_WEEKDAY;
1085
1095
  return week_format;
1116
1126
 @endverbatim
1117
1127
*/
1118
1128
 
1119
 
int64_t Item_func_week::val_int()
 
1129
longlong Item_func_week::val_int()
1120
1130
{
1121
 
  assert(fixed == 1);
1122
 
  uint32_t year;
1123
 
  DRIZZLE_TIME ltime;
 
1131
  DBUG_ASSERT(fixed == 1);
 
1132
  uint year;
 
1133
  MYSQL_TIME ltime;
1124
1134
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1125
1135
    return 0;
1126
 
  return (int64_t) calc_week(&ltime,
 
1136
  return (longlong) calc_week(&ltime,
1127
1137
                              week_mode((uint) args[1]->val_int()),
1128
1138
                              &year);
1129
1139
}
1130
1140
 
1131
1141
 
1132
 
int64_t Item_func_yearweek::val_int()
 
1142
longlong Item_func_yearweek::val_int()
1133
1143
{
1134
 
  assert(fixed == 1);
1135
 
  uint32_t year,week;
1136
 
  DRIZZLE_TIME ltime;
 
1144
  DBUG_ASSERT(fixed == 1);
 
1145
  uint year,week;
 
1146
  MYSQL_TIME ltime;
1137
1147
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1138
1148
    return 0;
1139
1149
  week= calc_week(&ltime, 
1143
1153
}
1144
1154
 
1145
1155
 
1146
 
int64_t Item_func_weekday::val_int()
 
1156
longlong Item_func_weekday::val_int()
1147
1157
{
1148
 
  assert(fixed == 1);
1149
 
  DRIZZLE_TIME ltime;
 
1158
  DBUG_ASSERT(fixed == 1);
 
1159
  MYSQL_TIME ltime;
1150
1160
  
1151
1161
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1152
1162
    return 0;
1153
1163
 
1154
 
  return (int64_t) calc_weekday(calc_daynr(ltime.year, ltime.month,
 
1164
  return (longlong) calc_weekday(calc_daynr(ltime.year, ltime.month,
1155
1165
                                            ltime.day),
1156
1166
                                 odbc_type) + test(odbc_type);
1157
1167
}
1159
1169
 
1160
1170
String* Item_func_dayname::val_str(String* str)
1161
1171
{
1162
 
  assert(fixed == 1);
1163
 
  uint32_t weekday=(uint) val_int();            // Always Item_func_daynr()
 
1172
  DBUG_ASSERT(fixed == 1);
 
1173
  uint weekday=(uint) val_int();                // Always Item_func_daynr()
1164
1174
  const char *day_name;
1165
1175
  THD *thd= current_thd;
1166
1176
 
1173
1183
}
1174
1184
 
1175
1185
 
1176
 
int64_t Item_func_year::val_int()
 
1186
longlong Item_func_year::val_int()
1177
1187
{
1178
 
  assert(fixed == 1);
1179
 
  DRIZZLE_TIME ltime;
 
1188
  DBUG_ASSERT(fixed == 1);
 
1189
  MYSQL_TIME ltime;
1180
1190
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1181
 
  return (int64_t) ltime.year;
 
1191
  return (longlong) ltime.year;
1182
1192
}
1183
1193
 
1184
1194
 
1199
1209
enum_monotonicity_info Item_func_year::get_monotonicity_info() const
1200
1210
{
1201
1211
  if (args[0]->type() == Item::FIELD_ITEM &&
1202
 
      (args[0]->field_type() == DRIZZLE_TYPE_NEWDATE ||
1203
 
       args[0]->field_type() == DRIZZLE_TYPE_DATETIME))
 
1212
      (args[0]->field_type() == MYSQL_TYPE_DATE ||
 
1213
       args[0]->field_type() == MYSQL_TYPE_DATETIME))
1204
1214
    return MONOTONIC_INCREASING;
1205
1215
  return NON_MONOTONIC;
1206
1216
}
1207
1217
 
1208
1218
 
1209
 
int64_t Item_func_year::val_int_endpoint(bool left_endp, bool *incl_endp)
 
1219
longlong Item_func_year::val_int_endpoint(bool left_endp, bool *incl_endp)
1210
1220
{
1211
 
  assert(fixed == 1);
1212
 
  DRIZZLE_TIME ltime;
 
1221
  DBUG_ASSERT(fixed == 1);
 
1222
  MYSQL_TIME ltime;
1213
1223
  if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
1214
1224
  {
1215
1225
    /* got NULL, leave the incl_endp intact */
1216
 
    return INT64_MIN;
 
1226
    return LONGLONG_MIN;
1217
1227
  }
1218
1228
 
1219
1229
  /*
1231
1241
      !(ltime.hour || ltime.minute || ltime.second || ltime.second_part))
1232
1242
    ; /* do nothing */
1233
1243
  else
1234
 
    *incl_endp= true;
 
1244
    *incl_endp= TRUE;
1235
1245
  return ltime.year;
1236
1246
}
1237
1247
 
1238
1248
 
1239
 
int64_t Item_func_unix_timestamp::val_int()
 
1249
longlong Item_func_unix_timestamp::val_int()
1240
1250
{
1241
 
  DRIZZLE_TIME ltime;
1242
 
  bool not_used;
 
1251
  MYSQL_TIME ltime;
 
1252
  my_bool not_used;
1243
1253
  
1244
 
  assert(fixed == 1);
 
1254
  DBUG_ASSERT(fixed == 1);
1245
1255
  if (arg_count == 0)
1246
 
    return (int64_t) current_thd->query_start();
 
1256
    return (longlong) current_thd->query_start();
1247
1257
  if (args[0]->type() == FIELD_ITEM)
1248
1258
  {                                             // Optimize timestamp field
1249
1259
    Field *field=((Item_field*) args[0])->field;
1250
 
    if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
 
1260
    if (field->type() == MYSQL_TYPE_TIMESTAMP)
1251
1261
      return ((Field_timestamp*) field)->get_timestamp(&null_value);
1252
1262
  }
1253
1263
  
1262
1272
    return 0;
1263
1273
  }
1264
1274
  
1265
 
  return (int64_t) TIME_to_timestamp(current_thd, &ltime, &not_used);
 
1275
  return (longlong) TIME_to_timestamp(current_thd, &ltime, &not_used);
1266
1276
}
1267
1277
 
1268
1278
 
1269
 
int64_t Item_func_time_to_sec::val_int()
 
1279
longlong Item_func_time_to_sec::val_int()
1270
1280
{
1271
 
  assert(fixed == 1);
1272
 
  DRIZZLE_TIME ltime;
1273
 
  int64_t seconds;
 
1281
  DBUG_ASSERT(fixed == 1);
 
1282
  MYSQL_TIME ltime;
 
1283
  longlong seconds;
1274
1284
  (void) get_arg0_time(&ltime);
1275
1285
  seconds=ltime.hour*3600L+ltime.minute*60+ltime.second;
1276
1286
  return ltime.neg ? -seconds : seconds;
1286
1296
bool get_interval_value(Item *args,interval_type int_type,
1287
1297
                               String *str_value, INTERVAL *interval)
1288
1298
{
1289
 
  uint64_t array[5];
1290
 
  int64_t value= 0;
 
1299
  ulonglong array[5];
 
1300
  longlong value= 0;
1291
1301
  const char *str= NULL;
1292
1302
  size_t length= 0;
1293
 
  const CHARSET_INFO * const cs= str_value->charset();
 
1303
  CHARSET_INFO *cs=str_value->charset();
1294
1304
 
1295
 
  memset(interval, 0, sizeof(*interval));
 
1305
  bzero((char*) interval,sizeof(*interval));
1296
1306
  if ((int) int_type <= INTERVAL_MICROSECOND)
1297
1307
  {
1298
1308
    value= args->val_int();
1428
1438
    interval->second_part= array[1];
1429
1439
    break;
1430
1440
  case INTERVAL_LAST: /* purecov: begin deadcode */
1431
 
    assert(0); 
 
1441
    DBUG_ASSERT(0); 
1432
1442
    break;            /* purecov: end */
1433
1443
  }
1434
1444
  return 0;
1437
1447
 
1438
1448
String *Item_date::val_str(String *str)
1439
1449
{
1440
 
  assert(fixed == 1);
1441
 
  DRIZZLE_TIME ltime;
 
1450
  DBUG_ASSERT(fixed == 1);
 
1451
  MYSQL_TIME ltime;
1442
1452
  if (get_date(&ltime, TIME_FUZZY_DATE))
1443
1453
    return (String *) 0;
1444
1454
  if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
1451
1461
}
1452
1462
 
1453
1463
 
1454
 
int64_t Item_date::val_int()
 
1464
longlong Item_date::val_int()
1455
1465
{
1456
 
  assert(fixed == 1);
1457
 
  DRIZZLE_TIME ltime;
 
1466
  DBUG_ASSERT(fixed == 1);
 
1467
  MYSQL_TIME ltime;
1458
1468
  if (get_date(&ltime, TIME_FUZZY_DATE))
1459
1469
    return 0;
1460
 
  return (int64_t) (ltime.year*10000L+ltime.month*100+ltime.day);
 
1470
  return (longlong) (ltime.year*10000L+ltime.month*100+ltime.day);
1461
1471
}
1462
1472
 
1463
1473
 
1464
 
bool Item_func_from_days::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
1474
bool Item_func_from_days::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
1465
1475
{
1466
 
  int64_t value=args[0]->val_int();
 
1476
  longlong value=args[0]->val_int();
1467
1477
  if ((null_value=args[0]->null_value))
1468
1478
    return 1;
1469
 
  memset(ltime, 0, sizeof(DRIZZLE_TIME));
 
1479
  bzero(ltime, sizeof(MYSQL_TIME));
1470
1480
  get_date_from_daynr((long) value, &ltime->year, &ltime->month, &ltime->day);
1471
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
1481
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
1472
1482
  return 0;
1473
1483
}
1474
1484
 
1483
1493
  
1484
1494
  /* We don't need to set second_part and neg because they already 0 */
1485
1495
  ltime.hour= ltime.minute= ltime.second= 0;
1486
 
  ltime.time_type= DRIZZLE_TIMESTAMP_DATE;
1487
 
  value= (int64_t) TIME_to_uint64_t_date(&ltime);
 
1496
  ltime.time_type= MYSQL_TIMESTAMP_DATE;
 
1497
  value= (longlong) TIME_to_ulonglong_date(&ltime);
1488
1498
}
1489
1499
 
1490
1500
String *Item_func_curdate::val_str(String *str)
1491
1501
{
1492
 
  assert(fixed == 1);
 
1502
  DBUG_ASSERT(fixed == 1);
1493
1503
  if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
1494
1504
  {
1495
1505
    null_value= 1;
1500
1510
}
1501
1511
 
1502
1512
/**
1503
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1513
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1504
1514
    time zone. Defines time zone (local) used for whole CURDATE function.
1505
1515
*/
1506
 
void Item_func_curdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1516
void Item_func_curdate_local::store_now_in_TIME(MYSQL_TIME *now_time)
1507
1517
{
1508
1518
  THD *thd= current_thd;
1509
1519
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1513
1523
 
1514
1524
 
1515
1525
/**
1516
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
1526
    Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
1517
1527
    time zone. Defines time zone (UTC) used for whole UTC_DATE function.
1518
1528
*/
1519
 
void Item_func_curdate_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1529
void Item_func_curdate_utc::store_now_in_TIME(MYSQL_TIME *now_time)
1520
1530
{
1521
1531
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1522
1532
                             (my_time_t)(current_thd->query_start()));
1527
1537
}
1528
1538
 
1529
1539
 
1530
 
bool Item_func_curdate::get_date(DRIZZLE_TIME *res,
1531
 
                                 uint32_t fuzzy_date __attribute__((unused)))
 
1540
bool Item_func_curdate::get_date(MYSQL_TIME *res,
 
1541
                                 uint fuzzy_date __attribute__((unused)))
1532
1542
{
1533
1543
  *res=ltime;
1534
1544
  return 0;
1535
1545
}
1536
1546
 
1537
1547
 
1538
 
String *Item_func_curtime::val_str(String *str __attribute__((unused)))
 
1548
String *Item_func_curtime::val_str(String *str)
1539
1549
{
1540
 
  assert(fixed == 1);
 
1550
  DBUG_ASSERT(fixed == 1);
1541
1551
  str_value.set(buff, buff_length, &my_charset_bin);
1542
1552
  return &str_value;
1543
1553
}
1545
1555
 
1546
1556
void Item_func_curtime::fix_length_and_dec()
1547
1557
{
1548
 
  DRIZZLE_TIME ltime;
 
1558
  MYSQL_TIME ltime;
1549
1559
 
1550
1560
  decimals= DATETIME_DEC;
1551
1561
  collation.set(&my_charset_bin);
1552
1562
  store_now_in_TIME(&ltime);
1553
 
  value= TIME_to_uint64_t_time(&ltime);
 
1563
  value= TIME_to_ulonglong_time(&ltime);
1554
1564
  buff_length= (uint) my_time_to_str(&ltime, buff);
1555
1565
  max_length= buff_length;
1556
1566
}
1557
1567
 
1558
1568
 
1559
1569
/**
1560
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1570
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1561
1571
    time zone. Defines time zone (local) used for whole CURTIME function.
1562
1572
*/
1563
 
void Item_func_curtime_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1573
void Item_func_curtime_local::store_now_in_TIME(MYSQL_TIME *now_time)
1564
1574
{
1565
1575
  THD *thd= current_thd;
1566
1576
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1570
1580
 
1571
1581
 
1572
1582
/**
1573
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
1583
    Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
1574
1584
    time zone. Defines time zone (UTC) used for whole UTC_TIME function.
1575
1585
*/
1576
 
void Item_func_curtime_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1586
void Item_func_curtime_utc::store_now_in_TIME(MYSQL_TIME *now_time)
1577
1587
{
1578
1588
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1579
1589
                             (my_time_t)(current_thd->query_start()));
1584
1594
}
1585
1595
 
1586
1596
 
1587
 
String *Item_func_now::val_str(String *str __attribute__((unused)))
 
1597
String *Item_func_now::val_str(String *str)
1588
1598
{
1589
 
  assert(fixed == 1);
 
1599
  DBUG_ASSERT(fixed == 1);
1590
1600
  str_value.set(buff,buff_length, &my_charset_bin);
1591
1601
  return &str_value;
1592
1602
}
1598
1608
  collation.set(&my_charset_bin);
1599
1609
 
1600
1610
  store_now_in_TIME(&ltime);
1601
 
  value= (int64_t) TIME_to_uint64_t_datetime(&ltime);
 
1611
  value= (longlong) TIME_to_ulonglong_datetime(&ltime);
1602
1612
 
1603
1613
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
1604
1614
  max_length= buff_length;
1606
1616
 
1607
1617
 
1608
1618
/**
1609
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1619
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1610
1620
    time zone. Defines time zone (local) used for whole NOW function.
1611
1621
*/
1612
 
void Item_func_now_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1622
void Item_func_now_local::store_now_in_TIME(MYSQL_TIME *now_time)
1613
1623
{
1614
1624
  THD *thd= current_thd;
1615
1625
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1619
1629
 
1620
1630
 
1621
1631
/**
1622
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
1632
    Converts current time in my_time_t to MYSQL_TIME represenatation for UTC
1623
1633
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
1624
1634
*/
1625
 
void Item_func_now_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1635
void Item_func_now_utc::store_now_in_TIME(MYSQL_TIME *now_time)
1626
1636
{
1627
1637
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1628
1638
                             (my_time_t)(current_thd->query_start()));
1633
1643
}
1634
1644
 
1635
1645
 
1636
 
bool Item_func_now::get_date(DRIZZLE_TIME *res,
1637
 
                             uint32_t fuzzy_date __attribute__((unused)))
 
1646
bool Item_func_now::get_date(MYSQL_TIME *res,
 
1647
                             uint fuzzy_date __attribute__((unused)))
1638
1648
{
1639
1649
  *res= ltime;
1640
1650
  return 0;
1641
1651
}
1642
1652
 
1643
1653
 
1644
 
int Item_func_now::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
 
1654
int Item_func_now::save_in_field(Field *to, bool no_conversions)
1645
1655
{
1646
1656
  to->set_notnull();
1647
 
  return to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
1657
  return to->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
1648
1658
}
1649
1659
 
1650
1660
 
1651
1661
/**
1652
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
1662
    Converts current time in my_time_t to MYSQL_TIME represenatation for local
1653
1663
    time zone. Defines time zone (local) used for whole SYSDATE function.
1654
1664
*/
1655
 
void Item_func_sysdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
1665
void Item_func_sysdate_local::store_now_in_TIME(MYSQL_TIME *now_time)
1656
1666
{
1657
1667
  THD *thd= current_thd;
1658
1668
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, (my_time_t) my_time(0));
1660
1670
}
1661
1671
 
1662
1672
 
1663
 
String *Item_func_sysdate_local::val_str(String *str __attribute__((unused)))
 
1673
String *Item_func_sysdate_local::val_str(String *str)
1664
1674
{
1665
 
  assert(fixed == 1);
 
1675
  DBUG_ASSERT(fixed == 1);
1666
1676
  store_now_in_TIME(&ltime);
1667
1677
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
1668
1678
  str_value.set(buff, buff_length, &my_charset_bin);
1670
1680
}
1671
1681
 
1672
1682
 
1673
 
int64_t Item_func_sysdate_local::val_int()
 
1683
longlong Item_func_sysdate_local::val_int()
1674
1684
{
1675
 
  assert(fixed == 1);
 
1685
  DBUG_ASSERT(fixed == 1);
1676
1686
  store_now_in_TIME(&ltime);
1677
 
  return (int64_t) TIME_to_uint64_t_datetime(&ltime);
 
1687
  return (longlong) TIME_to_ulonglong_datetime(&ltime);
1678
1688
}
1679
1689
 
1680
1690
 
1681
1691
double Item_func_sysdate_local::val_real()
1682
1692
{
1683
 
  assert(fixed == 1);
 
1693
  DBUG_ASSERT(fixed == 1);
1684
1694
  store_now_in_TIME(&ltime);
1685
 
  return uint64_t2double(TIME_to_uint64_t_datetime(&ltime));
 
1695
  return ulonglong2double(TIME_to_ulonglong_datetime(&ltime));
1686
1696
}
1687
1697
 
1688
1698
 
1694
1704
}
1695
1705
 
1696
1706
 
1697
 
bool Item_func_sysdate_local::get_date(DRIZZLE_TIME *res,
1698
 
                                       uint32_t fuzzy_date __attribute__((unused)))
 
1707
bool Item_func_sysdate_local::get_date(MYSQL_TIME *res,
 
1708
                                       uint fuzzy_date __attribute__((unused)))
1699
1709
{
1700
1710
  store_now_in_TIME(&ltime);
1701
1711
  *res= ltime;
1703
1713
}
1704
1714
 
1705
1715
 
1706
 
int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
 
1716
int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions)
1707
1717
{
1708
1718
  store_now_in_TIME(&ltime);
1709
1719
  to->set_notnull();
1710
 
  to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
1720
  to->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
1711
1721
  return 0;
1712
1722
}
1713
1723
 
1714
1724
 
1715
1725
String *Item_func_sec_to_time::val_str(String *str)
1716
1726
{
1717
 
  assert(fixed == 1);
1718
 
  DRIZZLE_TIME ltime;
1719
 
  int64_t arg_val= args[0]->val_int(); 
 
1727
  DBUG_ASSERT(fixed == 1);
 
1728
  MYSQL_TIME ltime;
 
1729
  longlong arg_val= args[0]->val_int(); 
1720
1730
 
1721
1731
  if ((null_value=args[0]->null_value) ||
1722
1732
      str->alloc(MAX_DATE_STRING_REP_LENGTH))
1732
1742
}
1733
1743
 
1734
1744
 
1735
 
int64_t Item_func_sec_to_time::val_int()
 
1745
longlong Item_func_sec_to_time::val_int()
1736
1746
{
1737
 
  assert(fixed == 1);
1738
 
  DRIZZLE_TIME ltime;
1739
 
  int64_t arg_val= args[0]->val_int(); 
 
1747
  DBUG_ASSERT(fixed == 1);
 
1748
  MYSQL_TIME ltime;
 
1749
  longlong arg_val= args[0]->val_int(); 
1740
1750
  
1741
1751
  if ((null_value=args[0]->null_value))
1742
1752
    return 0;
1758
1768
  Item *arg1= args[1]->this_item();
1759
1769
 
1760
1770
  decimals=0;
1761
 
  const CHARSET_INFO * const cs= thd->variables.collation_connection;
1762
 
  uint32_t repertoire= arg1->collation.repertoire;
 
1771
  CHARSET_INFO *cs= thd->variables.collation_connection;
 
1772
  uint32 repertoire= arg1->collation.repertoire;
1763
1773
  if (!thd->variables.lc_time_names->is_ascii)
1764
1774
    repertoire|= MY_REPERTOIRE_EXTENDED;
1765
1775
  collation.set(cs, arg1->collation.derivation, repertoire);
1772
1782
  else
1773
1783
  {
1774
1784
    fixed_length=0;
1775
 
    max_length=cmin(arg1->max_length,(uint32_t) MAX_BLOB_WIDTH) * 10 *
 
1785
    max_length=min(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
1776
1786
                   collation.collation->mbmaxlen;
1777
1787
    set_if_smaller(max_length,MAX_BLOB_WIDTH);
1778
1788
  }
1805
1815
 
1806
1816
 
1807
1817
 
1808
 
uint32_t Item_func_date_format::format_length(const String *format)
 
1818
uint Item_func_date_format::format_length(const String *format)
1809
1819
{
1810
 
  uint32_t size=0;
 
1820
  uint size=0;
1811
1821
  const char *ptr=format->ptr();
1812
1822
  const char *end=ptr+format->length();
1813
1823
 
1881
1891
String *Item_func_date_format::val_str(String *str)
1882
1892
{
1883
1893
  String *format;
1884
 
  DRIZZLE_TIME l_time;
1885
 
  uint32_t size;
1886
 
  assert(fixed == 1);
 
1894
  MYSQL_TIME l_time;
 
1895
  uint size;
 
1896
  DBUG_ASSERT(fixed == 1);
1887
1897
 
1888
1898
  if (!is_time_format)
1889
1899
  {
1924
1934
  /* Create the result string */
1925
1935
  str->set_charset(collation.collation);
1926
1936
  if (!make_date_time(&date_time_format, &l_time,
1927
 
                      is_time_format ? DRIZZLE_TIMESTAMP_TIME :
1928
 
                                       DRIZZLE_TIMESTAMP_DATE,
 
1937
                      is_time_format ? MYSQL_TIMESTAMP_TIME :
 
1938
                                       MYSQL_TIMESTAMP_DATE,
1929
1939
                      str))
1930
1940
    return str;
1931
1941
 
1948
1958
 
1949
1959
String *Item_func_from_unixtime::val_str(String *str)
1950
1960
{
1951
 
  DRIZZLE_TIME time_tmp;
 
1961
  MYSQL_TIME time_tmp;
1952
1962
 
1953
 
  assert(fixed == 1);
 
1963
  DBUG_ASSERT(fixed == 1);
1954
1964
 
1955
1965
  if (get_date(&time_tmp, 0))
1956
1966
    return 0;
1967
1977
}
1968
1978
 
1969
1979
 
1970
 
int64_t Item_func_from_unixtime::val_int()
 
1980
longlong Item_func_from_unixtime::val_int()
1971
1981
{
1972
 
  DRIZZLE_TIME time_tmp;
 
1982
  MYSQL_TIME time_tmp;
1973
1983
 
1974
 
  assert(fixed == 1);
 
1984
  DBUG_ASSERT(fixed == 1);
1975
1985
 
1976
1986
  if (get_date(&time_tmp, 0))
1977
1987
    return 0;
1978
1988
 
1979
 
  return (int64_t) TIME_to_uint64_t_datetime(&time_tmp);
 
1989
  return (longlong) TIME_to_ulonglong_datetime(&time_tmp);
1980
1990
}
1981
1991
 
1982
 
bool Item_func_from_unixtime::get_date(DRIZZLE_TIME *ltime,
1983
 
                                       uint32_t fuzzy_date __attribute__((unused)))
 
1992
bool Item_func_from_unixtime::get_date(MYSQL_TIME *ltime,
 
1993
                                       uint fuzzy_date __attribute__((unused)))
1984
1994
{
1985
 
  uint64_t tmp= (uint64_t)(args[0]->val_int());
 
1995
  ulonglong tmp= (ulonglong)(args[0]->val_int());
1986
1996
  /*
1987
1997
    "tmp > TIMESTAMP_MAX_VALUE" check also covers case of negative
1988
1998
    from_unixtime() argument since tmp is unsigned.
2009
2019
    The field type for the result of an Item_date function is defined as
2010
2020
    follows:
2011
2021
 
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
 
2022
    - If first arg is a MYSQL_TYPE_DATETIME result is MYSQL_TYPE_DATETIME
 
2023
    - If first arg is a MYSQL_TYPE_DATE and the interval type uses hours,
 
2024
      minutes or seconds then type is MYSQL_TYPE_DATETIME.
 
2025
    - Otherwise the result is MYSQL_TYPE_STRING
 
2026
      (This is because you can't know if the string contains a DATE, MYSQL_TIME or
2017
2027
      DATETIME argument)
2018
2028
  */
2019
 
  cached_field_type= DRIZZLE_TYPE_VARCHAR;
 
2029
  cached_field_type= MYSQL_TYPE_STRING;
2020
2030
  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)
 
2031
  if (arg0_field_type == MYSQL_TYPE_DATETIME ||
 
2032
      arg0_field_type == MYSQL_TYPE_TIMESTAMP)
 
2033
    cached_field_type= MYSQL_TYPE_DATETIME;
 
2034
  else if (arg0_field_type == MYSQL_TYPE_DATE)
2025
2035
  {
2026
2036
    if (int_type <= INTERVAL_DAY || int_type == INTERVAL_YEAR_MONTH)
2027
2037
      cached_field_type= arg0_field_type;
2028
2038
    else
2029
 
      cached_field_type= DRIZZLE_TYPE_DATETIME;
 
2039
      cached_field_type= MYSQL_TYPE_DATETIME;
2030
2040
  }
2031
2041
}
2032
2042
 
2033
2043
 
2034
2044
/* Here arg[1] is a Item_interval object */
2035
2045
 
2036
 
bool Item_date_add_interval::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
2046
bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
2037
2047
{
2038
2048
  INTERVAL interval;
2039
2049
 
2052
2062
 
2053
2063
String *Item_date_add_interval::val_str(String *str)
2054
2064
{
2055
 
  assert(fixed == 1);
2056
 
  DRIZZLE_TIME ltime;
 
2065
  DBUG_ASSERT(fixed == 1);
 
2066
  MYSQL_TIME ltime;
2057
2067
  enum date_time_format_types format;
2058
2068
 
2059
2069
  if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
2060
2070
    return 0;
2061
2071
 
2062
 
  if (ltime.time_type == DRIZZLE_TIMESTAMP_DATE)
 
2072
  if (ltime.time_type == MYSQL_TIMESTAMP_DATE)
2063
2073
    format= DATE_ONLY;
2064
2074
  else if (ltime.second_part)
2065
2075
    format= DATE_TIME_MICROSECOND;
2074
2084
}
2075
2085
 
2076
2086
 
2077
 
int64_t Item_date_add_interval::val_int()
 
2087
longlong Item_date_add_interval::val_int()
2078
2088
{
2079
 
  assert(fixed == 1);
2080
 
  DRIZZLE_TIME ltime;
2081
 
  int64_t date;
 
2089
  DBUG_ASSERT(fixed == 1);
 
2090
  MYSQL_TIME ltime;
 
2091
  longlong date;
2082
2092
  if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
2083
 
    return (int64_t) 0;
 
2093
    return (longlong) 0;
2084
2094
  date = (ltime.year*100L + ltime.month)*100L + ltime.day;
2085
 
  return ltime.time_type == DRIZZLE_TIMESTAMP_DATE ? date :
 
2095
  return ltime.time_type == MYSQL_TIMESTAMP_DATE ? date :
2086
2096
    ((date*100L + ltime.hour)*100L+ ltime.minute)*100L + ltime.second;
2087
2097
}
2088
2098
 
2159
2169
  case INTERVAL_HOUR_MICROSECOND: max_length=13; date_value=0; break;
2160
2170
  case INTERVAL_MINUTE_MICROSECOND: max_length=11; date_value=0; break;
2161
2171
  case INTERVAL_SECOND_MICROSECOND: max_length=9; date_value=0; break;
2162
 
  case INTERVAL_LAST: assert(0); break; /* purecov: deadcode */
 
2172
  case INTERVAL_LAST: DBUG_ASSERT(0); break; /* purecov: deadcode */
2163
2173
  }
2164
2174
}
2165
2175
 
2166
2176
 
2167
 
int64_t Item_extract::val_int()
 
2177
longlong Item_extract::val_int()
2168
2178
{
2169
 
  assert(fixed == 1);
2170
 
  DRIZZLE_TIME ltime;
2171
 
  uint32_t year;
 
2179
  DBUG_ASSERT(fixed == 1);
 
2180
  MYSQL_TIME ltime;
 
2181
  uint year;
2172
2182
  ulong week_format;
2173
2183
  long neg;
2174
2184
  if (date_value)
2203
2213
  case INTERVAL_DAY_MINUTE:     return (long) (ltime.day*10000L+
2204
2214
                                               ltime.hour*100L+
2205
2215
                                               ltime.minute)*neg;
2206
 
  case INTERVAL_DAY_SECOND:      return ((int64_t) ltime.day*1000000L+
2207
 
                                         (int64_t) (ltime.hour*10000L+
 
2216
  case INTERVAL_DAY_SECOND:      return ((longlong) ltime.day*1000000L+
 
2217
                                         (longlong) (ltime.hour*10000L+
2208
2218
                                                     ltime.minute*100+
2209
2219
                                                     ltime.second))*neg;
2210
2220
  case INTERVAL_HOUR:           return (long) ltime.hour*neg;
2215
2225
  case INTERVAL_MINUTE_SECOND:  return (long) (ltime.minute*100+ltime.second)*neg;
2216
2226
  case INTERVAL_SECOND:         return (long) ltime.second*neg;
2217
2227
  case INTERVAL_MICROSECOND:    return (long) ltime.second_part*neg;
2218
 
  case INTERVAL_DAY_MICROSECOND: return (((int64_t)ltime.day*1000000L +
2219
 
                                          (int64_t)ltime.hour*10000L +
 
2228
  case INTERVAL_DAY_MICROSECOND: return (((longlong)ltime.day*1000000L +
 
2229
                                          (longlong)ltime.hour*10000L +
2220
2230
                                          ltime.minute*100 +
2221
2231
                                          ltime.second)*1000000L +
2222
2232
                                         ltime.second_part)*neg;
2223
 
  case INTERVAL_HOUR_MICROSECOND: return (((int64_t)ltime.hour*10000L +
 
2233
  case INTERVAL_HOUR_MICROSECOND: return (((longlong)ltime.hour*10000L +
2224
2234
                                           ltime.minute*100 +
2225
2235
                                           ltime.second)*1000000L +
2226
2236
                                          ltime.second_part)*neg;
2227
 
  case INTERVAL_MINUTE_MICROSECOND: return (((int64_t)(ltime.minute*100+
 
2237
  case INTERVAL_MINUTE_MICROSECOND: return (((longlong)(ltime.minute*100+
2228
2238
                                                        ltime.second))*1000000L+
2229
2239
                                            ltime.second_part)*neg;
2230
 
  case INTERVAL_SECOND_MICROSECOND: return ((int64_t)ltime.second*1000000L+
 
2240
  case INTERVAL_SECOND_MICROSECOND: return ((longlong)ltime.second*1000000L+
2231
2241
                                            ltime.second_part)*neg;
2232
 
  case INTERVAL_LAST: assert(0); break;  /* purecov: deadcode */
 
2242
  case INTERVAL_LAST: DBUG_ASSERT(0); break;  /* purecov: deadcode */
2233
2243
  }
2234
2244
  return 0;                                     // Impossible
2235
2245
}
2291
2301
    char buffer[20];
2292
2302
    // my_charset_bin is good enough for numbers
2293
2303
    String st(buffer, sizeof(buffer), &my_charset_bin);
2294
 
    st.set((uint64_t)cast_length, &my_charset_bin);
 
2304
    st.set((ulonglong)cast_length, &my_charset_bin);
2295
2305
    str->append(st);
2296
2306
    str->append(')');
2297
2307
  }
2305
2315
 
2306
2316
String *Item_char_typecast::val_str(String *str)
2307
2317
{
2308
 
  assert(fixed == 1);
 
2318
  DBUG_ASSERT(fixed == 1);
2309
2319
  String *res;
2310
 
  uint32_t length;
 
2320
  uint32 length;
2311
2321
 
2312
2322
  if (!charset_conversion)
2313
2323
  {
2320
2330
  else
2321
2331
  {
2322
2332
    // Convert character set if differ
2323
 
    uint32_t dummy_errors;
 
2333
    uint dummy_errors;
2324
2334
    if (!(res= args[0]->val_str(&tmp_value)) ||
2325
2335
        str->copy(res->ptr(), res->length(), from_cs,
2326
2336
        cast_cs, &dummy_errors))
2340
2350
  */
2341
2351
  if (cast_length >= 0)
2342
2352
  {
2343
 
    if (res->length() > (length= (uint32_t) res->charpos(cast_length)))
 
2353
    if (res->length() > (length= (uint32) res->charpos(cast_length)))
2344
2354
    {                                           // Safe even if const arg
2345
2355
      char char_type[40];
2346
 
      snprintf(char_type, sizeof(char_type), "%s(%lu)",
2347
 
               cast_cs == &my_charset_bin ? "BINARY" : "CHAR",
2348
 
               (ulong) length);
 
2356
      my_snprintf(char_type, sizeof(char_type), "%s(%lu)",
 
2357
                  cast_cs == &my_charset_bin ? "BINARY" : "CHAR",
 
2358
                  (ulong) length);
2349
2359
 
2350
2360
      if (!res->alloced_length())
2351
2361
      {                                         // Don't change const str
2352
2362
        str_value= *res;                        // Not malloced string
2353
2363
        res= &str_value;
2354
2364
      }
2355
 
      push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2365
      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2356
2366
                          ER_TRUNCATED_WRONG_VALUE,
2357
2367
                          ER(ER_TRUNCATED_WRONG_VALUE), char_type,
2358
2368
                          res->c_ptr_safe());
2366
2376
        str->copy(*res);
2367
2377
        res= str;
2368
2378
      }
2369
 
      memset(res->ptr() + res->length(), 0,
2370
 
             (uint) cast_length - res->length());
 
2379
      bzero((char*) res->ptr() + res->length(),
 
2380
            (uint) cast_length - res->length());
2371
2381
      res->length(cast_length);
2372
2382
    }
2373
2383
  }
2378
2388
 
2379
2389
void Item_char_typecast::fix_length_and_dec()
2380
2390
{
2381
 
  uint32_t char_length;
 
2391
  uint32 char_length;
2382
2392
  /* 
2383
2393
     We always force character set conversion if cast_cs
2384
2394
     is a multi-byte character set. It garantees that the
2404
2414
  from_cs= (args[0]->result_type() == INT_RESULT || 
2405
2415
            args[0]->result_type() == DECIMAL_RESULT ||
2406
2416
            args[0]->result_type() == REAL_RESULT) ?
2407
 
           (cast_cs->mbminlen == 1 ? cast_cs : &my_charset_utf8_general_ci) :
 
2417
           (cast_cs->mbminlen == 1 ? cast_cs : &my_charset_latin1) :
2408
2418
           args[0]->collation.collation;
2409
2419
  charset_conversion= (cast_cs->mbmaxlen > 1) ||
2410
2420
                      (!my_charset_same(from_cs, cast_cs) && from_cs != &my_charset_bin && cast_cs != &my_charset_bin);
2417
2427
 
2418
2428
String *Item_datetime_typecast::val_str(String *str)
2419
2429
{
2420
 
  assert(fixed == 1);
2421
 
  DRIZZLE_TIME ltime;
 
2430
  DBUG_ASSERT(fixed == 1);
 
2431
  MYSQL_TIME ltime;
2422
2432
 
2423
2433
  if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
2424
2434
      !make_datetime(ltime.second_part ? DATE_TIME_MICROSECOND : DATE_TIME, 
2430
2440
}
2431
2441
 
2432
2442
 
2433
 
int64_t Item_datetime_typecast::val_int()
 
2443
longlong Item_datetime_typecast::val_int()
2434
2444
{
2435
 
  assert(fixed == 1);
2436
 
  DRIZZLE_TIME ltime;
 
2445
  DBUG_ASSERT(fixed == 1);
 
2446
  MYSQL_TIME ltime;
2437
2447
  if (get_arg0_date(&ltime,1))
2438
2448
  {
2439
2449
    null_value= 1;
2440
2450
    return 0;
2441
2451
  }
2442
2452
 
2443
 
  return TIME_to_uint64_t_datetime(&ltime);
 
2453
  return TIME_to_ulonglong_datetime(&ltime);
2444
2454
}
2445
2455
 
2446
2456
 
2447
 
bool Item_time_typecast::get_time(DRIZZLE_TIME *ltime)
 
2457
bool Item_time_typecast::get_time(MYSQL_TIME *ltime)
2448
2458
{
2449
2459
  bool res= get_arg0_time(ltime);
2450
2460
  /*
2451
 
    For DRIZZLE_TIMESTAMP_TIME value we can have non-zero day part,
 
2461
    For MYSQL_TIMESTAMP_TIME value we can have non-zero day part,
2452
2462
    which we should not lose.
2453
2463
  */
2454
 
  if (ltime->time_type == DRIZZLE_TIMESTAMP_DATETIME)
 
2464
  if (ltime->time_type == MYSQL_TIMESTAMP_DATETIME)
2455
2465
    ltime->year= ltime->month= ltime->day= 0;
2456
 
  ltime->time_type= DRIZZLE_TIMESTAMP_TIME;
 
2466
  ltime->time_type= MYSQL_TIMESTAMP_TIME;
2457
2467
  return res;
2458
2468
}
2459
2469
 
2460
2470
 
2461
 
int64_t Item_time_typecast::val_int()
 
2471
longlong Item_time_typecast::val_int()
2462
2472
{
2463
 
  DRIZZLE_TIME ltime;
 
2473
  MYSQL_TIME ltime;
2464
2474
  if (get_time(&ltime))
2465
2475
  {
2466
2476
    null_value= 1;
2471
2481
 
2472
2482
String *Item_time_typecast::val_str(String *str)
2473
2483
{
2474
 
  assert(fixed == 1);
2475
 
  DRIZZLE_TIME ltime;
 
2484
  DBUG_ASSERT(fixed == 1);
 
2485
  MYSQL_TIME ltime;
2476
2486
 
2477
2487
  if (!get_arg0_time(&ltime) &&
2478
2488
      !make_datetime(ltime.second_part ? TIME_MICROSECOND : TIME_ONLY,
2484
2494
}
2485
2495
 
2486
2496
 
2487
 
bool Item_date_typecast::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
2497
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
2488
2498
{
2489
2499
  bool res= get_arg0_date(ltime, TIME_FUZZY_DATE);
2490
2500
  ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
2491
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
2501
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
2492
2502
  return res;
2493
2503
}
2494
2504
 
2495
2505
 
2496
 
bool Item_date_typecast::get_time(DRIZZLE_TIME *ltime)
 
2506
bool Item_date_typecast::get_time(MYSQL_TIME *ltime)
2497
2507
{
2498
 
  memset(ltime, 0, sizeof(DRIZZLE_TIME));
 
2508
  bzero((char *)ltime, sizeof(MYSQL_TIME));
2499
2509
  return args[0]->null_value;
2500
2510
}
2501
2511
 
2502
2512
 
2503
2513
String *Item_date_typecast::val_str(String *str)
2504
2514
{
2505
 
  assert(fixed == 1);
2506
 
  DRIZZLE_TIME ltime;
 
2515
  DBUG_ASSERT(fixed == 1);
 
2516
  MYSQL_TIME ltime;
2507
2517
 
2508
2518
  if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
2509
2519
      !str->alloc(MAX_DATE_STRING_REP_LENGTH))
2516
2526
  return 0;
2517
2527
}
2518
2528
 
2519
 
int64_t Item_date_typecast::val_int()
 
2529
longlong Item_date_typecast::val_int()
2520
2530
{
2521
 
  assert(fixed == 1);
2522
 
  DRIZZLE_TIME ltime;
 
2531
  DBUG_ASSERT(fixed == 1);
 
2532
  MYSQL_TIME ltime;
2523
2533
  if ((null_value= args[0]->get_date(&ltime, TIME_FUZZY_DATE)))
2524
2534
    return 0;
2525
 
  return (int64_t) (ltime.year * 10000L + ltime.month * 100 + ltime.day);
 
2535
  return (longlong) (ltime.year * 10000L + ltime.month * 100 + ltime.day);
2526
2536
}
2527
2537
 
2528
2538
/**
2537
2547
 
2538
2548
String *Item_func_makedate::val_str(String *str)
2539
2549
{
2540
 
  assert(fixed == 1);
2541
 
  DRIZZLE_TIME l_time;
 
2550
  DBUG_ASSERT(fixed == 1);
 
2551
  MYSQL_TIME l_time;
2542
2552
  long daynr=  (long) args[1]->val_int();
2543
2553
  long year= (long) args[0]->val_int();
2544
2554
  long days;
2578
2588
    for dates between 0000-01-01 and 0099-12-31
2579
2589
*/
2580
2590
 
2581
 
int64_t Item_func_makedate::val_int()
 
2591
longlong Item_func_makedate::val_int()
2582
2592
{
2583
 
  assert(fixed == 1);
2584
 
  DRIZZLE_TIME l_time;
 
2593
  DBUG_ASSERT(fixed == 1);
 
2594
  MYSQL_TIME l_time;
2585
2595
  long daynr=  (long) args[1]->val_int();
2586
2596
  long year= (long) args[0]->val_int();
2587
2597
  long days;
2599
2609
  {
2600
2610
    null_value=0;
2601
2611
    get_date_from_daynr(days,&l_time.year,&l_time.month,&l_time.day);
2602
 
    return (int64_t) (l_time.year * 10000L + l_time.month * 100 + l_time.day);
 
2612
    return (longlong) (l_time.year * 10000L + l_time.month * 100 + l_time.day);
2603
2613
  }
2604
2614
 
2605
2615
err:
2619
2629
    The field type for the result of an Item_func_add_time function is defined
2620
2630
    as follows:
2621
2631
 
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
 
2632
    - If first arg is a MYSQL_TYPE_DATETIME or MYSQL_TYPE_TIMESTAMP 
 
2633
      result is MYSQL_TYPE_DATETIME
 
2634
    - If first arg is a MYSQL_TYPE_TIME result is MYSQL_TYPE_TIME
 
2635
    - Otherwise the result is MYSQL_TYPE_STRING
2626
2636
  */
2627
2637
 
2628
 
  cached_field_type= DRIZZLE_TYPE_VARCHAR;
 
2638
  cached_field_type= MYSQL_TYPE_STRING;
2629
2639
  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;
 
2640
  if (arg0_field_type == MYSQL_TYPE_DATE ||
 
2641
      arg0_field_type == MYSQL_TYPE_DATETIME ||
 
2642
      arg0_field_type == MYSQL_TYPE_TIMESTAMP)
 
2643
    cached_field_type= MYSQL_TYPE_DATETIME;
 
2644
  else if (arg0_field_type == MYSQL_TYPE_TIME)
 
2645
    cached_field_type= MYSQL_TYPE_TIME;
2636
2646
}
2637
2647
 
2638
2648
/**
2647
2657
 
2648
2658
String *Item_func_add_time::val_str(String *str)
2649
2659
{
2650
 
  assert(fixed == 1);
2651
 
  DRIZZLE_TIME l_time1, l_time2, l_time3;
 
2660
  DBUG_ASSERT(fixed == 1);
 
2661
  MYSQL_TIME l_time1, l_time2, l_time3;
2652
2662
  bool is_time= 0;
2653
2663
  long days, microseconds;
2654
 
  int64_t seconds;
 
2664
  longlong seconds;
2655
2665
  int l_sign= sign;
2656
2666
 
2657
2667
  null_value=0;
2659
2669
  {
2660
2670
    if (get_arg0_date(&l_time1, TIME_FUZZY_DATE) || 
2661
2671
        args[1]->get_time(&l_time2) ||
2662
 
        l_time1.time_type == DRIZZLE_TIMESTAMP_TIME || 
2663
 
        l_time2.time_type != DRIZZLE_TIMESTAMP_TIME)
 
2672
        l_time1.time_type == MYSQL_TIMESTAMP_TIME || 
 
2673
        l_time2.time_type != MYSQL_TIMESTAMP_TIME)
2664
2674
      goto null_date;
2665
2675
  }
2666
2676
  else                                // ADDTIME function
2667
2677
  {
2668
2678
    if (args[0]->get_time(&l_time1) || 
2669
2679
        args[1]->get_time(&l_time2) ||
2670
 
        l_time2.time_type == DRIZZLE_TIMESTAMP_DATETIME)
 
2680
        l_time2.time_type == MYSQL_TIMESTAMP_DATETIME)
2671
2681
      goto null_date;
2672
 
    is_time= (l_time1.time_type == DRIZZLE_TIMESTAMP_TIME);
 
2682
    is_time= (l_time1.time_type == MYSQL_TIMESTAMP_TIME);
2673
2683
  }
2674
2684
  if (l_time1.neg != l_time2.neg)
2675
2685
    l_sign= -l_sign;
2676
2686
  
2677
 
  memset(&l_time3, 0, sizeof(l_time3));
 
2687
  bzero((char *)&l_time3, sizeof(l_time3));
2678
2688
  
2679
2689
  l_time3.neg= calc_time_diff(&l_time1, &l_time2, -l_sign,
2680
2690
                              &seconds, &microseconds);
2720
2730
{
2721
2731
  if (is_date)
2722
2732
  {
2723
 
    assert(sign > 0);
 
2733
    DBUG_ASSERT(sign > 0);
2724
2734
    str->append(STRING_WITH_LEN("timestamp("));
2725
2735
  }
2726
2736
  else
2747
2757
 
2748
2758
String *Item_func_timediff::val_str(String *str)
2749
2759
{
2750
 
  assert(fixed == 1);
2751
 
  int64_t seconds;
 
2760
  DBUG_ASSERT(fixed == 1);
 
2761
  longlong seconds;
2752
2762
  long microseconds;
2753
2763
  int l_sign= 1;
2754
 
  DRIZZLE_TIME l_time1 ,l_time2, l_time3;
 
2764
  MYSQL_TIME l_time1 ,l_time2, l_time3;
2755
2765
 
2756
2766
  null_value= 0;  
2757
2767
  if (args[0]->get_time(&l_time1) ||
2762
2772
  if (l_time1.neg != l_time2.neg)
2763
2773
    l_sign= -l_sign;
2764
2774
 
2765
 
  memset(&l_time3, 0, sizeof(l_time3));
 
2775
  bzero((char *)&l_time3, sizeof(l_time3));
2766
2776
  
2767
2777
  l_time3.neg= calc_time_diff(&l_time1, &l_time2, l_sign,
2768
2778
                              &seconds, &microseconds);
2769
2779
 
2770
2780
  /*
2771
 
    For DRIZZLE_TIMESTAMP_TIME only:
 
2781
    For MYSQL_TIMESTAMP_TIME only:
2772
2782
      If first argument was negative and diff between arguments
2773
2783
      is non-zero we need to swap sign to get proper result.
2774
2784
  */
2795
2805
 
2796
2806
String *Item_func_maketime::val_str(String *str)
2797
2807
{
2798
 
  assert(fixed == 1);
2799
 
  DRIZZLE_TIME ltime;
 
2808
  DBUG_ASSERT(fixed == 1);
 
2809
  MYSQL_TIME ltime;
2800
2810
  bool overflow= 0;
2801
2811
 
2802
 
  int64_t hour=   args[0]->val_int();
2803
 
  int64_t minute= args[1]->val_int();
2804
 
  int64_t second= args[2]->val_int();
 
2812
  longlong hour=   args[0]->val_int();
 
2813
  longlong minute= args[1]->val_int();
 
2814
  longlong second= args[2]->val_int();
2805
2815
 
2806
2816
  if ((null_value=(args[0]->null_value || 
2807
2817
                   args[1]->null_value ||
2811
2821
                   str->alloc(MAX_DATE_STRING_REP_LENGTH))))
2812
2822
    return 0;
2813
2823
 
2814
 
  memset(&ltime, 0, sizeof(ltime));
 
2824
  bzero((char *)&ltime, sizeof(ltime));
2815
2825
  ltime.neg= 0;
2816
2826
 
2817
2827
  /* Check for integer overflows */
2818
2828
  if (hour < 0)
2819
 
    ltime.neg= 1;
2820
 
 
 
2829
  {
 
2830
    if (args[0]->unsigned_flag)
 
2831
      overflow= 1;
 
2832
    else
 
2833
      ltime.neg= 1;
 
2834
  }
2821
2835
  if (-hour > UINT_MAX || hour > UINT_MAX)
2822
2836
    overflow= 1;
2823
2837
 
2833
2847
    ltime.minute= TIME_MAX_MINUTE;
2834
2848
    ltime.second= TIME_MAX_SECOND;
2835
2849
    char buf[28];
2836
 
    char *ptr= int64_t10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
 
2850
    char *ptr= longlong10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
2837
2851
    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);
 
2852
      my_sprintf(ptr, (ptr, ":%02u:%02u", (uint)minute, (uint)second));
 
2853
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
2854
                                 buf, len, MYSQL_TIMESTAMP_TIME,
 
2855
                                 NullS);
2842
2856
  }
2843
2857
  
2844
2858
  if (make_time_with_warn((DATE_TIME_FORMAT *) 0, &ltime, str))
2858
2872
  Result: int value
2859
2873
*/
2860
2874
 
2861
 
int64_t Item_func_microsecond::val_int()
 
2875
longlong Item_func_microsecond::val_int()
2862
2876
{
2863
 
  assert(fixed == 1);
2864
 
  DRIZZLE_TIME ltime;
 
2877
  DBUG_ASSERT(fixed == 1);
 
2878
  MYSQL_TIME ltime;
2865
2879
  if (!get_arg0_time(&ltime))
2866
2880
    return ltime.second_part;
2867
2881
  return 0;
2868
2882
}
2869
2883
 
2870
2884
 
2871
 
int64_t Item_func_timestamp_diff::val_int()
 
2885
longlong Item_func_timestamp_diff::val_int()
2872
2886
{
2873
 
  DRIZZLE_TIME ltime1, ltime2;
2874
 
  int64_t seconds;
 
2887
  MYSQL_TIME ltime1, ltime2;
 
2888
  longlong seconds;
2875
2889
  long microseconds;
2876
2890
  long months= 0;
2877
2891
  int neg= 1;
2889
2903
      int_type == INTERVAL_QUARTER ||
2890
2904
      int_type == INTERVAL_MONTH)
2891
2905
  {
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;
 
2906
    uint year_beg, year_end, month_beg, month_end, day_beg, day_end;
 
2907
    uint years= 0;
 
2908
    uint second_beg, second_end, microsecond_beg, microsecond_end;
2895
2909
 
2896
2910
    if (neg == -1)
2897
2911
    {
2960
2974
  case INTERVAL_MICROSECOND:
2961
2975
    /*
2962
2976
      In MySQL difference between any two valid datetime values
2963
 
      in microseconds fits into int64_t.
 
2977
      in microseconds fits into longlong.
2964
2978
    */
2965
2979
    return (seconds*1000000L+microseconds)*neg;
2966
2980
  default:
3010
3024
    break;
3011
3025
  }
3012
3026
 
3013
 
  for (uint32_t i=0 ; i < 2 ; i++)
 
3027
  for (uint i=0 ; i < 2 ; i++)
3014
3028
  {
3015
3029
    str->append(',');
3016
3030
    args[i]->print(str, query_type);
3021
3035
 
3022
3036
String *Item_func_get_format::val_str(String *str)
3023
3037
{
3024
 
  assert(fixed == 1);
 
3038
  DBUG_ASSERT(fixed == 1);
3025
3039
  const char *format_name;
3026
3040
  KNOWN_DATE_TIME_FORMAT *format;
3027
3041
  String *val= args[0]->val_str(str);
3035
3049
       (format_name= format->format_name);
3036
3050
       format++)
3037
3051
  {
3038
 
    uint32_t format_name_len;
 
3052
    uint format_name_len;
3039
3053
    format_name_len= strlen(format_name);
3040
3054
    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))
 
3055
        !my_strnncoll(&my_charset_latin1, 
 
3056
                      (const uchar *) val->ptr(), val_len, 
 
3057
                      (const uchar *) format_name, val_len))
3044
3058
    {
3045
3059
      const char *format_str= get_date_time_format_str(format, type);
3046
3060
      str->set(format_str, strlen(format_str), &my_charset_bin);
3059
3073
  str->append('(');
3060
3074
 
3061
3075
  switch (type) {
3062
 
  case DRIZZLE_TIMESTAMP_DATE:
 
3076
  case MYSQL_TIMESTAMP_DATE:
3063
3077
    str->append(STRING_WITH_LEN("DATE, "));
3064
3078
    break;
3065
 
  case DRIZZLE_TIMESTAMP_DATETIME:
 
3079
  case MYSQL_TIMESTAMP_DATETIME:
3066
3080
    str->append(STRING_WITH_LEN("DATETIME, "));
3067
3081
    break;
3068
 
  case DRIZZLE_TIMESTAMP_TIME:
 
3082
  case MYSQL_TIMESTAMP_TIME:
3069
3083
    str->append(STRING_WITH_LEN("TIME, "));
3070
3084
    break;
3071
3085
  default:
3072
 
    assert(0);
 
3086
    DBUG_ASSERT(0);
3073
3087
  }
3074
3088
  args[0]->print(str, query_type);
3075
3089
  str->append(')');
3101
3115
*/
3102
3116
 
3103
3117
static date_time_format_types
3104
 
get_date_time_result_type(const char *format, uint32_t length)
 
3118
get_date_time_result_type(const char *format, uint length)
3105
3119
{
3106
3120
  const char *time_part_frms= "HISThiklrs";
3107
3121
  const char *date_part_frms= "MVUXYWabcjmvuxyw";
3149
3163
{
3150
3164
  maybe_null= 1;
3151
3165
  decimals=0;
3152
 
  cached_field_type= DRIZZLE_TYPE_DATETIME;
 
3166
  cached_field_type= MYSQL_TYPE_DATETIME;
3153
3167
  max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
3154
 
  cached_timestamp_type= DRIZZLE_TIMESTAMP_NONE;
 
3168
  cached_timestamp_type= MYSQL_TIMESTAMP_NONE;
3155
3169
  if ((const_item= args[1]->const_item()))
3156
3170
  {
3157
3171
    char format_buff[64];
3163
3177
                                                    format->length());
3164
3178
      switch (cached_format_type) {
3165
3179
      case DATE_ONLY:
3166
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_DATE;
3167
 
        cached_field_type= DRIZZLE_TYPE_NEWDATE; 
 
3180
        cached_timestamp_type= MYSQL_TIMESTAMP_DATE;
 
3181
        cached_field_type= MYSQL_TYPE_DATE; 
3168
3182
        max_length= MAX_DATE_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
3169
3183
        break;
3170
3184
      case TIME_ONLY:
3171
3185
      case TIME_MICROSECOND:
3172
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_TIME;
3173
 
        cached_field_type= DRIZZLE_TYPE_TIME; 
 
3186
        cached_timestamp_type= MYSQL_TIMESTAMP_TIME;
 
3187
        cached_field_type= MYSQL_TYPE_TIME; 
3174
3188
        max_length= MAX_TIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
3175
3189
        break;
3176
3190
      default:
3177
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_DATETIME;
3178
 
        cached_field_type= DRIZZLE_TYPE_DATETIME; 
 
3191
        cached_timestamp_type= MYSQL_TIMESTAMP_DATETIME;
 
3192
        cached_field_type= MYSQL_TYPE_DATETIME; 
3179
3193
        break;
3180
3194
      }
3181
3195
    }
3183
3197
}
3184
3198
 
3185
3199
 
3186
 
bool Item_func_str_to_date::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
 
3200
bool Item_func_str_to_date::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
3187
3201
{
3188
3202
  DATE_TIME_FORMAT date_time_format;
3189
3203
  char val_buff[64], format_buff[64];
3196
3210
    goto null_date;
3197
3211
 
3198
3212
  null_value= 0;
3199
 
  memset(ltime, 0, sizeof(*ltime));
 
3213
  bzero((char*) ltime, sizeof(*ltime));
3200
3214
  date_time_format.format.str=    (char*) format->ptr();
3201
3215
  date_time_format.format.length= format->length();
3202
3216
  if (extract_date_time(&date_time_format, val->ptr(), val->length(),
3204
3218
      ((fuzzy_date & TIME_NO_ZERO_DATE) &&
3205
3219
       (ltime->year == 0 || ltime->month == 0 || ltime->day == 0)))
3206
3220
    goto null_date;
3207
 
  if (cached_timestamp_type == DRIZZLE_TIMESTAMP_TIME && ltime->day)
 
3221
  if (cached_timestamp_type == MYSQL_TIMESTAMP_TIME && ltime->day)
3208
3222
  {
3209
3223
    /*
3210
3224
      Day part for time type can be nonzero value and so 
3223
3237
 
3224
3238
String *Item_func_str_to_date::val_str(String *str)
3225
3239
{
3226
 
  assert(fixed == 1);
3227
 
  DRIZZLE_TIME ltime;
 
3240
  DBUG_ASSERT(fixed == 1);
 
3241
  MYSQL_TIME ltime;
3228
3242
 
3229
3243
  if (Item_func_str_to_date::get_date(&ltime, TIME_FUZZY_DATE))
3230
3244
    return 0;
3237
3251
}
3238
3252
 
3239
3253
 
3240
 
bool Item_func_last_day::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
 
3254
bool Item_func_last_day::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
3241
3255
{
3242
3256
  if (get_arg0_date(ltime, fuzzy_date & ~TIME_FUZZY_DATE) ||
3243
3257
      (ltime->month == 0))
3246
3260
    return 1;
3247
3261
  }
3248
3262
  null_value= 0;
3249
 
  uint32_t month_idx= ltime->month-1;
 
3263
  uint month_idx= ltime->month-1;
3250
3264
  ltime->day= days_in_month[month_idx];
3251
3265
  if ( month_idx == 1 && calc_days_in_year(ltime->year) == 366)
3252
3266
    ltime->day= 29;
3253
3267
  ltime->hour= ltime->minute= ltime->second= 0;
3254
3268
  ltime->second_part= 0;
3255
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
3269
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
3256
3270
  return 0;
3257
3271
}