Commit 46129978 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 33674e5b
...@@ -5159,9 +5159,7 @@ int Field_temporal_with_date::store(const char *from, uint len, CHARSET_INFO *cs ...@@ -5159,9 +5159,7 @@ int Field_temporal_with_date::store(const char *from, uint len, CHARSET_INFO *cs
THD *thd= get_thd(); THD *thd= get_thd();
ErrConvString str(from, len, cs); ErrConvString str(from, len, cs);
bool func_res= !str_to_datetime(cs, from, len, &ltime, bool func_res= !str_to_datetime(cs, from, len, &ltime,
(thd->variables.sql_mode & sql_mode_for_dates(thd),
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES)),
&status); &status);
return store_TIME_with_warning(&ltime, &str, status.warnings, func_res); return store_TIME_with_warning(&ltime, &str, status.warnings, func_res);
} }
...@@ -5175,10 +5173,7 @@ int Field_temporal_with_date::store(double nr) ...@@ -5175,10 +5173,7 @@ int Field_temporal_with_date::store(double nr)
ErrConvDouble str(nr); ErrConvDouble str(nr);
longlong tmp= double_to_datetime(nr, &ltime, longlong tmp= double_to_datetime(nr, &ltime,
(thd->variables.sql_mode & sql_mode_for_dates(thd), &error);
(MODE_NO_ZERO_IN_DATE |
MODE_NO_ZERO_DATE |
MODE_INVALID_DATES)), &error);
return store_TIME_with_warning(&ltime, &str, error, tmp != -1); 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) ...@@ -5191,10 +5186,7 @@ int Field_temporal_with_date::store(longlong nr, bool unsigned_val)
THD *thd= get_thd(); THD *thd= get_thd();
ErrConvInteger str(nr); ErrConvInteger str(nr);
tmp= number_to_datetime(nr, 0, &ltime, (thd->variables.sql_mode & tmp= number_to_datetime(nr, 0, &ltime, sql_mode_for_dates(thd), &error);
(MODE_NO_ZERO_IN_DATE |
MODE_NO_ZERO_DATE |
MODE_INVALID_DATES)), &error);
return store_TIME_with_warning(&ltime, &str, error, tmp != -1); 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) ...@@ -5210,9 +5202,7 @@ int Field_temporal_with_date::store_time_dec(MYSQL_TIME *ltime, uint dec)
structure always fit into DATETIME range. structure always fit into DATETIME range.
*/ */
have_smth_to_conv= !check_date(&l_time, pack_time(&l_time) != 0, have_smth_to_conv= !check_date(&l_time, pack_time(&l_time) != 0,
(current_thd->variables.sql_mode & sql_mode_for_dates(current_thd), &error);
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES)), &error);
return store_TIME_with_warning(&l_time, &str, error, have_smth_to_conv); 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) ...@@ -5278,10 +5268,7 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
MYSQL_TIME_STATUS status; MYSQL_TIME_STATUS status;
ErrConvString str(from, len, cs); ErrConvString str(from, len, cs);
bool have_smth_to_conv= bool have_smth_to_conv=
!str_to_time(cs, from, len, &ltime, !str_to_time(cs, from, len, &ltime, sql_mode_for_dates(get_thd()),
get_thd()->variables.sql_mode &
(MODE_NO_ZERO_DATE | MODE_NO_ZERO_IN_DATE |
MODE_INVALID_DATES),
&status); &status);
return store_TIME_with_warning(&ltime, &str, return store_TIME_with_warning(&ltime, &str,
...@@ -6057,10 +6044,8 @@ int Field_temporal_with_date::store_decimal(const my_decimal *d) ...@@ -6057,10 +6044,8 @@ int Field_temporal_with_date::store_decimal(const my_decimal *d)
error= 2; error= 2;
} }
else else
tmp= number_to_datetime(nr, sec_part, &ltime, (thd->variables.sql_mode & tmp= number_to_datetime(nr, sec_part, &ltime, sql_mode_for_dates(thd),
(MODE_NO_ZERO_IN_DATE | &error);
MODE_NO_ZERO_DATE |
MODE_INVALID_DATES)), &error);
return store_TIME_with_warning(&ltime, &str, error, tmp != -1); return store_TIME_with_warning(&ltime, &str, error, tmp != -1);
} }
......
...@@ -840,8 +840,7 @@ int field_conv(Field *to,Field *from) ...@@ -840,8 +840,7 @@ int field_conv(Field *to,Field *from)
(to->real_type() != MYSQL_TYPE_NEWDECIMAL || (to->real_type() != MYSQL_TYPE_NEWDECIMAL ||
to->field_length == from->field_length) && to->field_length == from->field_length) &&
from->charset() == to->charset() && from->charset() == to->charset() &&
(!(to->table->in_use->variables.sql_mode & (!sql_mode_for_dates(to->table->in_use) ||
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) ||
(to->type() != MYSQL_TYPE_DATE && (to->type() != MYSQL_TYPE_DATE &&
to->type() != MYSQL_TYPE_DATETIME)) && to->type() != MYSQL_TYPE_DATETIME)) &&
(from->real_type() != MYSQL_TYPE_VARCHAR || (from->real_type() != MYSQL_TYPE_VARCHAR ||
......
...@@ -297,7 +297,7 @@ String *Item::val_string_from_decimal(String *str) ...@@ -297,7 +297,7 @@ String *Item::val_string_from_decimal(String *str)
String *Item::val_string_from_date(String *str) String *Item::val_string_from_date(String *str)
{ {
MYSQL_TIME ltime; 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)) str->alloc(MAX_DATE_STRING_REP_LENGTH))
{ {
null_value= 1; null_value= 1;
...@@ -354,7 +354,7 @@ my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value) ...@@ -354,7 +354,7 @@ my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; 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); my_decimal_set_zero(decimal_value);
null_value= 1; // set NULL, stop processing null_value= 1; // set NULL, stop processing
...@@ -434,9 +434,7 @@ int Item::save_time_in_field(Field *field) ...@@ -434,9 +434,7 @@ int Item::save_time_in_field(Field *field)
int Item::save_date_in_field(Field *field) int Item::save_date_in_field(Field *field)
{ {
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_date(&ltime, (current_thd->variables.sql_mode & if (get_date(&ltime, sql_mode_for_dates(current_thd)))
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
MODE_INVALID_DATES))))
return set_field_to_null_with_conversions(field, 0); return set_field_to_null_with_conversions(field, 0);
field->set_notnull(); field->set_notnull();
return field->store_time_dec(&ltime, decimals); return field->store_time_dec(&ltime, decimals);
...@@ -6487,7 +6485,7 @@ bool Item::send(Protocol *protocol, String *buffer) ...@@ -6487,7 +6485,7 @@ bool Item::send(Protocol *protocol, String *buffer)
case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_TIMESTAMP:
{ {
MYSQL_TIME tm; MYSQL_TIME tm;
get_date(&tm, sql_mode_for_dates()); get_date(&tm, sql_mode_for_dates(current_thd));
if (!null_value) if (!null_value)
{ {
if (f_type == MYSQL_TYPE_DATE) if (f_type == MYSQL_TYPE_DATE)
......
...@@ -2884,8 +2884,6 @@ class Item_bin_string: public Item_hex_hybrid ...@@ -2884,8 +2884,6 @@ class Item_bin_string: public Item_hex_hybrid
class Item_temporal_literal :public Item_basic_constant 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: protected:
MYSQL_TIME cached_time; MYSQL_TIME cached_time;
public: public:
......
...@@ -5815,10 +5815,7 @@ Item *create_temporal_literal(THD *thd, ...@@ -5815,10 +5815,7 @@ Item *create_temporal_literal(THD *thd,
MYSQL_TIME_STATUS status; MYSQL_TIME_STATUS status;
MYSQL_TIME ltime; MYSQL_TIME ltime;
Item *item= NULL; Item *item= NULL;
ulonglong flags= thd->variables.sql_mode & ulonglong flags= sql_mode_for_dates(thd);
(MODE_NO_ZERO_IN_DATE |
MODE_NO_ZERO_DATE |
MODE_INVALID_DATES);
switch(type) switch(type)
{ {
......
...@@ -4183,7 +4183,8 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg) ...@@ -4183,7 +4183,8 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg)
break; break;
case DYN_COL_DATETIME: case DYN_COL_DATETIME:
case DYN_COL_DATE: 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; break;
case DYN_COL_TIME: case DYN_COL_TIME:
args[valpos]->get_time(&vals[i].x.time_value); 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) ...@@ -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) 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)) if (get_arg0_date(ltime, fuzzy_date & ~TIME_TIME_ONLY))
return 1; return 1;
...@@ -2442,7 +2442,7 @@ bool Item_date_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) ...@@ -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) 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)) if (get_arg0_date(ltime, fuzzy_date & ~TIME_TIME_ONLY))
return 1; return 1;
...@@ -3111,7 +3111,7 @@ bool Item_func_str_to_date::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) ...@@ -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(); date_time_format.format.length= format->length();
if (extract_date_time(&date_time_format, val->ptr(), val->length(), if (extract_date_time(&date_time_format, val->ptr(), val->length(),
ltime, cached_timestamp_type, 0, "datetime", ltime, cached_timestamp_type, 0, "datetime",
fuzzy_date | sql_mode_for_dates())) fuzzy_date | sql_mode_for_dates(current_thd)))
return (null_value=1); return (null_value=1);
if (cached_timestamp_type == MYSQL_TIMESTAMP_TIME && ltime->day) if (cached_timestamp_type == MYSQL_TIMESTAMP_TIME && ltime->day)
{ {
......
...@@ -3494,25 +3494,10 @@ my_eof(THD *thd) ...@@ -3494,25 +3494,10 @@ my_eof(THD *thd)
#define reenable_binlog(A) (A)->variables.option_bits= tmp_disable_binlog__save_options;} #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) inline sql_mode_t sql_mode_for_dates(THD *thd)
{ {
if (strict_date_checking) return thd->variables.sql_mode &
return (thd->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_NO_ZERO_IN_DATE | MODE_INVALID_DATES);
(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);
} }
/* /*
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#include "sql_priv.h" #include "sql_priv.h"
#include "unireg.h" // REQUIRED by other includes #include "unireg.h" // REQUIRED by other includes
#include "sql_time.h" #include "sql_time.h"
#include "tztime.h" // struct Time_zone #include "tztime.h" // struct Time_zone
#include "sql_class.h" // THD, MODE_INVALID_DATES, MODE_NO_ZERO_DATE #include "sql_class.h" // THD
#include <m_ctype.h> #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