~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_timefunc.cc

Put errmsg.c in sql-common since it can be built only once and used twice.
Put client.c and net_serv.c in libmysql so that we can only have one
link_sources section. 
Got rid of just about all copying and other weirdness, other than some stuff
in client and client.c/net_serv.c, which need to be reworked.

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.
1996
2006
}
1997
2007
 
1998
2008
 
 
2009
void Item_func_convert_tz::fix_length_and_dec()
 
2010
{
 
2011
  collation.set(&my_charset_bin);
 
2012
  decimals= 0;
 
2013
  max_length= MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
 
2014
  maybe_null= 1;
 
2015
}
 
2016
 
 
2017
 
 
2018
String *Item_func_convert_tz::val_str(String *str)
 
2019
{
 
2020
  MYSQL_TIME time_tmp;
 
2021
 
 
2022
  if (get_date(&time_tmp, 0))
 
2023
    return 0;
 
2024
 
 
2025
  if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
 
2026
  {
 
2027
    null_value= 1;
 
2028
    return 0;
 
2029
  }
 
2030
 
 
2031
  make_datetime((DATE_TIME_FORMAT *) 0, &time_tmp, str);
 
2032
 
 
2033
  return str;
 
2034
}
 
2035
 
 
2036
 
 
2037
longlong Item_func_convert_tz::val_int()
 
2038
{
 
2039
  MYSQL_TIME time_tmp;
 
2040
 
 
2041
  if (get_date(&time_tmp, 0))
 
2042
    return 0;
 
2043
  
 
2044
  return (longlong)TIME_to_ulonglong_datetime(&time_tmp);
 
2045
}
 
2046
 
 
2047
 
 
2048
bool Item_func_convert_tz::get_date(MYSQL_TIME *ltime,
 
2049
                                    uint fuzzy_date __attribute__((unused)))
 
2050
{
 
2051
  my_time_t my_time_tmp;
 
2052
  String str;
 
2053
  THD *thd= current_thd;
 
2054
 
 
2055
  if (!from_tz_cached)
 
2056
  {
 
2057
    from_tz= my_tz_find(thd, args[1]->val_str(&str));
 
2058
    from_tz_cached= args[1]->const_item();
 
2059
  }
 
2060
 
 
2061
  if (!to_tz_cached)
 
2062
  {
 
2063
    to_tz= my_tz_find(thd, args[2]->val_str(&str));
 
2064
    to_tz_cached= args[2]->const_item();
 
2065
  }
 
2066
 
 
2067
  if (from_tz==0 || to_tz==0 || get_arg0_date(ltime, TIME_NO_ZERO_DATE))
 
2068
  {
 
2069
    null_value= 1;
 
2070
    return 1;
 
2071
  }
 
2072
 
 
2073
  {
 
2074
    my_bool not_used;
 
2075
    my_time_tmp= from_tz->TIME_to_gmt_sec(ltime, &not_used);
 
2076
    /* my_time_tmp is guranteed to be in the allowed range */
 
2077
    if (my_time_tmp)
 
2078
      to_tz->gmt_sec_to_TIME(ltime, my_time_tmp);
 
2079
  }
 
2080
 
 
2081
  null_value= 0;
 
2082
  return 0;
 
2083
}
 
2084
 
 
2085
 
 
2086
void Item_func_convert_tz::cleanup()
 
2087
{
 
2088
  from_tz_cached= to_tz_cached= 0;
 
2089
  Item_date_func::cleanup();
 
2090
}
 
2091
 
 
2092
 
1999
2093
void Item_date_add_interval::fix_length_and_dec()
2000
2094
{
2001
2095
  enum_field_types arg0_field_type;
2009
2103
    The field type for the result of an Item_date function is defined as
2010
2104
    follows:
2011
2105
 
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
 
2106
    - If first arg is a MYSQL_TYPE_DATETIME result is MYSQL_TYPE_DATETIME
 
2107
    - If first arg is a MYSQL_TYPE_DATE and the interval type uses hours,
 
2108
      minutes or seconds then type is MYSQL_TYPE_DATETIME.
 
2109
    - Otherwise the result is MYSQL_TYPE_STRING
 
2110
      (This is because you can't know if the string contains a DATE, MYSQL_TIME or
2017
2111
      DATETIME argument)
2018
2112
  */
2019
 
  cached_field_type= DRIZZLE_TYPE_VARCHAR;
 
2113
  cached_field_type= MYSQL_TYPE_STRING;
2020
2114
  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)
 
2115
  if (arg0_field_type == MYSQL_TYPE_DATETIME ||
 
2116
      arg0_field_type == MYSQL_TYPE_TIMESTAMP)
 
2117
    cached_field_type= MYSQL_TYPE_DATETIME;
 
2118
  else if (arg0_field_type == MYSQL_TYPE_DATE)
