My Project
|
00001 #ifndef ITEM_TIMEFUNC_INCLUDED 00002 #define ITEM_TIMEFUNC_INCLUDED 00003 00004 /* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; version 2 of the License. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00018 00019 00020 /* Function items used by mysql */ 00021 00022 #include <algorithm> 00023 00024 class MY_LOCALE; 00025 00026 bool get_interval_value(Item *args,interval_type int_type, 00027 String *str_value, INTERVAL *interval); 00028 00029 class Item_func_period_add :public Item_int_func 00030 { 00031 public: 00032 Item_func_period_add(Item *a,Item *b) :Item_int_func(a,b) {} 00033 longlong val_int(); 00034 const char *func_name() const { return "period_add"; } 00035 void fix_length_and_dec() 00036 { 00037 fix_char_length(6); /* YYYYMM */ 00038 } 00039 }; 00040 00041 00042 class Item_func_period_diff :public Item_int_func 00043 { 00044 public: 00045 Item_func_period_diff(Item *a,Item *b) :Item_int_func(a,b) {} 00046 longlong val_int(); 00047 const char *func_name() const { return "period_diff"; } 00048 void fix_length_and_dec() 00049 { 00050 fix_char_length(6); /* YYYYMM */ 00051 } 00052 }; 00053 00054 00055 class Item_func_to_days :public Item_int_func 00056 { 00057 public: 00058 Item_func_to_days(Item *a) :Item_int_func(a) {} 00059 longlong val_int(); 00060 const char *func_name() const { return "to_days"; } 00061 void fix_length_and_dec() 00062 { 00063 fix_char_length(6); 00064 maybe_null=1; 00065 } 00066 enum_monotonicity_info get_monotonicity_info() const; 00067 longlong val_int_endpoint(bool left_endp, bool *incl_endp); 00068 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00069 bool check_valid_arguments_processor(uchar *int_arg) 00070 { 00071 return !has_date_args(); 00072 } 00073 }; 00074 00075 00076 class Item_func_to_seconds :public Item_int_func 00077 { 00078 public: 00079 Item_func_to_seconds(Item *a) :Item_int_func(a) {} 00080 longlong val_int(); 00081 const char *func_name() const { return "to_seconds"; } 00082 void fix_length_and_dec() 00083 { 00084 fix_char_length(6); 00085 maybe_null=1; 00086 } 00087 enum_monotonicity_info get_monotonicity_info() const; 00088 longlong val_int_endpoint(bool left_endp, bool *incl_endp); 00089 bool check_partition_func_processor(uchar *bool_arg) { return FALSE;} 00090 00091 bool intro_version(uchar *int_arg) 00092 { 00093 using std::max; 00094 int *input_version= (int*)int_arg; 00095 /* This function was introduced in 5.5 */ 00096 int output_version= max(*input_version, 50500); 00097 *input_version= output_version; 00098 return 0; 00099 } 00100 00101 /* Only meaningful with date part and optional time part */ 00102 bool check_valid_arguments_processor(uchar *int_arg) 00103 { 00104 return !has_date_args(); 00105 } 00106 }; 00107 00108 00109 class Item_func_dayofmonth :public Item_int_func 00110 { 00111 public: 00112 Item_func_dayofmonth(Item *a) :Item_int_func(a) {} 00113 longlong val_int(); 00114 const char *func_name() const { return "dayofmonth"; } 00115 void fix_length_and_dec() 00116 { 00117 fix_char_length(2); /* 1..31 */ 00118 maybe_null=1; 00119 } 00120 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00121 bool check_valid_arguments_processor(uchar *int_arg) 00122 { 00123 return !has_date_args(); 00124 } 00125 }; 00126 00127 00131 class Item_func_month :public Item_func 00132 { 00133 public: 00134 Item_func_month(Item *a) :Item_func(a) { collation.set_numeric(); } 00135 longlong val_int(); 00136 double val_real() 00137 { DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); } 00138 String *val_str(String *str) 00139 { 00140 longlong nr= val_int(); 00141 if (null_value) 00142 return 0; 00143 str->set(nr, collation.collation); 00144 return str; 00145 } 00146 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 00147 { 00148 return get_date_from_int(ltime, fuzzydate); 00149 } 00150 bool get_time(MYSQL_TIME *ltime) 00151 { 00152 return get_time_from_int(ltime); 00153 } 00154 const char *func_name() const { return "month"; } 00155 enum Item_result result_type () const { return INT_RESULT; } 00156 void fix_length_and_dec() 00157 { 00158 fix_char_length(2); 00159 maybe_null= 1; 00160 } 00161 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00162 bool check_valid_arguments_processor(uchar *int_arg) 00163 { 00164 return !has_date_args(); 00165 } 00166 }; 00167 00168 00169 class Item_func_monthname :public Item_str_func 00170 { 00171 MY_LOCALE *locale; 00172 public: 00173 Item_func_monthname(Item *a) :Item_str_func(a) {} 00174 const char *func_name() const { return "monthname"; } 00175 String *val_str(String *str); 00176 void fix_length_and_dec(); 00177 bool check_partition_func_processor(uchar *int_arg) {return TRUE;} 00178 bool check_valid_arguments_processor(uchar *int_arg) 00179 { 00180 return !has_date_args(); 00181 } 00182 }; 00183 00184 00185 class Item_func_dayofyear :public Item_int_func 00186 { 00187 public: 00188 Item_func_dayofyear(Item *a) :Item_int_func(a) {} 00189 longlong val_int(); 00190 const char *func_name() const { return "dayofyear"; } 00191 void fix_length_and_dec() 00192 { 00193 fix_char_length(3); 00194 maybe_null= 1; 00195 } 00196 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00197 bool check_valid_arguments_processor(uchar *int_arg) 00198 { 00199 return !has_date_args(); 00200 } 00201 }; 00202 00203 00204 class Item_func_hour :public Item_int_func 00205 { 00206 public: 00207 Item_func_hour(Item *a) :Item_int_func(a) {} 00208 longlong val_int(); 00209 const char *func_name() const { return "hour"; } 00210 void fix_length_and_dec() 00211 { 00212 fix_char_length(2); /* 0..23 */ 00213 maybe_null=1; 00214 } 00215 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00216 bool check_valid_arguments_processor(uchar *int_arg) 00217 { 00218 return !has_time_args(); 00219 } 00220 }; 00221 00222 00223 class Item_func_minute :public Item_int_func 00224 { 00225 public: 00226 Item_func_minute(Item *a) :Item_int_func(a) {} 00227 longlong val_int(); 00228 const char *func_name() const { return "minute"; } 00229 void fix_length_and_dec() 00230 { 00231 fix_char_length(2); /* 0..59 */ 00232 maybe_null=1; 00233 } 00234 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00235 bool check_valid_arguments_processor(uchar *int_arg) 00236 { 00237 return !has_time_args(); 00238 } 00239 }; 00240 00241 00242 class Item_func_quarter :public Item_int_func 00243 { 00244 public: 00245 Item_func_quarter(Item *a) :Item_int_func(a) {} 00246 longlong val_int(); 00247 const char *func_name() const { return "quarter"; } 00248 void fix_length_and_dec() 00249 { 00250 fix_char_length(1); /* 1..4 */ 00251 maybe_null=1; 00252 } 00253 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00254 bool check_valid_arguments_processor(uchar *int_arg) 00255 { 00256 return !has_date_args(); 00257 } 00258 }; 00259 00260 00261 class Item_func_second :public Item_int_func 00262 { 00263 public: 00264 Item_func_second(Item *a) :Item_int_func(a) {} 00265 longlong val_int(); 00266 const char *func_name() const { return "second"; } 00267 void fix_length_and_dec() 00268 { 00269 fix_char_length(2); /* 0..59 */ 00270 maybe_null=1; 00271 } 00272 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00273 bool check_valid_arguments_processor(uchar *int_arg) 00274 { 00275 return !has_time_args(); 00276 } 00277 }; 00278 00279 00280 class Item_func_week :public Item_int_func 00281 { 00282 public: 00283 Item_func_week(Item *a,Item *b) :Item_int_func(a,b) {} 00284 longlong val_int(); 00285 const char *func_name() const { return "week"; } 00286 void fix_length_and_dec() 00287 { 00288 fix_char_length(2); /* 0..54 */ 00289 maybe_null=1; 00290 } 00291 }; 00292 00293 class Item_func_yearweek :public Item_int_func 00294 { 00295 public: 00296 Item_func_yearweek(Item *a,Item *b) :Item_int_func(a,b) {} 00297 longlong val_int(); 00298 const char *func_name() const { return "yearweek"; } 00299 void fix_length_and_dec() 00300 { 00301 fix_char_length(6); /* YYYYWW */ 00302 maybe_null=1; 00303 } 00304 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00305 bool check_valid_arguments_processor(uchar *int_arg) 00306 { 00307 return !has_date_args(); 00308 } 00309 }; 00310 00311 00312 class Item_func_year :public Item_int_func 00313 { 00314 public: 00315 Item_func_year(Item *a) :Item_int_func(a) {} 00316 longlong val_int(); 00317 const char *func_name() const { return "year"; } 00318 enum_monotonicity_info get_monotonicity_info() const; 00319 longlong val_int_endpoint(bool left_endp, bool *incl_endp); 00320 void fix_length_and_dec() 00321 { 00322 fix_char_length(4); /* 9999 */ 00323 maybe_null=1; 00324 } 00325 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00326 bool check_valid_arguments_processor(uchar *int_arg) 00327 { 00328 return !has_date_args(); 00329 } 00330 }; 00331 00332 00336 class Item_func_weekday :public Item_func 00337 { 00338 bool odbc_type; 00339 public: 00340 Item_func_weekday(Item *a,bool type_arg) 00341 :Item_func(a), odbc_type(type_arg) { collation.set_numeric(); } 00342 longlong val_int(); 00343 double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); } 00344 String *val_str(String *str) 00345 { 00346 DBUG_ASSERT(fixed == 1); 00347 str->set(val_int(), &my_charset_bin); 00348 return null_value ? 0 : str; 00349 } 00350 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 00351 { 00352 return get_date_from_int(ltime, fuzzydate); 00353 } 00354 bool get_time(MYSQL_TIME *ltime) 00355 { 00356 return get_time_from_int(ltime); 00357 } 00358 const char *func_name() const 00359 { 00360 return (odbc_type ? "dayofweek" : "weekday"); 00361 } 00362 enum Item_result result_type () const { return INT_RESULT; } 00363 void fix_length_and_dec() 00364 { 00365 fix_char_length(1); 00366 maybe_null= 1; 00367 } 00368 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00369 bool check_valid_arguments_processor(uchar *int_arg) 00370 { 00371 return !has_date_args(); 00372 } 00373 }; 00374 00380 class Item_func_dayname :public Item_func_weekday 00381 { 00382 MY_LOCALE *locale; 00383 public: 00384 Item_func_dayname(Item *a) :Item_func_weekday(a,0) {} 00385 const char *func_name() const { return "dayname"; } 00386 String *val_str(String *str); 00387 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 00388 { 00389 return get_date_from_string(ltime, fuzzydate); 00390 } 00391 bool get_time(MYSQL_TIME *ltime) 00392 { 00393 return get_time_from_string(ltime); 00394 } 00395 enum Item_result result_type () const { return STRING_RESULT; } 00396 void fix_length_and_dec(); 00397 bool check_partition_func_processor(uchar *int_arg) {return TRUE;} 00398 }; 00399 00400 00401 /* 00402 Abstract class for functions returning "struct timeval". 00403 */ 00404 class Item_timeval_func :public Item_func 00405 { 00406 public: 00407 Item_timeval_func() :Item_func() { } 00408 Item_timeval_func(Item *a) :Item_func(a) { } 00415 virtual bool val_timeval(struct timeval *tm)= 0; 00416 longlong val_int(); 00417 double val_real(); 00418 String *val_str(String *str); 00419 my_decimal *val_decimal(my_decimal *decimal_value); 00420 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 00421 { 00422 return get_date_from_numeric(ltime, fuzzydate); 00423 } 00424 bool get_time(MYSQL_TIME *ltime) 00425 { 00426 return get_time_from_numeric(ltime); 00427 } 00428 enum Item_result result_type() const 00429 { 00430 return decimals ? DECIMAL_RESULT : INT_RESULT; 00431 } 00432 }; 00433 00434 00435 class Item_func_unix_timestamp :public Item_timeval_func 00436 { 00437 public: 00438 Item_func_unix_timestamp() :Item_timeval_func() {} 00439 Item_func_unix_timestamp(Item *a) :Item_timeval_func(a) {} 00440 const char *func_name() const { return "unix_timestamp"; } 00441 enum_monotonicity_info get_monotonicity_info() const; 00442 longlong val_int_endpoint(bool left_endp, bool *incl_endp); 00443 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00444 /* 00445 UNIX_TIMESTAMP() depends on the current timezone 00446 (and thus may not be used as a partitioning function) 00447 when its argument is NOT of the TIMESTAMP type. 00448 */ 00449 bool check_valid_arguments_processor(uchar *int_arg) 00450 { 00451 return !has_timestamp_args(); 00452 } 00453 void fix_length_and_dec() 00454 { 00455 fix_length_and_dec_and_charset_datetime(11, arg_count == 0 ? 0 : 00456 args[0]->datetime_precision()); 00457 } 00458 bool val_timeval(struct timeval *tm); 00459 }; 00460 00461 00462 class Item_func_time_to_sec :public Item_int_func 00463 { 00464 public: 00465 Item_func_time_to_sec(Item *item) :Item_int_func(item) {} 00466 longlong val_int(); 00467 const char *func_name() const { return "time_to_sec"; } 00468 void fix_length_and_dec() 00469 { 00470 maybe_null= TRUE; 00471 fix_char_length(10); 00472 } 00473 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 00474 bool check_valid_arguments_processor(uchar *int_arg) 00475 { 00476 return !has_time_args(); 00477 } 00478 }; 00479 00480 00485 class Item_temporal_func :public Item_func 00486 { 00487 protected: 00488 bool check_precision(); 00489 public: 00490 Item_temporal_func() :Item_func() {} 00491 Item_temporal_func(Item *a) :Item_func(a) {} 00492 Item_temporal_func(Item *a, Item *b) :Item_func(a, b) {} 00493 Item_temporal_func(Item *a, Item *b, Item *c) :Item_func(a, b, c) {} 00494 enum Item_result result_type () const 00495 { 00496 return STRING_RESULT; 00497 } 00498 CHARSET_INFO *charset_for_protocol() const 00499 { 00500 return &my_charset_bin; 00501 } 00502 Field *tmp_table_field(TABLE *table) 00503 { 00504 return tmp_table_field_from_field_type(table, 0); 00505 } 00506 uint time_precision() 00507 { 00508 DBUG_ASSERT(fixed); 00509 return decimals; 00510 } 00511 uint datetime_precision() 00512 { 00513 DBUG_ASSERT(fixed); 00514 return decimals; 00515 } 00516 }; 00517 00518 00523 class Item_temporal_hybrid_func :public Item_str_func 00524 { 00525 protected: 00526 sql_mode_t sql_mode; // sql_mode value is cached here in fix_length_and_dec() 00527 enum_field_types cached_field_type; // TIME, DATE, DATETIME or STRING 00528 String ascii_buf; // Conversion buffer 00536 virtual bool val_datetime(MYSQL_TIME *ltime, uint fuzzy_date)= 0; 00537 00538 public: 00539 Item_temporal_hybrid_func(Item *a, Item *b) :Item_str_func(a, b), 00540 sql_mode(0) 00541 { } 00542 enum Item_result result_type () const { return STRING_RESULT; } 00543 enum_field_types field_type() const { return cached_field_type; } 00544 const CHARSET_INFO *charset_for_protocol() const 00545 { 00546 /* 00547 Can return TIME, DATE, DATETIME or VARCHAR depending on arguments. 00548 Send using "binary" when TIME, DATE or DATETIME, 00549 or using collation.collation when VARCHAR 00550 (which is fixed from @collation_connection in fix_length_and_dec). 00551 */ 00552 DBUG_ASSERT(fixed == 1); 00553 return cached_field_type == MYSQL_TYPE_STRING ? 00554 collation.collation : &my_charset_bin; 00555 } 00556 Field *tmp_table_field(TABLE *table) 00557 { 00558 return tmp_table_field_from_field_type(table, 0); 00559 } 00560 longlong val_int() { return val_int_from_decimal(); } 00561 double val_real() { return val_real_from_decimal(); } 00562 my_decimal *val_decimal(my_decimal *decimal_value); 00563 type_conversion_status save_in_field(Field *field, bool no_conversions); 00567 String *val_str_ascii(String *str); 00571 String *val_str(String *str) 00572 { 00573 return val_str_from_val_str_ascii(str, &ascii_buf); 00574 } 00575 bool get_date(MYSQL_TIME *ltime, uint fuzzydate); 00576 bool get_time(MYSQL_TIME *ltime); 00577 }; 00578 00579 00580 /* 00581 This can't be a Item_str_func, because the val_real() functions are special 00582 */ 00583 00587 class Item_date_func :public Item_temporal_func 00588 { 00589 public: 00590 Item_date_func() :Item_temporal_func() 00591 { } 00592 Item_date_func(Item *a) :Item_temporal_func(a) 00593 { } 00594 Item_date_func(Item *a, Item *b) :Item_temporal_func(a, b) 00595 { } 00596 enum_field_types field_type() const { return MYSQL_TYPE_DATE; } 00597 bool get_time(MYSQL_TIME *ltime) 00598 { 00599 return get_time_from_date(ltime); 00600 } 00601 String *val_str(String *str) 00602 { 00603 return val_string_from_date(str); 00604 } 00605 longlong val_int() 00606 { 00607 return val_int_from_date(); 00608 } 00609 longlong val_date_temporal(); 00610 double val_real() { return (double) val_int(); } 00611 const char *func_name() const { return "date"; } 00612 void fix_length_and_dec() 00613 { 00614 fix_length_and_dec_and_charset_datetime(MAX_DATE_WIDTH, 0); 00615 } 00616 my_decimal *val_decimal(my_decimal *decimal_value) 00617 { 00618 DBUG_ASSERT(fixed == 1); 00619 return val_decimal_from_date(decimal_value); 00620 } 00621 type_conversion_status save_in_field(Field *field, bool no_conversions) 00622 { 00623 return save_date_in_field(field); 00624 } 00625 // All date functions must implement get_date() 00626 // to avoid use of generic Item::get_date() 00627 // which converts to string and then parses the string as DATE. 00628 virtual bool get_date(MYSQL_TIME *res, uint fuzzy_date)= 0; 00629 }; 00630 00631 00635 class Item_datetime_func :public Item_temporal_func 00636 { 00637 public: 00638 Item_datetime_func() :Item_temporal_func() 00639 { } 00640 Item_datetime_func(Item *a) :Item_temporal_func(a) 00641 { } 00642 Item_datetime_func(Item *a,Item *b) :Item_temporal_func(a,b) 00643 { } 00644 Item_datetime_func(Item *a,Item *b, Item *c) :Item_temporal_func(a,b,c) 00645 { } 00646 enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } 00647 double val_real() { return val_real_from_decimal(); } 00648 String *val_str(String *str) 00649 { 00650 return val_string_from_datetime(str); 00651 } 00652 longlong val_int() 00653 { 00654 return val_int_from_datetime(); 00655 } 00656 longlong val_date_temporal(); 00657 my_decimal *val_decimal(my_decimal *decimal_value) 00658 { 00659 DBUG_ASSERT(fixed == 1); 00660 return val_decimal_from_date(decimal_value); 00661 } 00662 type_conversion_status save_in_field(Field *field, bool no_conversions) 00663 { 00664 return save_date_in_field(field); 00665 } 00666 bool get_time(MYSQL_TIME *ltime) 00667 { 00668 return get_time_from_datetime(ltime); 00669 } 00670 // All datetime functions must implement get_date() 00671 // to avoid use of generic Item::get_date() 00672 // which converts to string and then parses the string as DATETIME. 00673 virtual bool get_date(MYSQL_TIME *res, uint fuzzy_date)= 0; 00674 }; 00675 00676 00680 class Item_time_func :public Item_temporal_func 00681 { 00682 public: 00683 Item_time_func() :Item_temporal_func() {} 00684 Item_time_func(Item *a) :Item_temporal_func(a) {} 00685 Item_time_func(Item *a,Item *b) :Item_temporal_func(a,b) {} 00686 Item_time_func(Item *a, Item *b, Item *c) :Item_temporal_func(a, b ,c) {} 00687 enum_field_types field_type() const { return MYSQL_TYPE_TIME; } 00688 double val_real() { return val_real_from_decimal(); } 00689 my_decimal *val_decimal(my_decimal *decimal_value) 00690 { 00691 DBUG_ASSERT(fixed == 1); 00692 return val_decimal_from_time(decimal_value); 00693 } 00694 type_conversion_status save_in_field(Field *field, bool no_conversions) 00695 { 00696 return save_time_in_field(field); 00697 } 00698 longlong val_int() 00699 { 00700 return val_int_from_time(); 00701 } 00702 longlong val_time_temporal(); 00703 bool get_date(MYSQL_TIME *res, uint fuzzy_date) 00704 { 00705 return get_date_from_time(res); 00706 } 00707 String *val_str(String *str) 00708 { 00709 return val_string_from_time(str); 00710 } 00711 // All time functions must implement get_time() 00712 // to avoid use of generic Item::get_time() 00713 // which converts to string and then parses the string as TIME. 00714 virtual bool get_time(MYSQL_TIME *res)= 0; 00715 }; 00716 00717 00726 class MYSQL_TIME_cache 00727 { 00728 MYSQL_TIME time; 00729 longlong time_packed; 00730 char string_buff[MAX_DATE_STRING_REP_LENGTH]; 00731 uint string_length; 00732 uint8 dec; 00733 00737 void cache_string(); 00741 void reset_string() 00742 { 00743 string_length= 0; 00744 string_buff[0]= '\0'; 00745 } 00749 void reset() 00750 { 00751 time.time_type= MYSQL_TIMESTAMP_NONE; 00752 time_packed= 0; 00753 reset_string(); 00754 dec= 0; 00755 } 00759 void get_TIME(MYSQL_TIME *ltime) const 00760 { 00761 DBUG_ASSERT(time.time_type != MYSQL_TIMESTAMP_NONE); 00762 *ltime= time; 00763 } 00764 public: 00765 00766 MYSQL_TIME_cache() 00767 { 00768 reset(); 00769 } 00773 void set_date(MYSQL_TIME *ltime); 00777 void set_time(MYSQL_TIME *ltime, uint8 dec_arg); 00781 void set_datetime(MYSQL_TIME *ltime, uint8 dec_arg); 00786 void set_date(struct timeval tv, Time_zone *tz); 00791 void set_time(struct timeval tv, uint8 dec_arg, Time_zone *tz); 00796 void set_datetime(struct timeval tv, uint8 dec_arg, Time_zone *tz); 00800 bool eq(const MYSQL_TIME_cache &tm) const 00801 { 00802 return val_packed() == tm.val_packed(); 00803 } 00804 00808 uint8 decimals() const 00809 { 00810 DBUG_ASSERT(time.time_type != MYSQL_TIMESTAMP_NONE); 00811 return dec; 00812 } 00813 00817 longlong val_packed() const 00818 { 00819 DBUG_ASSERT(time.time_type != MYSQL_TIMESTAMP_NONE); 00820 return time_packed; 00821 } 00826 bool get_date(MYSQL_TIME *ltime, uint fuzzyflags) const; 00830 bool get_time(MYSQL_TIME *ltime) const 00831 { 00832 get_TIME(ltime); 00833 return false; 00834 } 00838 MYSQL_TIME *get_TIME_ptr() 00839 { 00840 DBUG_ASSERT(time.time_type != MYSQL_TIMESTAMP_NONE); 00841 return &time; 00842 } 00846 String *val_str(String *str); 00850 const char *cptr(); 00851 }; 00852 00853 00857 class Item_date_literal :public Item_date_func 00858 { 00859 MYSQL_TIME_cache cached_time; 00860 public: 00865 Item_date_literal(MYSQL_TIME *ltime) :Item_date_func() 00866 { 00867 cached_time.set_date(ltime); 00868 fix_length_and_dec(); 00869 fixed= 1; 00870 } 00871 const char *func_name() const { return "date_literal"; } 00872 void print(String *str, enum_query_type query_type); 00873 longlong val_date_temporal() 00874 { 00875 DBUG_ASSERT(fixed); 00876 return cached_time.val_packed(); 00877 } 00878 bool get_date(MYSQL_TIME *ltime, uint fuzzy_date) 00879 { 00880 DBUG_ASSERT(fixed); 00881 return cached_time.get_date(ltime, fuzzy_date); 00882 } 00883 String *val_str(String *str) 00884 { 00885 DBUG_ASSERT(fixed); 00886 return cached_time.val_str(str); 00887 } 00888 void fix_length_and_dec() 00889 { 00890 fix_length_and_dec_and_charset_datetime(MAX_DATE_WIDTH, 0); 00891 } 00892 bool check_partition_func_processor(uchar *int_arg) 00893 { 00894 return FALSE; 00895 } 00896 bool basic_const_item() const { return true; } 00897 bool const_item() const { return true; } 00898 table_map used_tables() const { return (table_map) 0L; } 00899 table_map not_null_tables() const { return used_tables(); } 00900 void cleanup() 00901 { 00902 // See Item_basic_const::cleanup() 00903 if (orig_name.is_set()) 00904 item_name= orig_name; 00905 } 00906 bool eq(const Item *item, bool binary_cmp) const; 00907 }; 00908 00909 00913 class Item_time_literal :public Item_time_func 00914 { 00915 MYSQL_TIME_cache cached_time; 00916 public: 00922 Item_time_literal(MYSQL_TIME *ltime, uint dec_arg) :Item_time_func() 00923 { 00924 decimals= MY_MIN(dec_arg, DATETIME_MAX_DECIMALS); 00925 cached_time.set_time(ltime, decimals); 00926 fix_length_and_dec(); 00927 fixed= 1; 00928 } 00929 const char *func_name() const { return "time_literal"; } 00930 void print(String *str, enum_query_type query_type); 00931 longlong val_time_temporal() 00932 { 00933 DBUG_ASSERT(fixed); 00934 return cached_time.val_packed(); 00935 } 00936 bool get_time(MYSQL_TIME *ltime) 00937 { 00938 DBUG_ASSERT(fixed); 00939 return cached_time.get_time(ltime); 00940 } 00941 String *val_str(String *str) 00942 { 00943 DBUG_ASSERT(fixed); 00944 return cached_time.val_str(str); 00945 } 00946 void fix_length_and_dec() 00947 { 00948 fix_length_and_dec_and_charset_datetime(MAX_TIME_WIDTH, decimals); 00949 } 00950 bool check_partition_func_processor(uchar *int_arg) 00951 { 00952 return FALSE; 00953 } 00954 bool basic_const_item() const { return true; } 00955 bool const_item() const { return true; } 00956 table_map used_tables() const { return (table_map) 0L; } 00957 table_map not_null_tables() const { return used_tables(); } 00958 void cleanup() 00959 { 00960 // See Item_basic_const::cleanup() 00961 if (orig_name.is_set()) 00962 item_name= orig_name; 00963 } 00964 bool eq(const Item *item, bool binary_cmp) const; 00965 }; 00966 00967 00971 class Item_datetime_literal :public Item_datetime_func 00972 { 00973 MYSQL_TIME_cache cached_time; 00974 public: 00980 Item_datetime_literal(MYSQL_TIME *ltime, uint dec_arg) :Item_datetime_func() 00981 { 00982 decimals= MY_MIN(dec_arg, DATETIME_MAX_DECIMALS); 00983 cached_time.set_datetime(ltime, decimals); 00984 fix_length_and_dec(); 00985 fixed= 1; 00986 } 00987 const char *func_name() const { return "datetime_literal"; } 00988 void print(String *str, enum_query_type query_type); 00989 longlong val_date_temporal() 00990 { 00991 DBUG_ASSERT(fixed); 00992 return cached_time.val_packed(); 00993 } 00994 bool get_date(MYSQL_TIME *ltime, uint fuzzy_date) 00995 { 00996 DBUG_ASSERT(fixed); 00997 return cached_time.get_date(ltime, fuzzy_date); 00998 } 00999 String *val_str(String *str) 01000 { 01001 DBUG_ASSERT(fixed); 01002 return cached_time.val_str(str); 01003 } 01004 void fix_length_and_dec() 01005 { 01006 fix_length_and_dec_and_charset_datetime(MAX_DATETIME_WIDTH, decimals); 01007 } 01008 bool check_partition_func_processor(uchar *int_arg) 01009 { 01010 return FALSE; 01011 } 01012 bool basic_const_item() const { return true; } 01013 bool const_item() const { return true; } 01014 table_map used_tables() const { return (table_map) 0L; } 01015 table_map not_null_tables() const { return used_tables(); } 01016 void cleanup() 01017 { 01018 // See Item_basic_const::cleanup() 01019 if (orig_name.is_set()) 01020 item_name= orig_name; 01021 } 01022 bool eq(const Item *item, bool binary_cmp) const; 01023 }; 01024 01025 01026 /* Abstract CURTIME function. Children should define what time zone is used */ 01027 01028 class Item_func_curtime :public Item_time_func 01029 { 01030 MYSQL_TIME_cache cached_time; // Initialized in fix_length_and_dec 01031 protected: 01032 // Abstract method that defines which time zone is used for conversion. 01033 virtual Time_zone *time_zone()= 0; 01034 public: 01039 Item_func_curtime(uint8 dec_arg) :Item_time_func() { decimals= dec_arg; } 01040 void fix_length_and_dec(); 01041 longlong val_time_temporal() 01042 { 01043 DBUG_ASSERT(fixed == 1); 01044 return cached_time.val_packed(); 01045 } 01046 bool get_time(MYSQL_TIME *ltime) 01047 { 01048 DBUG_ASSERT(fixed == 1); 01049 return cached_time.get_time(ltime); 01050 } 01051 String *val_str(String *str) 01052 { 01053 DBUG_ASSERT(fixed == 1); 01054 return cached_time.val_str(&str_value); 01055 } 01056 }; 01057 01058 01059 class Item_func_curtime_local :public Item_func_curtime 01060 { 01061 protected: 01062 Time_zone *time_zone(); 01063 public: 01064 Item_func_curtime_local(uint8 dec_arg) :Item_func_curtime(dec_arg) {} 01065 const char *func_name() const { return "curtime"; } 01066 }; 01067 01068 01069 class Item_func_curtime_utc :public Item_func_curtime 01070 { 01071 protected: 01072 Time_zone *time_zone(); 01073 public: 01074 Item_func_curtime_utc(uint8 dec_arg) :Item_func_curtime(dec_arg) {} 01075 const char *func_name() const { return "utc_time"; } 01076 }; 01077 01078 01079 /* Abstract CURDATE function. See also Item_func_curtime. */ 01080 01081 class Item_func_curdate :public Item_date_func 01082 { 01083 MYSQL_TIME_cache cached_time; // Initialized in fix_length_and_dec 01084 protected: 01085 virtual Time_zone *time_zone()= 0; 01086 public: 01087 Item_func_curdate() :Item_date_func() {} 01088 void fix_length_and_dec(); 01089 longlong val_date_temporal() 01090 { 01091 DBUG_ASSERT(fixed == 1); 01092 return cached_time.val_packed(); 01093 } 01094 bool get_date(MYSQL_TIME *res, uint fuzzy_date) 01095 { 01096 DBUG_ASSERT(fixed == 1); 01097 return cached_time.get_time(res); 01098 } 01099 String *val_str(String *str) 01100 { 01101 DBUG_ASSERT(fixed == 1); 01102 return cached_time.val_str(&str_value); 01103 } 01104 }; 01105 01106 01107 class Item_func_curdate_local :public Item_func_curdate 01108 { 01109 protected: 01110 Time_zone *time_zone(); 01111 public: 01112 Item_func_curdate_local() :Item_func_curdate() {} 01113 const char *func_name() const { return "curdate"; } 01114 }; 01115 01116 01117 class Item_func_curdate_utc :public Item_func_curdate 01118 { 01119 protected: 01120 Time_zone *time_zone(); 01121 public: 01122 Item_func_curdate_utc() :Item_func_curdate() {} 01123 const char *func_name() const { return "utc_date"; } 01124 }; 01125 01126 01127 /* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */ 01128 01129 class Item_func_now :public Item_datetime_func 01130 { 01131 MYSQL_TIME_cache cached_time; 01132 protected: 01133 virtual Time_zone *time_zone()= 0; 01134 public: 01139 Item_func_now(uint8 dec_arg) :Item_datetime_func() { decimals= dec_arg; } 01140 void fix_length_and_dec(); 01141 type_conversion_status save_in_field(Field *to, bool no_conversions); 01142 longlong val_date_temporal() 01143 { 01144 DBUG_ASSERT(fixed == 1); 01145 return cached_time.val_packed(); 01146 } 01147 bool get_date(MYSQL_TIME *res, uint fuzzy_date) 01148 { 01149 DBUG_ASSERT(fixed == 1); 01150 return cached_time.get_time(res); 01151 } 01152 String *val_str(String *str) 01153 { 01154 DBUG_ASSERT(fixed == 1); 01155 return cached_time.val_str(&str_value); 01156 } 01157 }; 01158 01159 01160 class Item_func_now_local :public Item_func_now 01161 { 01162 protected: 01163 Time_zone *time_zone(); 01164 public: 01171 static void store_in(Field *field); 01172 01173 Item_func_now_local(uint8 dec_arg) :Item_func_now(dec_arg) {} 01174 const char *func_name() const { return "now"; } 01175 virtual enum Functype functype() const { return NOW_FUNC; } 01176 }; 01177 01178 01179 class Item_func_now_utc :public Item_func_now 01180 { 01181 protected: 01182 Time_zone *time_zone(); 01183 public: 01184 Item_func_now_utc(uint8 dec_arg) :Item_func_now(dec_arg) {} 01185 const char *func_name() const { return "utc_timestamp"; } 01186 }; 01187 01188 01189 /* 01190 This is like NOW(), but always uses the real current time, not the 01191 query_start(). This matches the Oracle behavior. 01192 */ 01193 class Item_func_sysdate_local :public Item_datetime_func 01194 { 01195 public: 01196 Item_func_sysdate_local(uint8 dec_arg) : 01197 Item_datetime_func() { decimals= dec_arg; } 01198 bool const_item() const { return 0; } 01199 const char *func_name() const { return "sysdate"; } 01200 void fix_length_and_dec(); 01201 bool get_date(MYSQL_TIME *res, uint fuzzy_date); 01207 table_map get_initial_pseudo_tables() const { return RAND_TABLE_BIT; } 01208 }; 01209 01210 01211 class Item_func_from_days :public Item_date_func 01212 { 01213 public: 01214 Item_func_from_days(Item *a) :Item_date_func(a) {} 01215 const char *func_name() const { return "from_days"; } 01216 bool get_date(MYSQL_TIME *res, uint fuzzy_date); 01217 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 01218 bool check_valid_arguments_processor(uchar *int_arg) 01219 { 01220 return has_date_args() || has_time_args(); 01221 } 01222 }; 01223 01224 01225 class Item_func_date_format :public Item_str_func 01226 { 01227 int fixed_length; 01228 const bool is_time_format; 01229 String value; 01230 public: 01231 Item_func_date_format(Item *a,Item *b,bool is_time_format_arg) 01232 :Item_str_func(a,b),is_time_format(is_time_format_arg) {} 01233 String *val_str(String *str); 01234 const char *func_name() const 01235 { return is_time_format ? "time_format" : "date_format"; } 01236 void fix_length_and_dec(); 01237 uint format_length(const String *format); 01238 bool eq(const Item *item, bool binary_cmp) const; 01239 }; 01240 01241 01242 class Item_func_from_unixtime :public Item_datetime_func 01243 { 01244 THD *thd; 01245 public: 01246 Item_func_from_unixtime(Item *a) :Item_datetime_func(a) {} 01247 const char *func_name() const { return "from_unixtime"; } 01248 void fix_length_and_dec(); 01249 bool get_date(MYSQL_TIME *res, uint fuzzy_date); 01250 }; 01251 01252 01253 /* 01254 We need Time_zone class declaration for storing pointers in 01255 Item_func_convert_tz. 01256 */ 01257 class Time_zone; 01258 01259 /* 01260 This class represents CONVERT_TZ() function. 01261 The important fact about this function that it is handled in special way. 01262 When such function is met in expression time_zone system tables are added 01263 to global list of tables to open, so later those already opened and locked 01264 tables can be used during this function calculation for loading time zone 01265 descriptions. 01266 */ 01267 class Item_func_convert_tz :public Item_datetime_func 01268 { 01269 /* 01270 If time zone parameters are constants we are caching objects that 01271 represent them (we use separate from_tz_cached/to_tz_cached members 01272 to indicate this fact, since NULL is legal value for from_tz/to_tz 01273 members. 01274 */ 01275 bool from_tz_cached, to_tz_cached; 01276 Time_zone *from_tz, *to_tz; 01277 public: 01278 Item_func_convert_tz(Item *a, Item *b, Item *c): 01279 Item_datetime_func(a, b, c), from_tz_cached(0), to_tz_cached(0) {} 01280 const char *func_name() const { return "convert_tz"; } 01281 void fix_length_and_dec(); 01282 bool get_date(MYSQL_TIME *res, uint fuzzy_date); 01283 void cleanup(); 01284 }; 01285 01286 01287 class Item_func_sec_to_time :public Item_time_func 01288 { 01289 public: 01290 Item_func_sec_to_time(Item *item) :Item_time_func(item) {} 01291 void fix_length_and_dec() 01292 { 01293 maybe_null=1; 01294 fix_length_and_dec_and_charset_datetime(MAX_TIME_WIDTH, 01295 MY_MIN(args[0]->decimals, 01296 DATETIME_MAX_DECIMALS)); 01297 } 01298 const char *func_name() const { return "sec_to_time"; } 01299 bool get_time(MYSQL_TIME *ltime); 01300 }; 01301 01302 01303 class Item_date_add_interval :public Item_temporal_hybrid_func 01304 { 01305 String value; 01306 bool get_date_internal(MYSQL_TIME *res, uint fuzzy_date); 01307 bool get_time_internal(MYSQL_TIME *res); 01308 protected: 01309 bool val_datetime(MYSQL_TIME *ltime, uint fuzzy_date); 01310 01311 public: 01312 const interval_type int_type; // keep it public 01313 const bool date_sub_interval; // keep it public 01314 Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg) 01315 :Item_temporal_hybrid_func(a, b), 01316 int_type(type_arg), date_sub_interval(neg_arg) {} 01317 const char *func_name() const { return "date_add_interval"; } 01318 void fix_length_and_dec(); 01319 bool eq(const Item *item, bool binary_cmp) const; 01320 void print(String *str, enum_query_type query_type); 01321 }; 01322 01323 01324 class Item_extract :public Item_int_func 01325 { 01326 bool date_value; 01327 public: 01328 const interval_type int_type; // keep it public 01329 Item_extract(interval_type type_arg, Item *a) 01330 :Item_int_func(a), int_type(type_arg) {} 01331 longlong val_int(); 01332 enum Functype functype() const { return EXTRACT_FUNC; } 01333 const char *func_name() const { return "extract"; } 01334 void fix_length_and_dec(); 01335 bool eq(const Item *item, bool binary_cmp) const; 01336 virtual void print(String *str, enum_query_type query_type); 01337 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 01338 bool check_valid_arguments_processor(uchar *int_arg) 01339 { 01340 switch (int_type) { 01341 case INTERVAL_YEAR: 01342 case INTERVAL_YEAR_MONTH: 01343 case INTERVAL_QUARTER: 01344 case INTERVAL_MONTH: 01345 /* case INTERVAL_WEEK: Not allowed as partitioning function, bug#57071 */ 01346 case INTERVAL_DAY: 01347 return !has_date_args(); 01348 case INTERVAL_DAY_HOUR: 01349 case INTERVAL_DAY_MINUTE: 01350 case INTERVAL_DAY_SECOND: 01351 case INTERVAL_DAY_MICROSECOND: 01352 return !has_datetime_args(); 01353 case INTERVAL_HOUR: 01354 case INTERVAL_HOUR_MINUTE: 01355 case INTERVAL_HOUR_SECOND: 01356 case INTERVAL_MINUTE: 01357 case INTERVAL_MINUTE_SECOND: 01358 case INTERVAL_SECOND: 01359 case INTERVAL_MICROSECOND: 01360 case INTERVAL_HOUR_MICROSECOND: 01361 case INTERVAL_MINUTE_MICROSECOND: 01362 case INTERVAL_SECOND_MICROSECOND: 01363 return !has_time_args(); 01364 default: 01365 /* 01366 INTERVAL_LAST is only an end marker, 01367 INTERVAL_WEEK depends on default_week_format which is a session 01368 variable and cannot be used for partitioning. See bug#57071. 01369 */ 01370 break; 01371 } 01372 return true; 01373 } 01374 }; 01375 01376 01377 class Item_date_typecast :public Item_date_func 01378 { 01379 public: 01380 Item_date_typecast(Item *a) :Item_date_func(a) { maybe_null= 1; } 01381 void print(String *str, enum_query_type query_type); 01382 const char *func_name() const { return "cast_as_date"; } 01383 bool get_date(MYSQL_TIME *ltime, uint fuzzy_date); 01384 const char *cast_type() const { return "date"; } 01385 }; 01386 01387 01388 class Item_time_typecast :public Item_time_func 01389 { 01390 bool detect_precision_from_arg; 01391 public: 01392 Item_time_typecast(Item *a): Item_time_func(a) 01393 { 01394 detect_precision_from_arg= true; 01395 } 01396 Item_time_typecast(Item *a, uint8 dec_arg): Item_time_func(a) 01397 { 01398 detect_precision_from_arg= false; 01399 decimals= dec_arg; 01400 } 01401 void print(String *str, enum_query_type query_type); 01402 const char *func_name() const { return "cast_as_time"; } 01403 bool get_time(MYSQL_TIME *ltime); 01404 const char *cast_type() const { return "time"; } 01405 void fix_length_and_dec() 01406 { 01407 maybe_null= 1; 01408 fix_length_and_dec_and_charset_datetime(MAX_TIME_WIDTH, 01409 detect_precision_from_arg ? 01410 args[0]->time_precision() : 01411 decimals); 01412 } 01413 }; 01414 01415 01416 class Item_datetime_typecast :public Item_datetime_func 01417 { 01418 bool detect_precision_from_arg; 01419 public: 01420 Item_datetime_typecast(Item *a) :Item_datetime_func(a) 01421 { 01422 detect_precision_from_arg= true; 01423 } 01424 Item_datetime_typecast(Item *a, uint8 dec_arg) :Item_datetime_func(a) 01425 { 01426 detect_precision_from_arg= false; 01427 decimals= dec_arg; 01428 } 01429 void print(String *str, enum_query_type query_type); 01430 const char *func_name() const { return "cast_as_datetime"; } 01431 const char *cast_type() const { return "datetime"; } 01432 void fix_length_and_dec() 01433 { 01434 maybe_null= 1; 01435 fix_length_and_dec_and_charset_datetime(MAX_DATETIME_WIDTH, 01436 detect_precision_from_arg ? 01437 args[0]->datetime_precision(): 01438 decimals); 01439 } 01440 bool get_date(MYSQL_TIME *res, uint fuzzy_date); 01441 }; 01442 01443 01444 class Item_func_makedate :public Item_date_func 01445 { 01446 public: 01447 Item_func_makedate(Item *a, Item *b) :Item_date_func(a, b) { maybe_null= 1; } 01448 const char *func_name() const { return "makedate"; } 01449 bool get_date(MYSQL_TIME *ltime, uint fuzzy_date); 01450 }; 01451 01452 01453 class Item_func_add_time :public Item_temporal_hybrid_func 01454 { 01455 const bool is_date; 01456 int sign; 01457 bool val_datetime(MYSQL_TIME *time, uint fuzzy_date); 01458 public: 01459 Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg) 01460 :Item_temporal_hybrid_func(a, b), is_date(type_arg) 01461 { 01462 sign= neg_arg ? -1 : 1; 01463 } 01464 void fix_length_and_dec(); 01465 void print(String *str, enum_query_type query_type); 01466 const char *func_name() const { return "add_time"; } 01467 }; 01468 01469 01470 class Item_func_timediff :public Item_time_func 01471 { 01472 public: 01473 Item_func_timediff(Item *a, Item *b) :Item_time_func(a, b) {} 01474 const char *func_name() const { return "timediff"; } 01475 void fix_length_and_dec() 01476 { 01477 uint dec= MY_MAX(args[0]->time_precision(), args[1]->time_precision()); 01478 fix_length_and_dec_and_charset_datetime(MAX_TIME_WIDTH, dec); 01479 maybe_null= 1; 01480 } 01481 bool get_time(MYSQL_TIME *ltime); 01482 }; 01483 01484 class Item_func_maketime :public Item_time_func 01485 { 01486 public: 01487 Item_func_maketime(Item *a, Item *b, Item *c) :Item_time_func(a, b, c) 01488 { 01489 maybe_null= TRUE; 01490 } 01491 void fix_length_and_dec() 01492 { 01493 fix_length_and_dec_and_charset_datetime(MAX_TIME_WIDTH, 01494 MY_MIN(args[2]->decimals, 01495 DATETIME_MAX_DECIMALS)); 01496 } 01497 const char *func_name() const { return "maketime"; } 01498 bool get_time(MYSQL_TIME *ltime); 01499 }; 01500 01501 class Item_func_microsecond :public Item_int_func 01502 { 01503 public: 01504 Item_func_microsecond(Item *a) :Item_int_func(a) {} 01505 longlong val_int(); 01506 const char *func_name() const { return "microsecond"; } 01507 void fix_length_and_dec() 01508 { 01509 maybe_null=1; 01510 } 01511 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 01512 bool check_valid_arguments_processor(uchar *int_arg) 01513 { 01514 return !has_time_args(); 01515 } 01516 }; 01517 01518 01519 class Item_func_timestamp_diff :public Item_int_func 01520 { 01521 const interval_type int_type; 01522 public: 01523 Item_func_timestamp_diff(Item *a,Item *b,interval_type type_arg) 01524 :Item_int_func(a,b), int_type(type_arg) {} 01525 const char *func_name() const { return "timestampdiff"; } 01526 longlong val_int(); 01527 void fix_length_and_dec() 01528 { 01529 maybe_null=1; 01530 } 01531 virtual void print(String *str, enum_query_type query_type); 01532 }; 01533 01534 01535 enum date_time_format 01536 { 01537 USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT 01538 }; 01539 01540 class Item_func_get_format :public Item_str_ascii_func 01541 { 01542 public: 01543 const timestamp_type type; // keep it public 01544 Item_func_get_format(timestamp_type type_arg, Item *a) 01545 :Item_str_ascii_func(a), type(type_arg) 01546 {} 01547 String *val_str_ascii(String *str); 01548 const char *func_name() const { return "get_format"; } 01549 void fix_length_and_dec() 01550 { 01551 maybe_null= 1; 01552 decimals=0; 01553 fix_length_and_charset(17, default_charset()); 01554 } 01555 virtual void print(String *str, enum_query_type query_type); 01556 }; 01557 01558 01559 class Item_func_str_to_date :public Item_temporal_hybrid_func 01560 { 01561 timestamp_type cached_timestamp_type; 01562 bool const_item; 01563 void fix_from_format(const char *format, uint length); 01564 protected: 01565 bool val_datetime(MYSQL_TIME *ltime, uint fuzzy_date); 01566 public: 01567 Item_func_str_to_date(Item *a, Item *b) 01568 :Item_temporal_hybrid_func(a, b), const_item(false) 01569 {} 01570 const char *func_name() const { return "str_to_date"; } 01571 void fix_length_and_dec(); 01572 }; 01573 01574 01575 class Item_func_last_day :public Item_date_func 01576 { 01577 public: 01578 Item_func_last_day(Item *a) :Item_date_func(a) { maybe_null= 1; } 01579 const char *func_name() const { return "last_day"; } 01580 bool get_date(MYSQL_TIME *res, uint fuzzy_date); 01581 }; 01582 01583 01584 /* Function prototypes */ 01585 01586 bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time, 01587 timestamp_type type, String *str); 01588 01589 #endif /* ITEM_TIMEFUNC_INCLUDED */