diff options
author | Alexander Barkov <bar@mariadb.com> | 2018-09-28 14:01:17 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2018-09-28 14:01:17 +0400 |
commit | ad8e02ac452dc94d64b65cb9855b6dba97b651d4 (patch) | |
tree | 7c355aab42a911476eaa10520d1adbabb7091243 /sql | |
parent | 492998c0d80aa7d5c4804ac7792a38333e3b83dd (diff) | |
download | mariadb-git-ad8e02ac452dc94d64b65cb9855b6dba97b651d4.tar.gz |
MDEV-17317 Add THD* parameter into Item::get_date() and stricter data type control to "fuzzydate"
Diffstat (limited to 'sql')
40 files changed, 1017 insertions, 860 deletions
diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index 02da3c31c3e..a6803982171 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -654,7 +654,7 @@ my_time_t add_interval(MYSQL_TIME *ltime, const Time_zone *time_zone, interval_type scale, INTERVAL interval) { - if (date_add_interval(ltime, scale, interval)) + if (date_add_interval(current_thd, ltime, scale, interval)) return 0; uint not_used; diff --git a/sql/event_parse_data.cc b/sql/event_parse_data.cc index d20d322d864..bfda8438885 100644 --- a/sql/event_parse_data.cc +++ b/sql/event_parse_data.cc @@ -216,7 +216,7 @@ Event_parse_data::init_execute_at(THD *thd) (starts_null && ends_null))); DBUG_ASSERT(starts_null && ends_null); - if (item_execute_at->get_date(<ime, TIME_NO_ZERO_DATE)) + if (item_execute_at->get_date(thd, <ime, TIME_NO_ZERO_DATE)) goto wrong_value; ltime_utc= TIME_to_timestamp(thd,<ime,¬_used); @@ -275,7 +275,7 @@ Event_parse_data::init_interval(THD *thd) if (item_expression->fix_fields(thd, &item_expression)) goto wrong_value; - if (get_interval_value(item_expression, interval, &interval_tmp)) + if (get_interval_value(thd, item_expression, interval, &interval_tmp)) goto wrong_value; expression= 0; @@ -378,7 +378,7 @@ Event_parse_data::init_starts(THD *thd) if (item_starts->fix_fields(thd, &item_starts)) goto wrong_value; - if (item_starts->get_date(<ime, TIME_NO_ZERO_DATE)) + if (item_starts->get_date(thd, <ime, TIME_NO_ZERO_DATE)) goto wrong_value; ltime_utc= TIME_to_timestamp(thd, <ime, ¬_used); @@ -433,7 +433,7 @@ Event_parse_data::init_ends(THD *thd) goto error_bad_params; DBUG_PRINT("info", ("convert to TIME")); - if (item_ends->get_date(<ime, TIME_NO_ZERO_DATE)) + if (item_ends->get_date(thd, <ime, TIME_NO_ZERO_DATE)) goto error_bad_params; ltime_utc= TIME_to_timestamp(thd, <ime, ¬_used); diff --git a/sql/field.cc b/sql/field.cc index eb2dc2c8bd6..60823905233 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1832,7 +1832,7 @@ int Field::store_timestamp(my_time_t ts, ulong sec_part) { MYSQL_TIME ltime; THD *thd= get_thd(); - thd->timestamp_to_TIME(<ime, ts, sec_part, 0); + thd->timestamp_to_TIME(<ime, ts, sec_part, date_mode_t(0)); return store_time_dec(<ime, decimals()); } @@ -2064,17 +2064,17 @@ my_decimal* Field_int::val_decimal(my_decimal *decimal_value) } -bool Field_int::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) +bool Field_int::get_date(MYSQL_TIME *ltime,date_mode_t fuzzydate) { ASSERT_COLUMN_MARKED_FOR_READ; longlong nr= val_int(); bool neg= !(flags & UNSIGNED_FLAG) && nr < 0; - return int_to_datetime_with_warn(neg, neg ? -nr : nr, ltime, fuzzydate, - field_name.str); + return int_to_datetime_with_warn(get_thd(), neg, neg ? -nr : nr, ltime, + fuzzydate, field_name.str); } -bool Field_vers_trx_id::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate, ulonglong trx_id) +bool Field_vers_trx_id::get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate, ulonglong trx_id) { ASSERT_COLUMN_MARKED_FOR_READ; DBUG_ASSERT(ltime); @@ -2254,12 +2254,13 @@ uint Field::fill_cache_field(CACHE_FIELD *copy) } -bool Field::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) +bool Field::get_date(MYSQL_TIME *ltime,date_mode_t fuzzydate) { char buff[40]; String tmp(buff,sizeof(buff),&my_charset_bin),*res; if (!(res=val_str(&tmp)) || - str_to_datetime_with_warn(res->charset(), res->ptr(), res->length(), + str_to_datetime_with_warn(get_thd(), + res->charset(), res->ptr(), res->length(), ltime, fuzzydate)) return 1; return 0; @@ -4825,11 +4826,12 @@ my_decimal *Field_real::val_decimal(my_decimal *decimal_value) } -bool Field_real::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) +bool Field_real::get_date(MYSQL_TIME *ltime,date_mode_t fuzzydate) { ASSERT_COLUMN_MARKED_FOR_READ; double nr= val_real(); - return double_to_datetime_with_warn(nr, ltime, fuzzydate, field_name.str); + return double_to_datetime_with_warn(get_thd(), nr, ltime, fuzzydate, + field_name.str); } @@ -5073,10 +5075,10 @@ int Field_timestamp::store_TIME_with_warning(THD *thd, const Datetime *dt, } -sql_mode_t Field_timestamp::sql_mode_for_timestamp(THD *thd) const +date_mode_t Field_timestamp::sql_mode_for_timestamp(THD *thd) const { // We don't want to store invalid or fuzzy datetime values in TIMESTAMP - return (thd->variables.sql_mode & MODE_NO_ZERO_DATE) | MODE_NO_ZERO_IN_DATE; + return date_mode_t((thd->variables.sql_mode & MODE_NO_ZERO_DATE) | MODE_NO_ZERO_IN_DATE); } @@ -5124,7 +5126,7 @@ int Field_timestamp::store_timestamp(my_time_t ts, ulong sec_part) { store_TIME(ts, sec_part); if (ts == 0 && sec_part == 0 && - get_thd()->variables.sql_mode & TIME_NO_ZERO_DATE) + get_thd()->variables.sql_mode & (ulonglong) TIME_NO_ZERO_DATE) { ErrConvString s( STRING_WITH_LEN("0000-00-00 00:00:00.000000") - (decimals() ? 6 - decimals() : 7), @@ -5233,11 +5235,11 @@ Field_timestamp::validate_value_in_record(THD *thd, const uchar *record) const DBUG_ASSERT(!is_null_in_record(record)); ulong sec_part; return !get_timestamp(ptr_in_record(record), &sec_part) && !sec_part && - (sql_mode_for_dates(thd) & TIME_NO_ZERO_DATE) != 0; + bool(sql_mode_for_dates(thd) & TIME_NO_ZERO_DATE) != false; } -bool Field_timestamp::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Field_timestamp::get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { ulong sec_part; my_time_t ts= get_timestamp(&sec_part); @@ -5248,7 +5250,7 @@ bool Field_timestamp::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) bool Field_timestamp::send_binary(Protocol *protocol) { MYSQL_TIME ltime; - Field_timestamp::get_date(<ime, 0); + Field_timestamp::get_date(<ime, date_mode_t(0)); return protocol->store(<ime, 0); } @@ -5406,7 +5408,7 @@ double Field_timestamp_with_dec::val_real(void) my_decimal *Field_timestamp_with_dec::val_decimal(my_decimal *d) { MYSQL_TIME ltime; - get_date(<ime, 0); + get_date(<ime, date_mode_t(0)); return TIME_to_my_decimal(<ime, d); } @@ -5431,7 +5433,7 @@ int Field_timestamp_with_dec::set_time() bool Field_timestamp_with_dec::send_binary(Protocol *protocol) { MYSQL_TIME ltime; - Field_timestamp::get_date(<ime, 0); + Field_timestamp::get_date(<ime, date_mode_t(0)); return protocol->store(<ime, dec); } @@ -5609,7 +5611,7 @@ Field_temporal_with_date::validate_value_in_record(THD *thd, my_decimal *Field_temporal::val_decimal(my_decimal *d) { MYSQL_TIME ltime; - if (get_date(<ime, 0)) + if (get_date(<ime, date_mode_t(0))) { bzero(<ime, sizeof(ltime)); ltime.time_type= type_handler()->mysql_timestamp_type(); @@ -5642,7 +5644,7 @@ Item *Field_temporal::get_equal_const_item_datetime(THD *thd, const_item->field_type() != MYSQL_TYPE_TIMESTAMP) || const_item->decimals != decimals()) { - Datetime dt(thd, const_item, 0); + Datetime dt(thd, const_item, date_mode_t(0)); if (!dt.is_valid_datetime()) return NULL; /* @@ -5708,7 +5710,8 @@ int Field_time::store(const char *from,size_t len,CHARSET_INFO *cs) { ErrConvString str(from, len, cs); MYSQL_TIME_STATUS st; - Time tm(&st, from, len, cs, sql_mode_for_dates(get_thd()), decimals()); + THD *thd= get_thd(); + Time tm(thd, &st, from, len, cs, sql_mode_for_dates(thd), decimals()); return store_TIME_with_warning(&tm, &str, st.warnings); } @@ -5726,7 +5729,7 @@ int Field_time::store(double nr) { ErrConvDouble str(nr); int was_cut; - Time tm(&was_cut, nr, decimals()); + Time tm(get_thd(), &was_cut, nr, decimals()); return store_TIME_with_warning(&tm, &str, was_cut); } @@ -5736,7 +5739,7 @@ int Field_time::store(longlong nr, bool unsigned_val) ErrConvInteger str(nr, unsigned_val); int was_cut; // Need fractional digit truncation if nr overflows to '838:59:59.999999' - Time tm(&was_cut, nr, unsigned_val, decimals()); + Time tm(get_thd(), &was_cut, nr, unsigned_val, decimals()); return store_TIME_with_warning(&tm, &str, was_cut); } @@ -5796,7 +5799,7 @@ String *Field_time::val_str(String *str, } -bool Field_time::check_zero_in_date_with_warn(ulonglong fuzzydate) +bool Field_time::check_zero_in_date_with_warn(date_mode_t fuzzydate) { if (!(fuzzydate & TIME_TIME_ONLY) && (fuzzydate & TIME_NO_ZERO_IN_DATE)) { @@ -5818,7 +5821,7 @@ bool Field_time::check_zero_in_date_with_warn(ulonglong fuzzydate) DATE_FORMAT(time, "%l.%i %p") */ -bool Field_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Field_time::get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { if (check_zero_in_date_with_warn(fuzzydate)) return true; @@ -5894,7 +5897,7 @@ int Field_time::store_decimal(const my_decimal *d) { ErrConvDecimal str(d); int was_cut; - Time tm(&was_cut, d, decimals()); + Time tm(get_thd(), &was_cut, d, decimals()); return store_TIME_with_warning(&tm, &str, was_cut); } @@ -5954,7 +5957,7 @@ Item *Field_time::get_equal_const_item(THD *thd, const Context &ctx, if (const_item->field_type() != MYSQL_TYPE_TIME) { // Get the value of const_item with conversion from DATETIME to TIME - Time tm(const_item, + Time tm(get_thd(), const_item, Time::Options(Time::comparison_flags_for_get_date(), mode)); if (!tm.is_valid_time()) return NULL; @@ -5979,7 +5982,8 @@ Item *Field_time::get_equal_const_item(THD *thd, const Context &ctx, if (const_item->field_type() != MYSQL_TYPE_TIME || const_item->decimals != decimals()) { - Time tm(const_item, Time::Options(TIME_TIME_ONLY, mode)); + Time tm(get_thd(), const_item, + Time::Options(TIME_TIME_ONLY, mode)); if (!tm.is_valid_time()) return NULL; /* @@ -6022,7 +6026,7 @@ double Field_time_with_dec::val_real(void) return TIME_to_double(<ime); } -bool Field_time_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Field_time_hires::get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { if (check_zero_in_date_with_warn(fuzzydate)) return true; @@ -6074,7 +6078,7 @@ void Field_timef::store_TIME(const MYSQL_TIME *ltime) my_time_packed_to_binary(tmp, ptr, dec); } -bool Field_timef::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Field_timef::get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { if (check_zero_in_date_with_warn(fuzzydate)) return true; @@ -6208,12 +6212,12 @@ String *Field_year::val_str(String *val_buffer, } -bool Field_year::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) +bool Field_year::get_date(MYSQL_TIME *ltime,date_mode_t fuzzydate) { int tmp= (int) ptr[0]; if (tmp || field_length != 4) tmp+= 1900; - return int_to_datetime_with_warn(false, tmp * 10000, + return int_to_datetime_with_warn(get_thd(), false, tmp * 10000, ltime, fuzzydate, field_name.str); } @@ -6330,7 +6334,7 @@ longlong Field_date::val_int(void) bool Field_date::get_TIME(MYSQL_TIME *ltime, const uchar *pos, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { ASSERT_COLUMN_MARKED_FOR_READ; int32 tmp= sint4korr(pos); @@ -6347,7 +6351,7 @@ String *Field_date::val_str(String *val_buffer, String *val_ptr __attribute__((unused))) { MYSQL_TIME ltime; - get_TIME(<ime, ptr, 0); + get_TIME(<ime, ptr, date_mode_t(0)); val_buffer->alloc(MAX_DATE_STRING_REP_LENGTH); uint length= (uint) my_date_to_str(<ime, const_cast<char*>(val_buffer->ptr())); @@ -6397,7 +6401,7 @@ void Field_newdate::store_TIME(const MYSQL_TIME *ltime) bool Field_newdate::send_binary(Protocol *protocol) { MYSQL_TIME tm; - Field_newdate::get_date(&tm,0); + Field_newdate::get_date(&tm, date_mode_t(0)); return protocol->store_date(&tm); } @@ -6449,7 +6453,7 @@ String *Field_newdate::val_str(String *val_buffer, bool Field_newdate::get_TIME(MYSQL_TIME *ltime, const uchar *pos, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { ASSERT_COLUMN_MARKED_FOR_READ; uint32 tmp=(uint32) uint3korr(pos); @@ -6520,7 +6524,7 @@ Item *Field_newdate::get_equal_const_item(THD *thd, const Context &ctx, case IDENTITY_SUBST: if (const_item->field_type() != MYSQL_TYPE_DATE) { - Date d(thd, const_item, 0); + Date d(thd, const_item, date_mode_t(0)); if (!d.is_valid_date()) return NULL; return new (thd->mem_root) Item_date_literal(thd, d.get_mysql_time()); @@ -6547,7 +6551,7 @@ void Field_datetime::store_TIME(const MYSQL_TIME *ltime) bool Field_datetime::send_binary(Protocol *protocol) { MYSQL_TIME tm; - Field_datetime::get_date(&tm, 0); + Field_datetime::get_date(&tm, date_mode_t(0)); return protocol->store(&tm, 0); } @@ -6613,7 +6617,7 @@ String *Field_datetime::val_str(String *val_buffer, } bool Field_datetime::get_TIME(MYSQL_TIME *ltime, const uchar *pos, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { ASSERT_COLUMN_MARKED_FOR_READ; longlong tmp= sint8korr(pos); @@ -6692,7 +6696,7 @@ void Field_datetime_hires::store_TIME(const MYSQL_TIME *ltime) bool Field_datetime_with_dec::send_binary(Protocol *protocol) { MYSQL_TIME ltime; - get_date(<ime, 0); + get_date(<ime, date_mode_t(0)); return protocol->store(<ime, dec); } @@ -6700,14 +6704,14 @@ bool Field_datetime_with_dec::send_binary(Protocol *protocol) double Field_datetime_with_dec::val_real(void) { MYSQL_TIME ltime; - get_date(<ime, 0); + get_date(<ime, date_mode_t(0)); return TIME_to_double(<ime); } longlong Field_datetime_with_dec::val_int(void) { MYSQL_TIME ltime; - get_date(<ime, 0); + get_date(<ime, date_mode_t(0)); return TIME_to_ulonglong_datetime(<ime); } @@ -6716,7 +6720,7 @@ String *Field_datetime_with_dec::val_str(String *str, String *unused __attribute__((unused))) { MYSQL_TIME ltime; - get_date(<ime, 0); + get_date(<ime, date_mode_t(0)); str->alloc(field_length+1); str->length(field_length); my_datetime_to_str(<ime, (char*) str->ptr(), dec); @@ -6726,7 +6730,7 @@ String *Field_datetime_with_dec::val_str(String *str, bool Field_datetime_hires::get_TIME(MYSQL_TIME *ltime, const uchar *pos, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { ASSERT_COLUMN_MARKED_FOR_READ; ulonglong packed= read_bigendian(pos, Field_datetime_hires::pack_length()); @@ -6766,7 +6770,7 @@ void Field_datetimef::store_TIME(const MYSQL_TIME *ltime) } bool Field_datetimef::get_TIME(MYSQL_TIME *ltime, const uchar *pos, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { ASSERT_COLUMN_MARKED_FOR_READ; longlong tmp= my_datetime_packed_from_binary(pos, dec); diff --git a/sql/field.h b/sql/field.h index b753111f331..d5b2a621d48 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1342,7 +1342,7 @@ public: } void copy_from_tmp(int offset); uint fill_cache_field(struct st_cache_field *copy); - virtual bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + virtual bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); bool get_time(MYSQL_TIME *ltime) { return get_date(ltime, TIME_TIME_ONLY); } virtual TYPELIB *get_typelib() const { return NULL; } virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; } @@ -1958,7 +1958,7 @@ public: } int store_decimal(const my_decimal *dec) { return store(dec->to_double()); } int store_time_dec(const MYSQL_TIME *ltime, uint dec); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); my_decimal *val_decimal(my_decimal *); bool val_bool() { return val_real() != 0e0; } uint32 max_display_length() const { return field_length; } @@ -2075,10 +2075,10 @@ public: return my_decimal(ptr, precision, dec). to_string(val_buffer, fixed_precision, dec, '0'); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { return my_decimal(ptr, precision, dec). - to_datetime_with_warn(ltime, fuzzydate, field_name.str); + to_datetime_with_warn(get_thd(), ltime, fuzzydate, field_name.str); } bool val_bool() { @@ -2127,7 +2127,7 @@ public: return nr < 0 && !unsigned_flag ? 0 : (ulonglong) nr; } int store_time_dec(const MYSQL_TIME *ltime, uint dec); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); virtual const Type_limits_int *type_limits_int() const= 0; uint32 max_display_length() const { @@ -2410,8 +2410,8 @@ public: {} const Type_handler *type_handler() const { return &type_handler_vers_trx_id; } uint size_of() const { return sizeof(*this); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate, ulonglong trx_id); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate, ulonglong trx_id); + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { return get_date(ltime, fuzzydate, (ulonglong) val_int()); } @@ -2638,7 +2638,7 @@ public: int save_in_field(Field *to) { MYSQL_TIME ltime; - if (get_date(<ime, 0)) + if (get_date(<ime, date_mode_t(0))) return to->reset(); return to->store_time_dec(<ime, decimals()); } @@ -2688,14 +2688,14 @@ class Field_temporal_with_date: public Field_temporal { protected: virtual void store_TIME(const MYSQL_TIME *ltime) = 0; virtual bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, - ulonglong fuzzydate) const = 0; + date_mode_t fuzzydate) const = 0; bool validate_MMDD(bool not_zero_date, uint month, uint day, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { if (!not_zero_date) - return fuzzydate & TIME_NO_ZERO_DATE; + return bool(fuzzydate & TIME_NO_ZERO_DATE); if (!month || !day) - return fuzzydate & TIME_NO_ZERO_IN_DATE; + return bool(fuzzydate & TIME_NO_ZERO_IN_DATE); return false; } public: @@ -2712,7 +2712,7 @@ public: class Field_timestamp :public Field_temporal { protected: - sql_mode_t sql_mode_for_timestamp(THD *thd) const; + date_mode_t sql_mode_for_timestamp(THD *thd) const; int store_TIME_with_warning(THD *, const Datetime *, const ErrConv *, int warn); virtual void store_TIMEVAL(const timeval &tv) @@ -2762,7 +2762,7 @@ public: { store_TIMEVAL(Timeval(timestamp, sec_part).trunc(decimals())); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); uchar *pack(uchar *to, const uchar *from, uint max_length __attribute__((unused))) { @@ -2942,7 +2942,7 @@ public: double val_real(void); longlong val_int(void); String *val_str(String*,String *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); bool send_binary(Protocol *protocol); Information_schema_numeric_attributes information_schema_numeric_attributes() const @@ -2981,7 +2981,7 @@ public: class Field_date :public Field_date_common { void store_TIME(const MYSQL_TIME *ltime); - bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const; + bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, date_mode_t fuzzydate) const; public: Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg) @@ -2990,7 +2990,7 @@ public: const Type_handler *type_handler() const { return &type_handler_date; } enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { return Field_date::get_TIME(ltime, ptr, fuzzydate); } double val_real(void); longlong val_int(void); @@ -3017,7 +3017,7 @@ public: class Field_newdate :public Field_date_common { void store_TIME(const MYSQL_TIME *ltime); - bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const; + bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, date_mode_t fuzzydate) const; public: Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg) @@ -3035,7 +3035,7 @@ public: void sort_string(uchar *buff,uint length); uint32 pack_length() const { return 3; } void sql_type(String &str) const; - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { return Field_newdate::get_TIME(ltime, ptr, fuzzydate); } uint size_of() const { return sizeof(*this); } Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item); @@ -3052,7 +3052,7 @@ class Field_time :public Field_temporal { protected: virtual void store_TIME(const MYSQL_TIME *ltime); int store_TIME_with_warning(const Time *ltime, const ErrConv *str, int warn); - bool check_zero_in_date_with_warn(ulonglong fuzzydate); + bool check_zero_in_date_with_warn(date_mode_t fuzzydate); static void do_field_time(Copy_field *copy); public: Field_time(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg, @@ -3086,7 +3086,7 @@ public: double val_real(void); longlong val_int(void); String *val_str(String*,String *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); bool send_binary(Protocol *protocol); int cmp(const uchar *,const uchar *); void sort_string(uchar *buff,uint length); @@ -3147,7 +3147,7 @@ public: ((TIME_MAX_VALUE_SECONDS+1LL)*TIME_SECOND_PART_FACTOR), dec); } int reset(void); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); int cmp(const uchar *,const uchar *); void sort_string(uchar *buff,uint length); uint32 pack_length() const { return Type_handler_time::hires_bytes(dec); } @@ -3198,14 +3198,14 @@ public: return memcmp(a_ptr, b_ptr, pack_length()); } int reset(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); uint size_of() const { return sizeof(*this); } }; class Field_datetime :public Field_temporal_with_date { void store_TIME(const MYSQL_TIME *ltime); - bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const; + bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, date_mode_t fuzzydate) const; protected: int store_TIME_with_warning(const Datetime *ltime, const ErrConv *str, int was_cut); @@ -3235,7 +3235,7 @@ public: void sort_string(uchar *buff,uint length); uint32 pack_length() const { return 8; } void sql_type(String &str) const; - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { return Field_datetime::get_TIME(ltime, ptr, fuzzydate); } int set_time(); int evaluate_update_default_function() @@ -3306,7 +3306,7 @@ public: */ class Field_datetime_hires :public Field_datetime_with_dec { void store_TIME(const MYSQL_TIME *ltime); - bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const; + bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, date_mode_t fuzzydate) const; public: Field_datetime_hires(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, @@ -3318,7 +3318,7 @@ public: } int cmp(const uchar *,const uchar *); uint32 pack_length() const { return Type_handler_datetime::hires_bytes(dec); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { return Field_datetime_hires::get_TIME(ltime, ptr, fuzzydate); } uint size_of() const { return sizeof(*this); } }; @@ -3329,7 +3329,7 @@ public: */ class Field_datetimef :public Field_datetime_with_dec { void store_TIME(const MYSQL_TIME *ltime); - bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const; + bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, date_mode_t fuzzydate) const; int save_field_metadata(uchar *metadata_ptr) { *metadata_ptr= (uchar) decimals(); @@ -3360,7 +3360,7 @@ public: return memcmp(a_ptr, b_ptr, pack_length()); } int reset(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { return Field_datetimef::get_TIME(ltime, ptr, fuzzydate); } uint size_of() const { return sizeof(*this); } }; diff --git a/sql/field_conv.cc b/sql/field_conv.cc index f413dec82be..977cf3618fb 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -429,7 +429,7 @@ void Field::do_field_temporal(Copy_field *copy) { MYSQL_TIME ltime; // TODO: we now need to check result - if (copy->from_field->get_date(<ime, 0)) + if (copy->from_field->get_date(<ime, date_mode_t(0))) copy->to_field->reset(); else copy->to_field->store_time_dec(<ime, copy->from_field->decimals()); diff --git a/sql/filesort.cc b/sql/filesort.cc index 6901cee043f..6f2a6096aa2 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -1057,7 +1057,7 @@ Type_handler_temporal_result::make_sort_key(uchar *to, Item *item, Sort_param *param) const { MYSQL_TIME buf; - if (item->get_date_result(&buf, TIME_INVALID_DATES)) + if (item->get_date_result(current_thd, &buf, TIME_INVALID_DATES)) { DBUG_ASSERT(item->maybe_null); DBUG_ASSERT(item->null_value); diff --git a/sql/item.cc b/sql/item.cc index f6198e1df68..3fa2e536f20 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -115,14 +115,15 @@ void Item::push_note_converted_to_positive_complement(THD *thd) } -longlong Item::val_datetime_packed_result() +longlong Item::val_datetime_packed_result(THD *thd) { MYSQL_TIME ltime, tmp; - if (get_date_result(<ime, Datetime::comparison_flags_for_get_date())) + if (get_date_result(thd, <ime, Datetime::comparison_flags_for_get_date())) return 0; if (ltime.time_type != MYSQL_TIMESTAMP_TIME) return pack_time(<ime); - if ((null_value= time_to_datetime_with_warn(current_thd, <ime, &tmp, 0))) + if ((null_value= time_to_datetime_with_warn(thd, <ime, + &tmp, date_mode_t(0)))) return 0; return pack_time(&tmp); } @@ -293,7 +294,7 @@ my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value) int Item::save_time_in_field(Field *field, bool no_conversions) { MYSQL_TIME ltime; - if (get_time(<ime)) + if (get_time(field->table->in_use, <ime)) return set_field_to_null_with_conversions(field, no_conversions); field->set_notnull(); return field->store_time_dec(<ime, decimals); @@ -303,7 +304,8 @@ int Item::save_time_in_field(Field *field, bool no_conversions) int Item::save_date_in_field(Field *field, bool no_conversions) { MYSQL_TIME ltime; - if (get_date(<ime, sql_mode_for_dates(field->table->in_use))) + THD *thd= field->table->in_use; + if (get_date(thd, <ime, sql_mode_for_dates(thd))) return set_field_to_null_with_conversions(field, no_conversions); field->set_notnull(); return field->store_time_dec(<ime, decimals); @@ -1272,11 +1274,11 @@ Item *Item_param::safe_charset_converter(THD *thd, CHARSET_INFO *tocs) As a extra convenience the time structure is reset on error or NULL values! */ -bool Item::get_date_from_int(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item::get_date_from_int(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { longlong value= val_int(); bool neg= !unsigned_flag && value < 0; - if (null_value || int_to_datetime_with_warn(neg, neg ? -value : value, + if (null_value || int_to_datetime_with_warn(thd, neg, neg ? -value : value, ltime, fuzzydate, field_name_or_null())) return null_value|= make_zero_date(ltime, fuzzydate); @@ -1284,29 +1286,29 @@ bool Item::get_date_from_int(MYSQL_TIME *ltime, ulonglong fuzzydate) } -bool Item::get_date_from_real(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item::get_date_from_real(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { double value= val_real(); - if (null_value || double_to_datetime_with_warn(value, ltime, fuzzydate, + if (null_value || double_to_datetime_with_warn(thd, value, ltime, fuzzydate, field_name_or_null())) return null_value|= make_zero_date(ltime, fuzzydate); return null_value= false; } -bool Item::get_date_from_string(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item::get_date_from_string(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { char buff[40]; String tmp(buff,sizeof(buff), &my_charset_bin),*res; if (!(res=val_str(&tmp)) || - str_to_datetime_with_warn(res->charset(), res->ptr(), res->length(), + str_to_datetime_with_warn(thd, res->charset(), res->ptr(), res->length(), ltime, fuzzydate)) return null_value|= make_zero_date(ltime, fuzzydate); return null_value= false; } -bool Item::make_zero_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item::make_zero_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) { /* if the item was not null and convertion failed, we return a zero date @@ -1561,11 +1563,11 @@ my_decimal *Item_sp_variable::val_decimal(my_decimal *decimal_value) } -bool Item_sp_variable::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_sp_variable::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed); Item *it= this_item(); - bool val= it->get_date(ltime, fuzzydate); + bool val= it->get_date(thd, ltime, fuzzydate); null_value= it->null_value; return val; } @@ -1942,10 +1944,10 @@ my_decimal *Item_name_const::val_decimal(my_decimal *decimal_value) return val; } -bool Item_name_const::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_name_const::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed); - bool rc= value_item->get_date(ltime, fuzzydate); + bool rc= value_item->get_date(thd, ltime, fuzzydate); null_value= value_item->null_value; return rc; } @@ -3182,7 +3184,7 @@ String *Item_field::str_result(String *str) return result_field->val_str(str,&str_value); } -bool Item_field::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) +bool Item_field::get_date(THD *thd, MYSQL_TIME *ltime,date_mode_t fuzzydate) { if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate)) { @@ -3192,7 +3194,7 @@ bool Item_field::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) return 0; } -bool Item_field::get_date_result(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_field::get_date_result(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { if (result_field->is_null() || result_field->get_date(ltime,fuzzydate)) { @@ -3725,7 +3727,7 @@ my_decimal *Item_null::val_decimal(my_decimal *decimal_value) } -bool Item_null::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_null::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { make_zero_date(ltime, fuzzydate); return (null_value= true); @@ -4082,7 +4084,7 @@ bool Item_param::set_from_item(THD *thd, Item *item) } } struct st_value tmp; - if (!item->save_in_value(&tmp)) + if (!item->save_in_value(thd, &tmp)) { const Type_handler *h= item->type_handler(); set_handler(h); @@ -4185,7 +4187,7 @@ void Item_param::invalid_default_param() const } -bool Item_param::get_date(MYSQL_TIME *res, ulonglong fuzzydate) +bool Item_param::get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) { /* LIMIT clause parameter should not call get_date() @@ -4199,7 +4201,7 @@ bool Item_param::get_date(MYSQL_TIME *res, ulonglong fuzzydate) *res= value.time; return 0; } - return type_handler()->Item_get_date(this, res, fuzzydate); + return type_handler()->Item_get_date(thd, this, res, fuzzydate); } @@ -4615,7 +4617,7 @@ Item_param::set_value(THD *thd, sp_rcontext *ctx, Item **it) correctly fetches the value from the client-server protocol, using set_param_func(). */ - if (arg->save_in_value(&tmp) || + if (arg->save_in_value(thd, &tmp) || set_value(thd, arg, &tmp, arg->type_handler())) { set_null(); @@ -4972,9 +4974,9 @@ String* Item_ref_null_helper::val_str(String* s) } -bool Item_ref_null_helper::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_ref_null_helper::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return (owner->was_null|= null_value= (*ref)->get_date_result(ltime, fuzzydate)); + return (owner->was_null|= null_value= (*ref)->get_date_result(thd, ltime, fuzzydate)); } @@ -7013,11 +7015,11 @@ Item *Item_date_literal::clone_item(THD *thd) } -bool Item_date_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_date_literal::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - fuzzy_date |= sql_mode_for_dates(current_thd); + fuzzydate |= sql_mode_for_dates(thd); *ltime= cached_time; - return (null_value= check_date_with_warn(ltime, fuzzy_date, + return (null_value= check_date_with_warn(thd, ltime, fuzzydate, MYSQL_TIMESTAMP_ERROR)); } @@ -7038,11 +7040,11 @@ Item *Item_datetime_literal::clone_item(THD *thd) } -bool Item_datetime_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_datetime_literal::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - fuzzy_date |= sql_mode_for_dates(current_thd); + fuzzydate |= sql_mode_for_dates(thd); *ltime= cached_time; - return (null_value= check_date_with_warn(ltime, fuzzy_date, + return (null_value= check_date_with_warn(thd, ltime, fuzzydate, MYSQL_TIMESTAMP_ERROR)); } @@ -7063,12 +7065,12 @@ Item *Item_time_literal::clone_item(THD *thd) } -bool Item_time_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_time_literal::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { *ltime= cached_time; - if (fuzzy_date & TIME_TIME_ONLY) + if (fuzzydate & TIME_TIME_ONLY) return (null_value= false); - return (null_value= check_date_with_warn(ltime, fuzzy_date, + return (null_value= check_date_with_warn(thd, ltime, fuzzydate, MYSQL_TIMESTAMP_ERROR)); } @@ -8294,9 +8296,9 @@ bool Item_ref::is_null() } -bool Item_ref::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) +bool Item_ref::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return (null_value=(*ref)->get_date_result(ltime,fuzzydate)); + return (null_value=(*ref)->get_date_result(thd, ltime, fuzzydate)); } @@ -8431,9 +8433,9 @@ bool Item_direct_ref::is_null() } -bool Item_direct_ref::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) +bool Item_direct_ref::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return (null_value=(*ref)->get_date(ltime,fuzzydate)); + return (null_value=(*ref)->get_date(thd, ltime, fuzzydate)); } @@ -8810,18 +8812,18 @@ bool Item_cache_wrapper::is_null() Get the date value of the possibly cached item */ -bool Item_cache_wrapper::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_cache_wrapper::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { Item *cached_value; DBUG_ENTER("Item_cache_wrapper::get_date"); if (!expr_cache) - DBUG_RETURN((null_value= orig_item->get_date(ltime, fuzzydate))); + DBUG_RETURN((null_value= orig_item->get_date(thd, ltime, fuzzydate))); if ((cached_value= check_cache())) - DBUG_RETURN((null_value= cached_value->get_date(ltime, fuzzydate))); + DBUG_RETURN((null_value= cached_value->get_date(thd, ltime, fuzzydate))); cache(); - DBUG_RETURN((null_value= expr_value->get_date(ltime, fuzzydate))); + DBUG_RETURN((null_value= expr_value->get_date(thd, ltime, fuzzydate))); } @@ -9238,10 +9240,10 @@ my_decimal *Item_default_value::val_decimal(my_decimal *decimal_value) return Item_field::val_decimal(decimal_value); } -bool Item_default_value::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) +bool Item_default_value::get_date(THD *thd, MYSQL_TIME *ltime,date_mode_t fuzzydate) { calculate(); - return Item_field::get_date(ltime, fuzzydate); + return Item_field::get_date(thd, ltime, fuzzydate); } bool Item_default_value::send(Protocol *protocol, st_value *buffer) @@ -9344,7 +9346,7 @@ my_decimal *Item_ignore_value::val_decimal(my_decimal *decimal_value) return 0; } -bool Item_ignore_value::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_ignore_value::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(0); // never should be called null_value= 1; @@ -9779,7 +9781,7 @@ bool Item_cache_temporal::cache_value() if (!example) return false; value_cached= true; - value= example->val_datetime_packed_result(); + value= example->val_datetime_packed_result(current_thd); null_value= example->null_value; return true; } @@ -9790,13 +9792,13 @@ bool Item_cache_time::cache_value() if (!example) return false; value_cached= true; - value= example->val_time_packed_result(); + value= example->val_time_packed_result(current_thd); null_value= example->null_value; return true; } -bool Item_cache_temporal::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_cache_temporal::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { ErrConvInteger str(value); @@ -9814,7 +9816,7 @@ bool Item_cache_temporal::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) int Item_cache_temporal::save_in_field(Field *field, bool no_conversions) { MYSQL_TIME ltime; - if (get_date(<ime, 0)) + if (get_date(field->get_thd(), <ime, date_mode_t(0))) return set_field_to_null_with_conversions(field, no_conversions); field->set_notnull(); int error= field->store_time_dec(<ime, decimals); @@ -9857,21 +9859,21 @@ Item *Item_cache_temporal::convert_to_basic_const_item(THD *thd) Item *Item_cache_datetime::make_literal(THD *thd) { MYSQL_TIME ltime; - unpack_time(val_datetime_packed(), <ime, MYSQL_TIMESTAMP_DATETIME); + unpack_time(val_datetime_packed(thd), <ime, MYSQL_TIMESTAMP_DATETIME); return new (thd->mem_root) Item_datetime_literal(thd, <ime, decimals); } Item *Item_cache_date::make_literal(THD *thd) { MYSQL_TIME ltime; - unpack_time(val_datetime_packed(), <ime, MYSQL_TIMESTAMP_DATE); + unpack_time(val_datetime_packed(thd), <ime, MYSQL_TIMESTAMP_DATE); return new (thd->mem_root) Item_date_literal(thd, <ime); } Item *Item_cache_time::make_literal(THD *thd) { MYSQL_TIME ltime; - unpack_time(val_time_packed(), <ime, MYSQL_TIMESTAMP_TIME); + unpack_time(val_time_packed(thd), <ime, MYSQL_TIMESTAMP_TIME); return new (thd->mem_root) Item_time_literal(thd, <ime, decimals); } @@ -10219,7 +10221,7 @@ String *Item_type_holder::val_str(String*) return 0; } -bool Item_type_holder::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_type_holder::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(0); // should never be called return true; diff --git a/sql/item.h b/sql/item.h index c013781f30f..65396689fc1 100644 --- a/sql/item.h +++ b/sql/item.h @@ -861,9 +861,10 @@ protected: value= NULL; return value; } - bool get_date_from_item(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date_from_item(THD *thd, Item *item, + MYSQL_TIME *ltime, date_mode_t fuzzydate) { - bool rc= item->get_date(ltime, fuzzydate); + bool rc= item->get_date(thd, ltime, fuzzydate); null_value= MY_TEST(rc || item->null_value); return rc; } @@ -873,7 +874,7 @@ public: TIME/DATE/DATETIME failed. We return a zero date if allowed, otherwise - null. */ - bool make_zero_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool make_zero_date(MYSQL_TIME *ltime, date_mode_t fuzzydate); /* Cache val_str() into the own buffer, e.g. to evaluate constant @@ -994,9 +995,9 @@ public: DBUG_ASSERT(0); } - bool save_in_value(struct st_value *value) + bool save_in_value(THD *thd, struct st_value *value) { - return type_handler()->Item_save_in_value(this, value); + return type_handler()->Item_save_in_value(thd, this, value); } /* Function returns 1 on overflow and -1 on fatal errors */ @@ -1505,14 +1506,14 @@ public: /** TIME or DATETIME precision of the item: 0..6 */ - uint time_precision() + uint time_precision(THD *thd) { - return const_item() ? type_handler()->Item_time_precision(this) : + return const_item() ? type_handler()->Item_time_precision(thd, this) : MY_MIN(decimals, TIME_SECOND_PART_DIGITS); } - uint datetime_precision() + uint datetime_precision(THD *thd) { - return const_item() ? type_handler()->Item_datetime_precision(this) : + return const_item() ? type_handler()->Item_datetime_precision(thd, this) : MY_MIN(decimals, TIME_SECOND_PART_DIGITS); } virtual longlong val_int_min() const @@ -1610,33 +1611,33 @@ public: void split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array, List<Item> &fields, Item **ref, uint flags); - virtual bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)= 0; - bool get_date_from_int(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool get_date_from_real(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool get_date_from_string(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool get_time(MYSQL_TIME *ltime) - { return get_date(ltime, Time::flags_for_get_date()); } + virtual bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate)= 0; + bool get_date_from_int(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); + bool get_date_from_real(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); + bool get_date_from_string(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); + bool get_time(THD *thd, MYSQL_TIME *ltime) + { return get_date(thd, ltime, Time::flags_for_get_date()); } // Get a DATE or DATETIME value in numeric packed format for comparison - virtual longlong val_datetime_packed() + virtual longlong val_datetime_packed(THD *thd) { - ulonglong fuzzydate= Datetime::comparison_flags_for_get_date(); + date_mode_t fuzzydate= Datetime::comparison_flags_for_get_date(); return Datetime(current_thd, this, fuzzydate).to_packed(); } // Get a TIME value in numeric packed format for comparison - virtual longlong val_time_packed() + virtual longlong val_time_packed(THD *thd) { - return Time(this, Time::comparison_flags_for_get_date()).to_packed(); + return Time(thd, this, Time::comparison_flags_for_get_date()).to_packed(); } - longlong val_datetime_packed_result(); - longlong val_time_packed_result() + longlong val_datetime_packed_result(THD *thd); + longlong val_time_packed_result(THD *thd) { MYSQL_TIME ltime; - ulonglong fuzzydate= Time::comparison_flags_for_get_date(); - return get_date_result(<ime, fuzzydate) ? 0 : pack_time(<ime); + date_mode_t fuzzydate= Time::comparison_flags_for_get_date(); + return get_date_result(thd, <ime, fuzzydate) ? 0 : pack_time(<ime); } - virtual bool get_date_result(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date(ltime,fuzzydate); } + virtual bool get_date_result(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date(thd, ltime,fuzzydate); } /* The method allows to determine nullness of a complex expression without fully evaluating it, instead of calling val/result*() then @@ -2658,7 +2659,7 @@ public: longlong val_int(); String *val_str(String *sp); my_decimal *val_decimal(my_decimal *decimal_value); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); bool is_null(); public: @@ -2948,7 +2949,7 @@ public: longlong val_int(); String *val_str(String *sp); my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); bool is_null(); virtual void print(String *str, enum_query_type query_type); @@ -3008,9 +3009,9 @@ class Item_num: public Item_literal public: Item_num(THD *thd): Item_literal(thd) { collation.set_numeric(); } Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(this, ltime, fuzzydate); + return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } }; @@ -3141,7 +3142,7 @@ public: longlong val_int() { return field->val_int(); } String *val_str(String *str) { return field->val_str(str); } my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { return field->get_date(ltime, fuzzydate); } @@ -3259,8 +3260,8 @@ public: return MONOTONIC_STRICT_INCREASING; } longlong val_int_endpoint(bool left_endp, bool *incl_endp); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool get_date_result(MYSQL_TIME *ltime,ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); + bool get_date_result(THD *thd, MYSQL_TIME *ltime,date_mode_t fuzzydate); bool is_null() { return field->is_null(); } void update_null_value(); void update_table_bitmaps() @@ -3465,7 +3466,7 @@ public: longlong val_int(); String *val_str(String *str); my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); int save_in_field(Field *field, bool no_conversions); int save_safe_in_field(Field *field); bool send(Protocol *protocol, st_value *buffer); @@ -3784,7 +3785,7 @@ public: { return can_return_value() ? value.val_str(str, this) : NULL; } - bool get_date(MYSQL_TIME *tm, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *tm, date_mode_t fuzzydate); int save_in_field(Field *field, bool no_conversions); void set_default(); @@ -4032,7 +4033,7 @@ public: longlong val_int(); double val_real() { return (double)val_int(); } void set(longlong packed, enum_mysql_timestamp_type ts_type); - bool get_date(MYSQL_TIME *to, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate) { *to= ltime; return false; @@ -4231,9 +4232,9 @@ public: return (String*) &str_value; } my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return get_date_from_string(ltime, fuzzydate); + return get_date_from_string(thd, ltime, fuzzydate); } int save_in_field(Field *field, bool no_conversions); const Type_handler *type_handler() const { return &type_handler_varchar; } @@ -4483,9 +4484,9 @@ public: } const String *const_ptr_string() const { return &str_value; } String *val_str(String*) { return &str_value; } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(this, ltime, fuzzydate); + return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } }; @@ -4630,7 +4631,7 @@ public: double val_real() { return Date(this).to_double(); } String *val_str(String *to) { return Date(this).to_string(to); } my_decimal *val_decimal(my_decimal *to) { return Date(this).to_decimal(to); } - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); Item *get_copy(THD *thd) { return get_item_copy<Item_date_literal>(thd, this); } }; @@ -4654,7 +4655,7 @@ public: double val_real() { return Time(this).to_double(); } String *val_str(String *to) { return Time(this).to_string(to, decimals); } my_decimal *val_decimal(my_decimal *to) { return Time(this).to_decimal(to); } - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); Item *get_copy(THD *thd) { return get_item_copy<Item_time_literal>(thd, this); } }; @@ -4686,7 +4687,7 @@ public: { return Datetime(this).to_decimal(to); } - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); Item *get_copy(THD *thd) { return get_item_copy<Item_datetime_literal>(thd, this); } }; @@ -4723,7 +4724,7 @@ class Item_date_literal_for_invalid_dates: public Item_date_literal public: Item_date_literal_for_invalid_dates(THD *thd, const MYSQL_TIME *ltime) :Item_date_literal(thd, ltime) { } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { *ltime= cached_time; return (null_value= false); @@ -4741,7 +4742,7 @@ public: Item_datetime_literal_for_invalid_dates(THD *thd, const MYSQL_TIME *ltime, uint dec_arg) :Item_datetime_literal(thd, ltime, dec_arg) { } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { *ltime= cached_time; return (null_value= false); @@ -5023,7 +5024,7 @@ public: bool val_bool(); String *val_str(String* tmp); bool is_null(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); double val_result(); longlong val_int_result(); String *str_result(String* tmp); @@ -5234,7 +5235,7 @@ public: my_decimal *val_decimal(my_decimal *); bool val_bool(); bool is_null(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); virtual Ref_Type ref_type() { return DIRECT_REF; } Item *get_copy(THD *thd) { return get_item_copy<Item_direct_ref>(thd, this); } @@ -5330,7 +5331,7 @@ public: my_decimal *val_decimal(my_decimal *); bool val_bool(); bool is_null(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); bool send(Protocol *protocol, st_value *buffer); void save_org_in_field(Field *field, fast_field_copier data __attribute__ ((__unused__))) @@ -5544,14 +5545,14 @@ public: else return Item_direct_ref::is_null(); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { if (check_null_ref()) { bzero((char*) ltime,sizeof(*ltime)); return 1; } - return Item_direct_ref::get_date(ltime, fuzzydate); + return Item_direct_ref::get_date(thd, ltime, fuzzydate); } bool send(Protocol *protocol, st_value *buffer); void save_org_in_field(Field *field, @@ -5667,7 +5668,7 @@ public: String* val_str(String* s); my_decimal *val_decimal(my_decimal *); bool val_bool(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); virtual void print(String *str, enum_query_type query_type); table_map used_tables() const; Item *get_copy(THD *thd) @@ -5839,8 +5840,8 @@ public: my_decimal *val_decimal(my_decimal *); double val_real(); longlong val_int(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date_from_string(ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date_from_string(thd, ltime, fuzzydate); } void copy(); int save_in_field(Field *field, bool no_conversions); Item *get_copy(THD *thd) @@ -5866,8 +5867,8 @@ public: { return null_value ? 0 : cached_value; } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date_from_int(ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date_from_int(thd, ltime, fuzzydate); } virtual void copy(); Item *get_copy(THD *thd) { return get_item_copy<Item_copy_int>(thd, this); } @@ -5910,9 +5911,9 @@ public: { return (longlong) rint(val_real()); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return get_date_from_real(ltime, fuzzydate); + return get_date_from_real(thd, ltime, fuzzydate); } void copy() { @@ -5939,9 +5940,9 @@ public: } double val_real(); longlong val_int(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return VDec(this).to_datetime_with_warn(ltime, fuzzydate, this); + return VDec(this).to_datetime_with_warn(thd, ltime, fuzzydate, this); } void copy(); Item *get_copy(THD *thd) @@ -6082,7 +6083,7 @@ public: double val_real(); longlong val_int(); my_decimal *val_decimal(my_decimal *decimal_value); - bool get_date(MYSQL_TIME *ltime,ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime,date_mode_t fuzzydate); bool send(Protocol *protocol, st_value *buffer); int save_in_field(Field *field_arg, bool no_conversions); bool save_in_param(THD *thd, Item_param *param) @@ -6134,7 +6135,7 @@ public: double val_real(); longlong val_int(); my_decimal *val_decimal(my_decimal *decimal_value); - bool get_date(MYSQL_TIME *ltime,ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime,date_mode_t fuzzydate); bool send(Protocol *protocol, st_value *buffer); }; @@ -6451,8 +6452,8 @@ public: longlong val_int(); String* val_str(String *str); my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date_from_int(ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date_from_int(thd, ltime, fuzzydate); } bool cache_value(); int save_in_field(Field *field, bool no_conversions); Item *convert_to_basic_const_item(THD *thd); @@ -6466,10 +6467,10 @@ class Item_cache_year: public Item_cache_int public: Item_cache_year(THD *thd, const Type_handler *handler) :Item_cache_int(thd, handler) { } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { return null_value= - VYear(this).to_mysql_time_with_warn(ltime, fuzzydate, NULL); + VYear(this).to_mysql_time_with_warn(thd, ltime, fuzzydate, NULL); } }; @@ -6480,7 +6481,7 @@ protected: Item_cache_temporal(THD *thd, const Type_handler *handler); public: bool cache_value(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); int save_in_field(Field *field, bool no_conversions); void store_packed(longlong val_arg, Item *example); /* @@ -6503,12 +6504,12 @@ public: Item *get_copy(THD *thd) { return get_item_copy<Item_cache_time>(thd, this); } Item *make_literal(THD *); - longlong val_datetime_packed() + longlong val_datetime_packed(THD *thd) { - ulonglong fuzzy= Datetime::comparison_flags_for_get_date(); - return has_value() ? Datetime(current_thd, this, fuzzy).to_longlong() : 0; + date_mode_t fuzzy= Datetime::comparison_flags_for_get_date(); + return has_value() ? Datetime(thd, this, fuzzy).to_longlong() : 0; } - longlong val_time_packed() + longlong val_time_packed(THD *thd) { return has_value() ? value : 0; } @@ -6539,13 +6540,13 @@ public: Item *get_copy(THD *thd) { return get_item_copy<Item_cache_datetime>(thd, this); } Item *make_literal(THD *); - longlong val_datetime_packed() + longlong val_datetime_packed(THD *thd) { return has_value() ? value : 0; } - longlong val_time_packed() + longlong val_time_packed(THD *thd) { - return Time(this, Time::comparison_flags_for_get_date()).to_packed(); + return Time(thd, this, Time::comparison_flags_for_get_date()).to_packed(); } longlong val_int() { @@ -6574,13 +6575,13 @@ public: Item *get_copy(THD *thd) { return get_item_copy<Item_cache_date>(thd, this); } Item *make_literal(THD *); - longlong val_datetime_packed() + longlong val_datetime_packed(THD *thd) { return has_value() ? value : 0; } - longlong val_time_packed() + longlong val_time_packed(THD *thd) { - return Time(this, Time::comparison_flags_for_get_date()).to_packed(); + return Time(thd, this, Time::comparison_flags_for_get_date()).to_packed(); } longlong val_int() { return has_value() ? Date(this).to_longlong() : 0; } double val_real() { return has_value() ? Date(this).to_double() : 0; } @@ -6606,8 +6607,8 @@ public: longlong val_int(); String* val_str(String *str); my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date_from_real(ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date_from_real(thd, ltime, fuzzydate); } bool cache_value(); Item *convert_to_basic_const_item(THD *thd); Item *get_copy(THD *thd) @@ -6626,8 +6627,8 @@ public: longlong val_int(); String* val_str(String *str); my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return VDec(this).to_datetime_with_warn(ltime, fuzzydate, this); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return VDec(this).to_datetime_with_warn(thd, ltime, fuzzydate, this); } bool cache_value(); Item *convert_to_basic_const_item(THD *thd); Item *get_copy(THD *thd) @@ -6654,8 +6655,8 @@ public: longlong val_int(); String* val_str(String *); my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date_from_string(ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date_from_string(thd, ltime, fuzzydate); } CHARSET_INFO *charset() const { return value->charset(); }; int save_in_field(Field *field, bool no_conversions); bool cache_value(); @@ -6736,7 +6737,7 @@ public: illegal_method_call((const char*)"val_decimal"); return 0; }; - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { illegal_method_call((const char*)"val_decimal"); return true; @@ -6819,7 +6820,7 @@ public: longlong val_int(); my_decimal *val_decimal(my_decimal *); String *val_str(String*); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, const Tmp_field_param *param) { diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index fb6d99b9498..893f4534203 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -684,10 +684,11 @@ Item** Arg_comparator::cache_converted_constant(THD *thd_arg, Item **value, int Arg_comparator::compare_time() { - longlong val1= (*a)->val_time_packed(); + THD *thd= current_thd; + longlong val1= (*a)->val_time_packed(thd); if (!(*a)->null_value) { - longlong val2= (*b)->val_time_packed(); + longlong val2= (*b)->val_time_packed(thd); if (!(*b)->null_value) return compare_not_null_values(val1, val2); } @@ -699,8 +700,9 @@ int Arg_comparator::compare_time() int Arg_comparator::compare_e_time() { - longlong val1= (*a)->val_time_packed(); - longlong val2= (*b)->val_time_packed(); + THD *thd= current_thd; + longlong val1= (*a)->val_time_packed(thd); + longlong val2= (*b)->val_time_packed(thd); if ((*a)->null_value || (*b)->null_value) return MY_TEST((*a)->null_value && (*b)->null_value); return MY_TEST(val1 == val2); @@ -710,10 +712,11 @@ int Arg_comparator::compare_e_time() int Arg_comparator::compare_datetime() { - longlong val1= (*a)->val_datetime_packed(); + THD *thd= current_thd; + longlong val1= (*a)->val_datetime_packed(thd); if (!(*a)->null_value) { - longlong val2= (*b)->val_datetime_packed(); + longlong val2= (*b)->val_datetime_packed(thd); if (!(*b)->null_value) return compare_not_null_values(val1, val2); } @@ -725,8 +728,9 @@ int Arg_comparator::compare_datetime() int Arg_comparator::compare_e_datetime() { - longlong val1= (*a)->val_datetime_packed(); - longlong val2= (*b)->val_datetime_packed(); + THD *thd= current_thd; + longlong val1= (*a)->val_datetime_packed(thd); + longlong val2= (*b)->val_datetime_packed(thd); if ((*a)->null_value || (*b)->null_value) return MY_TEST((*a)->null_value && (*b)->null_value); return MY_TEST(val1 == val2); @@ -2099,22 +2103,24 @@ bool Item_func_between::fix_length_and_dec_temporal(THD *thd) longlong Item_func_between::val_int_cmp_datetime() { - longlong value= args[0]->val_datetime_packed(), a, b; + THD *thd= current_thd; + longlong value= args[0]->val_datetime_packed(thd), a, b; if ((null_value= args[0]->null_value)) return 0; - a= args[1]->val_datetime_packed(); - b= args[2]->val_datetime_packed(); + a= args[1]->val_datetime_packed(thd); + b= args[2]->val_datetime_packed(thd); return val_int_cmp_int_finalize(value, a, b); } longlong Item_func_between::val_int_cmp_time() { - longlong value= args[0]->val_time_packed(), a, b; + THD *thd= current_thd; + longlong value= args[0]->val_time_packed(thd), a, b; if ((null_value= args[0]->null_value)) return 0; - a= args[1]->val_time_packed(); - b= args[2]->val_time_packed(); + a= args[1]->val_time_packed(thd); + b= args[2]->val_time_packed(thd); return val_int_cmp_int_finalize(value, a, b); } @@ -2296,12 +2302,12 @@ Item_func_ifnull::str_op(String *str) } -bool Item_func_ifnull::date_op(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_func_ifnull::date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); for (uint i= 0; i < 2; i++) { - Datetime dt(current_thd, args[i], fuzzydate & ~TIME_FUZZY_DATES); + Datetime dt(thd, args[i], fuzzydate & ~TIME_FUZZY_DATES); if (!(dt.copy_to_mysql_time(ltime, mysql_timestamp_type()))) return (null_value= false); } @@ -2309,12 +2315,12 @@ bool Item_func_ifnull::date_op(MYSQL_TIME *ltime, ulonglong fuzzydate) } -bool Item_func_ifnull::time_op(MYSQL_TIME *ltime) +bool Item_func_ifnull::time_op(THD *thd, MYSQL_TIME *ltime) { DBUG_ASSERT(fixed == 1); for (uint i= 0; i < 2; i++) { - if (!Time(args[i]).copy_to_mysql_time(ltime)) + if (!Time(thd, args[i]).copy_to_mysql_time(ltime)) return (null_value= false); } return (null_value= true); @@ -2796,23 +2802,23 @@ Item_func_nullif::decimal_op(my_decimal * decimal_value) bool -Item_func_nullif::date_op(MYSQL_TIME *ltime, ulonglong fuzzydate) +Item_func_nullif::date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); if (!compare()) return (null_value= true); - Datetime dt(current_thd, args[2], fuzzydate); + Datetime dt(thd, args[2], fuzzydate); return (null_value= dt.copy_to_mysql_time(ltime, mysql_timestamp_type())); } bool -Item_func_nullif::time_op(MYSQL_TIME *ltime) +Item_func_nullif::time_op(THD *thd, MYSQL_TIME *ltime) { DBUG_ASSERT(fixed == 1); if (!compare()) return (null_value= true); - return (null_value= Time(args[2]).copy_to_mysql_time(ltime)); + return (null_value= Time(thd, args[2]).copy_to_mysql_time(ltime)); } @@ -2894,7 +2900,7 @@ Item *Item_func_case_simple::find_item() Item *Item_func_decode_oracle::find_item() { uint idx; - if (!Predicant_to_list_comparator::cmp_nulls_equal(this, &idx)) + if (!Predicant_to_list_comparator::cmp_nulls_equal(current_thd, this, &idx)) return args[idx + when_count()]; Item **pos= Item_func_decode_oracle::else_expr_addr(); return pos ? pos[0] : 0; @@ -2970,24 +2976,24 @@ my_decimal *Item_func_case::decimal_op(my_decimal *decimal_value) } -bool Item_func_case::date_op(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_func_case::date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); Item *item= find_item(); if (!item) return (null_value= true); - Datetime dt(current_thd, item, fuzzydate); + Datetime dt(thd, item, fuzzydate); return (null_value= dt.copy_to_mysql_time(ltime, mysql_timestamp_type())); } -bool Item_func_case::time_op(MYSQL_TIME *ltime) +bool Item_func_case::time_op(THD *thd, MYSQL_TIME *ltime) { DBUG_ASSERT(fixed == 1); Item *item= find_item(); if (!item) return (null_value= true); - return (null_value= Time(item).copy_to_mysql_time(ltime)); + return (null_value= Time(thd, item).copy_to_mysql_time(ltime)); } @@ -3323,12 +3329,12 @@ double Item_func_coalesce::real_op() } -bool Item_func_coalesce::date_op(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_func_coalesce::date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); for (uint i= 0; i < arg_count; i++) { - Datetime dt(current_thd, args[i], fuzzydate & ~TIME_FUZZY_DATES); + Datetime dt(thd, args[i], fuzzydate & ~TIME_FUZZY_DATES); if (!dt.copy_to_mysql_time(ltime, mysql_timestamp_type())) return (null_value= false); } @@ -3336,12 +3342,12 @@ bool Item_func_coalesce::date_op(MYSQL_TIME *ltime, ulonglong fuzzydate) } -bool Item_func_coalesce::time_op(MYSQL_TIME *ltime) +bool Item_func_coalesce::time_op(THD *thd, MYSQL_TIME *ltime) { DBUG_ASSERT(fixed == 1); for (uint i= 0; i < arg_count; i++) { - if (!Time(args[i]).copy_to_mysql_time(ltime)) + if (!Time(thd, args[i]).copy_to_mysql_time(ltime)) return (null_value= false); } return (null_value= true); @@ -3629,7 +3635,7 @@ void in_datetime::set(uint pos,Item *item) { struct packed_longlong *buff= &((packed_longlong*) base)[pos]; - buff->val= item->val_datetime_packed(); + buff->val= item->val_datetime_packed(current_thd); buff->unsigned_flag= 1L; } @@ -3637,13 +3643,13 @@ void in_time::set(uint pos,Item *item) { struct packed_longlong *buff= &((packed_longlong*) base)[pos]; - buff->val= item->val_time_packed(); + buff->val= item->val_time_packed(current_thd); buff->unsigned_flag= 1L; } uchar *in_datetime::get_value(Item *item) { - tmp.val= item->val_datetime_packed(); + tmp.val= item->val_datetime_packed(current_thd); if (item->null_value) return 0; tmp.unsigned_flag= 1L; @@ -3652,7 +3658,7 @@ uchar *in_datetime::get_value(Item *item) uchar *in_time::get_value(Item *item) { - tmp.val= item->val_time_packed(); + tmp.val= item->val_time_packed(current_thd); if (item->null_value) return 0; tmp.unsigned_flag= 1L; @@ -3993,7 +3999,7 @@ int cmp_item_datetime::cmp_not_null(const Value *val) int cmp_item_datetime::cmp(Item *arg) { - const bool rc= value != arg->val_datetime_packed(); + const bool rc= value != arg->val_datetime_packed(current_thd); return (m_null_value || arg->null_value) ? UNKNOWN : rc; } @@ -4008,7 +4014,7 @@ int cmp_item_time::cmp_not_null(const Value *val) int cmp_item_time::cmp(Item *arg) { - const bool rc= value != arg->val_time_packed(); + const bool rc= value != arg->val_time_packed(current_thd); return (m_null_value || arg->null_value) ? UNKNOWN : rc; } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index db1075b1936..c6a20d0f55a 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -1011,8 +1011,8 @@ public: longlong int_op(); String *str_op(String *); my_decimal *decimal_op(my_decimal *); - bool date_op(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool time_op(MYSQL_TIME *ltime); + bool date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); + bool time_op(THD *thd, MYSQL_TIME *ltime); bool fix_length_and_dec() { if (aggregate_for_result(func_name(), args, arg_count, true)) @@ -1090,8 +1090,8 @@ public: longlong int_op(); String *str_op(String *str); my_decimal *decimal_op(my_decimal *); - bool date_op(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool time_op(MYSQL_TIME *ltime); + bool date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); + bool time_op(THD *thd, MYSQL_TIME *ltime); bool fix_length_and_dec() { if (Item_func_case_abbreviation2::fix_length_and_dec2(args)) @@ -1125,12 +1125,12 @@ public: :Item_func_case_abbreviation2(thd, a, b, c) { } - bool date_op(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - Datetime dt(current_thd, find_item(), fuzzydate); + Datetime dt(thd, find_item(), fuzzydate); return (null_value= dt.copy_to_mysql_time(ltime, mysql_timestamp_type())); } - bool time_op(MYSQL_TIME *ltime) + bool time_op(THD *thd, MYSQL_TIME *ltime) { return (null_value= Time(find_item()).copy_to_mysql_time(ltime)); } @@ -1243,8 +1243,8 @@ public: Item_func_hybrid_field_type::cleanup(); arg_count= 2; // See the comment to the constructor } - bool date_op(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool time_op(MYSQL_TIME *ltime); + bool date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); + bool time_op(THD *thd, MYSQL_TIME *ltime); double real_op(); longlong int_op(); String *str_op(String *str); @@ -1641,7 +1641,7 @@ public: { } void store_value(Item *item) { - value= item->val_datetime_packed(); + value= item->val_datetime_packed(current_thd); m_null_value= item->null_value; } int cmp_not_null(const Value *val); @@ -1658,7 +1658,7 @@ public: { } void store_value(Item *item) { - value= item->val_time_packed(); + value= item->val_time_packed(current_thd); m_null_value= item->null_value; } int cmp_not_null(const Value *val); @@ -1897,7 +1897,7 @@ class Predicant_to_list_comparator return UNKNOWN; return in_item->cmp(args->arguments()[m_comparators[i].m_arg_index]); } - int cmp_args_nulls_equal(Item_args *args, uint i) + int cmp_args_nulls_equal(THD *thd, Item_args *args, uint i) { Predicant_to_value_comparator *cmp= &m_comparators[m_comparators[i].m_handler_index]; @@ -1908,7 +1908,7 @@ class Predicant_to_list_comparator ValueBuffer<MAX_FIELD_WIDTH> val; if (m_comparators[i].m_handler_index == i) in_item->store_value(predicant); - m_comparators[i].m_handler->Item_save_in_value(arg, &val); + m_comparators[i].m_handler->Item_save_in_value(thd, arg, &val); if (predicant->null_value && val.is_null()) return FALSE; // Two nulls are equal if (predicant->null_value || val.is_null()) @@ -2089,12 +2089,12 @@ public: /* Same as above, but treats two NULLs as equal, e.g. as in DECODE_ORACLE(). */ - bool cmp_nulls_equal(Item_args *args, uint *idx) + bool cmp_nulls_equal(THD *thd, Item_args *args, uint *idx) { for (uint i= 0 ; i < m_comparator_count ; i++) { DBUG_ASSERT(m_comparators[i].m_handler != NULL); - if (cmp_args_nulls_equal(args, i) == FALSE) + if (cmp_args_nulls_equal(thd, args, i) == FALSE) { *idx= m_comparators[i].m_arg_index; return false; // Found a matching value @@ -2130,8 +2130,8 @@ public: longlong int_op(); String *str_op(String *); my_decimal *decimal_op(my_decimal *); - bool date_op(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool time_op(MYSQL_TIME *ltime); + bool date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); + bool time_op(THD *thd, MYSQL_TIME *ltime); bool fix_fields(THD *thd, Item **ref); table_map not_null_tables() const { return 0; } const char *func_name() const { return "case"; } diff --git a/sql/item_func.cc b/sql/item_func.cc index fa14bc58f2e..976437d694b 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -834,12 +834,13 @@ Item_func_hybrid_field_type::val_decimal_from_int_op(my_decimal *dec) return dec; } -bool Item_func_hybrid_field_type::get_date_from_int_op(MYSQL_TIME *ltime, - ulonglong fuzzydate) +bool Item_func_hybrid_field_type::get_date_from_int_op(THD *thd, + MYSQL_TIME *ltime, + date_mode_t fuzzydate) { longlong value= int_op(); bool neg= !unsigned_flag && value < 0; - if (null_value || int_to_datetime_with_warn(neg, neg ? -value : value, + if (null_value || int_to_datetime_with_warn(thd, neg, neg ? -value : value, ltime, fuzzydate, NULL)) return make_zero_mysql_time(ltime, fuzzydate); return (null_value= 0); @@ -870,11 +871,13 @@ Item_func_hybrid_field_type::val_decimal_from_real_op(my_decimal *dec) return dec; } -bool Item_func_hybrid_field_type::get_date_from_real_op(MYSQL_TIME *ltime, - ulonglong fuzzydate) +bool Item_func_hybrid_field_type::get_date_from_real_op(THD *thd, + MYSQL_TIME *ltime, + date_mode_t fuzzydate) { double value= real_op(); - if (null_value || double_to_datetime_with_warn(value, ltime, fuzzydate, NULL)) + if (null_value || + double_to_datetime_with_warn(thd, value, ltime, fuzzydate, NULL)) return make_zero_mysql_time(ltime, fuzzydate); return (null_value= 0); } @@ -883,7 +886,7 @@ bool Item_func_hybrid_field_type::get_date_from_real_op(MYSQL_TIME *ltime, String *Item_func_hybrid_field_type::val_str_from_date_op(String *str) { MYSQL_TIME ltime; - if (date_op_with_null_check(<ime) || + if (date_op_with_null_check(current_thd, <ime) || (null_value= str->alloc(MAX_DATE_STRING_REP_LENGTH))) return (String *) 0; str->length(my_TIME_to_str(<ime, const_cast<char*>(str->ptr()), decimals)); @@ -895,7 +898,7 @@ String *Item_func_hybrid_field_type::val_str_from_date_op(String *str) double Item_func_hybrid_field_type::val_real_from_date_op() { MYSQL_TIME ltime; - if (date_op_with_null_check(<ime)) + if (date_op_with_null_check(current_thd, <ime)) return 0; return TIME_to_double(<ime); } @@ -903,7 +906,7 @@ double Item_func_hybrid_field_type::val_real_from_date_op() longlong Item_func_hybrid_field_type::val_int_from_date_op() { MYSQL_TIME ltime; - if (date_op_with_null_check(<ime)) + if (date_op_with_null_check(current_thd, <ime)) return 0; return TIME_to_ulonglong(<ime); } @@ -912,7 +915,7 @@ my_decimal * Item_func_hybrid_field_type::val_decimal_from_date_op(my_decimal *dec) { MYSQL_TIME ltime; - if (date_op_with_null_check(<ime)) + if (date_op_with_null_check(current_thd, <ime)) { my_decimal_set_zero(dec); return 0; @@ -924,7 +927,7 @@ Item_func_hybrid_field_type::val_decimal_from_date_op(my_decimal *dec) String *Item_func_hybrid_field_type::val_str_from_time_op(String *str) { MYSQL_TIME ltime; - if (time_op_with_null_check(<ime) || + if (time_op_with_null_check(current_thd, <ime) || (null_value= my_TIME_to_str(<ime, str, decimals))) return NULL; return str; @@ -933,20 +936,22 @@ String *Item_func_hybrid_field_type::val_str_from_time_op(String *str) double Item_func_hybrid_field_type::val_real_from_time_op() { MYSQL_TIME ltime; - return time_op_with_null_check(<ime) ? 0 : TIME_to_double(<ime); + return time_op_with_null_check(current_thd, <ime) ? 0 : + TIME_to_double(<ime); } longlong Item_func_hybrid_field_type::val_int_from_time_op() { MYSQL_TIME ltime; - return time_op_with_null_check(<ime) ? 0 : TIME_to_ulonglong(<ime); + return time_op_with_null_check(current_thd, <ime) ? 0 : + TIME_to_ulonglong(<ime); } my_decimal * Item_func_hybrid_field_type::val_decimal_from_time_op(my_decimal *dec) { MYSQL_TIME ltime; - if (time_op_with_null_check(<ime)) + if (time_op_with_null_check(current_thd, <ime)) { my_decimal_set_zero(dec); return 0; @@ -974,13 +979,14 @@ Item_func_hybrid_field_type::val_decimal_from_str_op(my_decimal *decimal_value) return res ? decimal_from_string_with_check(decimal_value, res) : 0; } -bool Item_func_hybrid_field_type::get_date_from_str_op(MYSQL_TIME *ltime, - ulonglong fuzzydate) +bool Item_func_hybrid_field_type::get_date_from_str_op(THD *thd, + MYSQL_TIME *ltime, + date_mode_t fuzzydate) { StringBuffer<40> tmp; String *res; if (!(res= str_op_with_null_check(&tmp)) || - str_to_datetime_with_warn(res->charset(), res->ptr(), res->length(), + str_to_datetime_with_warn(thd, res->charset(), res->ptr(), res->length(), ltime, fuzzydate)) return make_zero_mysql_time(ltime, fuzzydate); return (null_value= 0); @@ -2611,14 +2617,15 @@ bool Item_func_min_max::fix_attributes(Item **items, uint nitems) 0 Otherwise */ -bool Item_func_min_max::get_date_native(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_func_min_max::get_date_native(THD *thd, MYSQL_TIME *ltime, + date_mode_t fuzzydate) { longlong UNINIT_VAR(min_max); DBUG_ASSERT(fixed == 1); for (uint i=0; i < arg_count ; i++) { - longlong res= args[i]->val_datetime_packed(); + longlong res= args[i]->val_datetime_packed(thd); /* Check if we need to stop (because of error or KILL) and stop the loop */ if (unlikely(args[i]->null_value)) @@ -2629,8 +2636,8 @@ bool Item_func_min_max::get_date_native(MYSQL_TIME *ltime, ulonglong fuzzy_date) } unpack_time(min_max, ltime, mysql_timestamp_type()); - if (!(fuzzy_date & TIME_TIME_ONLY) && - unlikely((null_value= check_date_with_warn(ltime, fuzzy_date, + if (!(fuzzydate & TIME_TIME_ONLY) && + unlikely((null_value= check_date_with_warn(thd, ltime, fuzzydate, MYSQL_TIMESTAMP_ERROR)))) return true; @@ -2638,17 +2645,17 @@ bool Item_func_min_max::get_date_native(MYSQL_TIME *ltime, ulonglong fuzzy_date) } -bool Item_func_min_max::get_time_native(MYSQL_TIME *ltime) +bool Item_func_min_max::get_time_native(THD *thd, MYSQL_TIME *ltime) { DBUG_ASSERT(fixed == 1); - Time value(args[0]); + Time value(thd, args[0]); if (!value.is_valid_time()) return (null_value= true); for (uint i= 1; i < arg_count ; i++) { - Time tmp(args[i]); + Time tmp(thd, args[i]); if (!tmp.is_valid_time()) return (null_value= true); @@ -5416,7 +5423,8 @@ my_decimal* Item_user_var_as_out_param::val_decimal(my_decimal *decimal_buffer) } -bool Item_user_var_as_out_param::get_date(MYSQL_TIME *ltime, ulonglong fuzzy) +bool Item_user_var_as_out_param::get_date(THD *thd, MYSQL_TIME *ltime, + date_mode_t fuzzydate) { DBUG_ASSERT(0); return true; @@ -6512,10 +6520,10 @@ my_decimal *Item_func_last_value::val_decimal(my_decimal *decimal_value) } -bool Item_func_last_value::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_func_last_value::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { evaluate_sideeffects(); - bool tmp= last_value->get_date(ltime, fuzzydate); + bool tmp= last_value->get_date(thd, ltime, fuzzydate); null_value= last_value->null_value; return tmp; } diff --git a/sql/item_func.h b/sql/item_func.h index f3547444e9b..51929482b96 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -405,8 +405,8 @@ public: my_decimal *val_decimal(my_decimal *decimal_value); longlong val_int() { DBUG_ASSERT(fixed == 1); return (longlong) rint(val_real()); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date_from_real(ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date_from_real(thd, ltime, fuzzydate); } const Type_handler *type_handler() const { return &type_handler_double; } bool fix_length_and_dec() { @@ -458,7 +458,7 @@ public: virtual double val_real(Item_handled_func *) const= 0; virtual longlong val_int(Item_handled_func *) const= 0; virtual my_decimal *val_decimal(Item_handled_func *, my_decimal *) const= 0; - virtual bool get_date(Item_handled_func *, MYSQL_TIME *, ulonglong fuzzydate) const= 0; + virtual bool get_date(THD *thd, Item_handled_func *, MYSQL_TIME *, date_mode_t fuzzydate) const= 0; virtual const Type_handler *return_type_handler() const= 0; virtual bool fix_length_and_dec(Item_handled_func *) const= 0; }; @@ -626,9 +626,9 @@ public: { return m_func_handler->val_decimal(this, to); } - bool get_date(MYSQL_TIME *to, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate) { - return m_func_handler->get_date(this, to, fuzzydate); + return m_func_handler->get_date(thd, this, to, fuzzydate); } }; @@ -655,15 +655,15 @@ class Item_func_hybrid_field_type: public Item_hybrid_func Helper methods to make sure that the result of decimal_op(), str_op() and date_op() is properly synched with null_value. */ - bool date_op_with_null_check(MYSQL_TIME *ltime) + bool date_op_with_null_check(THD *thd, MYSQL_TIME *ltime) { - bool rc= date_op(ltime, 0); + bool rc= date_op(thd, ltime, date_mode_t(0)); DBUG_ASSERT(!rc ^ null_value); return rc; } - bool time_op_with_null_check(MYSQL_TIME *ltime) + bool time_op_with_null_check(THD *thd, MYSQL_TIME *ltime) { - bool rc= time_op(ltime); + bool rc= time_op(thd, ltime); DBUG_ASSERT(!rc ^ null_value); DBUG_ASSERT(rc || ltime->time_type == MYSQL_TIMESTAMP_TIME); return rc; @@ -674,7 +674,7 @@ class Item_func_hybrid_field_type: public Item_hybrid_func DBUG_ASSERT((res != NULL) ^ null_value); return res; } - bool make_zero_mysql_time(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool make_zero_mysql_time(MYSQL_TIME *ltime, date_mode_t fuzzydate) { bzero(ltime, sizeof(*ltime)); return null_value|= !(fuzzydate & TIME_FUZZY_DATES); @@ -717,9 +717,9 @@ public: double val_real_from_time_op(); double val_real_from_int_op(); - bool get_date_from_str_op(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool get_date_from_real_op(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool get_date_from_int_op(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date_from_str_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); + bool get_date_from_real_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); + bool get_date_from_int_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); public: Item_func_hybrid_field_type(THD *thd): @@ -764,11 +764,11 @@ public: DBUG_ASSERT(null_value == (res == NULL)); return res; } - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date) + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) { DBUG_ASSERT(fixed); return Item_func_hybrid_field_type::type_handler()-> - Item_func_hybrid_field_type_get_date(this, res, fuzzy_date); + Item_func_hybrid_field_type_get_date(thd, this, res, fuzzydate); } /** @@ -812,14 +812,14 @@ public: field type is DATETIME or DATE. @return The result of the operation. */ - virtual bool date_op(MYSQL_TIME *res, ulonglong fuzzy_date)= 0; + virtual bool date_op(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate)= 0; /** @brief Performs the operation that this functions implements when field type is TIME. @return The result of the operation. */ - virtual bool time_op(MYSQL_TIME *res)= 0; + virtual bool time_op(THD *thd, MYSQL_TIME *res)= 0; }; @@ -878,12 +878,12 @@ public: Item_func_hybrid_field_type(thd, list) { } String *str_op(String *str) { DBUG_ASSERT(0); return 0; } - bool date_op(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(0); return true; } - bool time_op(MYSQL_TIME *ltime) + bool time_op(THD *thd, MYSQL_TIME *ltime) { DBUG_ASSERT(0); return true; @@ -969,8 +969,8 @@ public: { collation.set_numeric(); } double val_real(); String *val_str(String*str); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date_from_int(ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date_from_int(thd, ltime, fuzzydate); } const Type_handler *type_handler() const= 0; bool fix_length_and_dec() { return FALSE; } }; @@ -1164,8 +1164,8 @@ public: double val_real() { return VDec(this).to_double(); } longlong val_int() { return VDec(this).to_longlong(unsigned_flag); } my_decimal *val_decimal(my_decimal*); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return VDec(this).to_datetime_with_warn(ltime, fuzzydate, this); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return VDec(this).to_datetime_with_warn(thd, ltime, fuzzydate, this); } const Type_handler *type_handler() const { return &type_handler_newdecimal; } void fix_length_and_dec_generic() {} bool fix_length_and_dec() @@ -1719,8 +1719,8 @@ public: double val_real_native(); longlong val_int_native(); my_decimal *val_decimal_native(my_decimal *); - bool get_date_native(MYSQL_TIME *res, ulonglong fuzzydate); - bool get_time_native(MYSQL_TIME *res); + bool get_date_native(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); + bool get_time_native(THD *thd, MYSQL_TIME *res); double val_real() { @@ -1746,11 +1746,11 @@ public: return Item_func_min_max::type_handler()-> Item_func_min_max_val_decimal(this, dec); } - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date) + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) { DBUG_ASSERT(fixed); return Item_func_min_max::type_handler()-> - Item_func_min_max_get_date(this, res, fuzzy_date); + Item_func_min_max_get_date(thd, this, res, fuzzydate); } void aggregate_attributes_real(Item **items, uint nitems) { @@ -1817,8 +1817,8 @@ public: String *val_str(String *str) { return val_str_from_item(args[0], str); } my_decimal *val_decimal(my_decimal *dec) { return val_decimal_from_item(args[0], dec); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date_from_item(args[0], ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date_from_item(thd, args[0], ltime, fuzzydate); } const char *func_name() const { return "rollup_const"; } bool const_item() const { return 0; } const Type_handler *type_handler() const { return args[0]->type_handler(); } @@ -2274,9 +2274,9 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_NON_DETERMINISTIC); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(this, ltime, fuzzydate); + return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } }; @@ -2584,8 +2584,8 @@ public: Field *create_field_for_create_select(TABLE *table) { return create_table_field_from_handler(table); } bool check_vcol_func_processor(void *arg); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return type_handler()->Item_get_date(this, ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } }; @@ -2766,7 +2766,7 @@ public: double val_real(); longlong val_int(); String *val_str(String *str); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); my_decimal *val_decimal(my_decimal *decimal_buffer); /* fix_fields() binds variable name with its entry structure */ bool fix_fields(THD *thd, Item **ref); @@ -2813,9 +2813,9 @@ public: String* val_str(String*); my_decimal *val_decimal(my_decimal *dec_buf) { return val_decimal_from_real(dec_buf); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(this, ltime, fuzzydate); + return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } /* TODO: fix to support views */ const char *func_name() const { return "get_system_var"; } @@ -3105,7 +3105,7 @@ public: return sp_result_field->val_decimal(dec_buf); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { if (execute()) return true; @@ -3259,7 +3259,7 @@ public: longlong val_int(); String *val_str(String *); my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); bool fix_length_and_dec(); const char *func_name() const { return "last_value"; } const Type_handler *type_handler() const { return last_value->type_handler(); } diff --git a/sql/item_row.h b/sql/item_row.h index 278dc88479d..4f60a33ab9f 100644 --- a/sql/item_row.h +++ b/sql/item_row.h @@ -91,7 +91,7 @@ public: illegal_method_call((const char*)"val_decimal"); return 0; }; - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { illegal_method_call((const char*)"get_date"); return true; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 50fe1624d48..bb10976c434 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -4543,11 +4543,11 @@ bool Item_func_dyncol_create::prepare_arguments(THD *thd, bool force_names_arg) break; case DYN_COL_DATETIME: case DYN_COL_DATE: - args[valpos]->get_date(&vals[i].x.time_value, + args[valpos]->get_date(thd, &vals[i].x.time_value, sql_mode_for_dates(thd)); break; case DYN_COL_TIME: - args[valpos]->get_time(&vals[i].x.time_value); + args[valpos]->get_time(thd, &vals[i].x.time_value); break; default: DBUG_ASSERT(0); @@ -5113,7 +5113,7 @@ null: } -bool Item_dyncol_get::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_dyncol_get::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DYNAMIC_COLUMN_VALUE val; char buff[STRING_BUFFER_USUAL_SIZE]; @@ -5135,9 +5135,9 @@ bool Item_dyncol_get::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) { longlong llval = (longlong)val.x.ulong_value; bool neg = llval < 0; - if (int_to_datetime_with_warn(neg, (ulonglong)(neg ? -llval : + if (int_to_datetime_with_warn(thd, neg, (ulonglong)(neg ? -llval : llval), - ltime, fuzzy_date, 0 /* TODO */)) + ltime, fuzzydate, 0 /* TODO */)) goto null; return 0; } @@ -5145,20 +5145,20 @@ bool Item_dyncol_get::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) val.x.double_value= static_cast<double>(ULONGLONG_MAX); /* fall through */ case DYN_COL_DOUBLE: - if (double_to_datetime_with_warn(val.x.double_value, ltime, fuzzy_date, + if (double_to_datetime_with_warn(thd, val.x.double_value, ltime, fuzzydate, 0 /* TODO */)) goto null; return 0; case DYN_COL_DECIMAL: - if (decimal_to_datetime_with_warn((my_decimal*)&val.x.decimal.value, ltime, - fuzzy_date, 0 /* TODO */)) + if (decimal_to_datetime_with_warn(thd, (my_decimal*)&val.x.decimal.value, + ltime, fuzzydate, 0 /* TODO */)) goto null; return 0; case DYN_COL_STRING: - if (str_to_datetime_with_warn(&my_charset_numeric, + if (str_to_datetime_with_warn(thd, &my_charset_numeric, val.x.string.value.str, val.x.string.value.length, - ltime, fuzzy_date)) + ltime, fuzzydate)) goto null; return 0; case DYN_COL_DATETIME: diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 7c4ab93dc80..762a3c2559e 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -62,8 +62,8 @@ public: longlong val_int(); double val_real(); my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date_from_string(ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date_from_string(thd, ltime, fuzzydate); } const Type_handler *type_handler() const { return string_type_handler(); } void left_right_max_length(); bool fix_fields(THD *thd, Item **ref); @@ -1465,11 +1465,11 @@ public: return NULL; return res; } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { if (args[0]->result_type() == STRING_RESULT) - return Item_str_func::get_date(ltime, fuzzydate); - bool res= args[0]->get_date(ltime, fuzzydate); + return Item_str_func::get_date(thd, ltime, fuzzydate); + bool res= args[0]->get_date(thd, ltime, fuzzydate); if ((null_value= args[0]->null_value)) return 1; return res; @@ -1764,7 +1764,7 @@ public: double val_real(); my_decimal *val_decimal(my_decimal *); bool get_dyn_value(THD *thd, DYNAMIC_COLUMN_VALUE *val, String *tmp); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); void print(String *str, enum_query_type query_type); Item *get_copy(THD *thd) { return get_item_copy<Item_dyncol_get>(thd, this); } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index eef6755bc98..9298c9998a8 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1388,15 +1388,15 @@ bool Item_singlerow_subselect::val_bool() } -bool Item_singlerow_subselect::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) +bool Item_singlerow_subselect::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); if (forced_const) - return value->get_date(ltime, fuzzydate); + return value->get_date(thd, ltime, fuzzydate); if (!exec() && !value->null_value) { null_value= FALSE; - return value->get_date(ltime, fuzzydate); + return value->get_date(thd, ltime, fuzzydate); } else { diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 4980709b979..443354f4900 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -308,7 +308,7 @@ public: String *val_str (String *); my_decimal *val_decimal(my_decimal *); bool val_bool(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); const Type_handler *type_handler() const; bool fix_length_and_dec(); @@ -405,8 +405,8 @@ public: String *val_str(String*); my_decimal *val_decimal(my_decimal *); bool val_bool(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) - { return get_date_from_int(ltime, fuzzydate); } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { return get_date_from_int(thd, ltime, fuzzydate); } bool fix_fields(THD *thd, Item **ref); bool fix_length_and_dec(); void print(String *str, enum_query_type query_type); diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 98a3f6116a6..d1865c7e771 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -2305,12 +2305,12 @@ void Item_sum_hybrid::clear() bool -Item_sum_hybrid::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +Item_sum_hybrid::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); if (null_value) return true; - bool retval= value->get_date(ltime, fuzzydate); + bool retval= value->get_date(thd, ltime, fuzzydate); if ((null_value= value->null_value)) DBUG_ASSERT(retval == true); return retval; diff --git a/sql/item_sum.h b/sql/item_sum.h index fe055673328..c88a850c241 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -742,9 +742,9 @@ public: longlong val_int() { return val_int_from_real(); /* Real as default */ } String *val_str(String*str); my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(this, ltime, fuzzydate); + return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } void reset_field(); }; @@ -1067,7 +1067,7 @@ protected: double val_real(); longlong val_int(); my_decimal *val_decimal(my_decimal *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); void reset_field(); String *val_str(String *); const Type_handler *real_type_handler() const @@ -1363,7 +1363,7 @@ public: void update_field(){DBUG_ASSERT(0);} void clear(); void cleanup(); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { return execute() || sp_result_field->get_date(ltime, fuzzydate); } @@ -1403,9 +1403,9 @@ public: { return mark_unsupported_function(name.str, arg, VCOL_IMPOSSIBLE); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(this, ltime, fuzzydate); + return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } }; @@ -1565,9 +1565,9 @@ public: void update_field() {}; void cleanup(); virtual void print(String *str, enum_query_type query_type); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(this, ltime, fuzzydate); + return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } }; @@ -1874,9 +1874,9 @@ public: { return val_decimal_from_string(decimal_value); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return get_date_from_string(ltime, fuzzydate); + return get_date_from_string(thd, ltime, fuzzydate); } String* val_str(String* str); Item *copy_or_same(THD* thd); diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 236c45f0136..94757e16d41 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -125,12 +125,12 @@ static DATE_TIME_FORMAT time_24hrs_format= {{0}, '\0', 0, 1 error */ -static bool extract_date_time(DATE_TIME_FORMAT *format, +static bool extract_date_time(THD *thd, DATE_TIME_FORMAT *format, const char *val, uint length, MYSQL_TIME *l_time, timestamp_type cached_timestamp_type, const char **sub_pattern_end, const char *date_time_type, - ulonglong fuzzy_date) + date_mode_t fuzzydate) { int weekday= 0, yearday= 0, daypart= 0; int week_number= -1; @@ -325,17 +325,17 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, We can't just set error here, as we don't want to generate two warnings in case of errors */ - if (extract_date_time(&time_ampm_format, val, + if (extract_date_time(thd, &time_ampm_format, val, (uint)(val_end - val), l_time, - cached_timestamp_type, &val, "time", fuzzy_date)) + cached_timestamp_type, &val, "time", fuzzydate)) DBUG_RETURN(1); break; /* Time in 24-hour notation */ case 'T': - if (extract_date_time(&time_24hrs_format, val, + if (extract_date_time(thd, &time_24hrs_format, val, (uint)(val_end - val), l_time, - cached_timestamp_type, &val, "time", fuzzy_date)) + cached_timestamp_type, &val, "time", fuzzydate)) DBUG_RETURN(1); break; @@ -441,7 +441,7 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, goto err; int was_cut; - if (check_date(l_time, fuzzy_date | TIME_INVALID_DATES, &was_cut)) + if (check_date(l_time, ulonglong(fuzzydate | TIME_INVALID_DATES), &was_cut)) goto err; if (val != val_end) @@ -451,8 +451,7 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, if (!my_isspace(&my_charset_latin1,*val)) { ErrConvString err(val_begin, length, &my_charset_bin); - make_truncated_value_warning(current_thd, - Sql_condition::WARN_LEVEL_WARN, + make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN, &err, cached_timestamp_type, NullS); break; } @@ -462,7 +461,6 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, err: { - THD *thd= current_thd; char buff[128]; strmake(buff, val_begin, MY_MIN(length, sizeof(buff)-1)); push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, @@ -881,7 +879,7 @@ enum_monotonicity_info Item_func_to_seconds::get_monotonicity_info() const longlong Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp) { DBUG_ASSERT(fixed == 1); - Datetime dt(current_thd, args[0], 0); + Datetime dt(current_thd, args[0], date_mode_t(0)); longlong res; if ((null_value= !dt.is_valid_datetime())) { @@ -941,14 +939,14 @@ longlong Item_func_dayofyear::val_int() longlong Item_func_dayofmonth::val_int() { DBUG_ASSERT(fixed == 1); - Date d(current_thd, args[0], 0); + Date d(current_thd, args[0], date_mode_t(0)); return (null_value= !d.is_valid_date()) ? 0 : d.get_mysql_time()->day; } longlong Item_func_month::val_int() { DBUG_ASSERT(fixed == 1); - Date d(current_thd, args[0], 0); + Date d(current_thd, args[0], date_mode_t(0)); return (null_value= !d.is_valid_date()) ? 0 : d.get_mysql_time()->month; } @@ -971,7 +969,7 @@ String* Item_func_monthname::val_str(String* str) DBUG_ASSERT(fixed == 1); const char *month_name; uint err; - Date d(current_thd, args[0], 0); + Date d(current_thd, args[0], date_mode_t(0)); if ((null_value= (!d.is_valid_date() || !d.get_mysql_time()->month))) return (String *) 0; @@ -990,21 +988,21 @@ String* Item_func_monthname::val_str(String* str) longlong Item_func_quarter::val_int() { DBUG_ASSERT(fixed == 1); - Date d(current_thd, args[0], 0); + Date d(current_thd, args[0], date_mode_t(0)); return (null_value= !d.is_valid_date()) ? 0 : d.quarter(); } longlong Item_func_hour::val_int() { DBUG_ASSERT(fixed == 1); - Time tm(args[0], Time::Options_for_cast()); + Time tm(current_thd, args[0], Time::Options_for_cast()); return (null_value= !tm.is_valid_time()) ? 0 : tm.get_mysql_time()->hour; } longlong Item_func_minute::val_int() { DBUG_ASSERT(fixed == 1); - Time tm(args[0], Time::Options_for_cast()); + Time tm(current_thd, args[0], Time::Options_for_cast()); return (null_value= !tm.is_valid_time()) ? 0 : tm.get_mysql_time()->minute; } @@ -1014,7 +1012,7 @@ longlong Item_func_minute::val_int() longlong Item_func_second::val_int() { DBUG_ASSERT(fixed == 1); - Time tm(args[0], Time::Options_for_cast()); + Time tm(current_thd, args[0], Time::Options_for_cast()); return (null_value= !tm.is_valid_time()) ? 0 : tm.get_mysql_time()->second; } @@ -1062,13 +1060,14 @@ longlong Item_func_week::val_int() { DBUG_ASSERT(fixed == 1); uint week_format; - Date d(current_thd, args[0], TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE); + THD *thd= current_thd; + Date d(thd, args[0], TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE); if ((null_value= !d.is_valid_date())) return 0; if (arg_count > 1) week_format= (uint)args[1]->val_int(); else - week_format= current_thd->variables.default_week_format; + week_format= thd->variables.default_week_format; return d.week(week_mode(week_format)); } @@ -1123,7 +1122,7 @@ String* Item_func_dayname::val_str(String* str) longlong Item_func_year::val_int() { DBUG_ASSERT(fixed == 1); - Date d(current_thd, args[0], 0); + Date d(current_thd, args[0], date_mode_t(0)); return (null_value= !d.is_valid_date()) ? 0 : d.get_mysql_time()->year; } @@ -1155,7 +1154,7 @@ enum_monotonicity_info Item_func_year::get_monotonicity_info() const longlong Item_func_year::val_int_endpoint(bool left_endp, bool *incl_endp) { DBUG_ASSERT(fixed == 1); - Datetime dt(current_thd, args[0], 0); + Datetime dt(current_thd, args[0], date_mode_t(0)); if ((null_value= !dt.is_valid_datetime())) { /* got NULL, leave the incl_endp intact */ @@ -1264,7 +1263,7 @@ longlong Item_func_unix_timestamp::val_int_endpoint(bool left_endp, bool *incl_e longlong Item_func_time_to_sec::int_op() { DBUG_ASSERT(fixed == 1); - Time tm(args[0], Time::Options_for_cast()); + Time tm(current_thd, args[0], Time::Options_for_cast()); return ((null_value= !tm.is_valid_time())) ? 0 : tm.to_seconds(); } @@ -1272,7 +1271,7 @@ longlong Item_func_time_to_sec::int_op() my_decimal *Item_func_time_to_sec::decimal_op(my_decimal* buf) { DBUG_ASSERT(fixed == 1); - Time tm(args[0], Time::Options_for_cast()); + Time tm(current_thd, args[0], Time::Options_for_cast()); if ((null_value= !tm.is_valid_time())) return 0; const MYSQL_TIME *ltime= tm.get_mysql_time(); @@ -1287,7 +1286,8 @@ my_decimal *Item_func_time_to_sec::decimal_op(my_decimal* buf) To make code easy, allow interval objects without separators. */ -bool get_interval_value(Item *args,interval_type int_type, INTERVAL *interval) +bool get_interval_value(THD *thd, Item *args, + interval_type int_type, INTERVAL *interval) { ulonglong array[5]; longlong UNINIT_VAR(value); @@ -1308,7 +1308,7 @@ bool get_interval_value(Item *args,interval_type int_type, INTERVAL *interval) if (d.sec() >= LONGLONG_MAX) { ErrConvDecimal err(val.ptr()); - current_thd->push_warning_truncated_wrong_value("seconds", err.ptr()); + thd->push_warning_truncated_wrong_value("seconds", err.ptr()); return true; } interval->second= d.sec(); @@ -1458,11 +1458,11 @@ bool get_interval_value(Item *args,interval_type int_type, INTERVAL *interval) } -bool Item_func_from_days::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_func_from_days::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { longlong value=args[0]->val_int(); if ((null_value= (args[0]->null_value || - ((fuzzy_date & TIME_NO_ZERO_DATE) && value == 0)))) + ((fuzzydate & TIME_NO_ZERO_DATE) && value == 0)))) return true; bzero(ltime, sizeof(MYSQL_TIME)); if (get_date_from_daynr((long) value, <ime->year, <ime->month, @@ -1499,10 +1499,9 @@ void Item_func_curdate_utc::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time) } -bool Item_func_curdate::get_date(MYSQL_TIME *res, - ulonglong fuzzy_date __attribute__((unused))) +bool Item_func_curdate::get_date(THD *thd, MYSQL_TIME *res, + date_mode_t fuzzydate __attribute__((unused))) { - THD *thd= current_thd; query_id_t query_id= thd->query_id; /* Cache value for this query */ if (last_query_id != query_id) @@ -1529,10 +1528,9 @@ bool Item_func_curtime::fix_fields(THD *thd, Item **items) return Item_timefunc::fix_fields(thd, items); } -bool Item_func_curtime::get_date(MYSQL_TIME *res, - ulonglong fuzzy_date __attribute__((unused))) +bool Item_func_curtime::get_date(THD *thd, MYSQL_TIME *res, + date_mode_t fuzzydate __attribute__((unused))) { - THD *thd= current_thd; query_id_t query_id= thd->query_id; /* Cache value for this query */ if (last_query_id != query_id) @@ -1661,10 +1659,9 @@ void Item_func_now_utc::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time) } -bool Item_func_now::get_date(MYSQL_TIME *res, - ulonglong fuzzy_date __attribute__((unused))) +bool Item_func_now::get_date(THD *thd, MYSQL_TIME *res, + date_mode_t fuzzydate __attribute__((unused))) { - THD *thd= current_thd; query_id_t query_id= thd->query_id; /* Cache value for this query */ if (last_query_id != query_id) @@ -1690,21 +1687,21 @@ void Item_func_sysdate_local::store_now_in_TIME(THD *thd, MYSQL_TIME *now_time) } -bool Item_func_sysdate_local::get_date(MYSQL_TIME *res, - ulonglong fuzzy_date __attribute__((unused))) +bool Item_func_sysdate_local::get_date(THD *thd, MYSQL_TIME *res, + date_mode_t fuzzydate __attribute__((unused))) { - store_now_in_TIME(current_thd, res); + store_now_in_TIME(thd, res); return 0; } -bool Item_func_sec_to_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_func_sec_to_time::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); - VSec6 sec(args[0], "seconds", LONGLONG_MAX); + VSec6 sec(thd, args[0], "seconds", LONGLONG_MAX); if ((null_value= sec.is_null())) return true; if (sec.sec_to_time(ltime, decimals) && !sec.truncated()) - sec.make_truncated_warning(current_thd, "seconds"); + sec.make_truncated_warning(thd, "seconds"); return false; } @@ -1861,7 +1858,9 @@ String *Item_func_date_format::val_str(String *str) const MY_LOCALE *lc= 0; DBUG_ASSERT(fixed == 1); - if ((null_value= args[0]->get_date(&l_time, is_time_format ? TIME_TIME_ONLY : 0))) + if ((null_value= args[0]->get_date(current_thd, &l_time, + is_time_format ? TIME_TIME_ONLY : + date_mode_t(0)))) return 0; if (!(format = args[1]->val_str(str)) || !format->length()) @@ -1912,13 +1911,13 @@ bool Item_func_from_unixtime::fix_length_and_dec() } -bool Item_func_from_unixtime::get_date(MYSQL_TIME *ltime, - ulonglong fuzzy_date __attribute__((unused))) +bool Item_func_from_unixtime::get_date(THD *thd, MYSQL_TIME *ltime, + date_mode_t fuzzydate __attribute__((unused))) { bzero((char *)ltime, sizeof(*ltime)); ltime->time_type= MYSQL_TIMESTAMP_TIME; - VSec6 sec(args[0], "unixtime", TIMESTAMP_MAX_VALUE); + VSec6 sec(thd, args[0], "unixtime", TIMESTAMP_MAX_VALUE); DBUG_ASSERT(sec.sec() <= TIMESTAMP_MAX_VALUE); if (sec.is_null() || sec.truncated() || sec.neg()) @@ -1931,12 +1930,11 @@ bool Item_func_from_unixtime::get_date(MYSQL_TIME *ltime, } -bool Item_func_convert_tz::get_date(MYSQL_TIME *ltime, - ulonglong fuzzy_date __attribute__((unused))) +bool Item_func_convert_tz::get_date(THD *thd, MYSQL_TIME *ltime, + date_mode_t fuzzydate __attribute__((unused))) { my_time_t my_time_tmp; String str; - THD *thd= current_thd; if (!from_tz_cached) { @@ -2036,9 +2034,9 @@ bool Item_date_add_interval::fix_length_and_dec() bool Func_handler_date_add_interval_datetime_arg0_time:: - get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { - THD *thd= current_thd; // time_expr + INTERVAL {YEAR|QUARTER|MONTH|WEEK|YEAR_MONTH} push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_DATETIME_FUNCTION_OVERFLOW, @@ -2127,10 +2125,10 @@ longlong Item_extract::val_int() uint year; ulong week_format; long neg; - int is_time_flag = date_value ? 0 : TIME_TIME_ONLY; + date_mode_t is_time_flag = date_value ? date_mode_t(0) : TIME_TIME_ONLY; // Not using get_arg0_date to avoid automatic TIME to DATETIME conversion - if ((null_value= args[0]->get_date(<ime, is_time_flag))) + if ((null_value= args[0]->get_date(current_thd, <ime, is_time_flag))) return 0; neg= ltime.neg ? -1 : 1; @@ -2441,26 +2439,26 @@ void Item_char_typecast::fix_length_and_dec_internal(CHARSET_INFO *from_cs) } -bool Item_time_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_time_typecast::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - Time *tm= new(ltime) Time(args[0], Time::Options_for_cast(), + Time *tm= new(ltime) Time(thd, args[0], Time::Options_for_cast(), MY_MIN(decimals, TIME_SECOND_PART_DIGITS)); return (null_value= !tm->is_valid_time()); } -bool Item_date_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_date_typecast::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - fuzzy_date= (fuzzy_date | sql_mode_for_dates(current_thd)) & ~TIME_TIME_ONLY; - Date *d= new(ltime) Date(current_thd, args[0], fuzzy_date); + date_mode_t tmp= (fuzzydate | sql_mode_for_dates(thd)) & ~TIME_TIME_ONLY; + Date *d= new(ltime) Date(thd, args[0], tmp); return (null_value= !d->is_valid_date()); } -bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_datetime_typecast::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - fuzzy_date= (fuzzy_date | sql_mode_for_dates(current_thd)) & ~TIME_TIME_ONLY; - Datetime *dt= new(ltime) Datetime(current_thd, args[0], fuzzy_date, + date_mode_t tmp= (fuzzydate | sql_mode_for_dates(thd)) & ~TIME_TIME_ONLY; + Datetime *dt= new(ltime) Datetime(thd, args[0], tmp, MY_MIN(decimals, TIME_SECOND_PART_DIGITS)); return (null_value= !dt->is_valid_datetime()); } @@ -2477,7 +2475,7 @@ bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) 0099-12-31 */ -bool Item_func_makedate::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_func_makedate::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); long year, days, daynr= (long) args[1]->val_int(); @@ -2555,7 +2553,7 @@ bool Item_func_add_time::fix_length_and_dec() Result: Time value */ -bool Item_func_timediff::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_func_timediff::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); int l_sign= 1; @@ -2563,22 +2561,22 @@ bool Item_func_timediff::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) ErrConvTime str(&l_time3); /* the following may be true in, for example, date_add(timediff(...), ... */ - if (fuzzy_date & TIME_NO_ZERO_IN_DATE) + if (fuzzydate & TIME_NO_ZERO_IN_DATE) return (null_value= 1); - if (args[0]->get_time(&l_time1) || - args[1]->get_time(&l_time2) || + if (args[0]->get_time(thd, &l_time1) || + args[1]->get_time(thd, &l_time2) || l_time1.time_type != l_time2.time_type) return (null_value= 1); if (l_time1.neg != l_time2.neg) l_sign= -l_sign; - if (calc_time_diff(&l_time1, &l_time2, l_sign, &l_time3, fuzzy_date)) + if (calc_time_diff(&l_time1, &l_time2, l_sign, &l_time3, fuzzydate)) return (null_value= 1); *ltime= l_time3; - return (null_value= adjust_time_range_with_warn(ltime, decimals)); + return (null_value= adjust_time_range_with_warn(thd, ltime, decimals)); } /** @@ -2587,13 +2585,13 @@ bool Item_func_timediff::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) Result: Time value */ -bool Item_func_maketime::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_func_maketime::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); bool overflow= 0; longlong hour= args[0]->val_int(); longlong minute= args[1]->val_int(); - VSec6 sec(args[2], "seconds", 59); + VSec6 sec(thd, args[2], "seconds", 59); DBUG_ASSERT(sec.sec() <= 59); if (args[0]->null_value || args[1]->null_value || sec.is_null() || @@ -2631,7 +2629,7 @@ bool Item_func_maketime::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) int len = (int)(ptr - buf) + sprintf(ptr, ":%02u:%02u", (uint) minute, (uint) sec.sec()); ErrConvString err(buf, len, &my_charset_bin); - current_thd->push_warning_truncated_wrong_value("time", err.ptr()); + thd->push_warning_truncated_wrong_value("time", err.ptr()); } return (null_value= 0); @@ -2649,7 +2647,7 @@ bool Item_func_maketime::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) longlong Item_func_microsecond::val_int() { DBUG_ASSERT(fixed == 1); - Time tm(args[0], Time::Options_for_cast()); + Time tm(current_thd, args[0], Time::Options_for_cast()); return ((null_value= !tm.is_valid_time())) ? 0 : tm.get_mysql_time()->second_part; } @@ -2663,7 +2661,7 @@ longlong Item_func_timestamp_diff::val_int() long months= 0; int neg= 1; THD *thd= current_thd; - ulonglong fuzzydate= TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE; + date_mode_t fuzzydate= TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE; null_value= 0; @@ -2960,8 +2958,8 @@ bool Item_func_str_to_date::fix_length_and_dec() } -bool Item_func_str_to_date::get_date_common(MYSQL_TIME *ltime, - ulonglong fuzzy_date, +bool Item_func_str_to_date::get_date_common(THD *thd, MYSQL_TIME *ltime, + date_mode_t fuzzydate, timestamp_type tstype) { DATE_TIME_FORMAT date_time_format; @@ -2975,17 +2973,17 @@ bool Item_func_str_to_date::get_date_common(MYSQL_TIME *ltime, date_time_format.format.str= (char*) format->ptr(); date_time_format.format.length= format->length(); - if (extract_date_time(&date_time_format, val->ptr(), val->length(), + if (extract_date_time(thd, &date_time_format, val->ptr(), val->length(), ltime, tstype, 0, "datetime", - fuzzy_date | sql_mode_for_dates(current_thd))) + fuzzydate | sql_mode_for_dates(thd))) return (null_value=1); return (null_value= 0); } -bool Item_func_last_day::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +bool Item_func_last_day::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - Date *d= new(ltime) Date(current_thd, args[0], fuzzy_date & ~TIME_TIME_ONLY); + Date *d= new(ltime) Date(thd, args[0], fuzzydate & ~TIME_TIME_ONLY); if ((null_value= (!d->is_valid_date() || ltime->month == 0))) return true; uint month_idx= ltime->month-1; diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index f9709b8f72a..ad261635cc0 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -26,7 +26,8 @@ class MY_LOCALE; -bool get_interval_value(Item *args,interval_type int_type, INTERVAL *interval); +bool get_interval_value(THD *thd, Item *args, + interval_type int_type, INTERVAL *interval); class Item_long_func_date_field: public Item_long_func @@ -181,9 +182,9 @@ public: str->set(nr, collation.collation); return str; } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return get_date_from_int(ltime, fuzzydate); + return get_date_from_int(thd, ltime, fuzzydate); } const char *func_name() const { return "month"; } const Type_handler *type_handler() const { return &type_handler_long; } @@ -454,9 +455,9 @@ public: { return (odbc_type ? "dayofweek" : "weekday"); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(this, ltime, fuzzydate); + return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } const Type_handler *type_handler() const { return &type_handler_long; } bool fix_length_and_dec() @@ -511,7 +512,7 @@ public: } double real_op() { DBUG_ASSERT(0); return 0; } String *str_op(String *str) { DBUG_ASSERT(0); return 0; } - bool date_op(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(0); return true; @@ -547,7 +548,8 @@ public: } bool fix_length_and_dec() { - fix_length_and_dec_generic(arg_count ? args[0]->datetime_precision() : 0); + fix_length_and_dec_generic(arg_count ? + args[0]->datetime_precision(current_thd) : 0); return FALSE; } longlong int_op(); @@ -571,7 +573,7 @@ public: } bool fix_length_and_dec() { - fix_length_and_dec_generic(args[0]->time_precision()); + fix_length_and_dec_generic(args[0]->time_precision(current_thd)); return FALSE; } longlong int_op(); @@ -643,7 +645,7 @@ public: { decimals= dec; } bool fix_fields(THD *, Item **); bool fix_length_and_dec() { fix_attributes_time(decimals); return FALSE; } - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); /* Abstract method that defines which time zone is used for conversion. Converts time current time in my_time_t representation to broken-down @@ -688,7 +690,7 @@ class Item_func_curdate :public Item_datefunc MYSQL_TIME ltime; public: Item_func_curdate(THD *thd): Item_datefunc(thd), last_query_id(0) {} - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)=0; bool check_vcol_func_processor(void *arg) { @@ -731,7 +733,7 @@ public: bool fix_fields(THD *, Item **); bool fix_length_and_dec() { fix_attributes_datetime(decimals); return FALSE;} - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)=0; bool check_vcol_func_processor(void *arg) { @@ -786,7 +788,7 @@ public: bool const_item() const { return 0; } const char *func_name() const { return "sysdate"; } void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time); - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); table_map used_tables() const { return RAND_TABLE_BIT; } bool check_vcol_func_processor(void *arg) { @@ -806,7 +808,7 @@ class Item_func_from_days :public Item_datefunc public: Item_func_from_days(THD *thd, Item *a): Item_datefunc(thd, a) {} const char *func_name() const { return "from_days"; } - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); bool check_partition_func_processor(void *int_arg) {return FALSE;} bool check_vcol_func_processor(void *arg) { return FALSE;} bool check_valid_arguments_processor(void *int_arg) @@ -871,7 +873,7 @@ class Item_func_from_unixtime :public Item_datetimefunc Item_func_from_unixtime(THD *thd, Item *a): Item_datetimefunc(thd, a) {} const char *func_name() const { return "from_unixtime"; } bool fix_length_and_dec(); - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); Item *get_copy(THD *thd) { return get_item_copy<Item_func_from_unixtime>(thd, this); } }; @@ -912,11 +914,11 @@ class Item_func_convert_tz :public Item_datetimefunc const char *func_name() const { return "convert_tz"; } bool fix_length_and_dec() { - fix_attributes_datetime(args[0]->datetime_precision()); + fix_attributes_datetime(args[0]->datetime_precision(current_thd)); maybe_null= true; return FALSE; } - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); void cleanup(); Item *get_copy(THD *thd) { return get_item_copy<Item_func_convert_tz>(thd, this); } @@ -929,7 +931,7 @@ class Item_func_sec_to_time :public Item_timefunc { return args[0]->check_type_can_return_decimal(func_name()); } public: Item_func_sec_to_time(THD *thd, Item *item): Item_timefunc(thd, item) {} - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); bool fix_length_and_dec() { fix_attributes_time(args[0]->decimals); @@ -1119,7 +1121,7 @@ public: { print_cast_temporal(str, query_type); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); bool fix_length_and_dec() { return args[0]->type_handler()->Item_date_typecast_fix_length_and_dec(this); @@ -1139,7 +1141,7 @@ public: { print_cast_temporal(str, query_type); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); bool fix_length_and_dec() { return args[0]->type_handler()-> @@ -1160,7 +1162,7 @@ public: { print_cast_temporal(str, query_type); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); bool fix_length_and_dec() { return args[0]->type_handler()-> @@ -1179,7 +1181,7 @@ public: Item_func_makedate(THD *thd, Item *a, Item *b): Item_datefunc(thd, a, b) {} const char *func_name() const { return "makedate"; } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); Item *get_copy(THD *thd) { return get_item_copy<Item_func_makedate>(thd, this); } }; @@ -1199,17 +1201,19 @@ public: const char *func_name() const { return "timestamp"; } bool fix_length_and_dec() { - uint dec= MY_MAX(args[0]->datetime_precision(), args[1]->time_precision()); + THD *thd= current_thd; + uint dec= MY_MAX(args[0]->datetime_precision(thd), + args[1]->time_precision(thd)); fix_attributes_datetime(dec); maybe_null= true; return false; } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - Datetime dt(current_thd, args[0], 0); + Datetime dt(thd, args[0], date_mode_t(0)); MYSQL_TIME ltime2; return (null_value= (!dt.is_valid_datetime() || - args[1]->get_time(<ime2) || + args[1]->get_time(thd, <ime2) || Sec6_add(dt.get_mysql_time(), <ime2, 1). to_datetime(ltime))); } @@ -1251,12 +1255,14 @@ public: const char *func_name() const { return "timediff"; } bool fix_length_and_dec() { - uint dec= MY_MAX(args[0]->time_precision(), args[1]->time_precision()); + THD *thd= current_thd; + uint dec= MY_MAX(args[0]->time_precision(thd), + args[1]->time_precision(thd)); fix_attributes_time(dec); maybe_null= true; return FALSE; } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); Item *get_copy(THD *thd) { return get_item_copy<Item_func_timediff>(thd, this); } }; @@ -1279,7 +1285,7 @@ public: return FALSE; } const char *func_name() const { return "maketime"; } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); Item *get_copy(THD *thd) { return get_item_copy<Item_func_maketime>(thd, this); } }; @@ -1369,7 +1375,8 @@ public: Item_handled_func(thd, a, b), const_item(false), internal_charset(NULL) {} - bool get_date_common(MYSQL_TIME *ltime, ulonglong fuzzy_date, timestamp_type); + bool get_date_common(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate, + timestamp_type); const char *func_name() const { return "str_to_date"; } bool fix_length_and_dec(); Item *get_copy(THD *thd) @@ -1384,7 +1391,7 @@ class Item_func_last_day :public Item_datefunc public: Item_func_last_day(THD *thd, Item *a): Item_datefunc(thd, a) {} const char *func_name() const { return "last_day"; } - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); Item *get_copy(THD *thd) { return get_item_copy<Item_func_last_day>(thd, this); } }; @@ -1413,14 +1420,14 @@ protected: { return static_cast<const Item_date_add_interval*>(item)->date_sub_interval; } - bool add(Item *item, interval_type type, bool sub, MYSQL_TIME *to) const + bool add(THD *thd, Item *item, interval_type type, bool sub, MYSQL_TIME *to) const { INTERVAL interval; - if (get_interval_value(item, type, &interval)) + if (get_interval_value(thd, item, type, &interval)) return true; if (sub) interval.neg = !interval.neg; - return date_add_interval(to, type, interval); + return date_add_interval(thd, to, type, interval); } }; @@ -1432,19 +1439,20 @@ class Func_handler_date_add_interval_datetime: public: bool fix_length_and_dec(Item_handled_func *item) const { - uint dec= MY_MAX(item->arguments()[0]->datetime_precision(), + uint dec= MY_MAX(item->arguments()[0]->datetime_precision(current_thd), interval_dec(item->arguments()[1], int_type(item))); item->fix_attributes_datetime(dec); return false; } - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { - Datetime dt(current_thd, item->arguments()[0], 0); + Datetime dt(thd, item->arguments()[0], date_mode_t(0)); if (!dt.is_valid_datetime() || - dt.check_date_with_warn(TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE)) + dt.check_date_with_warn(thd, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE)) return (item->null_value= true); dt.copy_to_mysql_time(to); - return (item->null_value= add(item->arguments()[1], + return (item->null_value= add(thd, item->arguments()[1], int_type(item), sub(item), to)); } }; @@ -1454,7 +1462,8 @@ class Func_handler_date_add_interval_datetime_arg0_time: public Func_handler_date_add_interval_datetime { public: - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const; + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const; }; @@ -1463,14 +1472,15 @@ class Func_handler_date_add_interval_date: public Func_handler_date_add_interval { public: - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { - Date d(current_thd, item->arguments()[0], 0); + Date d(thd, item->arguments()[0], date_mode_t(0)); if (!d.is_valid_date() || - d.check_date_with_warn(TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE)) + d.check_date_with_warn(thd, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE)) return (item->null_value= true); d.copy_to_mysql_time(to); - return (item->null_value= add(item->arguments()[1], + return (item->null_value= add(thd, item->arguments()[1], int_type(item), sub(item), to)); } }; @@ -1483,18 +1493,19 @@ class Func_handler_date_add_interval_time: public: bool fix_length_and_dec(Item_handled_func *item) const { - uint dec= MY_MAX(item->arguments()[0]->time_precision(), + uint dec= MY_MAX(item->arguments()[0]->time_precision(current_thd), interval_dec(item->arguments()[1], int_type(item))); item->fix_attributes_time(dec); return false; } - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { - Time t(item->arguments()[0]); + Time t(thd, item->arguments()[0]); if (!t.is_valid_time()) return (item->null_value= true); t.copy_to_mysql_time(to); - return (item->null_value= add(item->arguments()[1], + return (item->null_value= add(thd, item->arguments()[1], int_type(item), sub(item), to)); } }; @@ -1507,21 +1518,22 @@ class Func_handler_date_add_interval_string: public: bool fix_length_and_dec(Item_handled_func *item) const { - uint dec= MY_MAX(item->arguments()[0]->datetime_precision(), + uint dec= MY_MAX(item->arguments()[0]->datetime_precision(current_thd), interval_dec(item->arguments()[1], int_type(item))); item->collation.set(item->default_charset(), DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII); item->fix_char_length_temporal_not_fixed_dec(MAX_DATETIME_WIDTH, dec); return false; } - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { - if (item->arguments()[0]->get_date(to, 0) || + if (item->arguments()[0]->get_date(thd, to, date_mode_t(0)) || (to->time_type != MYSQL_TIMESTAMP_TIME && - check_date_with_warn(to, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE, + check_date_with_warn(thd, to, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE, MYSQL_TIMESTAMP_ERROR))) return (item->null_value= true); - return (item->null_value= add(item->arguments()[1], + return (item->null_value= add(thd, item->arguments()[1], int_type(item), sub(item), to)); } }; @@ -1545,18 +1557,20 @@ public: { } bool fix_length_and_dec(Item_handled_func *item) const { - uint dec= MY_MAX(item->arguments()[0]->datetime_precision(), - item->arguments()[1]->time_precision()); + THD *thd= current_thd; + uint dec= MY_MAX(item->arguments()[0]->datetime_precision(thd), + item->arguments()[1]->time_precision(thd)); item->fix_attributes_datetime(dec); return false; } - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { DBUG_ASSERT(item->is_fixed()); MYSQL_TIME l_time2; - Datetime dt(current_thd, item->arguments()[0], 0); + Datetime dt(thd, item->arguments()[0], date_mode_t(0)); return (item->null_value= (!dt.is_valid_datetime() || - item->arguments()[1]->get_time(&l_time2) || + item->arguments()[1]->get_time(current_thd, &l_time2) || Sec6_add(dt.get_mysql_time(), &l_time2, m_sign). to_datetime(to))); } @@ -1573,20 +1587,22 @@ public: { } bool fix_length_and_dec(Item_handled_func *item) const { - uint dec= MY_MAX(item->arguments()[0]->time_precision(), - item->arguments()[1]->time_precision()); + THD *thd= current_thd; + uint dec= MY_MAX(item->arguments()[0]->time_precision(thd), + item->arguments()[1]->time_precision(thd)); item->fix_attributes_time(dec); return false; } - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { DBUG_ASSERT(item->is_fixed()); MYSQL_TIME l_time2; - Time t(item->arguments()[0]); + Time t(thd, item->arguments()[0]); return (item->null_value= (!t.is_valid_time() || - item->arguments()[1]->get_time(&l_time2) || + item->arguments()[1]->get_time(current_thd, &l_time2) || Sec6_add(t.get_mysql_time(), &l_time2, m_sign). - to_time(to, item->decimals))); + to_time(thd, to, item->decimals))); } }; @@ -1608,17 +1624,18 @@ public: item->fix_char_length_temporal_not_fixed_dec(MAX_DATETIME_WIDTH, dec); return false; } - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { DBUG_ASSERT(item->is_fixed()); // Detect a proper timestamp type based on the argument values MYSQL_TIME l_time1, l_time2; - if (item->arguments()[0]->get_time(&l_time1) || - item->arguments()[1]->get_time(&l_time2)) + if (item->arguments()[0]->get_time(thd, &l_time1) || + item->arguments()[1]->get_time(thd, &l_time2)) return (item->null_value= true); Sec6_add add(&l_time1, &l_time2, m_sign); return (item->null_value= (l_time1.time_type == MYSQL_TIMESTAMP_TIME ? - add.to_time(to, item->decimals) : + add.to_time(thd, to, item->decimals) : add.to_datetime(to))); } }; @@ -1633,10 +1650,11 @@ public: item->fix_attributes_datetime(0); return false; } - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { return static_cast<Item_func_str_to_date*>(item)-> - get_date_common(to, fuzzy, MYSQL_TIMESTAMP_DATETIME); + get_date_common(thd, to, fuzzy, MYSQL_TIMESTAMP_DATETIME); } }; @@ -1650,10 +1668,11 @@ public: item->fix_attributes_datetime(TIME_SECOND_PART_DIGITS); return false; } - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { return static_cast<Item_func_str_to_date*>(item)-> - get_date_common(to, fuzzy, MYSQL_TIMESTAMP_DATETIME); + get_date_common(thd, to, fuzzy, MYSQL_TIMESTAMP_DATETIME); } }; @@ -1661,10 +1680,11 @@ public: class Func_handler_str_to_date_date: public Item_handled_func::Handler_date { public: - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { return static_cast<Item_func_str_to_date*>(item)-> - get_date_common(to, fuzzy, MYSQL_TIMESTAMP_DATE); + get_date_common(thd, to, fuzzy, MYSQL_TIMESTAMP_DATE); } }; @@ -1672,10 +1692,11 @@ public: class Func_handler_str_to_date_time: public Item_handled_func::Handler_time { public: - bool get_date(Item_handled_func *item, MYSQL_TIME *to, ulonglong fuzzy) const + bool get_date(THD *thd, Item_handled_func *item, + MYSQL_TIME *to, date_mode_t fuzzy) const { if (static_cast<Item_func_str_to_date*>(item)-> - get_date_common(to, fuzzy, MYSQL_TIMESTAMP_TIME)) + get_date_common(thd, to, fuzzy, MYSQL_TIMESTAMP_TIME)) return true; if (to->day) { diff --git a/sql/item_vers.cc b/sql/item_vers.cc index d7361f687f9..6946ae0e1e5 100644 --- a/sql/item_vers.cc +++ b/sql/item_vers.cc @@ -37,9 +37,8 @@ Item_func_trt_ts::Item_func_trt_ts(THD *thd, Item* a, TR_table::field_id_t _trt_ bool -Item_func_trt_ts::get_date(MYSQL_TIME *res, ulonglong fuzzy_date) +Item_func_trt_ts::get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) { - THD *thd= current_thd; // can it differ from constructor's? DBUG_ASSERT(thd); DBUG_ASSERT(args[0]); if (args[0]->result_type() != INT_RESULT) @@ -67,7 +66,7 @@ Item_func_trt_ts::get_date(MYSQL_TIME *res, ulonglong fuzzy_date) return true; } - return trt[trt_field]->get_date(res, fuzzy_date); + return trt[trt_field]->get_date(res, fuzzydate); } @@ -143,7 +142,7 @@ Item_func_trt_id::val_int() else { MYSQL_TIME commit_ts; - if (args[0]->get_date(&commit_ts, 0)) + if (args[0]->get_date(current_thd, &commit_ts, date_mode_t(0))) { null_value= true; return 0; diff --git a/sql/item_vers.h b/sql/item_vers.h index 8b9c0e6056c..a42b5a033f2 100644 --- a/sql/item_vers.h +++ b/sql/item_vers.h @@ -35,7 +35,7 @@ public: } return "trt_commit_ts"; } - bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); + bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); Item *get_copy(THD *thd) { return get_item_copy<Item_func_trt_ts>(thd, this); } bool fix_length_and_dec() diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index a17f9482ea0..764a8b26c3e 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -439,12 +439,12 @@ Item_sum_hybrid_simple::val_str(String *str) return retval; } -bool Item_sum_hybrid_simple::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +bool Item_sum_hybrid_simple::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { DBUG_ASSERT(fixed == 1); if (null_value) return true; - bool retval= value->get_date(ltime, fuzzydate); + bool retval= value->get_date(thd, ltime, fuzzydate); if ((null_value= value->null_value)) DBUG_ASSERT(retval == true); return retval; diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index b3e23748246..5fd48af8f51 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -319,7 +319,7 @@ class Item_sum_hybrid_simple : public Item_sum, my_decimal *val_decimal(my_decimal *); void reset_field(); String *val_str(String *); - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); const Type_handler *type_handler() const { return Type_handler_hybrid_field_type::type_handler(); } void update_field(); @@ -1272,7 +1272,7 @@ public: return res; } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { bool res; if (force_return_blank) @@ -1289,7 +1289,7 @@ public: } else { - res= window_func()->get_date(ltime, fuzzydate); + res= window_func()->get_date(thd, ltime, fuzzydate); null_value= window_func()->null_value; } return res; diff --git a/sql/my_decimal.h b/sql/my_decimal.h index d035641cfa6..f0bb69c60c8 100644 --- a/sql/my_decimal.h +++ b/sql/my_decimal.h @@ -29,6 +29,8 @@ #ifndef my_decimal_h #define my_decimal_h +#include "sql_basic_types.h" + #if defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY) #include "sql_string.h" /* String */ #endif @@ -215,7 +217,7 @@ public: { return check_result(mask, decimal_round(this, to, (int) scale, mode)); } - bool to_datetime_with_warn(MYSQL_TIME *to, ulonglong fuzzydate, + bool to_datetime_with_warn(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate, const char *field_name); int to_binary(uchar *bin, int prec, int scale, uint mask= E_DEC_FATAL_ERROR) const; diff --git a/sql/partition_info.h b/sql/partition_info.h index e00a2c44341..a0cde570d03 100644 --- a/sql/partition_info.h +++ b/sql/partition_info.h @@ -394,12 +394,13 @@ public: bool has_unique_name(partition_element *element); bool vers_init_info(THD *thd); - bool vers_set_interval(Item *item, interval_type int_type, my_time_t start) + bool vers_set_interval(THD *thd, Item *item, + interval_type int_type, my_time_t start) { DBUG_ASSERT(part_type == VERSIONING_PARTITION); vers_info->interval.type= int_type; vers_info->interval.start= start; - return get_interval_value(item, int_type, &vers_info->interval.step) || + return get_interval_value(thd, item, int_type, &vers_info->interval.step) || vers_info->interval.step.neg || vers_info->interval.step.second_part || !(vers_info->interval.step.year || vers_info->interval.step.month || vers_info->interval.step.day || vers_info->interval.step.hour || diff --git a/sql/procedure.h b/sql/procedure.h index 8826b397fb2..2169091c0a6 100644 --- a/sql/procedure.h +++ b/sql/procedure.h @@ -69,9 +69,9 @@ public: DBUG_ASSERT(0); // impossible return mark_unsupported_function("proc", arg, VCOL_IMPOSSIBLE); } - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - return type_handler()->Item_get_date(this, ltime, fuzzydate); + return type_handler()->Item_get_date(thd, this, ltime, fuzzydate); } Item* get_copy(THD *thd) { return 0; } }; diff --git a/sql/sql_basic_types.h b/sql/sql_basic_types.h index 1e97262cdf0..132393c1b29 100644 --- a/sql/sql_basic_types.h +++ b/sql/sql_basic_types.h @@ -22,4 +22,81 @@ typedef ulonglong sql_mode_t; typedef int64 query_id_t; + + +/* + "fuzzydate" with strict data type control. + Please keep "explicit" in constructors and conversion methods. +*/ +class date_mode_t +{ +public: + enum value_t + { + FUZZY_DATES= 1U, // C_TIME_FUZZY_DATES + TIME_ONLY= 4U, // C_TIME_TIME_ONLY + NO_ZERO_IN_DATE= (1UL << 23), // MODE_NO_ZERO_IN_DATE + NO_ZERO_DATE= (1UL << 24), // MODE_NO_ZERO_DATE + INVALID_DATES= (1UL << 25) // MODE_INVALID_DATES + }; + +private: + value_t m_mode; +public: + + // Constructors + explicit date_mode_t(ulonglong fuzzydate) + :m_mode((value_t) fuzzydate) + { } + + // Conversion operators + explicit operator ulonglong() const + { + return m_mode; + } + explicit operator bool() const + { + return m_mode != 0; + } + + // Unary operators + date_mode_t operator~() const + { + return date_mode_t(~m_mode); + } + + // Dyadic bitwise operators + date_mode_t operator&(const date_mode_t &other) const + { + return date_mode_t(m_mode & other.m_mode); + } + + date_mode_t operator|(const date_mode_t &other) const + { + return date_mode_t(m_mode | other.m_mode); + } + + // Dyadic bitwise assignment operators + date_mode_t &operator&=(const date_mode_t &other) + { + m_mode= value_t(m_mode & other.m_mode); + return *this; + } + + date_mode_t &operator|=(const date_mode_t &other) + { + m_mode= value_t(m_mode | other.m_mode); + return *this; + } +}; + + +const date_mode_t + TIME_FUZZY_DATES (date_mode_t::value_t::FUZZY_DATES), + TIME_TIME_ONLY (date_mode_t::value_t::TIME_ONLY), + TIME_NO_ZERO_IN_DATE (date_mode_t::value_t::NO_ZERO_IN_DATE), + TIME_NO_ZERO_DATE (date_mode_t::value_t::NO_ZERO_DATE), + TIME_INVALID_DATES (date_mode_t::value_t::INVALID_DATES); + + #endif diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 0bbfdba88c7..7f64a45fac4 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -7696,7 +7696,7 @@ Query_arena_stmt::~Query_arena_stmt() bool THD::timestamp_to_TIME(MYSQL_TIME *ltime, my_time_t ts, - ulong sec_part, ulonglong fuzzydate) + ulong sec_part, date_mode_t fuzzydate) { time_zone_used= 1; if (ts == 0 && sec_part == 0) diff --git a/sql/sql_class.h b/sql/sql_class.h index 30622fde577..ff7ef16a9ed 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3410,7 +3410,7 @@ public: } const Type_handler *type_handler_for_date() const; bool timestamp_to_TIME(MYSQL_TIME *ltime, my_time_t ts, - ulong sec_part, ulonglong fuzzydate); + ulong sec_part, date_mode_t fuzzydate); inline my_time_t query_start() { return start_time; } inline ulong query_start_sec_part() { query_start_sec_part_used=1; return start_time_sec_part; } @@ -4952,10 +4952,17 @@ my_eof(THD *thd) (A)->variables.sql_log_bin_off= 0;} -inline sql_mode_t sql_mode_for_dates(THD *thd) +inline date_mode_t sql_mode_for_dates(THD *thd) { - return thd->variables.sql_mode & - (MODE_NO_ZERO_DATE | MODE_NO_ZERO_IN_DATE | MODE_INVALID_DATES); + static_assert(C_TIME_FUZZY_DATES == date_mode_t::FUZZY_DATES && + C_TIME_TIME_ONLY == date_mode_t::TIME_ONLY, + "sql_mode_t and pure C library date flags must be equal"); + static_assert(MODE_NO_ZERO_DATE == date_mode_t::NO_ZERO_DATE && + MODE_NO_ZERO_IN_DATE == date_mode_t::NO_ZERO_IN_DATE && + MODE_INVALID_DATES == date_mode_t::INVALID_DATES, + "sql_mode_t and date_mode_t values must be equal"); + return date_mode_t(thd->variables.sql_mode & + (MODE_NO_ZERO_DATE | MODE_NO_ZERO_IN_DATE | MODE_INVALID_DATES)); } /* diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 3133b94fa5b..67e792ca5ab 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1559,7 +1559,7 @@ static bool check_vers_constants(THD *thd, partition_info *part_info) my_tz_OFFSET0->gmt_sec_to_TIME(<ime, vers_info->interval.start); while ((el= it++)->id < hist_parts) { - if (date_add_interval(<ime, vers_info->interval.type, + if (date_add_interval(thd, <ime, vers_info->interval.type, vers_info->interval.step)) goto err; uint error= 0; @@ -8205,7 +8205,7 @@ static int get_part_iter_for_interval_via_mapping(partition_info *part_info, field->type() == MYSQL_TYPE_DATETIME)) { /* Monotonic, but return NULL for dates with zeros in month/day. */ - zero_in_start_date= field->get_date(&start_date, 0); + zero_in_start_date= field->get_date(&start_date, date_mode_t(0)); DBUG_PRINT("info", ("zero start %u %04d-%02d-%02d", zero_in_start_date, start_date.year, start_date.month, start_date.day)); @@ -8229,7 +8229,7 @@ static int get_part_iter_for_interval_via_mapping(partition_info *part_info, !part_info->part_expr->null_value) { MYSQL_TIME end_date; - bool zero_in_end_date= field->get_date(&end_date, 0); + bool zero_in_end_date= field->get_date(&end_date, date_mode_t(0)); /* This is an optimization for TO_DAYS()/TO_SECONDS() to avoid scanning the NULL partition for ranges that cannot include a date with 0 as diff --git a/sql/sql_time.cc b/sql/sql_time.cc index c3e1b7c28f4..469096ffa52 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -289,14 +289,14 @@ ulong convert_month_to_period(ulong month) bool -check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date, +check_date_with_warn(THD *thd, const MYSQL_TIME *ltime, date_mode_t fuzzydate, timestamp_type ts_type) { int unused; - if (check_date(ltime, fuzzy_date, &unused)) + if (check_date(ltime, ulonglong(fuzzydate), &unused)) { ErrConvTime str(ltime); - make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, + make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN, &str, ts_type, 0); return true; } @@ -305,7 +305,7 @@ check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date, bool -adjust_time_range_with_warn(MYSQL_TIME *ltime, uint dec) +adjust_time_range_with_warn(THD *thd, MYSQL_TIME *ltime, uint dec) { MYSQL_TIME copy= *ltime; ErrConvTime str(©); @@ -313,7 +313,7 @@ adjust_time_range_with_warn(MYSQL_TIME *ltime, uint dec) if (check_time_range(ltime, dec, &warnings)) return true; if (warnings) - current_thd->push_warning_truncated_wrong_value("time", str.ptr()); + thd->push_warning_truncated_wrong_value("time", str.ptr()); return false; } @@ -374,20 +374,20 @@ public: /* Character set-aware version of str_to_time() */ bool Temporal::str_to_time(MYSQL_TIME_STATUS *status, const char *str, size_t length, CHARSET_INFO *cs, - sql_mode_t fuzzydate) + date_mode_t fuzzydate) { TemporalAsciiBuffer tmp(str, length, cs); - return ::str_to_time(tmp.str, tmp.length, this, fuzzydate, status); + return ::str_to_time(tmp.str, tmp.length, this, ulonglong(fuzzydate), status); } /* Character set-aware version of str_to_datetime() */ bool Temporal::str_to_datetime(MYSQL_TIME_STATUS *status, const char *str, size_t length, CHARSET_INFO *cs, - sql_mode_t flags) + date_mode_t flags) { TemporalAsciiBuffer tmp(str, length, cs); - return ::str_to_datetime(tmp.str, tmp.length, this, flags, status); + return ::str_to_datetime(tmp.str, tmp.length, this, ulonglong(flags), status); } @@ -400,14 +400,14 @@ bool Temporal::str_to_datetime(MYSQL_TIME_STATUS *status, */ bool -str_to_datetime_with_warn(CHARSET_INFO *cs, +str_to_datetime_with_warn(THD *thd, CHARSET_INFO *cs, const char *str, size_t length, MYSQL_TIME *l_time, - ulonglong flags) + date_mode_t flags) { MYSQL_TIME_STATUS status; - THD *thd= current_thd; TemporalAsciiBuffer tmp(str, length, cs); - bool ret_val= str_to_datetime(tmp.str, tmp.length, l_time, flags, &status); + bool ret_val= str_to_datetime(tmp.str, tmp.length, l_time, + ulonglong(flags), &status); if (ret_val || status.warnings) { const ErrConvString err(str, length, &my_charset_bin); @@ -424,28 +424,32 @@ str_to_datetime_with_warn(CHARSET_INFO *cs, } -bool double_to_datetime_with_warn(double value, MYSQL_TIME *ltime, - ulonglong fuzzydate, const char *field_name) +bool double_to_datetime_with_warn(THD *thd, double value, MYSQL_TIME *ltime, + date_mode_t fuzzydate, const char *field_name) { const ErrConvDouble str(value); - return Sec6(value).convert_to_mysql_time(ltime, fuzzydate, &str, field_name); + return Sec6(value).convert_to_mysql_time(thd, ltime, fuzzydate, + &str, field_name); } -bool decimal_to_datetime_with_warn(const my_decimal *value, MYSQL_TIME *ltime, - ulonglong fuzzydate, const char *field_name) +bool decimal_to_datetime_with_warn(THD *thd, const my_decimal *value, + MYSQL_TIME *ltime, + date_mode_t fuzzydate, const char *field_name) { const ErrConvDecimal str(value); - return Sec6(value).convert_to_mysql_time(ltime, fuzzydate, &str, field_name); + return Sec6(value).convert_to_mysql_time(thd, ltime, fuzzydate, + &str, field_name); } -bool int_to_datetime_with_warn(bool neg, ulonglong value, MYSQL_TIME *ltime, - ulonglong fuzzydate, const char *field_name) +bool int_to_datetime_with_warn(THD *thd, bool neg, ulonglong value, + MYSQL_TIME *ltime, + date_mode_t fuzzydate, const char *field_name) { const ErrConvInteger str(neg ? - (longlong) value : (longlong) value, !neg); Sec6 sec(neg, value, 0); - return sec.convert_to_mysql_time(ltime, fuzzydate, &str, field_name); + return sec.convert_to_mysql_time(thd, ltime, fuzzydate, &str, field_name); } @@ -902,7 +906,7 @@ void make_truncated_value_warning(THD *thd, (X)->second_part) #define GET_PART(X, N) X % N ## LL; X/= N ## LL -bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, +bool date_add_interval(THD *thd, MYSQL_TIME *ltime, interval_type int_type, const INTERVAL &interval) { long period, sign; @@ -1017,7 +1021,6 @@ bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, invalid_date: { - THD *thd= current_thd; push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_DATETIME_FUNCTION_OVERFLOW, ER_THD(thd, ER_DATETIME_FUNCTION_OVERFLOW), @@ -1106,7 +1109,7 @@ calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, - int l_sign, MYSQL_TIME *l_time3, ulonglong fuzzydate) + int l_sign, MYSQL_TIME *l_time3, date_mode_t fuzzydate) { ulonglong seconds; ulong microseconds; @@ -1323,7 +1326,7 @@ time_to_datetime(THD *thd, const MYSQL_TIME *from, MYSQL_TIME *to) bool time_to_datetime_with_warn(THD *thd, const MYSQL_TIME *from, MYSQL_TIME *to, - ulonglong fuzzydate) + date_mode_t fuzzydate) { int warn= 0; DBUG_ASSERT(from->time_type == MYSQL_TIMESTAMP_TIME); @@ -1336,7 +1339,7 @@ time_to_datetime_with_warn(THD *thd, */ if (time_to_datetime(thd, from, to) || ((thd->variables.old_behavior & OLD_MODE_ZERO_DATE_TIME_CAST) && - check_date(to, fuzzydate, &warn))) + check_date(to, ulonglong(fuzzydate), &warn))) { ErrConvTime str(from); thd->push_warning_truncated_wrong_value("datetime", str.ptr()); @@ -1389,8 +1392,9 @@ void unpack_time(longlong packed, MYSQL_TIME *my_time, } -bool my_decimal::to_datetime_with_warn(MYSQL_TIME *to, ulonglong fuzzydate, +bool my_decimal::to_datetime_with_warn(THD *thd, MYSQL_TIME *to, + date_mode_t fuzzydate, const char *field_name) { - return decimal_to_datetime_with_warn(this, to, fuzzydate, field_name); + return decimal_to_datetime_with_warn(thd, this, to, fuzzydate, field_name); } diff --git a/sql/sql_time.h b/sql/sql_time.h index 0966dacf4f8..f9edf661240 100644 --- a/sql/sql_time.h +++ b/sql/sql_time.h @@ -17,6 +17,7 @@ #ifndef SQL_TIME_INCLUDED #define SQL_TIME_INCLUDED +#include "sql_basic_types.h" #include "my_time.h" #include "mysql_time.h" /* timestamp_type */ #include "sql_error.h" /* Sql_condition */ @@ -38,22 +39,26 @@ bool time_to_datetime(MYSQL_TIME *ltime); void time_to_daytime_interval(MYSQL_TIME *l_time); bool get_date_from_daynr(long daynr,uint *year, uint *month, uint *day); my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, uint *error_code); -bool str_to_datetime_with_warn(CHARSET_INFO *cs, const char *str, size_t length, MYSQL_TIME *l_time, - ulonglong flags); -bool double_to_datetime_with_warn(double value, MYSQL_TIME *ltime, - ulonglong fuzzydate, +bool str_to_datetime_with_warn(THD *thd, + CHARSET_INFO *cs, const char *str, size_t length, + MYSQL_TIME *l_time, + date_mode_t flags); +bool double_to_datetime_with_warn(THD *thd, double value, MYSQL_TIME *ltime, + date_mode_t fuzzydate, const char *name); -bool decimal_to_datetime_with_warn(const my_decimal *value, MYSQL_TIME *ltime, - ulonglong fuzzydate, +bool decimal_to_datetime_with_warn(THD *thd, + const my_decimal *value, MYSQL_TIME *ltime, + date_mode_t fuzzydate, const char *name); -bool int_to_datetime_with_warn(bool neg, ulonglong value, MYSQL_TIME *ltime, - ulonglong fuzzydate, +bool int_to_datetime_with_warn(THD *thd, bool neg, ulonglong value, + MYSQL_TIME *ltime, + date_mode_t fuzzydate, const char *name); bool time_to_datetime(THD *thd, const MYSQL_TIME *tm, MYSQL_TIME *dt); bool time_to_datetime_with_warn(THD *thd, const MYSQL_TIME *tm, MYSQL_TIME *dt, - ulonglong fuzzydate); + date_mode_t fuzzydate); inline void datetime_to_date(MYSQL_TIME *ltime) { @@ -86,7 +91,7 @@ const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format, bool my_TIME_to_str(const MYSQL_TIME *ltime, String *str, uint dec); /* MYSQL_TIME operations */ -bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, +bool date_add_interval(THD *thd, MYSQL_TIME *ltime, interval_type int_type, const INTERVAL &interval); bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, int l_sign, ulonglong *seconds_out, ulong *microseconds_out); @@ -115,7 +120,7 @@ int append_interval(String *str, interval_type int_type, @return false - otherwise */ bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, - int lsign, MYSQL_TIME *l_time3, ulonglong fuzzydate); + int lsign, MYSQL_TIME *l_time3, date_mode_t fuzzydate); int my_time_compare(const MYSQL_TIME *a, const MYSQL_TIME *b); void localtime_to_TIME(MYSQL_TIME *to, struct tm *from); @@ -166,9 +171,9 @@ check_date(const MYSQL_TIME *ltime, ulonglong flags, int *was_cut) { return check_date(ltime, non_zero_date(ltime), flags, was_cut); } -bool check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date, +bool check_date_with_warn(THD *thd, const MYSQL_TIME *ltime, date_mode_t fuzzy_date, timestamp_type ts_type); -bool adjust_time_range_with_warn(MYSQL_TIME *ltime, uint dec); +bool adjust_time_range_with_warn(THD *thd, MYSQL_TIME *ltime, uint dec); longlong pack_time(const MYSQL_TIME *my_time); void unpack_time(longlong packed, MYSQL_TIME *my_time, diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 31a066271db..8a6022ae5de 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -154,10 +154,10 @@ VDec_op::VDec_op(Item_func_hybrid_field_type *item) } -bool Dec_ptr::to_datetime_with_warn(MYSQL_TIME *to, ulonglong fuzzydate, - Item *item) +bool Dec_ptr::to_datetime_with_warn(THD *thd, MYSQL_TIME *to, + date_mode_t fuzzydate, Item *item) { - if (to_datetime_with_warn(to, fuzzydate, item->field_name_or_null())) + if (to_datetime_with_warn(thd, to, fuzzydate, item->field_name_or_null())) return item->null_value|= item->make_zero_date(to, fuzzydate); return item->null_value= false; } @@ -178,7 +178,7 @@ my_decimal *Temporal::bad_to_decimal(my_decimal *to) const Temporal_hybrid::Temporal_hybrid(THD *thd, Item *item) { - if (item->get_date(this, sql_mode_for_dates(thd))) + if (item->get_date(thd, this, sql_mode_for_dates(thd))) time_type= MYSQL_TIMESTAMP_NONE; } @@ -211,42 +211,39 @@ void Sec6::make_truncated_warning(THD *thd, const char *type_str) const { char buff[1 + MAX_BIGINT_WIDTH + 1 + 6 + 1]; // '-' int '.' frac '\0' to_string(buff, sizeof(buff)); - current_thd->push_warning_truncated_wrong_value(type_str, buff); + thd->push_warning_truncated_wrong_value(type_str, buff); } -bool Sec6::convert_to_mysql_time(MYSQL_TIME *ltime, ulonglong fuzzydate, - const ErrConv *str, const char *field_name) - const +bool Sec6::convert_to_mysql_time(THD *thd, MYSQL_TIME *ltime, + date_mode_t fuzzydate, const ErrConv *str, + const char *field_name) const { int warn; - bool is_time= fuzzydate & TIME_TIME_ONLY; + bool is_time= bool(fuzzydate & TIME_TIME_ONLY); const char *typestr= is_time ? "time" : "datetime"; bool rc= is_time ? to_time(ltime, &warn) : to_datetime(ltime, fuzzydate, &warn); if (truncated()) { // The value was already truncated at the constructor call time - current_thd-> - push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN, - !is_time, typestr, - str->ptr(), field_name); + thd->push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN, + !is_time, typestr, + str->ptr(), field_name); } else if (rc || MYSQL_TIME_WARN_HAVE_WARNINGS(warn)) - current_thd-> - push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN, - rc, typestr, str->ptr(), - field_name); + thd->push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN, + rc, typestr, str->ptr(), + field_name); else if (MYSQL_TIME_WARN_HAVE_NOTES(warn)) - current_thd-> - push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_NOTE, - rc, typestr, str->ptr(), - field_name); + thd->push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_NOTE, + rc, typestr, str->ptr(), + field_name); return rc; } -VSec6::VSec6(Item *item, const char *type_str, ulonglong limit) +VSec6::VSec6(THD *thd, Item *item, const char *type_str, ulonglong limit) { if (item->decimals == 0) { // optimize for an important special case @@ -258,7 +255,7 @@ VSec6::VSec6(Item *item, const char *type_str, ulonglong limit) m_sec= limit; m_truncated= true; ErrConvInteger err(nr, item->unsigned_flag); - current_thd->push_warning_truncated_wrong_value(type_str, err.ptr()); + thd->push_warning_truncated_wrong_value(type_str, err.ptr()); } } else if (item->cmp_type() == REAL_RESULT) @@ -274,7 +271,7 @@ VSec6::VSec6(Item *item, const char *type_str, ulonglong limit) if (m_truncated) { ErrConvDouble err(nr); - current_thd->push_warning_truncated_wrong_value(type_str, err.ptr()); + thd->push_warning_truncated_wrong_value(type_str, err.ptr()); } } else @@ -289,7 +286,7 @@ VSec6::VSec6(Item *item, const char *type_str, ulonglong limit) if (m_truncated) { ErrConvDecimal err(tmp.ptr()); - current_thd->push_warning_truncated_wrong_value(type_str, err.ptr()); + thd->push_warning_truncated_wrong_value(type_str, err.ptr()); } } } @@ -334,13 +331,13 @@ VYear_op::VYear_op(Item_func_hybrid_field_type *item) { } -void Time::make_from_item(int *warn, Item *item, const Options opt) +void Time::make_from_item(THD *thd, int *warn, Item *item, const Options opt) { *warn= 0; - if (item->get_date(this, opt.get_date_flags())) + if (item->get_date(thd, this, opt.get_date_flags())) time_type= MYSQL_TIMESTAMP_NONE; else - valid_MYSQL_TIME_to_valid_value(warn, opt); + valid_MYSQL_TIME_to_valid_value(thd, warn, opt); } @@ -449,7 +446,7 @@ Time::Time(int *warn, const MYSQL_TIME *from, long curdays) } -void Temporal_with_date::make_from_item(THD *thd, Item *item, sql_mode_t flags) +void Temporal_with_date::make_from_item(THD *thd, Item *item, date_mode_t flags) { flags&= ~TIME_TIME_ONLY; /* @@ -459,10 +456,10 @@ void Temporal_with_date::make_from_item(THD *thd, Item *item, sql_mode_t flags) In the legacy time->datetime conversion mode we do not add TIME_TIME_ONLY and leave it to get_date() to check date. */ - ulonglong time_flag= (item->field_type() == MYSQL_TYPE_TIME && - !(thd->variables.old_behavior & OLD_MODE_ZERO_DATE_TIME_CAST)) ? - TIME_TIME_ONLY : 0; - if (item->get_date(this, flags | time_flag)) + date_mode_t time_flag= (item->field_type() == MYSQL_TYPE_TIME && + !(thd->variables.old_behavior & OLD_MODE_ZERO_DATE_TIME_CAST)) ? + TIME_TIME_ONLY : date_mode_t(0); + if (item->get_date(thd, this, flags | time_flag)) time_type= MYSQL_TIMESTAMP_NONE; else if (time_type == MYSQL_TIMESTAMP_TIME) { @@ -481,15 +478,15 @@ void Temporal_with_date::make_from_item(THD *thd, Item *item) } -void Temporal_with_date::check_date_or_invalidate(int *warn, sql_mode_t flags) +void Temporal_with_date::check_date_or_invalidate(int *warn, date_mode_t flags) { - if (check_date(this, pack_time(this) != 0, flags, warn)) + if (check_date(this, pack_time(this) != 0, ulonglong(flags), warn)) time_type= MYSQL_TIMESTAMP_NONE; } void Datetime::make_from_time(THD *thd, int *warn, const MYSQL_TIME *from, - sql_mode_t flags) + date_mode_t flags) { DBUG_ASSERT(from->time_type == MYSQL_TIMESTAMP_TIME); if (time_to_datetime(thd, from, this)) @@ -503,7 +500,7 @@ void Datetime::make_from_time(THD *thd, int *warn, const MYSQL_TIME *from, void Datetime::make_from_datetime(THD *thd, int *warn, const MYSQL_TIME *from, - sql_mode_t flags) + date_mode_t flags) { DBUG_ASSERT(from->time_type == MYSQL_TIMESTAMP_DATE || from->time_type == MYSQL_TIMESTAMP_DATETIME); @@ -520,9 +517,9 @@ void Datetime::make_from_datetime(THD *thd, int *warn, const MYSQL_TIME *from, Datetime::Datetime(THD *thd, int *warn, const MYSQL_TIME *from, - sql_mode_t flags) + date_mode_t flags) { - DBUG_ASSERT((flags & TIME_TIME_ONLY) == 0); + DBUG_ASSERT(bool(flags & TIME_TIME_ONLY) == false); switch (from->time_type) { case MYSQL_TIMESTAMP_ERROR: case MYSQL_TIMESTAMP_NONE: @@ -3004,14 +3001,14 @@ void Type_handler_row::Item_update_null_value(Item *item) const void Type_handler_time_common::Item_update_null_value(Item *item) const { MYSQL_TIME ltime; - (void) item->get_date(<ime, TIME_TIME_ONLY); + (void) item->get_date(current_thd, <ime, TIME_TIME_ONLY); } void Type_handler_temporal_with_date::Item_update_null_value(Item *item) const { MYSQL_TIME ltime; - (void) item->get_date(<ime, sql_mode_for_dates(current_thd)); + (void) item->get_date(current_thd, <ime, sql_mode_for_dates(current_thd)); } @@ -3781,38 +3778,42 @@ bool Type_handler_string_result::Item_val_bool(Item *item) const /*************************************************************************/ -bool Type_handler_int_result::Item_get_date(Item *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const +bool Type_handler_int_result::Item_get_date(THD *thd, Item *item, + MYSQL_TIME *ltime, + date_mode_t fuzzydate) const { - return item->get_date_from_int(ltime, fuzzydate); + return item->get_date_from_int(thd, ltime, fuzzydate); } -bool Type_handler_year::Item_get_date(Item *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const +bool Type_handler_year::Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const { return item->null_value= - VYear(item).to_mysql_time_with_warn(ltime, fuzzydate, + VYear(item).to_mysql_time_with_warn(thd, ltime, fuzzydate, item->field_name_or_null()); } -bool Type_handler_real_result::Item_get_date(Item *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const +bool Type_handler_real_result::Item_get_date(THD *thd, Item *item, + MYSQL_TIME *ltime, + date_mode_t fuzzydate) const { - return item->get_date_from_real(ltime, fuzzydate); + return item->get_date_from_real(thd, ltime, fuzzydate); } -bool Type_handler_string_result::Item_get_date(Item *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const +bool Type_handler_string_result::Item_get_date(THD *thd, Item *item, + MYSQL_TIME *ltime, + date_mode_t fuzzydate) const { - return item->get_date_from_string(ltime, fuzzydate); + return item->get_date_from_string(thd, ltime, fuzzydate); } -bool Type_handler_temporal_result::Item_get_date(Item *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const +bool Type_handler_temporal_result::Item_get_date(THD *thd, Item *item, + MYSQL_TIME *ltime, + date_mode_t fuzzydate) const { DBUG_ASSERT(0); // Temporal type items must implement native get_date() item->null_value= true; @@ -3960,22 +3961,24 @@ Type_handler_decimal_result::Item_func_hybrid_field_type_val_decimal( bool Type_handler_decimal_result::Item_func_hybrid_field_type_get_date( + THD *thd, Item_func_hybrid_field_type *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { - return VDec_op(item).to_datetime_with_warn(ltime, fuzzydate, item); + return VDec_op(item).to_datetime_with_warn(thd, ltime, fuzzydate, item); } bool Type_handler_year::Item_func_hybrid_field_type_get_date( + THD *thd, Item_func_hybrid_field_type *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { return item->null_value= - VYear_op(item).to_mysql_time_with_warn(ltime, fuzzydate, NULL); + VYear_op(item).to_mysql_time_with_warn(thd, ltime, fuzzydate, NULL); } @@ -4020,11 +4023,12 @@ Type_handler_int_result::Item_func_hybrid_field_type_val_decimal( bool Type_handler_int_result::Item_func_hybrid_field_type_get_date( + THD *thd, Item_func_hybrid_field_type *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { - return item->get_date_from_int_op(ltime, fuzzydate); + return item->get_date_from_int_op(thd, ltime, fuzzydate); } @@ -4069,11 +4073,12 @@ Type_handler_real_result::Item_func_hybrid_field_type_val_decimal( bool Type_handler_real_result::Item_func_hybrid_field_type_get_date( + THD *thd, Item_func_hybrid_field_type *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { - return item->get_date_from_real_op(ltime, fuzzydate); + return item->get_date_from_real_op(thd, ltime, fuzzydate); } @@ -4117,11 +4122,12 @@ Type_handler_temporal_result::Item_func_hybrid_field_type_val_decimal( bool Type_handler_temporal_result::Item_func_hybrid_field_type_get_date( + THD *thd, Item_func_hybrid_field_type *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { - return item->date_op(ltime, fuzzydate); + return item->date_op(thd, ltime, fuzzydate); } @@ -4165,11 +4171,12 @@ Type_handler_time_common::Item_func_hybrid_field_type_val_decimal( bool Type_handler_time_common::Item_func_hybrid_field_type_get_date( + THD *thd, Item_func_hybrid_field_type *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { - return item->time_op(ltime); + return item->time_op(thd, ltime); } @@ -4213,11 +4220,12 @@ Type_handler_string_result::Item_func_hybrid_field_type_val_decimal( bool Type_handler_string_result::Item_func_hybrid_field_type_get_date( + THD *thd, Item_func_hybrid_field_type *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { - return item->get_date_from_str_op(ltime, fuzzydate); + return item->get_date_from_str_op(thd, ltime, fuzzydate); } /***************************************************************************/ @@ -4544,7 +4552,7 @@ double Type_handler_temporal_result:: Item_func_min_max_val_real(Item_func_min_max *func) const { MYSQL_TIME ltime; - if (func->get_date(<ime, 0)) + if (func->get_date(current_thd, <ime, date_mode_t(0))) return 0; return TIME_to_double(<ime); } @@ -4568,7 +4576,7 @@ longlong Type_handler_temporal_result:: Item_func_min_max_val_int(Item_func_min_max *func) const { MYSQL_TIME ltime; - if (func->get_date(<ime, 0)) + if (func->get_date(current_thd, <ime, date_mode_t(0))) return 0; return TIME_to_ulonglong(<ime); } @@ -4602,15 +4610,15 @@ my_decimal *Type_handler_temporal_result:: my_decimal *dec) const { MYSQL_TIME ltime; - if (func->get_date(<ime, 0)) + if (func->get_date(current_thd, <ime, date_mode_t(0))) return 0; return date2my_decimal(<ime, dec); } bool Type_handler_string_result:: - Item_func_min_max_get_date(Item_func_min_max *func, - MYSQL_TIME *ltime, ulonglong fuzzydate) const + Item_func_min_max_get_date(THD *thd, Item_func_min_max *func, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const { /* just like ::val_int() method of a string item can be called, @@ -4618,30 +4626,30 @@ bool Type_handler_string_result:: ::get_date() can be called for non-temporal values, for example, SELECT MONTH(GREATEST("2011-11-21", "2010-10-09")) */ - return func->get_date_from_string(ltime, fuzzydate); + return func->get_date_from_string(thd, ltime, fuzzydate); } bool Type_handler_numeric:: - Item_func_min_max_get_date(Item_func_min_max *func, - MYSQL_TIME *ltime, ulonglong fuzzydate) const + Item_func_min_max_get_date(THD *thd, Item_func_min_max *func, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const { - return Item_get_date(func, ltime, fuzzydate); + return Item_get_date(thd, func, ltime, fuzzydate); } bool Type_handler_temporal_result:: - Item_func_min_max_get_date(Item_func_min_max *func, - MYSQL_TIME *ltime, ulonglong fuzzydate) const + Item_func_min_max_get_date(THD *thd, Item_func_min_max *func, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const { - return func->get_date_native(ltime, fuzzydate); + return func->get_date_native(thd, ltime, fuzzydate); } bool Type_handler_time_common:: - Item_func_min_max_get_date(Item_func_min_max *func, - MYSQL_TIME *ltime, ulonglong fuzzydate) const + Item_func_min_max_get_date(THD *thd, Item_func_min_max *func, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const { - return func->get_time_native(ltime); + return func->get_time_native(thd, ltime); } /***************************************************************************/ @@ -5106,7 +5114,7 @@ bool Type_handler:: Item_time_typecast_fix_length_and_dec(Item_time_typecast *item) const { uint dec= item->decimals == NOT_FIXED_DEC ? - item->arguments()[0]->time_precision() : + item->arguments()[0]->time_precision(current_thd) : item->decimals; item->fix_attributes_temporal(MIN_TIME_WIDTH, dec); item->maybe_null= true; @@ -5128,7 +5136,7 @@ bool Type_handler:: const { uint dec= item->decimals == NOT_FIXED_DEC ? - item->arguments()[0]->datetime_precision() : + item->arguments()[0]->datetime_precision(current_thd) : item->decimals; item->fix_attributes_temporal(MAX_DATETIME_WIDTH, dec); item->maybe_null= true; @@ -5448,19 +5456,19 @@ bool Type_handler_string_result:: /***************************************************************************/ -uint Type_handler::Item_time_precision(Item *item) const +uint Type_handler::Item_time_precision(THD *thd, Item *item) const { return MY_MIN(item->decimals, TIME_SECOND_PART_DIGITS); } -uint Type_handler::Item_datetime_precision(Item *item) const +uint Type_handler::Item_datetime_precision(THD *thd, Item *item) const { return MY_MIN(item->decimals, TIME_SECOND_PART_DIGITS); } -uint Type_handler_string_result::Item_temporal_precision(Item *item, +uint Type_handler_string_result::Item_temporal_precision(THD *thd, Item *item, bool is_time) const { StringBuffer<64> buf; @@ -5469,7 +5477,7 @@ uint Type_handler_string_result::Item_temporal_precision(Item *item, DBUG_ASSERT(item->is_fixed()); if ((tmp= item->val_str(&buf)) && (is_time ? - Time(&status, tmp->ptr(), tmp->length(), tmp->charset(), + Time(thd, &status, tmp->ptr(), tmp->length(), tmp->charset(), Time::Options(TIME_TIME_ONLY, Time::DATETIME_TO_TIME_YYYYMMDD_TRUNCATE)). is_valid_time() : @@ -5664,7 +5672,7 @@ bool Type_handler::check_null(const Item *item, st_value *value) const bool Type_handler_null:: - Item_save_in_value(Item *item, st_value *value) const + Item_save_in_value(THD *thd, Item *item, st_value *value) const { value->m_type= DYN_COL_NULL; return true; @@ -5672,7 +5680,7 @@ bool Type_handler_null:: bool Type_handler_row:: - Item_save_in_value(Item *item, st_value *value) const + Item_save_in_value(THD *thd, Item *item, st_value *value) const { DBUG_ASSERT(0); value->m_type= DYN_COL_NULL; @@ -5681,7 +5689,7 @@ bool Type_handler_row:: bool Type_handler_int_result:: - Item_save_in_value(Item *item, st_value *value) const + Item_save_in_value(THD *thd, Item *item, st_value *value) const { value->m_type= item->unsigned_flag ? DYN_COL_UINT : DYN_COL_INT; value->value.m_longlong= item->val_int(); @@ -5690,7 +5698,7 @@ bool Type_handler_int_result:: bool Type_handler_real_result:: - Item_save_in_value(Item *item, st_value *value) const + Item_save_in_value(THD *thd, Item *item, st_value *value) const { value->m_type= DYN_COL_DOUBLE; value->value.m_double= item->val_real(); @@ -5699,7 +5707,7 @@ bool Type_handler_real_result:: bool Type_handler_decimal_result:: - Item_save_in_value(Item *item, st_value *value) const + Item_save_in_value(THD *thd, Item *item, st_value *value) const { value->m_type= DYN_COL_DECIMAL; my_decimal *dec= item->val_decimal(&value->m_decimal); @@ -5710,7 +5718,7 @@ bool Type_handler_decimal_result:: bool Type_handler_string_result:: - Item_save_in_value(Item *item, st_value *value) const + Item_save_in_value(THD *thd, Item *item, st_value *value) const { value->m_type= DYN_COL_STRING; String *str= item->val_str(&value->m_string); @@ -5721,19 +5729,19 @@ bool Type_handler_string_result:: bool Type_handler_temporal_with_date:: - Item_save_in_value(Item *item, st_value *value) const + Item_save_in_value(THD *thd, Item *item, st_value *value) const { value->m_type= DYN_COL_DATETIME; - item->get_date(&value->value.m_time, sql_mode_for_dates(current_thd)); + item->get_date(thd, &value->value.m_time, sql_mode_for_dates(thd)); return check_null(item, value); } bool Type_handler_time_common:: - Item_save_in_value(Item *item, st_value *value) const + Item_save_in_value(THD *thd, Item *item, st_value *value) const { value->m_type= DYN_COL_DATETIME; - item->get_time(&value->value.m_time); + item->get_time(thd, &value->value.m_time); return check_null(item, value); } @@ -5917,7 +5925,8 @@ bool Type_handler:: bool Type_handler:: Item_send_datetime(Item *item, Protocol *protocol, st_value *buf) const { - item->get_date(&buf->value.m_time, sql_mode_for_dates(current_thd)); + item->get_date(protocol->thd, &buf->value.m_time, + sql_mode_for_dates(protocol->thd)); if (!item->null_value) return protocol->store(&buf->value.m_time, item->decimals); return protocol->store_null(); @@ -5927,7 +5936,8 @@ bool Type_handler:: bool Type_handler:: Item_send_date(Item *item, Protocol *protocol, st_value *buf) const { - item->get_date(&buf->value.m_time, sql_mode_for_dates(current_thd)); + item->get_date(protocol->thd, &buf->value.m_time, + sql_mode_for_dates(protocol->thd)); if (!item->null_value) return protocol->store_date(&buf->value.m_time); return protocol->store_null(); @@ -5937,7 +5947,7 @@ bool Type_handler:: bool Type_handler:: Item_send_time(Item *item, Protocol *protocol, st_value *buf) const { - item->get_time(&buf->value.m_time); + item->get_time(protocol->thd, &buf->value.m_time); if (!item->null_value) return protocol->store_time(&buf->value.m_time, item->decimals); return protocol->store_null(); @@ -5996,7 +6006,7 @@ Item *Type_handler_time_common:: make_const_item_for_comparison(THD *thd, Item *item, const Item *cmp) const { Item_cache_temporal *cache; - longlong value= item->val_time_packed(); + longlong value= item->val_time_packed(thd); if (item->null_value) return new (thd->mem_root) Item_null(thd, item->name.str); cache= new (thd->mem_root) Item_cache_time(thd); @@ -6010,7 +6020,7 @@ Item *Type_handler_temporal_with_date:: make_const_item_for_comparison(THD *thd, Item *item, const Item *cmp) const { Item_cache_temporal *cache; - longlong value= item->val_datetime_packed(); + longlong value= item->val_datetime_packed(thd); if (item->null_value) return new (thd->mem_root) Item_null(thd, item->name.str); cache= new (thd->mem_root) Item_cache_datetime(thd); @@ -7029,8 +7039,8 @@ bool Type_handler_time_common::Item_eq_value(THD *thd, const Type_cmp_attributes *attr, Item *a, Item *b) const { - longlong value0= a->val_time_packed(); - longlong value1= b->val_time_packed(); + longlong value0= a->val_time_packed(thd); + longlong value1= b->val_time_packed(thd); return !a->null_value && !b->null_value && value0 == value1; } @@ -7039,8 +7049,8 @@ bool Type_handler_temporal_with_date::Item_eq_value(THD *thd, const Type_cmp_attributes *attr, Item *a, Item *b) const { - longlong value0= a->val_datetime_packed(); - longlong value1= b->val_datetime_packed(); + longlong value0= a->val_datetime_packed(thd); + longlong value1= b->val_datetime_packed(thd); return !a->null_value && !b->null_value && value0 == value1; } @@ -7106,7 +7116,7 @@ int Type_handler_temporal_with_date::stored_field_cmp_to_item(THD *thd, { MYSQL_TIME field_time, item_time, item_time2, *item_time_cmp= &item_time; field->get_date(&field_time, TIME_INVALID_DATES); - item->get_date(&item_time, TIME_INVALID_DATES); + item->get_date(thd, &item_time, TIME_INVALID_DATES); if (item_time.time_type == MYSQL_TIMESTAMP_TIME && time_to_datetime(thd, &item_time, item_time_cmp= &item_time2)) return 1; @@ -7120,7 +7130,7 @@ int Type_handler_time_common::stored_field_cmp_to_item(THD *thd, { MYSQL_TIME field_time, item_time; field->get_time(&field_time); - item->get_time(&item_time); + item->get_time(thd, &item_time); return my_time_compare(&field_time, &item_time); } @@ -7257,7 +7267,7 @@ Type_handler_time_common::create_literal_item(THD *thd, MYSQL_TIME_STATUS st; Item_literal *item= NULL; Time::Options opt(TIME_TIME_ONLY, Time::DATETIME_TO_TIME_DISALLOW); - Time tmp(&st, str, length, cs, opt); + Time tmp(thd, &st, str, length, cs, opt); if (tmp.is_valid_time() && !have_important_literal_warnings(&st)) item= new (thd->mem_root) Item_time_literal(thd, tmp.get_mysql_time(), diff --git a/sql/sql_type.h b/sql/sql_type.h index f48d0c3af51..06cfb330097 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -113,13 +113,14 @@ public: longlong to_longlong(bool unsigned_flag) { return m_ptr ? m_ptr->to_longlong(unsigned_flag) : 0; } bool to_bool() const { return m_ptr ? m_ptr->to_bool() : false; } - bool to_datetime_with_warn(MYSQL_TIME *to, ulonglong fuzzydate, + bool to_datetime_with_warn(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate, const char *field_name) { - return m_ptr ? m_ptr->to_datetime_with_warn(to, fuzzydate, field_name) : + return m_ptr ? m_ptr->to_datetime_with_warn(thd, to, fuzzydate, field_name) : true; } - bool to_datetime_with_warn(MYSQL_TIME *to, ulonglong fuzzydate, Item *item); + bool to_datetime_with_warn(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate, + Item *item); String *to_string(String *to) const { return m_ptr ? m_ptr->to_string(to) : NULL; @@ -265,7 +266,7 @@ public: @param field_name field name or NULL if not a field. For the warning @returns false for success, true for a failure */ - bool convert_to_mysql_time(MYSQL_TIME *ltime, ulonglong fuzzydate, + bool convert_to_mysql_time(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate, const ErrConv *str, const char *field_name) const; // Convert a number in format hhhmmss.ff to TIME'hhh:mm:ss.ff' @@ -277,14 +278,14 @@ public: Convert a number in format YYYYMMDDhhmmss.ff to TIMESTAMP'YYYY-MM-DD hh:mm:ss.ff' */ - bool to_datetime(MYSQL_TIME *to, ulonglong flags, int *warn) const + bool to_datetime(MYSQL_TIME *to, date_mode_t flags, int *warn) const { if (m_neg) { *warn= MYSQL_TIME_WARN_OUT_OF_RANGE; return true; } - return number_to_datetime(m_sec, m_usec, to, flags, warn) == -1; + return number_to_datetime(m_sec, m_usec, to, ulonglong(flags), warn) == -1; } // Convert elapsed seconds to TIME bool sec_to_time(MYSQL_TIME *ltime, uint dec) const @@ -321,7 +322,7 @@ class VSec6: public Sec6 { bool m_is_null; public: - VSec6(Item *item, const char *type_str, ulonglong limit); + VSec6(THD *thd, Item *item, const char *type_str, ulonglong limit); bool is_null() const { return m_is_null; } }; @@ -364,13 +365,13 @@ public: m_neg= !m_neg; // Swap sign } } - bool to_time(MYSQL_TIME *ltime, uint decimals) const + bool to_time(THD *thd, MYSQL_TIME *ltime, uint decimals) const { if (m_error) return true; to_hh24mmssff(ltime, MYSQL_TIMESTAMP_TIME); ltime->hour+= to_days_abs() * 24; - return adjust_time_range_with_warn(ltime, decimals); + return adjust_time_range_with_warn(thd, ltime, decimals); } bool to_datetime(MYSQL_TIME *ltime) const { @@ -390,13 +391,13 @@ class Year protected: uint m_year; bool m_truncated; - bool to_mysql_time_with_warn(MYSQL_TIME *to, ulonglong fuzzydate, + bool to_mysql_time_with_warn(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate, const char *field_name) const { longlong value= m_year * 10000; // Make it YYYYMMDD const ErrConvInteger str(value, true); Sec6 sec(false, value, 0); - return sec.convert_to_mysql_time(to, fuzzydate, &str, field_name); + return sec.convert_to_mysql_time(thd, to, fuzzydate, &str, field_name); } uint year_precision(const Item *item) const; public: @@ -417,11 +418,11 @@ public: m_is_null(is_null) { } bool is_null() const { return m_is_null; } - bool to_mysql_time_with_warn(MYSQL_TIME *to, ulonglong fuzzydate, + bool to_mysql_time_with_warn(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate, const char *field_name) const { return m_is_null ? true : - Year::to_mysql_time_with_warn(to, fuzzydate, field_name); + Year::to_mysql_time_with_warn(thd, to, fuzzydate, field_name); } }; @@ -463,9 +464,9 @@ protected: time_type= MYSQL_TIMESTAMP_NONE; } bool str_to_time(MYSQL_TIME_STATUS *st, const char *str, size_t length, - CHARSET_INFO *cs, sql_mode_t fuzzydate); + CHARSET_INFO *cs, date_mode_t fuzzydate); bool str_to_datetime(MYSQL_TIME_STATUS *st, const char *str, size_t length, - CHARSET_INFO *cs, sql_mode_t fuzzydate); + CHARSET_INFO *cs, date_mode_t fuzzydate); public: static void *operator new(size_t size, MYSQL_TIME *ltime) throw() { @@ -490,9 +491,9 @@ class Temporal_hybrid: public Temporal { public: Temporal_hybrid(THD *thd, Item *item); - Temporal_hybrid(Item *item) { *this= Temporal_hybrid(current_thd, item); } + Temporal_hybrid(Item *item): Temporal_hybrid(current_thd, item) { } Temporal_hybrid(MYSQL_TIME_STATUS *st, const char *str, size_t length, - CHARSET_INFO *cs, sql_mode_t fuzzydate) + CHARSET_INFO *cs, date_mode_t fuzzydate) { if (str_to_datetime(st, str, length, cs, fuzzydate)) time_type= MYSQL_TIMESTAMP_NONE; @@ -560,22 +561,22 @@ public: }; class Options { - sql_mode_t m_get_date_flags; + date_mode_t m_get_date_flags; datetime_to_time_mode_t m_datetime_to_time_mode; public: Options() :m_get_date_flags(flags_for_get_date()), m_datetime_to_time_mode(DATETIME_TO_TIME_YYYYMMDD_000000DD_MIX_TO_HOURS) { } - Options(sql_mode_t flags) + Options(date_mode_t flags) :m_get_date_flags(flags), m_datetime_to_time_mode(DATETIME_TO_TIME_YYYYMMDD_000000DD_MIX_TO_HOURS) { } - Options(sql_mode_t flags, datetime_to_time_mode_t dtmode) + Options(date_mode_t flags, datetime_to_time_mode_t dtmode) :m_get_date_flags(flags), m_datetime_to_time_mode(dtmode) { } - sql_mode_t get_date_flags() const + date_mode_t get_date_flags() const { return m_get_date_flags; } datetime_to_time_mode_t datetime_to_time_mode() const { return m_datetime_to_time_mode; } @@ -631,7 +632,7 @@ private: { MYSQL_TIME current_date, tmp; set_current_date(thd, ¤t_date); - calc_time_diff(this, ¤t_date, 1, &tmp, 0); + calc_time_diff(this, ¤t_date, 1, &tmp, date_mode_t(0)); static_cast<MYSQL_TIME*>(this)[0]= tmp; int warnings= 0; (void) check_time_range(this, TIME_SECOND_PART_DIGITS, &warnings); @@ -643,7 +644,7 @@ private: e.g. returned from Item::get_date(), str_to_time(), number_to_time(). After this call, "this" is a valid TIME value. */ - void valid_datetime_to_valid_time(int *warn, const Options opt) + void valid_datetime_to_valid_time(THD *thd, int *warn, const Options opt) { DBUG_ASSERT(time_type == MYSQL_TIMESTAMP_DATE || time_type == MYSQL_TIMESTAMP_DATETIME); @@ -660,7 +661,7 @@ private: DBUG_ASSERT(hour < 24); if (opt.datetime_to_time_mode() == DATETIME_TO_TIME_MINUS_CURRENT_DATE) { - datetime_to_time_minus_current_date(current_thd); + datetime_to_time_minus_current_date(thd); } else { @@ -685,7 +686,7 @@ private: - either a valid TIME (within the supported TIME range), - or MYSQL_TIMESTAMP_NONE */ - void valid_MYSQL_TIME_to_valid_value(int *warn, const Options opt) + void valid_MYSQL_TIME_to_valid_value(THD *thd, int *warn, const Options opt) { switch (time_type) { case MYSQL_TIMESTAMP_DATE: @@ -697,7 +698,7 @@ private: else if (opt.datetime_to_time_mode() == DATETIME_TO_TIME_DISALLOW) make_from_out_of_range(warn); else - valid_datetime_to_valid_time(warn, opt); + valid_datetime_to_valid_time(thd, warn, opt); break; case MYSQL_TIMESTAMP_NONE: break; @@ -716,11 +717,11 @@ private: We trust that xxx_to_time() returns a valid TIME/DATE/DATETIME value, so here we need to do only simple validation. */ - void xxx_to_time_result_to_valid_value(int *warn, const Options opt) + void xxx_to_time_result_to_valid_value(THD *thd, int *warn, const Options opt) { // str_to_time(), number_to_time() never return MYSQL_TIMESTAMP_ERROR DBUG_ASSERT(time_type != MYSQL_TIMESTAMP_ERROR); - valid_MYSQL_TIME_to_valid_value(warn, opt); + valid_MYSQL_TIME_to_valid_value(thd, warn, opt); } void adjust_time_range_or_invalidate(int *warn) { @@ -733,7 +734,7 @@ private: long curdays); void make_from_time(int *warn, const MYSQL_TIME *from); void make_from_datetime(int *warn, const MYSQL_TIME *from, long curdays); - void make_from_item(int *warn, Item *item, const Options opt); + void make_from_item(THD *thd, int *warn, Item *item, const Options opt); public: /* All constructors that accept an "int *warn" parameter initialize *warn. @@ -741,63 +742,66 @@ public: */ Time() { time_type= MYSQL_TIMESTAMP_NONE; } Time(Item *item) + :Time(current_thd, item, Options()) + { } + Time(THD *thd, Item *item, const Options opt) { int warn; - make_from_item(&warn, item, Options()); - } - Time(Item *item, const Options opt) - { - int warn; - make_from_item(&warn, item, opt); + make_from_item(thd, &warn, item, opt); } + Time(THD *thd, Item *item) + :Time(thd, item, Options()) + { } Time(int *warn, const MYSQL_TIME *from, long curdays); - Time(MYSQL_TIME_STATUS *status, const char *str, size_t len, CHARSET_INFO *cs, + Time(THD *thd, MYSQL_TIME_STATUS *status, + const char *str, size_t len, CHARSET_INFO *cs, const Options opt) { if (str_to_time(status, str, len, cs, opt.get_date_flags())) time_type= MYSQL_TIMESTAMP_NONE; // The below call will optionally add notes to already collected warnings: - xxx_to_time_result_to_valid_value(&status->warnings, opt); + xxx_to_time_result_to_valid_value(thd, &status->warnings, opt); } - Time(int *warn, const Sec6 &nr, const Options opt) + Time(THD *thd, int *warn, const Sec6 &nr, const Options opt) { if (nr.to_time(this, warn)) time_type= MYSQL_TIMESTAMP_NONE; - xxx_to_time_result_to_valid_value(warn, opt); + xxx_to_time_result_to_valid_value(thd, warn, opt); } - Time(int *warn, double nr) - :Temporal(Time(warn, Sec6(nr), Options())) + Time(THD *thd, int *warn, double nr) + :Time(thd, warn, Sec6(nr), Options()) { } - Time(int *warn, longlong nr, bool unsigned_val) - :Temporal(Time(warn, Sec6(nr, unsigned_val), Options())) + Time(THD *thd, int *warn, longlong nr, bool unsigned_val) + :Time(thd, warn, Sec6(nr, unsigned_val), Options()) { } - Time(int *warn, const my_decimal *d) - :Temporal(Time(warn, Sec6(d), Options())) + Time(THD *thd, int *warn, const my_decimal *d) + :Time(thd, warn, Sec6(d), Options()) { } - Time(Item *item, const Options opt, uint dec) - :Temporal(Time(item, opt)) + Time(THD *thd, Item *item, const Options opt, uint dec) + :Time(thd, item, opt) { trunc(dec); } Time(int *warn, const MYSQL_TIME *from, long curdays, uint dec) - :Temporal(Time(warn, from, curdays)) + :Time(warn, from, curdays) { trunc(dec); } - Time(MYSQL_TIME_STATUS *status, const char *str, size_t len, CHARSET_INFO *cs, + Time(THD *thd, MYSQL_TIME_STATUS *status, + const char *str, size_t len, CHARSET_INFO *cs, const Options &opt, uint dec) - :Temporal(Time(status, str, len, cs, opt)) + :Time(thd, status, str, len, cs, opt) { trunc(dec); } - Time(int *warn, double nr, uint dec) - :Temporal(Time(warn, nr)) + Time(THD *thd, int *warn, double nr, uint dec) + :Time(thd, warn, nr) { trunc(dec); } - Time(int *warn, longlong nr, bool unsigned_val, uint dec) - :Time(warn, nr, unsigned_val) + Time(THD *thd, int *warn, longlong nr, bool unsigned_val, uint dec) + :Time(thd, warn, nr, unsigned_val) { /* Decimal digit truncation is needed here in case if nr was out @@ -805,15 +809,15 @@ public: */ trunc(dec); } - Time(int *warn, const my_decimal *d, uint dec) - :Temporal(Time(warn, d)) + Time(THD *thd, int *warn, const my_decimal *d, uint dec) + :Time(thd, warn, d) { trunc(dec); } - static sql_mode_t flags_for_get_date() + static date_mode_t flags_for_get_date() { return TIME_TIME_ONLY | TIME_INVALID_DATES; } - static sql_mode_t comparison_flags_for_get_date() + static date_mode_t comparison_flags_for_get_date() { return TIME_TIME_ONLY | TIME_INVALID_DATES | TIME_FUZZY_DATES; } bool is_valid_time() const { @@ -922,8 +926,8 @@ public: class Temporal_with_date: public Temporal { protected: - void check_date_or_invalidate(int *warn, sql_mode_t flags); - void make_from_item(THD *thd, Item *item, sql_mode_t flags); + void check_date_or_invalidate(int *warn, date_mode_t flags); + void make_from_item(THD *thd, Item *item, date_mode_t flags); void make_from_item(THD *thd, Item *item); ulong daynr() const @@ -954,7 +958,7 @@ protected: { time_type= MYSQL_TIMESTAMP_NONE; } - Temporal_with_date(THD *thd, Item *item, sql_mode_t flags) + Temporal_with_date(THD *thd, Item *item, date_mode_t flags) { make_from_item(thd, item, flags); } @@ -962,26 +966,26 @@ protected: { make_from_item(thd, item); } - Temporal_with_date(int *warn, const Sec6 &nr, sql_mode_t flags) + Temporal_with_date(int *warn, const Sec6 &nr, date_mode_t flags) { - DBUG_ASSERT((flags & TIME_TIME_ONLY) == 0); + DBUG_ASSERT(bool(flags & TIME_TIME_ONLY) == false); if (nr.to_datetime(this, flags, warn)) time_type= MYSQL_TIMESTAMP_NONE; } Temporal_with_date(MYSQL_TIME_STATUS *status, const char *str, size_t len, CHARSET_INFO *cs, - sql_mode_t flags) + date_mode_t flags) { - DBUG_ASSERT((flags & TIME_TIME_ONLY) == 0); + DBUG_ASSERT(bool(flags & TIME_TIME_ONLY) == false); if (str_to_datetime(status, str, len, cs, flags)) time_type= MYSQL_TIMESTAMP_NONE; } public: - bool check_date_with_warn(ulonglong flags) + bool check_date_with_warn(THD *thd, date_mode_t flags) { - return ::check_date_with_warn(this, flags, MYSQL_TIMESTAMP_ERROR); + return ::check_date_with_warn(thd, this, flags, MYSQL_TIMESTAMP_ERROR); } - static sql_mode_t comparison_flags_for_get_date() + static date_mode_t comparison_flags_for_get_date() { return TIME_INVALID_DATES | TIME_FUZZY_DATES; } }; @@ -1007,7 +1011,7 @@ class Date: public Temporal_with_date return !check_datetime_range(this); } public: - Date(THD *thd, Item *item, sql_mode_t flags) + Date(THD *thd, Item *item, date_mode_t flags) :Temporal_with_date(thd, item, flags) { if (time_type == MYSQL_TIMESTAMP_DATETIME) @@ -1022,12 +1026,8 @@ public: DBUG_ASSERT(is_valid_value_slow()); } Date(Item *item) - :Temporal_with_date(current_thd, item) - { - if (time_type == MYSQL_TIMESTAMP_DATETIME) - datetime_to_date(this); - DBUG_ASSERT(is_valid_value_slow()); - } + :Date(current_thd, item) + { } Date(const Temporal_with_date *d) :Temporal_with_date(*d) { @@ -1132,11 +1132,11 @@ class Datetime: public Temporal_with_date date_to_datetime(this); } void make_from_time(THD *thd, int *warn, const MYSQL_TIME *from, - sql_mode_t flags); + date_mode_t flags); void make_from_datetime(THD *thd, int *warn, const MYSQL_TIME *from, - sql_mode_t flags); + date_mode_t flags); public: - Datetime(THD *thd, Item *item, sql_mode_t flags) + Datetime(THD *thd, Item *item, date_mode_t flags) :Temporal_with_date(thd, item, flags) { date_to_datetime_if_needed(); @@ -1149,31 +1149,28 @@ public: DBUG_ASSERT(is_valid_value_slow()); } Datetime(Item *item) - :Temporal_with_date(current_thd, item) - { - date_to_datetime_if_needed(); - DBUG_ASSERT(is_valid_value_slow()); - } - Datetime(THD *thd, int *warn, const MYSQL_TIME *from, sql_mode_t flags); + :Datetime(current_thd, item) + { } + Datetime(THD *thd, int *warn, const MYSQL_TIME *from, date_mode_t flags); Datetime() { set_zero_time(this, MYSQL_TIMESTAMP_DATETIME); } Datetime(MYSQL_TIME_STATUS *status, const char *str, size_t len, CHARSET_INFO *cs, - sql_mode_t flags) + date_mode_t flags) :Temporal_with_date(status, str, len, cs, flags) { date_to_datetime_if_needed(); DBUG_ASSERT(is_valid_value_slow()); } - Datetime(int *warn, double nr, sql_mode_t flags) + Datetime(int *warn, double nr, date_mode_t flags) :Temporal_with_date(warn, Sec6(nr), flags) { date_to_datetime_if_needed(); DBUG_ASSERT(is_valid_value_slow()); } - Datetime(int *warn, const my_decimal *d, sql_mode_t flags) + Datetime(int *warn, const my_decimal *d, date_mode_t flags) :Temporal_with_date(warn, Sec6(d), flags) { date_to_datetime_if_needed(); @@ -1185,38 +1182,37 @@ public: as it's not important if overflow happened because of a negative number, or because of a huge positive number. */ - Datetime(int *warn, longlong sec, ulong usec, sql_mode_t flags) + Datetime(int *warn, longlong sec, ulong usec, date_mode_t flags) :Temporal_with_date(warn, Sec6(false, (ulonglong) sec, usec), flags) { - Sec6 nr(false, (ulonglong) sec, usec); date_to_datetime_if_needed(); DBUG_ASSERT(is_valid_value_slow()); } - Datetime(THD *thd, Item *item, sql_mode_t flags, uint dec) + Datetime(THD *thd, Item *item, date_mode_t flags, uint dec) :Temporal_with_date(Datetime(thd, item, flags)) { trunc(dec); } Datetime(MYSQL_TIME_STATUS *status, const char *str, size_t len, CHARSET_INFO *cs, - sql_mode_t fuzzydate, uint dec) + date_mode_t fuzzydate, uint dec) :Temporal_with_date(Datetime(status, str, len, cs, fuzzydate)) { trunc(dec); } - Datetime(int *warn, double nr, sql_mode_t fuzzydate, uint dec) + Datetime(int *warn, double nr, date_mode_t fuzzydate, uint dec) :Temporal_with_date(Datetime(warn, nr, fuzzydate)) { trunc(dec); } - Datetime(int *warn, const my_decimal *d, sql_mode_t fuzzydate, uint dec) + Datetime(int *warn, const my_decimal *d, date_mode_t fuzzydate, uint dec) :Temporal_with_date(Datetime(warn, d, fuzzydate)) { trunc(dec); } Datetime(THD *thd, int *warn, const MYSQL_TIME *from, - sql_mode_t fuzzydate, uint dec) + date_mode_t fuzzydate, uint dec) :Temporal_with_date(Datetime(thd, warn, from, fuzzydate)) { trunc(dec); @@ -1231,12 +1227,12 @@ public: DBUG_ASSERT(is_valid_value_slow()); return time_type == MYSQL_TIMESTAMP_DATETIME; } - bool check_date(longlong flags, int *warnings) const + bool check_date(date_mode_t flags, int *warnings) const { DBUG_ASSERT(is_valid_datetime_slow()); - return ::check_date(this, (year || month || day), flags, warnings); + return ::check_date(this, (year || month || day), ulonglong(flags), warnings); } - bool check_date(longlong flags) const + bool check_date(date_mode_t flags) const { int dummy; /* unused */ return check_date(flags, &dummy); @@ -2136,8 +2132,8 @@ public: virtual bool can_return_time() const { return true; } virtual bool is_bool_type() const { return false; } virtual bool is_general_purpose_string_type() const { return false; } - virtual uint Item_time_precision(Item *item) const; - virtual uint Item_datetime_precision(Item *item) const; + virtual uint Item_time_precision(THD *thd, Item *item) const; + virtual uint Item_datetime_precision(THD *thd, Item *item) const; virtual uint Item_decimal_scale(const Item *item) const; virtual uint Item_decimal_precision(const Item *item) const= 0; /* @@ -2260,7 +2256,7 @@ public: virtual uint32 max_display_length(const Item *item) const= 0; virtual uint32 calc_pack_length(uint32 length) const= 0; virtual void Item_update_null_value(Item *item) const= 0; - virtual bool Item_save_in_value(Item *item, st_value *value) const= 0; + virtual bool Item_save_in_value(THD *thd, Item *item, st_value *value) const= 0; virtual void Item_param_setup_conversion(THD *thd, Item_param *) const {} virtual void Item_param_set_param_func(Item_param *param, uchar **pos, ulong len) const; @@ -2395,8 +2391,8 @@ public: bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const= 0; virtual bool Item_val_bool(Item *item) const= 0; - virtual bool Item_get_date(Item *item, MYSQL_TIME *ltime, - ulonglong fuzzydate) const= 0; + virtual bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const= 0; virtual longlong Item_val_int_signed_typecast(Item *item) const= 0; virtual longlong Item_val_int_unsigned_typecast(Item *item) const= 0; @@ -2417,9 +2413,10 @@ public: Item_func_hybrid_field_type *, my_decimal *) const= 0; virtual - bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *, + bool Item_func_hybrid_field_type_get_date(THD *, + Item_func_hybrid_field_type *, MYSQL_TIME *, - ulonglong fuzzydate) const= 0; + date_mode_t fuzzydate) const= 0; virtual String *Item_func_min_max_val_str(Item_func_min_max *, String *) const= 0; virtual @@ -2430,8 +2427,8 @@ public: my_decimal *Item_func_min_max_val_decimal(Item_func_min_max *, my_decimal *) const= 0; virtual - bool Item_func_min_max_get_date(Item_func_min_max*, - MYSQL_TIME *, ulonglong fuzzydate) const= 0; + bool Item_func_min_max_get_date(THD *thd, Item_func_min_max*, + MYSQL_TIME *, date_mode_t fuzzydate) const= 0; virtual bool Item_func_between_fix_length_and_dec(Item_func_between *func) const= 0; virtual longlong @@ -2619,7 +2616,7 @@ public: DBUG_ASSERT(0); return DECIMAL_MAX_PRECISION; } - bool Item_save_in_value(Item *item, st_value *value) const; + bool Item_save_in_value(THD *thd, Item *item, st_value *value) const; bool Item_param_set_from_value(THD *thd, Item_param *param, const Type_all_attributes *attr, @@ -2681,7 +2678,8 @@ public: DBUG_ASSERT(0); return false; } - bool Item_get_date(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate) const + bool Item_get_date(THD *thd, Item *item, + MYSQL_TIME *ltime, date_mode_t fuzzydate) const { DBUG_ASSERT(0); return true; @@ -2726,9 +2724,10 @@ public: DBUG_ASSERT(0); return NULL; } - bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *, + bool Item_func_hybrid_field_type_get_date(THD *, + Item_func_hybrid_field_type *, MYSQL_TIME *, - ulonglong fuzzydate) const + date_mode_t fuzzydate) const { DBUG_ASSERT(0); return true; @@ -2755,8 +2754,8 @@ public: DBUG_ASSERT(0); return NULL; } - bool Item_func_min_max_get_date(Item_func_min_max*, - MYSQL_TIME *, ulonglong fuzzydate) const + bool Item_func_min_max_get_date(THD *thd, Item_func_min_max*, + MYSQL_TIME *, date_mode_t fuzzydate) const { DBUG_ASSERT(0); return true; @@ -2840,8 +2839,8 @@ public: longlong Item_func_min_max_val_int(Item_func_min_max *) const; my_decimal *Item_func_min_max_val_decimal(Item_func_min_max *, my_decimal *) const; - bool Item_func_min_max_get_date(Item_func_min_max*, - MYSQL_TIME *, ulonglong fuzzydate) const; + bool Item_func_min_max_get_date(THD *thd, Item_func_min_max*, + MYSQL_TIME *, date_mode_t fuzzydate) const; virtual ~Type_handler_numeric() { } bool can_change_cond_ref_to_const(Item_bool_func2 *target, Item *target_expr, Item *target_value, @@ -2877,7 +2876,7 @@ public: bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr, Item *a, Item *b) const; uint Item_decimal_precision(const Item *item) const; - bool Item_save_in_value(Item *item, st_value *value) const; + bool Item_save_in_value(THD *thd, Item *item, st_value *value) const; bool Item_param_set_from_value(THD *thd, Item_param *param, const Type_all_attributes *attr, @@ -2901,7 +2900,8 @@ public: bool Item_func_signed_fix_length_and_dec(Item_func_signed *item) const; bool Item_func_unsigned_fix_length_and_dec(Item_func_unsigned *item) const; bool Item_val_bool(Item *item) const; - bool Item_get_date(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate) const; + bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const; longlong Item_val_int_signed_typecast(Item *item) const; longlong Item_val_int_unsigned_typecast(Item *item) const; String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const; @@ -2914,9 +2914,10 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *, + bool Item_func_hybrid_field_type_get_date(THD *, + Item_func_hybrid_field_type *, MYSQL_TIME *, - ulonglong fuzzydate) const; + date_mode_t fuzzydate) const; String *Item_func_min_max_val_str(Item_func_min_max *, String *) const; longlong Item_func_between_val_int(Item_func_between *func) const; cmp_item *make_cmp_item(THD *thd, CHARSET_INFO *cs) const; @@ -2968,7 +2969,7 @@ public: return va.ptr() && vb.ptr() && !va.cmp(vb); } uint Item_decimal_precision(const Item *item) const; - bool Item_save_in_value(Item *item, st_value *value) const; + bool Item_save_in_value(THD *thd, Item *item, st_value *value) const; void Item_param_set_param_func(Item_param *param, uchar **pos, ulong len) const; bool Item_param_set_from_value(THD *thd, @@ -2997,9 +2998,10 @@ public: { return VDec(item).to_bool(); } - bool Item_get_date(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate) const + bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const { - return VDec(item).to_datetime_with_warn(ltime, fuzzydate, item); + return VDec(item).to_datetime_with_warn(thd, ltime, fuzzydate, item); } longlong Item_val_int_signed_typecast(Item *item) const; longlong Item_val_int_unsigned_typecast(Item *item) const @@ -3016,9 +3018,10 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *, + bool Item_func_hybrid_field_type_get_date(THD *, + Item_func_hybrid_field_type *, MYSQL_TIME *, - ulonglong fuzzydate) const; + date_mode_t fuzzydate) const; String *Item_func_min_max_val_str(Item_func_min_max *, String *) const; longlong Item_func_between_val_int(Item_func_between *func) const; cmp_item *make_cmp_item(THD *thd, CHARSET_INFO *cs) const; @@ -3185,7 +3188,7 @@ public: bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr, Item *a, Item *b) const; uint Item_decimal_precision(const Item *item) const; - bool Item_save_in_value(Item *item, st_value *value) const; + bool Item_save_in_value(THD *thd, Item *item, st_value *value) const; bool Item_param_set_from_value(THD *thd, Item_param *param, const Type_all_attributes *attr, @@ -3205,7 +3208,8 @@ public: bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; bool Item_val_bool(Item *item) const; - bool Item_get_date(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate) const; + bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const; longlong Item_val_int_signed_typecast(Item *item) const; longlong Item_val_int_unsigned_typecast(Item *item) const; String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const; @@ -3218,9 +3222,10 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *, + bool Item_func_hybrid_field_type_get_date(THD *, + Item_func_hybrid_field_type *, MYSQL_TIME *, - ulonglong fuzzydate) const; + date_mode_t fuzzydate) const; String *Item_func_min_max_val_str(Item_func_min_max *, String *) const; longlong Item_func_between_val_int(Item_func_between *func) const; cmp_item *make_cmp_item(THD *thd, CHARSET_INFO *cs) const; @@ -3283,7 +3288,8 @@ public: bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; bool Item_val_bool(Item *item) const; - bool Item_get_date(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate) const; + bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const; longlong Item_val_int_signed_typecast(Item *item) const; longlong Item_val_int_unsigned_typecast(Item *item) const; String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const; @@ -3296,15 +3302,16 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *, + bool Item_func_hybrid_field_type_get_date(THD *, + Item_func_hybrid_field_type *, MYSQL_TIME *, - ulonglong fuzzydate) const; + date_mode_t fuzzydate) const; double Item_func_min_max_val_real(Item_func_min_max *) const; longlong Item_func_min_max_val_int(Item_func_min_max *) const; my_decimal *Item_func_min_max_val_decimal(Item_func_min_max *, my_decimal *) const; - bool Item_func_min_max_get_date(Item_func_min_max*, - MYSQL_TIME *, ulonglong fuzzydate) const; + bool Item_func_min_max_get_date(THD *thd, Item_func_min_max*, + MYSQL_TIME *, date_mode_t fuzzydate) const; bool Item_func_between_fix_length_and_dec(Item_func_between *func) const; bool Item_func_in_fix_comparator_compatible_types(THD *thd, Item_func_in *) const; @@ -3323,7 +3330,7 @@ public: class Type_handler_string_result: public Type_handler { - uint Item_temporal_precision(Item *item, bool is_time) const; + uint Item_temporal_precision(THD *thd, Item *item, bool is_time) const; public: Item_result result_type() const { return STRING_RESULT; } Item_result cmp_type() const { return STRING_RESULT; } @@ -3354,17 +3361,17 @@ public: bool binary_cmp) const; bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr, Item *a, Item *b) const; - uint Item_time_precision(Item *item) const + uint Item_time_precision(THD *thd, Item *item) const { - return Item_temporal_precision(item, true); + return Item_temporal_precision(thd, item, true); } - uint Item_datetime_precision(Item *item) const + uint Item_datetime_precision(THD *thd, Item *item) const { - return Item_temporal_precision(item, false); + return Item_temporal_precision(thd, item, false); } uint Item_decimal_precision(const Item *item) const; void Item_update_null_value(Item *item) const; - bool Item_save_in_value(Item *item, st_value *value) const; + bool Item_save_in_value(THD *thd, Item *item, st_value *value) const; void Item_param_setup_conversion(THD *thd, Item_param *) const; void Item_param_set_param_func(Item_param *param, uchar **pos, ulong len) const; @@ -3402,7 +3409,8 @@ public: bool Item_func_signed_fix_length_and_dec(Item_func_signed *item) const; bool Item_func_unsigned_fix_length_and_dec(Item_func_unsigned *item) const; bool Item_val_bool(Item *item) const; - bool Item_get_date(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate) const; + bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const; longlong Item_val_int_signed_typecast(Item *item) const; longlong Item_val_int_unsigned_typecast(Item *item) const; String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const; @@ -3415,16 +3423,17 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *, + bool Item_func_hybrid_field_type_get_date(THD *, + Item_func_hybrid_field_type *, MYSQL_TIME *, - ulonglong fuzzydate) const; + date_mode_t fuzzydate) const; String *Item_func_min_max_val_str(Item_func_min_max *, String *) const; double Item_func_min_max_val_real(Item_func_min_max *) const; longlong Item_func_min_max_val_int(Item_func_min_max *) const; my_decimal *Item_func_min_max_val_decimal(Item_func_min_max *, my_decimal *) const; - bool Item_func_min_max_get_date(Item_func_min_max*, - MYSQL_TIME *, ulonglong fuzzydate) const; + bool Item_func_min_max_get_date(THD *thd, Item_func_min_max*, + MYSQL_TIME *, date_mode_t fuzzydate) const; bool Item_func_between_fix_length_and_dec(Item_func_between *func) const; longlong Item_func_between_val_int(Item_func_between *func) const; bool Item_char_typecast_fix_length_and_dec(Item_char_typecast *) const; @@ -3736,10 +3745,12 @@ public: const Column_definition_attributes *attr, uint32 flags) const; Item_cache *Item_get_cache(THD *thd, const Item *item) const; - bool Item_get_date(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate) const; - bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *item, + bool Item_get_date(THD *thd, Item *item, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const; + bool Item_func_hybrid_field_type_get_date(THD *, + Item_func_hybrid_field_type *item, MYSQL_TIME *to, - ulonglong fuzzydate) const; + date_mode_t fuzzydate) const; }; @@ -3898,7 +3909,7 @@ public: int stored_field_cmp_to_item(THD *thd, Field *field, Item *item) const; void Column_definition_implicit_upgrade(Column_definition *c) const; bool Column_definition_fix_attributes(Column_definition *c) const; - bool Item_save_in_value(Item *item, st_value *value) const; + bool Item_save_in_value(THD *thd, Item *item, st_value *value) const; bool Item_send(Item *item, Protocol *protocol, st_value *buf) const { return Item_send_time(item, protocol, buf); @@ -3921,12 +3932,13 @@ public: my_decimal *Item_func_hybrid_field_type_val_decimal( Item_func_hybrid_field_type *, my_decimal *) const; - bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *, + bool Item_func_hybrid_field_type_get_date(THD *, + Item_func_hybrid_field_type *, MYSQL_TIME *, - ulonglong fuzzydate) const; + date_mode_t fuzzydate) const; String *Item_func_min_max_val_str(Item_func_min_max *, String *) const; - bool Item_func_min_max_get_date(Item_func_min_max*, - MYSQL_TIME *, ulonglong fuzzydate) const; + bool Item_func_min_max_get_date(THD *thd, Item_func_min_max*, + MYSQL_TIME *, date_mode_t fuzzydate) const; longlong Item_func_between_val_int(Item_func_between *func) const; Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const; bool set_comparator_func(Arg_comparator *cmp) const; @@ -4002,7 +4014,7 @@ public: bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr, Item *a, Item *b) const; int stored_field_cmp_to_item(THD *thd, Field *field, Item *item) const; - bool Item_save_in_value(Item *item, st_value *value) const; + bool Item_save_in_value(THD *thd, Item *item, st_value *value) const; bool Item_send(Item *item, Protocol *protocol, st_value *buf) const { return Item_send_date(item, protocol, buf); @@ -4389,7 +4401,7 @@ public: uint32 calc_pack_length(uint32 length) const { return 0; } bool Item_const_eq(const Item_const *a, const Item_const *b, bool binary_cmp) const; - bool Item_save_in_value(Item *item, st_value *value) const; + bool Item_save_in_value(THD *thd, Item *item, st_value *value) const; bool Item_send(Item *item, Protocol *protocol, st_value *buf) const; Field *make_conversion_table_field(TABLE *, uint metadata, const Field *target) const; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index cc22908ec4b..f6650a3b289 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -5939,7 +5939,7 @@ opt_versioning_rotation: | INTERVAL_SYM expr interval opt_versioning_interval_start { partition_info *part_info= Lex->part_info; - if (unlikely(part_info->vers_set_interval($2, $3, $4))) + if (unlikely(part_info->vers_set_interval(thd, $2, $3, $4))) { my_error(ER_PART_WRONG_VALUE, MYF(0), Lex->create_last_non_select_table->table_name.str, diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index d4838590075..0e091813aca 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -5965,7 +5965,7 @@ opt_versioning_rotation: | INTERVAL_SYM expr interval opt_versioning_interval_start { partition_info *part_info= Lex->part_info; - if (unlikely(part_info->vers_set_interval($2, $3, $4))) + if (unlikely(part_info->vers_set_interval(thd, $2, $3, $4))) { my_error(ER_PART_WRONG_VALUE, MYF(0), Lex->create_last_non_select_table->table_name.str, diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic index 373df354268..dbc3565e202 100644 --- a/sql/sys_vars.ic +++ b/sql/sys_vars.ic @@ -2659,7 +2659,7 @@ public: if (!Sys_var_enum::do_check(thd, var)) return false; MYSQL_TIME ltime; - bool res= var->value->get_date(<ime, 0); + bool res= var->value->get_date(thd, <ime, date_mode_t(0)); if (!res) { var->save_result.ulonglong_value= SYSTEM_TIME_AS_OF; @@ -2676,7 +2676,7 @@ private: { if (var->value) { - res= var->value->get_date(&out.ltime, 0); + res= var->value->get_date(current_thd, &out.ltime, date_mode_t(0)); } else // set DEFAULT from global var { diff --git a/sql/table.cc b/sql/table.cc index de5a71f6af1..58adb94cc17 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -8642,7 +8642,7 @@ bool TR_table::query(MYSQL_TIME &commit_time, bool backwards) if (res > 0) { MYSQL_TIME commit_ts; - if ((*this)[FLD_COMMIT_TS]->get_date(&commit_ts, 0)) + if ((*this)[FLD_COMMIT_TS]->get_date(&commit_ts, date_mode_t(0))) { found= false; break; |