summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-08-12 22:05:23 +0200
committerSergei Golubchik <sergii@pisem.net>2013-08-12 22:05:23 +0200
commita91a23858de4b346ef6f419b05cd8d87ede51f78 (patch)
treebdbd2b3f4464f967fca27cbd44ba8921cc26fcc6 /sql
parent847e0f152bc803bc850f11bc291f8f135bf06556 (diff)
downloadmariadb-git-a91a23858de4b346ef6f419b05cd8d87ede51f78.tar.gz
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)
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc29
-rw-r--r--sql/field_conv.cc3
-rw-r--r--sql/item.cc10
-rw-r--r--sql/item.h2
-rw-r--r--sql/item_create.cc5
-rw-r--r--sql/item_strfunc.cc3
-rw-r--r--sql/item_timefunc.cc6
-rw-r--r--sql/sql_class.h19
-rw-r--r--sql/sql_time.cc4
9 files changed, 22 insertions, 59 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 16c00dfd201..bea8062ea32 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -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);
}
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index 5e16166531d..71ab4265ee3 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -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 ||
diff --git a/sql/item.cc b/sql/item.cc
index ac920004b80..441470a0df1 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -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)
diff --git a/sql/item.h b/sql/item.h
index fb2948a9149..e0f2d26ba14 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -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:
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 962ea73f320..4bd3d4f7e47 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -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)
{
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 854a99bea02..039c4417f7b 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -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);
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index a4b5a18de35..8557b5ce50d 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -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)
{
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 889028ce8e5..a6613ec23c1 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -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);
}
/*
diff --git a/sql/sql_time.cc b/sql/sql_time.cc
index f4612ec517e..e2771d0500e 100644
--- a/sql/sql_time.cc
+++ b/sql/sql_time.cc
@@ -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>