diff options
author | unknown <jimw@mysql.com> | 2005-02-01 15:08:31 -0800 |
---|---|---|
committer | unknown <jimw@mysql.com> | 2005-02-01 15:08:31 -0800 |
commit | 6162c4a6eb22b413a477bb6b9b0f08ec9b98a193 (patch) | |
tree | 0bf268db7a1d7bc463e1002972311bb760a711be /sql/field.cc | |
parent | eca1f04aa43a9c02a6af1ed9ba9f666a5b684607 (diff) | |
download | mariadb-git-6162c4a6eb22b413a477bb6b9b0f08ec9b98a193.tar.gz |
Fix value of YEAR field when set from a non-numeric string. (Bug #6067)
mysql-test/t/type_date.test:
Add new regression test
mysql-test/r/type_date.result:
Add result
sql/field.cc:
Set YEAR to 0 when set to a non-numeric string, not 2000,
and issue a warning.
Diffstat (limited to 'sql/field.cc')
-rw-r--r-- | sql/field.cc | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/sql/field.cc b/sql/field.cc index 7357bc06f11..a2b749257df 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -3511,9 +3511,17 @@ void Field_time::sql_type(String &res) const int Field_year::store(const char *from, uint len,CHARSET_INFO *cs) { - int not_used; // We can ignore result from str2int + int err; char *end; - long nr= my_strntol(cs, from, len, 10, &end, ¬_used); + long nr= my_strntol(cs, from, len, 10, &end, &err); + + if (err) + { + if (table->in_use->count_cuted_fields) + set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); + *ptr= 0; + return 0; + } if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155) { |