2025
2119
  {
2026
2120
    if (int_type <= INTERVAL_DAY || int_type == INTERVAL_YEAR_MONTH)
2027
2121
      cached_field_type= arg0_field_type;
2028
2122
    else
2029
 
      cached_field_type= DRIZZLE_TYPE_DATETIME;
 
2123
      cached_field_type= MYSQL_TYPE_DATETIME;
2030
2124
  }
2031
2125
}
2032
2126
 
2033
2127
 
2034
2128
/* Here arg[1] is a Item_interval object */
2035
2129
 
2036
 
bool Item_date_add_interval::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
2130
bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
2037
2131
{
2038
2132
  INTERVAL interval;
2039
2133
 
2052
2146
 
2053
2147
String *Item_date_add_interval::val_str(String *str)
2054
2148
{
2055
 
  assert(fixed == 1);
2056
 
  DRIZZLE_TIME ltime;
 
2149
  DBUG_ASSERT(fixed == 1);
 
2150
  MYSQL_TIME ltime;
2057
2151
  enum date_time_format_types format;
2058
2152
 
2059
2153
  if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
2060
2154
    return 0;
2061
2155
 
2062
 
  if (ltime.time_type == DRIZZLE_TIMESTAMP_DATE)
 
2156
  if (ltime.time_type == MYSQL_TIMESTAMP_DATE)
2063
2157
    format= DATE_ONLY;
2064
2158
  else if (ltime.second_part)
2065
2159
    format= DATE_TIME_MICROSECOND;
2074
2168
}
2075
2169
 
2076
2170
 
2077
 
int64_t Item_date_add_interval::val_int()
 
2171
longlong Item_date_add_interval::val_int()
2078
2172
{
2079
 
  assert(fixed == 1);
2080
 
  DRIZZLE_TIME ltime;
2081
 
  int64_t date;
 
2173
  DBUG_ASSERT(fixed == 1);
 
2174
  MYSQL_TIME ltime;
 
2175
  longlong date;
2082
2176
  if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
2083
 
    return (int64_t) 0;
 
2177
    return (longlong) 0;
2084
2178
  date = (ltime.year*100L + ltime.month)*100L + ltime.day;
2085
 
  return ltime.time_type == DRIZZLE_TIMESTAMP_DATE ? date :
 
2179
  return ltime.time_type == MYSQL_TIMESTAMP_DATE ? date :
2086
2180
    ((date*100L + ltime.hour)*100L+ ltime.minute)*100L + ltime.second;
2087
2181
}
2088
2182
 
2159
2253
  case INTERVAL_HOUR_MICROSECOND: max_length=13; date_value=0; break;
2160
2254
  case INTERVAL_MINUTE_MICROSECOND: max_length=11; date_value=0; break;
2161
2255
  case INTERVAL_SECOND_MICROSECOND: max_length=9; date_value=0; break;
2162
 
  case INTERVAL_LAST: assert(0); break; /* purecov: deadcode */
 
2256
  case INTERVAL_LAST: DBUG_ASSERT(0); break; /* purecov: deadcode */
2163
2257
  }
2164
2258
}
2165
2259
 
2166
2260
 
2167
 
int64_t Item_extract::val_int()
 
