summaryrefslogtreecommitdiff
path: root/sql-common
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
commitcf5e6660290382dea43f52edd84e28fcb0a41b7b (patch)
tree7f0311baaca32e6242f23dcf0a89ed38e39c9ac0 /sql-common
parentd209efc0a90258aa1f67b47ede06f28746adfe08 (diff)
downloadmariadb-git-cf5e6660290382dea43f52edd84e28fcb0a41b7b.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-common')
-rw-r--r--sql-common/my_time.c69
1 files changed, 64 insertions, 5 deletions
diff --git a/sql-common/my_time.c b/sql-common/my_time.c
index 4b5daf53bea..703cfb089c0 100644
--- a/sql-common/my_time.c
+++ b/sql-common/my_time.c
@@ -47,6 +47,43 @@ uchar days_in_month[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
static long my_time_zone=0;
+/* 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);
+}
+
+/*
+ check date.
+
+ SYNOPOSIS
+ bool check_date()
+ time Date to check.
+
+ NOTES
+ Here we assume that year and month is ok !
+ If month is 0 we allow any date. (This only happens if we allow zero
+ date parts in str_to_datetime())
+
+ RETURN
+ 0 ok
+ 1 errro
+*/
+
+bool check_date(MYSQL_TIME *ltime)
+{
+ if (ltime->month && ltime->day > days_in_month[ltime->month-1])
+ {
+ if (ltime->month != 2 || calc_days_in_year(ltime->year) != 366 ||
+ ltime->day != 29)
+ return 1;
+ }
+ return 0;
+}
+
+
/*
Convert a timestamp string to a MYSQL_TIME value.
@@ -58,8 +95,12 @@ static long my_time_zone=0;
flags Bitmap of following items
TIME_FUZZY_DATE Set if we should allow partial dates
TIME_DATETIME_ONLY Set if we only allow full datetimes.
- was_cut Set to 1 if value was cut during conversion or to 0
- otherwise.
+ TIME_NO_ZERO_IN_DATE Don't allow partial dates
+ TIME_NO_ZERO_DATE Don't allow 0000-00-00 date
+ TIME_INVALID_DATES Allow 2000-02-31
+ was_cut 0 Value ok
+ 1 If value was cut during conversion
+ 2 Date part was withing ranges but date was wrong
DESCRIPTION
At least the following formats are recogniced (based on number of digits)
@@ -127,6 +168,8 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
*was_cut= 1;
DBUG_RETURN(MYSQL_TIMESTAMP_NONE);
}
+ if (flags & TIME_NO_ZERO_IN_DATE)
+ flags&= ~TIME_FUZZY_DATE;
is_internal_format= 0;
/* This has to be changed if want to activate different timestamp formats */
@@ -343,10 +386,21 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
(l_time->month || l_time->day))
l_time->year+= (l_time->year < YY_PART_YEAR ? 2000 : 1900);
+ if (!not_zero_date && (flags & TIME_NO_ZERO_DATE))
+ {
+ /*
+ We don't set *was_cut here to signal that the problem was a zero date
+ and not an invalid date
+ */
+ goto err;
+ }
+
if (number_of_fields < 3 || l_time->month > 12 ||
l_time->day > 31 || l_time->hour > 23 ||
l_time->minute > 59 || l_time->second > 59 ||
- (!(flags & TIME_FUZZY_DATE) && (l_time->month == 0 || l_time->day == 0)))
+ (!(flags & TIME_FUZZY_DATE) && (l_time->month == 0 ||
+ l_time->day == 0) &&
+ not_zero_date))
{
/* Only give warning for a zero date if there is some garbage after */
if (!not_zero_date) /* If zero date */
@@ -360,14 +414,19 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
}
}
}
- if (not_zero_date)
- *was_cut= 1;
+ *was_cut= test(not_zero_date);
goto err;
}
l_time->time_type= (number_of_fields <= 3 ?
MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME);
+ if (not_zero_date && !(flags & TIME_INVALID_DATES) && check_date(l_time))
+ {
+ *was_cut= 2; /* Not correct date */
+ goto err;
+ }
+
for (; str != end ; str++)
{
if (!my_isspace(&my_charset_latin1,*str))