@@ -5489,17 +5489,19 @@ uint Type_handler::Item_datetime_precision(Item *item) const
54895489uint Type_handler_string_result::Item_temporal_precision (Item *item,
54905490 bool is_time) const
54915491{
5492- MYSQL_TIME ltime;
54935492 StringBuffer<64 > buf;
54945493 String *tmp;
54955494 MYSQL_TIME_STATUS status;
54965495 DBUG_ASSERT (item->is_fixed ());
54975496 if ((tmp= item->val_str (&buf)) &&
5498- !(is_time ?
5499- str_to_time (tmp->charset (), tmp->ptr (), tmp->length (),
5500- <ime, TIME_TIME_ONLY, &status) :
5501- str_to_datetime (tmp->charset (), tmp->ptr (), tmp->length (),
5502- <ime, TIME_FUZZY_DATES, &status)))
5497+ (is_time ?
5498+ Time (&status, tmp->ptr (), tmp->length (), tmp->charset (),
5499+ Time::Options (TIME_TIME_ONLY,
5500+ Time::DATETIME_TO_TIME_YYYYMMDD_TRUNCATE)).
5501+ is_valid_time () :
5502+ Datetime (&status, tmp->ptr (), tmp->length (), tmp->charset (),
5503+ TIME_FUZZY_DATES).
5504+ is_valid_datetime ()))
55035505 return MY_MIN (status.precision , TIME_SECOND_PART_DIGITS);
55045506 return MY_MIN (item->decimals , TIME_SECOND_PART_DIGITS);
55055507}
@@ -7208,7 +7210,7 @@ static bool have_important_literal_warnings(const MYSQL_TIME_STATUS *status)
72087210
72097211static void literal_warn (THD *thd, const Item *item,
72107212 const char *str, size_t length, CHARSET_INFO *cs,
7211- const MYSQL_TIME *ltime ,
7213+ timestamp_type time_type ,
72127214 const MYSQL_TIME_STATUS *st,
72137215 const char *typestr, bool send_error)
72147216{
@@ -7219,7 +7221,7 @@ static void literal_warn(THD *thd, const Item *item,
72197221 ErrConvString err (str, length, cs);
72207222 make_truncated_value_warning (thd,
72217223 Sql_condition::time_warn_level (st->warnings ),
7222- &err, ltime-> time_type , 0 );
7224+ &err, time_type, 0 );
72237225 }
72247226 }
72257227 else if (send_error)
@@ -7238,13 +7240,14 @@ Type_handler_date_common::create_literal_item(THD *thd,
72387240 bool send_error) const
72397241{
72407242 MYSQL_TIME_STATUS st;
7241- MYSQL_TIME ltime;
72427243 Item_literal *item= NULL ;
7243- sql_mode_t flags= sql_mode_for_dates (thd);
7244- if (!str_to_datetime (cs, str, length, <ime, flags, &st) &&
7245- ltime.time_type == MYSQL_TIMESTAMP_DATE && !st.warnings )
7246- item= new (thd->mem_root ) Item_date_literal (thd, <ime);
7247- literal_warn (thd, item, str, length, cs, <ime, &st, " DATE" , send_error);
7244+ Temporal_hybrid tmp (&st, str, length, cs, sql_mode_for_dates (thd));
7245+ if (tmp.is_valid_temporal () &&
7246+ tmp.get_mysql_time ()->time_type == MYSQL_TIMESTAMP_DATE &&
7247+ !have_important_literal_warnings (&st))
7248+ item= new (thd->mem_root ) Item_date_literal (thd, tmp.get_mysql_time ());
7249+ literal_warn (thd, item, str, length, cs, MYSQL_TIMESTAMP_DATE,
7250+ &st, " DATE" , send_error);
72487251 return item;
72497252}
72507253
@@ -7257,14 +7260,15 @@ Type_handler_temporal_with_date::create_literal_item(THD *thd,
72577260 bool send_error) const
72587261{
72597262 MYSQL_TIME_STATUS st;
7260- MYSQL_TIME ltime;
72617263 Item_literal *item= NULL ;
7262- sql_mode_t flags= sql_mode_for_dates (thd);
7263- if (! str_to_datetime (cs, str, length, <ime, flags, &st ) &&
7264- ltime. time_type == MYSQL_TIMESTAMP_DATETIME &&
7264+ Temporal_hybrid tmp (&st, str, length, cs, sql_mode_for_dates (thd) );
7265+ if (tmp. is_valid_temporal ( ) &&
7266+ tmp. get_mysql_time ()-> time_type == MYSQL_TIMESTAMP_DATETIME &&
72657267 !have_important_literal_warnings (&st))
7266- item= new (thd->mem_root ) Item_datetime_literal (thd, <ime, st.precision );
7267- literal_warn (thd, item, str, length, cs, <ime, &st, " DATETIME" , send_error);
7268+ item= new (thd->mem_root ) Item_datetime_literal (thd, tmp.get_mysql_time (),
7269+ st.precision );
7270+ literal_warn (thd, item, str, length, cs, MYSQL_TIMESTAMP_DATETIME,
7271+ &st, " DATETIME" , send_error);
72687272 return item;
72697273}
72707274
@@ -7277,12 +7281,14 @@ Type_handler_time_common::create_literal_item(THD *thd,
72777281 bool send_error) const
72787282{
72797283 MYSQL_TIME_STATUS st;
7280- MYSQL_TIME ltime;
72817284 Item_literal *item= NULL ;
7282- if (!str_to_time (cs, str, length, <ime, 0 , &st) &&
7283- ltime.time_type == MYSQL_TIMESTAMP_TIME &&
7285+ Time::Options opt (TIME_TIME_ONLY, Time::DATETIME_TO_TIME_DISALLOW);
7286+ Time tmp (&st, str, length, cs, opt);
7287+ if (tmp.is_valid_time () &&
72847288 !have_important_literal_warnings (&st))
7285- item= new (thd->mem_root ) Item_time_literal (thd, <ime, st.precision );
7286- literal_warn (thd, item, str, length, cs, <ime, &st, " TIME" , send_error);
7289+ item= new (thd->mem_root ) Item_time_literal (thd, tmp.get_mysql_time (),
7290+ st.precision );
7291+ literal_warn (thd, item, str, length, cs, MYSQL_TIMESTAMP_TIME,
7292+ &st, " TIME" , send_error);
72877293 return item;
72887294}
0 commit comments