2261
longlong Item_extract::val_int()
2168
2262
{
2169
 
  assert(fixed == 1);
2170
 
  DRIZZLE_TIME ltime;
2171
 
  uint32_t year;
 
2263
  DBUG_ASSERT(fixed == 1);
 
2264
  MYSQL_TIME ltime;
 
2265
  uint year;
2172
2266
  ulong week_format;
2173
2267
  long neg;
2174
2268
  if (date_value)
2203
2297
  case INTERVAL_DAY_MINUTE:     return (long) (ltime.day*10000L+
2204
2298
                                               ltime.hour*100L+
2205
2299
                                               ltime.minute)*neg;
2206
 
  case INTERVAL_DAY_SECOND:      return ((int64_t) ltime.day*1000000L+
2207
 
                                         (int64_t) (ltime.hour*10000L+
 
2300
  case INTERVAL_DAY_SECOND:      return ((longlong) ltime.day*1000000L+
 
2301
                                         (longlong) (ltime.hour*10000L+
2208
2302
                                                     ltime.minute*100+
2209
2303
                                                     ltime.second))*neg;
2210
2304
  case INTERVAL_HOUR:           return (long) ltime.hour*neg;
2215
2309
  case INTERVAL_MINUTE_SECOND:  return (long) (ltime.minute*100+ltime.second)*neg;
2216
2310
  case INTERVAL_SECOND:         return (long) ltime.second*neg;
2217
2311
  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 +
 
2312
  case INTERVAL_DAY_MICROSECOND: return (((longlong)ltime.day*1000000L +
 
2313
                                          (longlong)ltime.hour*10000L +
2220
2314
                                          ltime.minute*100 +
2221
2315
                                          ltime.second)*1000000L +
2222
2316
                                         ltime.second_part)*neg;
2223
 
  case INTERVAL_HOUR_MICROSECOND: return (((int64_t)ltime.hour*10000L +
 
2317
  case INTERVAL_HOUR_MICROSECOND: return (((longlong)ltime.hour*10000L +
2224
2318
                                           ltime.minute*100 +
2225
2319
                                           ltime.second)*1000000L +
2226
2320
                                          ltime.second_part)*neg;
2227
 
  case INTERVAL_MINUTE_MICROSECOND: return (((int64_t)(ltime.minute*100+
 
2321
  case INTERVAL_MINUTE_MICROSECOND: return (((longlong)(ltime.minute*100+
2228
2322
                                                        ltime.second))*1000000L+
2229
2323
                                            ltime.second_part)*neg;
2230
 
  case INTERVAL_SECOND_MICROSECOND: return ((int64_t)ltime.second*1000000L+
 
2324
  case INTERVAL_SECOND_MICROSECOND: return ((longlong)ltime.second*1000000L+
2231
2325
                                            ltime.second_part)*neg;
2232
 
  case INTERVAL_LAST: assert(0); break;  /* purecov: deadcode */
 
2326
  case INTERVAL_LAST: DBUG_ASSERT(0); break;  /* purecov: deadcode */
2233
2327
  }
2234
2328
  return 0;                                     // Impossible
2235
2329
}
2291
2385
    char buffer[20];
2292
2386
    // my_charset_bin is good enough for numbers
2293
2387
    String st(buffer, sizeof(buffer), &my_charset_bin);
2294
 
    st.set((uint64_t)cast_length, &my_charset_bin);
 
2388
    st.set((ulonglong)cast_length, &my_charset_bin);
2295
2389
    str->append(st);
2296
2390
    str->append(')');
2297
2391
  }
2305
2399
 
2306
2400
String *Item_char_typecast::val_str(String *str)
2307
2401
{
2308
 
  assert(fixed == 1);
 
2402
  DBUG_ASSERT(fixed == 1);
2309
2403
  String *res;
2310
 
  uint32_t length;
 
2404
  uint32 length;
2311
2405
 
2312
2406
  if (!charset_conversion)
2313
2407
  {
2320
2414
  else
2321
2415
  {
2322
2416
    // Convert character set if differ
2323
 
    uint32_t dummy_errors;
 
2417
    uint dummy_errors;
2324
2418
    if (!(res= args[0]->val_str(&tmp_value)) ||
2325
2419
        str->copy(res->ptr(), res->length(), from_cs,
2326
2420
        cast_cs, &dummy_errors))
2340
2434
  */
2341
2435
  if (cast_length >= 0)
2342
2436
  {
2343
 
    if (res->length() > (length= (uint32_t) res->charpos(cast_length)))
 
2437
    if (res->length() > (length= (uint32) res->charpos(cast_length)))
2344
2438
    {                                           // Safe even if const arg
2345
2439
      char char_type[40];
2346
 
      snprintf(char_type, sizeof(char_type), "%s(%lu)",
2347
 
               cast_cs == &my_charset_bin ? "BINARY" : "CHAR",
2348
 
               (ulong) length);
 
2440
      my_snprintf(char_type, sizeof(char_type), "%s(%lu)",
 
2441
                  cast_cs == &my_charset_bin ? "BINARY" : "CHAR",
 
2442
                  (ulong) length);
2349
2443
 
2350
2444
      if (!res->alloced_length())
2351
2445
      {                                         // Don't change const str
2352
2446
        str_value= *res;                        // Not malloced string
2353
2447
        res= &str_value;
2354
2448
      }
2355
 
      push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2449
      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2356
2450
                          ER_TRUNCATED_WRONG_VALUE,
2357
2451
                          ER(ER_TRUNCATED_WRONG_VALUE), char_type,
2358
2452
                          res->c_ptr_safe());
2366
2460
        str->copy(*res);
2367
2461
        res= str;
2368
2462
      }
2369
 
      memset(res->ptr() + res->length(), 0,
2370
 
             (uint) cast_length - res->length());
 
2463
      bzero((char*) res->ptr() + res->length(),
 
2464
            (uint) cast_length - res->length());
2371
2465
      res->length(cast_length);
2372
2466
    }
2373
2467
  }
2378
2472
 
2379
2473
void Item_char_typecast::fix_length_and_dec()
2380
2474
{
2381
 
  uint32_t char_length;
 
2475
  uint32 char_length;
2382
2476
  /* 
2383
2477
     We always force character set conversion if cast_cs
2384
2478
     is a multi-byte character set. It garantees that the
2404
2498
  from_cs= (args[0]->result_type() == INT_RESULT || 
2405
2499
            args[0]->result_type() == DECIMAL_RESULT ||
2406
2500
            args[0]->result_type() == REAL_RESULT) ?
2407
 
           (cast_cs->mbminlen == 1 ? cast_cs : &my_charset_utf8_general_ci) :
 
2501
           (cast_cs->mbminlen == 1 ? cast_cs : &my_charset_latin1) :
2408
2502
           args[0]->collation.collation;
2409
2503
  charset_conversion= (cast_cs->mbmaxlen > 1) ||
2410
2504
                      (!my_charset_same(from_cs, cast_cs) && from_cs != &my_charset_bin && cast_cs != &my_charset_bin);
2417
2511
 
2418
2512
String *Item_datetime_typecast::val_str(String *str)
2419
2513
{
2420
 
  assert(fixed == 1);
2421
 
  DRIZZLE_TIME ltime;
 
2514
  DBUG_ASSERT(fixed == 1);
 
2515
  MYSQL_TIME ltime;
2422
2516
 
2423
2517
  if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
2424
2518
      !make_datetime(ltime.second_part ? DATE_TIME_MICROSECOND : DATE_TIME, 
2430
2524
}
2431
2525
 
2432
2526
 
2433
 
int64_t Item_datetime_typecast::val_int()
 
2527
longlong Item_datetime_typecast::val_int()
2434
2528
{
2435
 
  assert(fixed == 1);
2436
 
  DRIZZLE_TIME ltime;
 
2529
  DBUG_ASSERT(fixed == 1);
 
2530
  MYSQL_TIME ltime;
2437
2531
  if (get_arg0_date(&ltime,1))
2438
2532
  {
2439
2533
    null_value= 1;
2440
2534
    return 0;
2441
2535
  }
2442
2536
 
2443
 
  return TIME_to_uint64_t_datetime(&ltime);
 
2537
  return TIME_to_ulonglong_datetime(&ltime);
2444
2538
}
2445
2539
 
2446
2540
 
2447
 
bool Item_time_typecast::get_time(DRIZZLE_TIME *ltime)
 
2541
bool Item_time_typecast::get_time(MYSQL_TIME *ltime)
2448
2542
{
2449
2543
  bool res= get_arg0_time(ltime);
2450
2544
  /*
2451
 
    For DRIZZLE_TIMESTAMP_TIME value we can have non-zero day part,
 
2545
    For MYSQL_TIMESTAMP_TIME value we can have non-zero day part,
2452
2546
    which we should not lose.
2453
2547
  */
2454
 
  if (ltime->time_type == DRIZZLE_TIMESTAMP_DATETIME)
 
2548
  if (ltime->time_type == MYSQL_TIMESTAMP_DATETIME)
2455
2549
    ltime->year= ltime->month= ltime->day= 0;
2456
 
  ltime->time_type= DRIZZLE_TIMESTAMP_TIME;
 
2550
  ltime->time_type= MYSQL_TIMESTAMP_TIME;
2457
2551
  return res;
2458
2552
}
2459
2553
 
2460
2554
 
2461
 
int64_t Item_time_typecast::val_int()
 
2555
longlong Item_time_typecast::val_int()
2462
2556
{
2463
 
  DRIZZLE_TIME ltime;
 
2557
  MYSQL_TIME ltime;
2464
2558
  if (get_time(&ltime))
2465
2559
  {
2466
2560
    null_value= 1;
2471
2565
 
2472
2566
String *Item_time_typecast::val_str(String *str)
2473
2567
{
2474
 
  assert(fixed == 1);
2475
 
  DRIZZLE_TIME ltime;
 
2568
  DBUG_ASSERT(fixed == 1);
 
2569
  MYSQL_TIME ltime;
2476
2570
 
2477
2571
  if (!get_arg0_time(&ltime) &&
2478
2572
      !make_datetime(ltime.second_part ? TIME_MICROSECOND : TIME_ONLY,
2484
2578
}
2485
2579
 
2486
2580
 
2487
 
bool Item_date_typecast::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date __attribute__((unused)))
 
2581
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
2488
2582
{
2489
2583
  bool res= get_arg0_date(ltime, TIME_FUZZY_DATE);
2490
2584
  ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
2491
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
2585
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
2492
2586
  return res;
2493
2587
}
2494
2588
 
2495
2589
 
2496
 
bool Item_date_typecast::get_time(DRIZZLE_TIME *ltime)
 
2590
bool Item_date_typecast::get_time(MYSQL_TIME *ltime)
2497
2591
{
2498
 
  memset(ltime, 0, sizeof(DRIZZLE_TIME));
 
2592
  bzero((char *)ltime, sizeof(MYSQL_TIME));
2499
2593
  return args[0]->null_value;
2500
2594
}
2501
2595
 
2502
2596
 
2503
2597
String *Item_date_typecast::val_str(String *str)
2504
2598
{
2505
 
  assert(fixed == 1);
2506
 
  DRIZZLE_TIME ltime;
 
2599
  DBUG_ASSERT(fixed == 1);
 
2600
  MYSQL_TIME ltime;
2507
2601
 
2508
2602
  if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
2509
2603
      !str->alloc(MAX_DATE_STRING_REP_LENGTH))
2516
2610
  return 0;
2517
2611
}
2518
2612
 
2519
 
int64_t Item_date_typecast::val_int()
 
2613
longlong Item_date_typecast::val_int()
2520
2614
{
2521
 
  assert(fixed == 1);
2522
 
  DRIZZLE_TIME ltime;
 
2615
  DBUG_ASSERT(fixed == 1);
 
2616
  MYSQL_TIME ltime;
2523
2617
  if ((null_value= args[0]->get_date(&ltime, TIME_FUZZY_DATE)))
2524
2618
    return 0;
2525
 
  return (int64_t) (ltime.year * 10000L + ltime.month * 100 + ltime.day);
 
2619
  return (longlong) (ltime.year * 10000L + ltime.month * 100 + ltime.day);
2526
2620
}
2527
2621
 
2528
2622
/**
2537
2631
 
2538
2632
String *Item_func_makedate::val_str(String *str)
2539
2633
{
2540
 
  assert(fixed == 1);
2541
 
  DRIZZLE_TIME l_time;
 
2634
  DBUG_ASSERT(fixed == 1);
 
2635
  MYSQL_TIME l_time;
2542
2636
  long daynr=  (long) args[1]->val_int();
2543
2637
  long year= (long) args[0]->val_int();
2544
2638
  long days;
2578
2672
    for dates between 0000-01-01 and 0099-12-31
2579
2673
*/
2580
2674
 
2581
 
int64_t Item_func_makedate::val_int()
 
2675
longlong Item_func_makedate::val_int()
2582
2676
{
2583
 
  assert(fixed == 1);
2584
 
  DRIZZLE_TIME l_time;
 
2677
  DBUG_ASSERT(fixed == 1);
 
2678
  MYSQL_TIME l_time;
2585
2679
  long daynr=  (long) args[1]->val_int();
2586
2680
  long year= (long) args[0]->val_int();
2587
2681
  long days;
2599
2693
  {
2600
2694
    null_value=0;
2601
2695
    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);
 
2696
    return (longlong) (l_time.year * 10000L + l_time.month * 100 + l_time.day);
2603
2697
  }
2604
2698
 
2605
2699
err:
2619
2713
    The field type for the result of an Item_func_add_time function is defined
2620
2714
    as follows:
2621
2715
 
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
 
2716
    - If first arg is a MYSQL_TYPE_DATETIME or MYSQL_TYPE_TIMESTAMP 
 
2717
      result is MYSQL_TYPE_DATETIME
 
2718
    - If first arg is a MYSQL_TYPE_TIME result is MYSQL_TYPE_TIME
 
2719
    - Otherwise the result is MYSQL_TYPE_STRING
2626
2720
  */
2627
2721
 
2628
 
  cached_field_type= DRIZZLE_TYPE_VARCHAR;
 
2722
  cached_field_type= MYSQL_TYPE_STRING;
2629
2723
  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;
 
2724
  if (arg0_field_type == MYSQL_TYPE_DATE ||
 
2725
      arg0_field_type == MYSQL_TYPE_DATETIME ||
 
2726
      arg0_field_type == MYSQL_TYPE_TIMESTAMP)
 
2727
    cached_field_type= MYSQL_TYPE_DATETIME;
 
2728
  else if (arg0_field_type == MYSQL_TYPE_TIME)
 
2729
    cached_field_type= MYSQL_TYPE_TIME;
2636
2730
}
2637
2731
 
2638
2732
/**
2647
2741
 
2648
2742
String *Item_func_add_time::val_str(String *str)
2649
2743
{
2650
 
  assert(fixed == 1);
2651
 
  DRIZZLE_TIME l_time1, l_time2, l_time3;
 
2744
  DBUG_ASSERT(fixed == 1);
 
2745
  MYSQL_TIME l_time1, l_time2, l_time3;
2652
2746
  bool is_time= 0;
2653
2747
  long days, microseconds;
2654
 
  int64_t seconds;
 
2748
  longlong seconds;
2655
2749
  int l_sign= sign;
2656
2750
 
2657
2751
  null_value=0;
2659
2753
  {
2660
2754
    if (get_arg0_date(&l_time1, TIME_FUZZY_DATE) || 
2661
2755
        args[1]->get_time(&l_time2) ||
2662
 
        l_time1.time_type == DRIZZLE_TIMESTAMP_TIME || 
2663
 
        l_time2.time_type != DRIZZLE_TIMESTAMP_TIME)
 
2756
        l_time1.time_type == MYSQL_TIMESTAMP_TIME || 
 
2757
        l_time2.time_type != MYSQL_TIMESTAMP_TIME)
2664
2758
      goto null_date;
2665
2759
  }
2666
2760
  else                                // ADDTIME function
2667
2761
  {
2668
2762
    if (args[0]->get_time(&l_time1) || 
2669
2763
        args[1]->get_time(&l_time2) ||
2670
 
        l_time2.time_type == DRIZZLE_TIMESTAMP_DATETIME)
 
2764
        l_time2.time_type == MYSQL_TIMESTAMP_DATETIME)
2671
2765
      goto null_date;
2672
 
    is_time= (l_time1.time_type == DRIZZLE_TIMESTAMP_TIME);
 
2766
    is_time= (l_time1.time_type == MYSQL_TIMESTAMP_TIME);
2673
2767
  }
2674
2768
  if (l_time1.neg != l_time2.neg)
2675
2769
    l_sign= -l_sign;
2676
2770
  
2677
 
  memset(&l_time3, 0, sizeof(l_time3));
 
2771
  bzero((char *)&l_time3, sizeof(l_time3));
2678
2772
  
2679
2773
  l_time3.neg= calc_time_diff(&l_time1, &l_time2, -l_sign,
2680
2774
                              &seconds, &microseconds);
2720
2814
{
2721
2815
  if (is_date)
2722
2816
  {
2723
 
    assert(sign > 0);
 
2817
    DBUG_ASSERT(sign > 0);
2724
2818
    str->append(STRING_WITH_LEN("timestamp("));
2725
2819
  }
2726
2820
  else
2747
2841
 
2748
2842
String *Item_func_timediff::val_str(String *str)
2749
2843
{
2750
 
  assert(fixed == 1);
2751
 
  int64_t seconds;
 
2844
  DBUG_ASSERT(fixed == 1);
 
2845
  longlong seconds;
2752
2846
  long microseconds;
2753
2847
  int l_sign= 1;
2754
 
  DRIZZLE_TIME l_time1 ,l_time2, l_time3;
 
2848
  MYSQL_TIME l_time1 ,l_time2, l_time3;
2755
2849
 
2756
2850
  null_value= 0;  
2757
2851
  if (args[0]->get_time(&l_time1) ||
2762
2856
  if (l_time1.neg != l_time2.neg)
2763
2857
    l_sign= -l_sign;
2764
2858
 
2765
 
  memset(&l_time3, 0, sizeof(l_time3));
 
2859
  bzero((char *)&l_time3, sizeof(l_time3));
2766
2860
  
2767
2861
  l_time3.neg= calc_time_diff(&l_time1, &l_time2, l_sign,
2768
2862
                              &seconds, &microseconds);
2769
2863
 
2770
2864
  /*
2771
 
    For DRIZZLE_TIMESTAMP_TIME only:
 
2865
    For MYSQL_TIMESTAMP_TIME only:
2772
2866
      If first argument was negative and diff between arguments
2773
2867
      is non-zero we need to swap sign to get proper result.
2774
2868
  */
2795
2889
 
2796
2890
String *Item_func_maketime::val_str(String *str)
2797
2891
{
2798
 
  assert(fixed == 1);
2799
 
  DRIZZLE_TIME ltime;
 
2892
  DBUG_ASSERT(fixed == 1);
 
2893
  MYSQL_TIME ltime;
2800
2894
  bool overflow= 0;
2801
2895
 
2802
 
  int64_t hour=   args[0]->val_int();
2803
 
  int64_t minute= args[1]->val_int();
2804
 
  int64_t second= args[2]->val_int();
 
2896
  longlong hour=   args[0]->val_int();
 
2897
  longlong minute= args[1]->val_int();
 
2898
  longlong second= args[2]->val_int();
2805
2899
 
2806
2900
  if ((null_value=(args[0]->null_value || 
2807
2901
                   args[1]->null_value ||
2811
2905
                   str->alloc(MAX_DATE_STRING_REP_LENGTH))))
2812
2906
    return 0;
2813
2907
 
2814
 
  memset(&ltime, 0, sizeof(ltime));
 
2908
  bzero((char *)&ltime, sizeof(ltime));
2815
2909
  ltime.neg= 0;
2816
2910
 
2817
2911
  /* Check for integer overflows */
2818
2912
  if (hour < 0)
2819
 
    ltime.neg= 1;
2820
 
 
 
2913
  {
 
2914
    if (args[0]->unsigned_flag)
 
2915
      overflow= 1;
 
2916
    else
 
2917
      ltime.neg= 1;
 
2918
  }
2821
2919
  if (-hour > UINT_MAX || hour > UINT_MAX)
2822
2920
    overflow= 1;
2823
2921
 
2833
2931
    ltime.minute= TIME_MAX_MINUTE;
2834
2932
    ltime.second= TIME_MAX_SECOND;
2835
2933
    char buf[28];
2836
 
    char *ptr= int64_t10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
 
2934
    char *ptr= longlong10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
2837
2935
    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);
 
2936
      my_sprintf(ptr, (ptr, ":%02u:%02u", (uint)minute, (uint)second));
 
2937
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
2938
                                 buf, len, MYSQL_TIMESTAMP_TIME,
 
2939
                                 NullS);
2842
2940
  }
2843
2941
  
2844
2942
  if (make_time_with_warn((DATE_TIME_FORMAT *) 0, &ltime, str))
2858
2956
  Result: int value
2859
2957
*/
2860
2958
 
2861
 
int64_t Item_func_microsecond::val_int()
 
2959
longlong Item_func_microsecond::val_int()
2862
2960
{
2863
 
  assert(fixed == 1);
2864
 
  DRIZZLE_TIME ltime;
 
2961
  DBUG_ASSERT(fixed == 1);
 
2962
  MYSQL_TIME ltime;
2865
2963
  if (!get_arg0_time(&ltime))
2866
2964
    return ltime.second_part;
2867
2965
  return 0;
2868
2966
}
2869
2967
 
2870
2968
 
2871
 
int64_t Item_func_timestamp_diff::val_int()
 
2969
longlong Item_func_timestamp_diff::val_int()
2872
2970
{
2873
 
  DRIZZLE_TIME ltime1, ltime2;
2874
 
  int64_t seconds;
 
2971
  MYSQL_TIME ltime1, ltime2;
 
2972
  longlong seconds;
2875
2973
  long microseconds;
2876
2974
  long months= 0;
2877
2975
  int neg= 1;
2889
2987
      int_type == INTERVAL_QUARTER ||
2890
2988
      int_type == INTERVAL_MONTH)
2891
2989
  {
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;
 
2990
    uint year_beg, year_end, month_beg, month_end, day_beg, day_end;
 
2991
    uint years= 0;
 
2992
    uint second_beg, second_end, microsecond_beg, microsecond_end;
2895
2993
 
2896
2994
    if (neg == -1)
2897
2995
    {
2960
3058
  case INTERVAL_MICROSECOND:
2961
3059
    /*
2962
3060
      In MySQL difference between any two valid datetime values
2963
 
      in microseconds fits into int64_t.
 
3061
      in microseconds fits into longlong.
2964
3062
    */
2965
3063
    return (seconds*1000000L+microseconds)*neg;
2966
3064
  default:
3010
3108
    break;
3011
3109
  }
3012
3110
 
3013
 
  for (uint32_t i=0 ; i < 2 ; i++)
 
3111
  for (uint i=0 ; i < 2 ; i++)
3014
3112
  {
3015
3113
    str->append(',');
3016
3114
    args[i]->print(str, query_type);
3021
3119
 
3022
3120
String *Item_func_get_format::val_str(String *str)
3023
3121
{
3024
 
  assert(fixed == 1);
 
3122
  DBUG_ASSERT(fixed == 1);
3025
3123
  const char *format_name;
3026
3124
  KNOWN_DATE_TIME_FORMAT *format;
3027
3125
  String *val= args[0]->val_str(str);
3035
3133
       (format_name= format->format_name);
3036
3134
       format++)
3037
3135
  {
3038
 
    uint32_t format_name_len;
 
3136
    uint format_name_len;
3039
3137
    format_name_len= strlen(format_name);
3040
3138
    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))
 
3139
        !my_strnncoll(&my_charset_latin1, 
 
3140
                      (const uchar *) val->ptr(), val_len, 
 
3141
                      (const uchar *) format_name, val_len))
3044
3142
    {
3045
3143
      const char *format_str= get_date_time_format_str(format, type);
3046
3144
      str->set(format_str, strlen(format_str), &my_charset_bin);
3059
3157
  str->append('(');
3060
3158
 
3061
3159
  switch (type) {
3062
 
  case DRIZZLE_TIMESTAMP_DATE:
 
3160
  case MYSQL_TIMESTAMP_DATE:
3063
3161
    str->append(STRING_WITH_LEN("DATE, "));
3064
3162
    break;
3065
 
  case DRIZZLE_TIMESTAMP_DATETIME:
 
3163
  case MYSQL_TIMESTAMP_DATETIME:
3066
3164
    str->append(STRING_WITH_LEN("DATETIME, "));
3067
3165
    break;
3068
 
  case DRIZZLE_TIMESTAMP_TIME:
 
3166
  case MYSQL_TIMESTAMP_TIME:
3069
3167
    str->append(STRING_WITH_LEN("TIME, "));
3070
3168
    break;
3071
3169
  default:
3072
 
    assert(0);
 
3170
    DBUG_ASSERT(0);
3073
3171
  }
3074
3172
  args[0]->print(str, query_type);
3075
3173
  str->append(')');
3101
3199
*/
3102
3200
 
3103
3201
static date_time_format_types
3104
 
get_date_time_result_type(const char *format, uint32_t length)
 
3202
get_date_time_result_type(const char *format, uint length)
3105
3203
{
3106
3204
  const char *time_part_frms= "HISThiklrs";
3107
3205
  const char *date_part_frms= "MVUXYWabcjmvuxyw";
3149
3247
{
3150
3248
  maybe_null= 1;
3151
3249
  decimals=0;
3152
 
  cached_field_type= DRIZZLE_TYPE_DATETIME;
 
3250
  cached_field_type= MYSQL_TYPE_DATETIME;
3153
3251
  max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
3154
 
  cached_timestamp_type= DRIZZLE_TIMESTAMP_NONE;
 
3252
  cached_timestamp_type= MYSQL_TIMESTAMP_NONE;
3155
3253
  if ((const_item= args[1]->const_item()))
3156
3254
  {
3157
3255
    char format_buff[64];
3163
3261
                                                    format->length());
3164
3262
      switch (cached_format_type) {
3165
3263
      case DATE_ONLY:
3166
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_DATE;
3167
 
        cached_field_type= DRIZZLE_TYPE_NEWDATE; 
 
3264
        cached_timestamp_type= MYSQL_TIMESTAMP_DATE;
 
3265
        cached_field_type= MYSQL_TYPE_DATE; 
3168
3266
        max_length= MAX_DATE_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
3169
3267
        break;
3170
3268
      case TIME_ONLY:
3171
3269
      case TIME_MICROSECOND:
3172
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_TIME;
3173
 
        cached_field_type= DRIZZLE_TYPE_TIME; 
 
3270
        cached_timestamp_type= MYSQL_TIMESTAMP_TIME;
 
3271
        cached_field_type= MYSQL_TYPE_TIME; 
3174
3272
        max_length= MAX_TIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
3175
3273
        break;
3176
3274
      default:
3177
 
        cached_timestamp_type= DRIZZLE_TIMESTAMP_DATETIME;
3178
 
        cached_field_type= DRIZZLE_TYPE_DATETIME; 
 
3275
        cached_timestamp_type= MYSQL_TIMESTAMP_DATETIME;
 
3276
        cached_field_type= MYSQL_TYPE_DATETIME; 
3179
3277
        break;
3180
3278
      }
3181
3279
    }
3183
3281
}
3184
3282
 
3185
3283
 
3186
 
bool Item_func_str_to_date::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
 
3284
bool Item_func_str_to_date::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
3187
3285
{
3188
3286
  DATE_TIME_FORMAT date_time_format;
3189
3287
  char val_buff[64], format_buff[64];
3196
3294
    goto null_date;
3197
3295
 
3198
3296
  null_value= 0;
3199
 
  memset(ltime, 0, sizeof(*ltime));
 
3297
  bzero((char*) ltime, sizeof(*ltime));
3200
3298
  date_time_format.format.str=    (char*) format->ptr();
3201
3299
  date_time_format.format.length= format->length();
3202
3300
  if (extract_date_time(&date_time_format, val->ptr(), val->length(),
3204
3302
      ((fuzzy_date & TIME_NO_ZERO_DATE) &&
3205
3303
       (ltime->year == 0 || ltime->month == 0 || ltime->day == 0)))
3206
3304
    goto null_date;
3207
 
  if (cached_timestamp_type == DRIZZLE_TIMESTAMP_TIME && ltime->day)
 
3305
  if (cached_timestamp_type == MYSQL_TIMESTAMP_TIME && ltime->day)
3208
3306
  {
3209
3307
    /*
3210
3308
      Day part for time type can be nonzero value and so 
3223
3321
 
3224
3322
String *Item_func_str_to_date::val_str(String *str)
3225
3323
{
3226
 
  assert(fixed == 1);
3227
 
  DRIZZLE_TIME ltime;
 
3324
  DBUG_ASSERT(fixed == 1);
 
3325
  MYSQL_TIME ltime;
3228
3326
 
3229
3327
  if (Item_func_str_to_date::get_date(&ltime, TIME_FUZZY_DATE))
3230
3328
    return 0;
3237
3335
}
3238
3336
 
3239
3337
 
3240
 
bool Item_func_last_day::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date)
 
3338
bool Item_func_last_day::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
3241
3339
{
3242
3340
  if (get_arg0_date(ltime, fuzzy_date & ~TIME_FUZZY_DATE) ||
3243
3341
      (ltime->month == 0))
3246
3344
    return 1;
3247
3345
  }
3248
3346
  null_value= 0;
3249
 
  uint32_t month_idx= ltime->month-1;
 
3347
  uint month_idx= ltime->month-1;
3250
3348
  ltime->day= days_in_month[month_idx];
3251
3349
  if ( month_idx == 1 && calc_days_in_year(ltime->year) == 366)
3252
3350
    ltime->day= 29;
3253
3351
  ltime->hour= ltime->minute= ltime->second= 0;
3254
3352
  ltime->second_part= 0;
3255
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
3353
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
3256
3354
  return 0;
3257
3355
}