summaryrefslogtreecommitdiff
path: root/sql/field_conv.cc
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2015-11-14 22:51:54 +0100
committerSergei Golubchik <serg@mariadb.org>2015-12-21 21:30:54 +0100
commit0686c34d22a5cbf93015012eaf77a4a977b63afb (patch)
tree3c95207d5e01a905f9e87820e6439fe6c6547653 /sql/field_conv.cc
parentad5db17e882fea36dcae6f6e61996b5f9bf28962 (diff)
downloadmariadb-git-0686c34d22a5cbf93015012eaf77a4a977b63afb.tar.gz
MDEV-8605 MariaDB not use DEFAULT value even when inserted NULL for NOT NULLABLE column
NOT NULL constraint must be checked *after* the BEFORE triggers. That is for INSERT and UPDATE statements even NOT NULL fields must be able to store a NULL temporarily at least while BEFORE INSERT/UPDATE triggers are running.
Diffstat (limited to 'sql/field_conv.cc')
-rw-r--r--sql/field_conv.cc51
1 files changed, 31 insertions, 20 deletions
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index df4730a50ce..0f6c85f50e8 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -153,6 +153,36 @@ int set_field_to_null(Field *field)
/**
+ Set TIMESTAMP to NOW(), AUTO_INCREMENT to the next number, or report an error
+
+ @param field Field to update
+
+ @retval
+ 0 Field could take 0 or an automatic conversion was used
+ @retval
+ -1 Field could not take NULL and no conversion was used.
+ If no_conversion was not set, an error message is printed
+*/
+
+int convert_null_to_field_value_or_error(Field *field)
+{
+ if (field->type() == MYSQL_TYPE_TIMESTAMP)
+ {
+ ((Field_timestamp*) field)->set_time();
+ return 0;
+ }
+
+ field->reset(); // Note: we ignore any potential failure of reset() here.
+
+ if (field == field->table->next_number_field)
+ {
+ field->table->auto_increment_field_not_null= FALSE;
+ return 0; // field is set in fill_record()
+ }
+ return set_bad_null_error(field, ER_BAD_NULL_ERROR);
+}
+
+/**
Set field to NULL or TIMESTAMP or to next auto_increment number.
@param field Field to update
@@ -186,26 +216,7 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions)
if (no_conversions)
return -1;
- /*
- Check if this is a special type, which will get a special walue
- when set to NULL (TIMESTAMP fields which allow setting to NULL
- are handled by first check).
- */
- if (field->type() == MYSQL_TYPE_TIMESTAMP)
- {
- ((Field_timestamp*) field)->set_time();
- return 0; // Ok to set time to NULL
- }
-
- // Note: we ignore any potential failure of reset() here.
- field->reset();
-
- if (field == field->table->next_number_field)
- {
- field->table->auto_increment_field_not_null= FALSE;
- return 0; // field is set in fill_record()
- }
- return set_bad_null_error(field, ER_BAD_NULL_ERROR);
+ return convert_null_to_field_value_or_error(field);
}