diff options
author | unknown <jimw@rama.(none)> | 2006-07-18 16:04:18 -0700 |
---|---|---|
committer | unknown <jimw@rama.(none)> | 2006-07-18 16:04:18 -0700 |
commit | 20c2ddaf0c51f4a9564f67e67d56ab8acf6f1dd9 (patch) | |
tree | 7a901fad8e45dd3cfa24659bf23114d4ef56c2ad /sql/field.cc | |
parent | a7dddd3b67e70292c0813e80ad255f1dc2f3a867 (diff) | |
download | mariadb-git-20c2ddaf0c51f4a9564f67e67d56ab8acf6f1dd9.tar.gz |
Bug #19498: Inconsistent support for DEFAULT in TEXT columns
When a default of '' was specified for TEXT/BLOB columns, the specification
was silently ignored. This is presumably to be nice to applications (or
people) who generate their column definitions in a not-very-clever fashion.
For clarity, doing this now results in a warning, or an error in strict
mode.
mysql-test/r/federated.result:
Update results
mysql-test/r/fulltext_distinct.result:
Update results
mysql-test/r/fulltext_update.result:
Update results
mysql-test/r/gis-rtree.result:
Update results
mysql-test/r/gis.result:
Update results
mysql-test/r/join_outer.result:
Update results
mysql-test/r/order_by.result:
Update results
mysql-test/r/type_blob.result:
Add new results
mysql-test/r/type_ranges.result:
Update results
mysql-test/t/type_blob.test:
Add new test
sql/field.cc:
Issue a warning when setting '' as the default on a BLOB/TEXT column,
and make it an error in strict mode. Also, clarify comments about when
NO_DEFAULT_VALUE_FLAG is set.
Diffstat (limited to 'sql/field.cc')
-rw-r--r-- | sql/field.cc | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/sql/field.cc b/sql/field.cc index 946351efe36..31184a9f08c 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -8363,7 +8363,8 @@ bool create_field::init(THD *thd, char *fld_name, enum_field_types fld_type, comment= *fld_comment; /* - Set flag if this field doesn't have a default value + Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and + it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP. */ if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) && (fld_type_modifier & NOT_NULL_FLAG) && fld_type != FIELD_TYPE_TIMESTAMP) @@ -8440,12 +8441,28 @@ bool create_field::init(THD *thd, char *fld_name, enum_field_types fld_type, /* Allow empty as default value. */ String str,*res; res= fld_default_value->val_str(&str); - if (res->length()) + /* + A default other than '' is always an error, and any non-NULL + specified default is an error in strict mode. + */ + if (res->length() || (thd->variables.sql_mode & + (MODE_STRICT_TRANS_TABLES | + MODE_STRICT_ALL_TABLES))) { my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), fld_name); /* purecov: inspected */ DBUG_RETURN(TRUE); } + else + { + /* + Otherwise a default of '' is just a warning. + */ + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_BLOB_CANT_HAVE_DEFAULT, + ER(ER_BLOB_CANT_HAVE_DEFAULT), + fld_name); + } def= 0; } flags|= BLOB_FLAG; |