Commit a91a2385 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup

* use sql_mode_for_dates() where appropriate.
* always specify an argument for sql_mode_for_dates()
  (future-proof. easier to notice and fix if the caller
   will start using thd from a local variable or an argument)
parent 847e0f15
......@@ -5159,9 +5159,7 @@ int Field_temporal_with_date::store(const char *from, uint len, CHARSET_INFO *cs
THD *thd= get_thd();
ErrConvString str(from, len, cs);
bool func_res= !str_to_datetime(cs, from, len, &ltime,
(thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES)),
sql_mode_for_dates(thd),
&status);
return store_TIME_with_warning(&ltime, &str, status.warnings, func_res);
}
......@@ -5175,10 +5173,7 @@ int Field_temporal_with_date::store(double nr)
ErrConvDouble str(nr);
longlong tmp= double_to_datetime(nr, &ltime,
(thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE |
MODE_NO_ZERO_DATE |
MODE_INVALID_DATES)), &error);
sql_mode_for_dates(thd), &error);
return store_TIME_with_warning(&ltime, &str, error, tmp != -1);
}
......@@ -5191,10 +5186,7 @@ int Field_temporal_with_date::store(longlong nr, bool unsigned_val)
THD *thd= get_thd();
ErrConvInteger str(nr);
tmp= number_to_datetime(nr, 0, &ltime, (thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE |
MODE_NO_ZERO_DATE |
MODE_INVALID_DATES)), &error);
tmp= number_to_datetime(nr, 0, &ltime, sql_mode_for_dates(thd), &error);
return store_TIME_with_warning(&ltime, &str, error, tmp != -1);
}
......@@ -5210,9 +5202,7 @@ int Field_temporal_with_date::store_time_dec(MYSQL_TIME *ltime, uint dec)
structure always fit into DATETIME range.
*/
have_smth_to_conv= !check_date(&l_time, pack_time(&l_time) != 0,
(current_thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES)), &error);
sql_mode_for_dates(current_thd), &error);
return store_TIME_with_warning(&l_time, &str, error, have_smth_to_conv);
}
......@@ -5278,10 +5268,7 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
MYSQL_TIME_STATUS status;
ErrConvString str(from, len, cs);
bool have_smth_to_conv=
!str_to_time(cs, from, len, &ltime,
get_thd()->variables.sql_mode &
(MODE_NO_ZERO_DATE | MODE_NO_ZERO_IN_DATE |
MODE_INVALID_DATES),
!str_to_time(cs, from, len, &ltime, sql_mode_for_dates(get_thd()),
&status);
return store_TIME_with_warning(&ltime, &str,
......@@ -6057,10 +6044,8 @@ int Field_temporal_with_date::store_decimal(const my_decimal *d)
error= 2;
}
else
tmp= number_to_datetime(nr, sec_part, &ltime, (thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE |
MODE_NO_ZERO_DATE |
MODE_INVALID_DATES)), &error);
tmp= number_to_datetime(nr, sec_part, &ltime, sql_mode_for_dates(thd),
&error);
return store_TIME_with_warning(&ltime, &str, error, tmp != -1);
}
......
......@@ -840,8 +840,7 @@ int field_conv(Field *to,Field *from)
(to->real_type() != MYSQL_TYPE_NEWDECIMAL ||
to->field_length == from->field_length) &&
from->charset() == to->charset() &&
(!(to->table->in_use->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) ||
(!sql_mode_for_dates(to->table->in_use) ||
(to->type() != MYSQL_TYPE_DATE &&
to->type() != MYSQL_TYPE_DATETIME)) &&
(from->real_type() != MYSQL_TYPE_VARCHAR ||
......
......@@ -297,7 +297,7 @@ String *Item::val_string_from_decimal(String *str)
String *Item::val_string_from_date(String *str)
{
MYSQL_TIME ltime;
if (get_date(&ltime, sql_mode_for_dates()) ||
if (get_date(&ltime, sql_mode_for_dates(current_thd)) ||
str->alloc(MAX_DATE_STRING_REP_LENGTH))
{
null_value= 1;
......@@ -354,7 +354,7 @@ my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
if (get_date(&ltime, sql_mode_for_dates()))
if (get_date(&ltime, sql_mode_for_dates(current_thd)))
{
my_decimal_set_zero(decimal_value);
null_value= 1; // set NULL, stop processing
......@@ -434,9 +434,7 @@ int Item::save_time_in_field(Field *field)
int Item::save_date_in_field(Field *field)
{
MYSQL_TIME ltime;
if (get_date(&ltime, (current_thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES))))
if (get_date(&ltime, sql_mode_for_dates(current_thd)))
return set_field_to_null_with_conversions(field, 0);
field->set_notnull();
return field->store_time_dec(&ltime, decimals);
......@@ -6487,7 +6485,7 @@ bool Item::send(Protocol *protocol, String *buffer)
case MYSQL_TYPE_TIMESTAMP:
{
MYSQL_TIME tm;
get_date(&tm, sql_mode_for_dates());
get_date(&tm, sql_mode_for_dates(current_thd));
if (!null_value)
{
if (f_type == MYSQL_TYPE_DATE)
......
......@@ -2884,8 +2884,6 @@ public:
class Item_temporal_literal :public Item_basic_constant
{
//sql_mode= current_thd->variables.sql_mode &
// (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
protected:
MYSQL_TIME cached_time;
public:
......
......@@ -5815,10 +5815,7 @@ Item *create_temporal_literal(THD *thd,
MYSQL_TIME_STATUS status;
MYSQL_TIME ltime;
Item *item= NULL;
ulonglong flags= thd->variables.sql_mode &
(MODE_NO_ZERO_IN_DATE |
MODE_NO_ZERO_DATE |
MODE_INVALID_DATES);
ulonglong flags= sql_mode_for_dates(thd);
switch(type)
{
......
......@@ -4183,7 +4183,8 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg)
break;
case DYN_COL_DATETIME:
case DYN_COL_DATE:
args[valpos]->get_date(&vals[i].x.time_value, sql_mode_for_dates());
args[valpos]->get_date(&vals[i].x.time_value,
sql_mode_for_dates(current_thd));
break;
case DYN_COL_TIME:
args[valpos]->get_time(&vals[i].x.time_value);
......
......@@ -2429,7 +2429,7 @@ bool Item_time_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{
fuzzy_date |= sql_mode_for_dates();
fuzzy_date |= sql_mode_for_dates(current_thd);
if (get_arg0_date(ltime, fuzzy_date & ~TIME_TIME_ONLY))
return 1;
......@@ -2442,7 +2442,7 @@ bool Item_date_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{
fuzzy_date |= sql_mode_for_dates();
fuzzy_date |= sql_mode_for_dates(current_thd);
if (get_arg0_date(ltime, fuzzy_date & ~TIME_TIME_ONLY))
return 1;
......@@ -3111,7 +3111,7 @@ bool Item_func_str_to_date::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
date_time_format.format.length= format->length();
if (extract_date_time(&date_time_format, val->ptr(), val->length(),
ltime, cached_timestamp_type, 0, "datetime",
fuzzy_date | sql_mode_for_dates()))
fuzzy_date | sql_mode_for_dates(current_thd)))
return (null_value=1);
if (cached_timestamp_type == MYSQL_TIMESTAMP_TIME && ltime->day)
{
......
......@@ -3494,25 +3494,10 @@ my_eof(THD *thd)
#define reenable_binlog(A) (A)->variables.option_bits= tmp_disable_binlog__save_options;}
/*
These functions are for making it later easy to add strict
checking for all date handling.
*/
const my_bool strict_date_checking= 1;
inline sql_mode_t sql_mode_for_dates(THD *thd)
{
if (strict_date_checking)
return (thd->variables.sql_mode &
(MODE_NO_ZERO_DATE | MODE_NO_ZERO_IN_DATE |
MODE_INVALID_DATES));
return (thd->variables.sql_mode & MODE_INVALID_DATES);
}
inline sql_mode_t sql_mode_for_dates()
{
return sql_mode_for_dates(current_thd);
return thd->variables.sql_mode &
(MODE_NO_ZERO_DATE | MODE_NO_ZERO_IN_DATE | MODE_INVALID_DATES);
}
/*
......
......@@ -20,8 +20,8 @@
#include "sql_priv.h"
#include "unireg.h" // REQUIRED by other includes
#include "sql_time.h"
#include "tztime.h" // struct Time_zone
#include "sql_class.h" // THD, MODE_INVALID_DATES, MODE_NO_ZERO_DATE
#include "tztime.h" // struct Time_zone
#include "sql_class.h" // THD
#include <m_ctype.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment