summaryrefslogtreecommitdiff
path: root/sql/time.cc
diff options
context:
space:
mode:
authorunknown <monty@mishka.local>2004-09-28 20:08:00 +0300
committerunknown <monty@mishka.local>2004-09-28 20:08:00 +0300
commit2a49121590930ad9ef69718caad67304e94b9c00 (patch)
tree7f0311baaca32e6242f23dcf0a89ed38e39c9ac0 /sql/time.cc
parente74b00bbc98c1082086422dc9c8578dade9d4a11 (diff)
downloadmariadb-git-2a49121590930ad9ef69718caad67304e94b9c00.tar.gz
Strict mode & better warnings
Under strict mode MySQL will generate an error message if there was any conversion when assigning data to a field. Added checking of date/datetime fields. If strict mode, give error if we have not given value to field without a default value (for INSERT) client/mysqltest.c: Added --exit as an option to abort a test in a middle (good for debugging) include/my_time.h: Added flags to allow checking of dates in strict mode include/mysql_com.h: Added flag to check if field has a default value or not include/mysqld_error.h: New error messages for strict mode include/sql_state.h: Fixed SQL states (for strict mode tests) mysql-test/r/auto_increment.result: Updated error messages mysql-test/r/func_sapdb.result: Added test for ALLOW_INVALID_DATES mysql-test/r/func_str.result: Updated error messages mysql-test/r/func_time.result: Updated error messages mysql-test/r/insert.result: Updated error messages mysql-test/r/loaddata.result: Updated error messages mysql-test/r/select.result: Updated error messages mysql-test/r/sp.result: Updated error messages mysql-test/r/timezone2.result: Updated error messages mysql-test/r/type_datetime.result: Updated error messages mysql-test/r/type_decimal.result: Updated error messages mysql-test/r/type_float.result: Updated error messages mysql-test/r/type_ranges.result: Updated error messages mysql-test/r/type_time.result: Updated error messages mysql-test/r/type_uint.result: Updated error messages mysql-test/r/warnings.result: Updated error messages mysql-test/t/func_sapdb.test: Aded test sql-common/my_time.c: Added checking of dates sql/field.cc: Better error messages Optimization of warning handling (by introducing of check_int()) Changed to use my_strtoll10() sql/field.h: Added check_int() sql/item_func.cc: Warnings when dividing by NULL sql/item_func.h: Warnings when dividing by NULL sql/item_timefunc.cc: Testing of date/datetime Use macros instead of constants sql/mysql_priv.h: New modes (part of strict mode) sql/mysqld.cc: New modes (part of strict mode) sql/opt_range.cc: Simple optimizations sql/protocol.cc: Add note/warning level to find_handler() sql/set_var.cc: Added mode 'traditional' sql/share/czech/errmsg.txt: New error messages for strict mode sql/share/danish/errmsg.txt: New error messages for strict mode sql/share/dutch/errmsg.txt: New error messages for strict mode sql/share/english/errmsg.txt: New error messages for strict mode sql/share/estonian/errmsg.txt: New error messages for strict mode sql/share/french/errmsg.txt: New error messages for strict mode sql/share/german/errmsg.txt: New error messages for strict mode sql/share/greek/errmsg.txt: New error messages for strict mode sql/share/hungarian/errmsg.txt: New error messages for strict mode sql/share/italian/errmsg.txt: New error messages for strict mode sql/share/japanese/errmsg.txt: New error messages for strict mode sql/share/korean/errmsg.txt: New error messages for strict mode sql/share/norwegian-ny/errmsg.txt: New error messages for strict mode sql/share/norwegian/errmsg.txt: New error messages for strict mode sql/share/polish/errmsg.txt: New error messages for strict mode sql/share/portuguese/errmsg.txt: New error messages for strict mode sql/share/romanian/errmsg.txt: New error messages for strict mode sql/share/russian/errmsg.txt: New error messages for strict mode sql/share/serbian/errmsg.txt: New error messages for strict mode sql/share/slovak/errmsg.txt: New error messages for strict mode sql/share/spanish/errmsg.txt: New error messages for strict mode sql/share/swedish/errmsg.txt: New error messages for strict mode sql/share/ukrainian/errmsg.txt: New error messages for strict mode sql/sp_rcontext.cc: Add note/warning level to find_handler() sql/sp_rcontext.h: Add note/warning level to find_handler() sql/sql_base.cc: Fix bug for detecting crashed table sql/sql_class.cc: Variables for strct mode sql/sql_class.h: Variables for strct mode sql/sql_error.cc: In strict mode, convert warnings to errors sql/sql_insert.cc: Strict mode If strict mode, give error if we have not given value to field without a default value sql/sql_load.cc: Strict mode sql/sql_parse.cc: Strict mode. Add flag to field if it doesn't have a default value sql/sql_select.cc: Added comment Prepare for upper level handling of table->status sql/sql_union.cc: Added THD to write_record() sql/sql_update.cc: Strict mode sql/table.cc: Handling of default values sql/time.cc: Checking of dates
Diffstat (limited to 'sql/time.cc')
-rw-r--r--sql/time.cc43
1 files changed, 24 insertions, 19 deletions
diff --git a/sql/time.cc b/sql/time.cc
index 4421b6aa00f..f47d7652864 100644
--- a/sql/time.cc
+++ b/sql/time.cc
@@ -33,15 +33,6 @@ int calc_weekday(long daynr,bool sunday_first_day_of_week)
DBUG_RETURN ((int) ((daynr + 5L + (sunday_first_day_of_week ? 1L : 0L)) % 7));
}
- /* Calc days in one year. works with 0 <= year <= 99 */
-
-uint calc_days_in_year(uint year)
-{
- return (year & 3) == 0 && (year%100 || (year%400 == 0 && year)) ?
- 366 : 365;
-}
-
-
/*
The bits in week_format has the following meaning:
WEEK_MONDAY_FIRST (0) If not set Sunday is first day of week
@@ -200,9 +191,16 @@ str_to_datetime_with_warn(const char *str, uint length, TIME *l_time,
uint flags)
{
int was_cut;
- timestamp_type ts_type= str_to_datetime(str, length, l_time, flags, &was_cut);
+ THD *thd= current_thd;
+ timestamp_type ts_type;
+
+ ts_type= str_to_datetime(str, length, l_time,
+ (flags | (thd->variables.sql_mode &
+ (MODE_INVALID_DATES |
+ MODE_NO_ZERO_DATE))),
+ &was_cut);
if (was_cut)
- make_truncated_value_warning(current_thd, str, length, ts_type);
+ make_truncated_value_warning(current_thd, str, length, ts_type, NullS);
return ts_type;
}
@@ -258,7 +256,8 @@ str_to_time_with_warn(const char *str, uint length, TIME *l_time)
int was_cut;
bool ret_val= str_to_time(str, length, l_time, &was_cut);
if (was_cut)
- make_truncated_value_warning(current_thd, str, length, MYSQL_TIMESTAMP_TIME);
+ make_truncated_value_warning(current_thd, str, length,
+ MYSQL_TIMESTAMP_TIME, NullS);
return ret_val;
}
@@ -791,16 +790,15 @@ void make_datetime(const DATE_TIME_FORMAT *format __attribute__((unused)),
void make_truncated_value_warning(THD *thd, const char *str_val,
- uint str_length, timestamp_type time_type)
+ uint str_length, timestamp_type time_type,
+ const char *field_name)
{
char warn_buff[MYSQL_ERRMSG_SIZE];
const char *type_str;
-
+ CHARSET_INFO *cs= &my_charset_latin1;
char buff[128];
String str(buff,(uint32) sizeof(buff), system_charset_info);
- str.length(0);
- str.append(str_val, str_length);
- str.append('\0');
+ str.copy(str_val, str_length, system_charset_info);
switch (time_type) {
case MYSQL_TIMESTAMP_DATE:
@@ -814,8 +812,15 @@ void make_truncated_value_warning(THD *thd, const char *str_val,
type_str= "datetime";
break;
}
- sprintf(warn_buff, ER(ER_TRUNCATED_WRONG_VALUE),
- type_str, str.ptr());
+ if (field_name)
+ cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
+ ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
+ type_str, str.c_ptr(), field_name,
+ (ulong) thd->row_count);
+ else
+ cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
+ ER(ER_TRUNCATED_WRONG_VALUE),
+ type_str, str.ptr());
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE, warn_buff);
}