diff options
author | Sergei Golubchik <serg@mariadb.org> | 2015-11-14 22:51:54 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2015-12-21 21:30:54 +0100 |
commit | 0686c34d22a5cbf93015012eaf77a4a977b63afb (patch) | |
tree | 3c95207d5e01a905f9e87820e6439fe6c6547653 /sql/sql_trigger.h | |
parent | ad5db17e882fea36dcae6f6e61996b5f9bf28962 (diff) | |
download | mariadb-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/sql_trigger.h')
-rw-r--r-- | sql/sql_trigger.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h index 1885720bf8b..fa858a0582b 100644 --- a/sql/sql_trigger.h +++ b/sql/sql_trigger.h @@ -68,6 +68,13 @@ class Table_triggers_list: public Sql_alloc */ Item_trigger_field *trigger_fields[TRG_EVENT_MAX][TRG_ACTION_MAX]; /** + Copy of TABLE::Field array which all fields made nullable + (using extra_null_bitmap, if needed). Used for NEW values in + BEFORE INSERT/UPDATE triggers. + */ + Field **record0_field; + uchar *extra_null_bitmap; + /** Copy of TABLE::Field array with field pointers set to TABLE::record[1] buffer instead of TABLE::record[0] (used for OLD values in on UPDATE trigger and DELETE trigger when it is called for REPLACE). @@ -143,7 +150,8 @@ public: /* End of character ser context. */ Table_triggers_list(TABLE *table_arg) - :record1_field(0), trigger_table(table_arg), + :record0_field(0), extra_null_bitmap(0), record1_field(0), + trigger_table(table_arg), m_has_unparseable_trigger(false) { bzero((char *)bodies, sizeof(bodies)); @@ -211,8 +219,16 @@ public: trg_event_type event_type, trg_action_time_type action_time); + Field **nullable_fields() { return record0_field; } + void reset_extra_null_bitmap() + { + int null_bytes= (trigger_table->s->stored_fields - + trigger_table->s->null_fields + 7)/8; + bzero(extra_null_bitmap, null_bytes); + } + private: - bool prepare_record1_accessors(TABLE *table); + bool prepare_record_accessors(TABLE *table); LEX_STRING* change_table_name_in_trignames(const char *old_db_name, const char *new_db_name, LEX_STRING *new_table_name, @@ -234,6 +250,13 @@ private: } }; +inline Field **TABLE::field_to_fill() +{ + return triggers && triggers->nullable_fields() ? triggers->nullable_fields() + : field; +} + + extern const LEX_STRING trg_action_time_type_names[]; extern const LEX_STRING trg_event_type_names[]; |