Commit 2d715ba6 authored by Dmitry Shulga's avatar Dmitry Shulga

Manual-merge of patch for bug#11753738 from mysql-5.1 tree.

parents 155df6c6 1fea8c1b
......@@ -41,3 +41,98 @@ DROP TABLE t2;
DROP USER mysqltest_dfn@localhost;
DROP USER mysqltest_inv@localhost;
DROP DATABASE mysqltest_db1;
USE test;
#
# Bug#45235: 5.1 does not support 5.0-only syntax triggers in any way
#
DROP TABLE IF EXISTS t1, t2, t3;
CREATE TABLE t1 ( a INT );
CREATE TABLE t2 ( a INT );
CREATE TABLE t3 ( a INT );
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (1), (2), (3);
INSERT INTO t3 VALUES (1), (2), (3);
# We simulate importing a trigger from 5.0 by writing a .TRN file for
# each trigger plus a .TRG file the way MySQL 5.0 would have done it,
# with syntax allowed in 5.0 only.
#
# Note that in 5.0 the following lines are missing from t1.TRG:
#
# client_cs_names='latin1'
# connection_cl_names='latin1_swedish_ci'
# db_cl_names='latin1_swedish_ci'
FLUSH TABLE t1;
FLUSH TABLE t2;
# We will get parse errors for most DDL and DML statements when the table
# has broken triggers. The parse error refers to the first broken
# trigger.
CREATE TRIGGER tr16 AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t1 VALUES (1);
ERROR 42000: Trigger 'tr13' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a USING t1 a' at line 1'
CREATE TRIGGER tr22 BEFORE INSERT ON t2 FOR EACH ROW DELETE FROM non_existing_table;
ERROR 42000: Unknown trigger has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Not allowed syntax here, and trigger name cant be extracted either.' at line 1'
SHOW TRIGGERS;
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
tr11 INSERT t1 DELETE FROM t3 BEFORE NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
tr12 INSERT t1 DELETE FROM t3 AFTER NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
tr14 DELETE t1 DELETE FROM non_existing_table AFTER NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
INSERT INTO t1 VALUES (1);
ERROR 42000: Trigger 'tr13' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a USING t1 a' at line 1'
INSERT INTO t2 VALUES (1);
ERROR 42000: Unknown trigger has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Not allowed syntax here, and trigger name cant be extracted either.' at line 1'
DELETE FROM t1;
ERROR 42000: Trigger 'tr13' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a USING t1 a' at line 1'
UPDATE t1 SET a = 1 WHERE a = 1;
ERROR 42000: Trigger 'tr13' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a USING t1 a' at line 1'
SELECT * FROM t1;
a
1
2
3
RENAME TABLE t1 TO t1_2;
ERROR 42000: Trigger 'tr13' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a USING t1 a' at line 1'
SHOW TRIGGERS;
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
tr11 INSERT t1 DELETE FROM t3 BEFORE NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
tr12 INSERT t1 DELETE FROM t3 AFTER NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
tr14 DELETE t1 DELETE FROM non_existing_table AFTER NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
DROP TRIGGER tr11;
Warnings:
Warning 1603 Triggers for table `test`.`t1` have no creation context
DROP TRIGGER tr12;
DROP TRIGGER tr13;
DROP TRIGGER tr14;
DROP TRIGGER tr15;
SHOW TRIGGERS;
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
# Make sure there is no trigger file left.
# We write the same trigger files one more time to test DROP TABLE.
FLUSH TABLE t1;
FLUSH TABLE t2;
DROP TABLE t1;
Warnings:
Warning 1603 Triggers for table `test`.`t1` have no creation context
DROP TABLE t2;
Warnings:
Warning 1603 Triggers for table `test`.`t2` have no creation context
DROP TABLE t3;
# Make sure there is no trigger file left.
CREATE TABLE t1 ( a INT );
CREATE TABLE t2 ( a INT );
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (1), (2), (3);
# We write three trigger files. First trigger is syntaxically incorrect, next trigger is correct
# and last trigger is broken.
# Next we try to execute SHOW CREATE TRGGIR command for broken trigger and then try to drop one.
FLUSH TABLE t1;
SHOW CREATE TRIGGER tr12;
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation
tr12 CREATE DEFINER=`root`@`localhost` TRIGGER tr12 BEFORE INSERT ON t1 FOR EACH ROW DELETE FROM t2 latin1 latin1_swedish_ci latin1_swedish_ci
Warnings:
Warning 1603 Triggers for table `test`.`t1` have no creation context
SHOW CREATE TRIGGER tr11;
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation
tr11 CREATE DEFINER=`root`@`localhost` TRIGGER tr11 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a latin1 latin1_swedish_ci latin1_swedish_ci
DROP TRIGGER tr12;
DROP TRIGGER tr11;
DROP TABLE t1;
DROP TABLE t2;
......@@ -2118,7 +2118,7 @@ CREATE TRIGGER trg1 BEFORE INSERT ON t2 FOR EACH ROW INSERT/*!INTO*/t1 VALUES (1
SHOW TRIGGERS IN db1;
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
INSERT INTO t2 VALUES (1);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES (1)' at line 1
ERROR 42000: Trigger 'trg1' has an error in its body: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES (1)' at line 1'
SELECT * FROM t1;
b
# Work around Bug#45235
......
......@@ -106,4 +106,184 @@ DROP TABLE t2;
DROP USER mysqltest_dfn@localhost;
DROP USER mysqltest_inv@localhost;
DROP DATABASE mysqltest_db1;
USE test;
--echo #
--echo # Bug#45235: 5.1 does not support 5.0-only syntax triggers in any way
--echo #
let $MYSQLD_DATADIR=`SELECT @@datadir`;
--disable_warnings
DROP TABLE IF EXISTS t1, t2, t3;
--enable_warnings
CREATE TABLE t1 ( a INT );
CREATE TABLE t2 ( a INT );
CREATE TABLE t3 ( a INT );
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (1), (2), (3);
INSERT INTO t3 VALUES (1), (2), (3);
--echo # We simulate importing a trigger from 5.0 by writing a .TRN file for
--echo # each trigger plus a .TRG file the way MySQL 5.0 would have done it,
--echo # with syntax allowed in 5.0 only.
--echo #
--echo # Note that in 5.0 the following lines are missing from t1.TRG:
--echo #
--echo # client_cs_names='latin1'
--echo # connection_cl_names='latin1_swedish_ci'
--echo # db_cl_names='latin1_swedish_ci'
--write_file $MYSQLD_DATADIR/test/tr11.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr12.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr13.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr14.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr15.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/t1.TRG
TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr11 BEFORE INSERT ON t1 FOR EACH ROW DELETE FROM t3' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr12 AFTER INSERT ON t1 FOR EACH ROW DELETE FROM t3' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr13 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr14 AFTER DELETE ON t1 FOR EACH ROW DELETE FROM non_existing_table' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr15 BEFORE UPDATE ON t1 FOR EACH ROW DELETE FROM non_existing_table a USING non_existing_table a'
sql_modes=0 0 0 0 0
definers='root@localhost' 'root@localhost' 'root@localhost' 'root@localhost' 'root@localhost'
EOF
--write_file $MYSQLD_DATADIR/test/t2.TRG
TYPE=TRIGGERS
triggers='Not allowed syntax here, and trigger name cant be extracted either.'
sql_modes=0
definers='root@localhost'
EOF
FLUSH TABLE t1;
FLUSH TABLE t2;
--echo # We will get parse errors for most DDL and DML statements when the table
--echo # has broken triggers. The parse error refers to the first broken
--echo # trigger.
--error ER_PARSE_ERROR
CREATE TRIGGER tr16 AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t1 VALUES (1);
--error ER_PARSE_ERROR
CREATE TRIGGER tr22 BEFORE INSERT ON t2 FOR EACH ROW DELETE FROM non_existing_table;
SHOW TRIGGERS;
--error ER_PARSE_ERROR
INSERT INTO t1 VALUES (1);
--error ER_PARSE_ERROR
INSERT INTO t2 VALUES (1);
--error ER_PARSE_ERROR
DELETE FROM t1;
--error ER_PARSE_ERROR
UPDATE t1 SET a = 1 WHERE a = 1;
SELECT * FROM t1;
--error ER_PARSE_ERROR
RENAME TABLE t1 TO t1_2;
SHOW TRIGGERS;
DROP TRIGGER tr11;
DROP TRIGGER tr12;
DROP TRIGGER tr13;
DROP TRIGGER tr14;
DROP TRIGGER tr15;
SHOW TRIGGERS;
--echo # Make sure there is no trigger file left.
--list_files $MYSQLD_DATADIR/test/ tr*
--echo # We write the same trigger files one more time to test DROP TABLE.
--write_file $MYSQLD_DATADIR/test/tr11.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr12.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr13.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr14.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr15.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/t1.TRG
TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr11 BEFORE INSERT ON t1 FOR EACH ROW DELETE FROM t3' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr12 AFTER INSERT ON t1 FOR EACH ROW DELETE FROM t3' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr13 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr14 AFTER DELETE ON t1 FOR EACH ROW DELETE FROM non_existing_table' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr15 BEFORE UPDATE ON t1 FOR EACH ROW DELETE FROM non_existing_table a USING non_existing_table a'
sql_modes=0 0 0 0 0
definers='root@localhost' 'root@localhost' 'root@localhost' 'root@localhost' 'root@localhost'
EOF
FLUSH TABLE t1;
FLUSH TABLE t2;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
--echo # Make sure there is no trigger file left.
--list_files $MYSQLD_DATADIR/test/ tr*
CREATE TABLE t1 ( a INT );
CREATE TABLE t2 ( a INT );
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (1), (2), (3);
--echo # We write three trigger files. First trigger is syntaxically incorrect, next trigger is correct
--echo # and last trigger is broken.
--echo # Next we try to execute SHOW CREATE TRGGIR command for broken trigger and then try to drop one.
--write_file $MYSQLD_DATADIR/test/tr11.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/tr12.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
--write_file $MYSQLD_DATADIR/test/t1.TRG
TYPE=TRIGGERS
triggers='CREATE the wrongest trigger_in_the_world' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr11 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr12 BEFORE INSERT ON t1 FOR EACH ROW DELETE FROM t2'
sql_modes=0 0 0
definers='root@localhost' 'root@localhost' 'root@localhost'
EOF
FLUSH TABLE t1;
SHOW CREATE TRIGGER tr12;
SHOW CREATE TRIGGER tr11;
DROP TRIGGER tr12;
DROP TRIGGER tr11;
DROP TABLE t1;
DROP TABLE t2;
......@@ -6408,3 +6408,10 @@ WARN_OPTION_BELOW_LIMIT
ER_INDEX_COLUMN_TOO_LONG
eng "Index column size too large. The maximum column size is %lu bytes."
ER_ERROR_IN_TRIGGER_BODY
eng "Trigger '%-.64s' has an error in its body: '%-.256s'"
ER_ERROR_IN_UNKNOWN_TRIGGER_BODY
eng "Unknown trigger has an error in its body: '%-.256s'"
......@@ -2543,7 +2543,22 @@ void
sp_head::restore_thd_mem_root(THD *thd)
{
DBUG_ENTER("sp_head::restore_thd_mem_root");
Item *flist= free_list; // The old list
/*
In some cases our parser detects a syntax error and calls
LEX::cleanup_lex_after_parse_error() method only after
finishing parsing the whole routine. In such a situation
sp_head::restore_thd_mem_root() will be called twice - the
first time as part of normal parsing process and the second
time by cleanup_lex_after_parse_error().
To avoid ruining active arena/mem_root state in this case we
skip restoration of old arena/mem_root if this method has been
already called for this routine.
*/
if (!m_thd)
DBUG_VOID_RETURN;
Item *flist= free_list; // The old list
set_query_arena(thd); // Get new free_list and mem_root
state= STMT_INITIALIZED_FOR_SP;
......
......@@ -31,6 +31,7 @@
#include "sql_acl.h" // *_ACL, is_acl_user
#include "sql_handler.h" // mysql_ha_rm_tables
#include "sp_cache.h" // sp_invalidate_cache
#include <mysys_err.h>
/*************************************************************************/
......@@ -304,6 +305,55 @@ class Handle_old_incorrect_trigger_table_hook: public Unknown_key_hook
};
/**
An error handler that catches all non-OOM errors which can occur during
parsing of trigger body. Such errors are ignored and corresponding error
message is used to construct a more verbose error message which contains
name of problematic trigger. This error message is later emitted when
one tries to perform DML or some of DDL on this table.
Also, if possible, grabs name of the trigger being parsed so it can be
used to correctly drop problematic trigger.
*/
class Deprecated_trigger_syntax_handler : public Internal_error_handler
{
private:
char m_message[MYSQL_ERRMSG_SIZE];
LEX_STRING *m_trigger_name;
public:
Deprecated_trigger_syntax_handler() : m_trigger_name(NULL) {}
virtual bool handle_condition(THD *thd,
uint sql_errno,
const char* sqlstate,
MYSQL_ERROR::enum_warning_level level,
const char* message,
MYSQL_ERROR ** cond_hdl)
{
if (sql_errno != EE_OUTOFMEMORY &&
sql_errno != ER_OUT_OF_RESOURCES)
{
if(thd->lex->spname)
m_trigger_name= &thd->lex->spname->m_name;
if (m_trigger_name)
my_snprintf(m_message, sizeof(m_message),
ER(ER_ERROR_IN_TRIGGER_BODY),
m_trigger_name->str, message);
else
my_snprintf(m_message, sizeof(m_message),
ER(ER_ERROR_IN_UNKNOWN_TRIGGER_BODY), message);
return true;
}
return false;
}
LEX_STRING *get_trigger_name() { return m_trigger_name; }
char *get_error_message() { return m_message; }
};
/**
Create or drop trigger for table.
......@@ -591,6 +641,8 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
LEX_STRING *trg_connection_cl_name;
LEX_STRING *trg_db_cl_name;
if (check_for_broken_triggers())
return true;
/* Trigger must be in the same schema as target table. */
if (my_strcasecmp(table_alias_charset, table->s->db.str,
......@@ -864,7 +916,7 @@ static bool rm_trigger_file(char *path, const char *db,
@param path char buffer of size FN_REFLEN to be used
for constructing path to .TRN file.
@param db trigger's database name
@param table_name trigger's name
@param trigger_name trigger's name
@retval
False success
......@@ -1329,12 +1381,11 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
lex_start(thd);
thd->spcont= NULL;
if (parse_sql(thd, & parser_state, creation_ctx))
{
/* Currently sphead is always deleted in case of a parse error */
DBUG_ASSERT(lex.sphead == 0);
goto err_with_lex_cleanup;
}
Deprecated_trigger_syntax_handler error_handler;
thd->push_internal_handler(&error_handler);
bool parse_error= parse_sql(thd, & parser_state, creation_ctx);
thd->pop_internal_handler();
/*
Not strictly necessary to invoke this method here, since we know
that we've parsed CREATE TRIGGER and not an
......@@ -1345,6 +1396,54 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
*/
lex.set_trg_event_type_for_tables();
if (parse_error)
{
if (!triggers->m_has_unparseable_trigger)
triggers->set_parse_error_message(error_handler.get_error_message());
/* Currently sphead is always set to NULL in case of a parse error */
DBUG_ASSERT(lex.sphead == 0);
if (error_handler.get_trigger_name())
{
LEX_STRING *trigger_name;
const LEX_STRING *orig_trigger_name= error_handler.get_trigger_name();
if (!(trigger_name= alloc_lex_string(&table->mem_root)) ||
!(trigger_name->str= strmake_root(&table->mem_root,
orig_trigger_name->str,
orig_trigger_name->length)))
goto err_with_lex_cleanup;
trigger_name->length= orig_trigger_name->length;
if (triggers->names_list.push_back(trigger_name,
&table->mem_root))
goto err_with_lex_cleanup;
}
else
{
/*
The Table_triggers_list is not constructed as a list of
trigger objects as one would expect, but rather of lists of
properties of equal length. Thus, even if we don't get the
trigger name, we still fill all in all the lists with
placeholders as we might otherwise create a skew in the
lists. Obviously, this has to be refactored.
*/
LEX_STRING *empty= alloc_lex_string(&table->mem_root);
if (!empty)
goto err_with_lex_cleanup;
empty->str= const_cast<char*>("");
empty->length= 0;
if (triggers->names_list.push_back(empty, &table->mem_root))
goto err_with_lex_cleanup;
}
lex_end(&lex);
continue;
}
lex.sphead->set_info(0, 0, &lex.sp_chistics, (ulong) *trg_sql_mode);
int event= lex.trg_chistics.event;
int action_time= lex.trg_chistics.action_time;
......@@ -1411,9 +1510,8 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
char fname[NAME_LEN + 1];
DBUG_ASSERT((!my_strcasecmp(table_alias_charset, lex.query_tables->db, db) ||
(check_n_cut_mysql50_prefix(db, fname, sizeof(fname)) &&
!my_strcasecmp(table_alias_charset, lex.query_tables->db, fname))) &&
(!my_strcasecmp(table_alias_charset, lex.query_tables->table_name,
table_name) ||
!my_strcasecmp(table_alias_charset, lex.query_tables->db, fname))));
DBUG_ASSERT((!my_strcasecmp(table_alias_charset, lex.query_tables->table_name, table_name) ||
(check_n_cut_mysql50_prefix(table_name, fname, sizeof(fname)) &&
!my_strcasecmp(table_alias_charset, lex.query_tables->table_name, fname))));
#endif
......@@ -1695,6 +1793,13 @@ bool Table_triggers_list::drop_all_triggers(THD *thd, char *db, char *name)
while ((trigger= it_name++))
{
/*
Trigger, which body we failed to parse during call
Table_triggers_list::check_n_load(), might be missing name.
Such triggers have zero-length name and are skipped here.
*/
if (trigger->length == 0)
continue;
if (rm_trigname_file(path, db, trigger->str))
{
/*
......@@ -1913,6 +2018,11 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db,
}
if (table.triggers)
{
if (table.triggers->check_for_broken_triggers())
{
result= 1;
goto end;
}
LEX_STRING old_table_name= { (char *) old_alias, strlen(old_alias) };
LEX_STRING new_table_name= { (char *) new_table, strlen(new_table) };
/*
......@@ -2001,6 +2111,9 @@ bool Table_triggers_list::process_triggers(THD *thd,
sp_head *sp_trigger= bodies[event][time_type];
SELECT_LEX *save_current_select;
if (check_for_broken_triggers())
return true;
if (sp_trigger == NULL)
return FALSE;
......@@ -2134,6 +2247,22 @@ void Table_triggers_list::mark_fields_used(trg_event_type event)
}
/**
Signals to the Table_triggers_list that a parse error has occured when
reading a trigger from file. This makes the Table_triggers_list enter an
error state flagged by m_has_unparseable_trigger == true. The error message
will be used whenever a statement invoking or manipulating triggers is
issued against the Table_triggers_list's table.
@param error_message The error message thrown by the parser.
*/
void Table_triggers_list::set_parse_error_message(char *error_message)
{
m_has_unparseable_trigger= true;
strcpy(m_parse_error_message, error_message);
}
/**
Trigger BUG#14090 compatibility hook.
......
......@@ -97,6 +97,27 @@ class Table_triggers_list: public Sql_alloc
*/
GRANT_INFO subject_table_grants[TRG_EVENT_MAX][TRG_ACTION_MAX];
/**
This flag indicates that one of the triggers was not parsed successfully,
and as a precaution the object has entered a state where all trigger
access results in errors until all such triggers are dropped. It is not
safe to add triggers since we don't know if the broken trigger has the
same name or event type. Nor is it safe to invoke any trigger for the
aforementioned reasons. The only safe operations are drop_trigger and
drop_all_triggers.
@see Table_triggers_list::set_parse_error
*/
bool m_has_unparseable_trigger;
/**
This error will be displayed when the user tries to manipulate or invoke
triggers on a table that has broken triggers. It will get set only once
per statement and thus will contain the first parse error encountered in
the trigger file.
*/
char m_parse_error_message[MYSQL_ERRMSG_SIZE];
public:
/**
Field responsible for storing triggers definitions in file.
......@@ -118,8 +139,9 @@ class Table_triggers_list: public Sql_alloc
/* End of character ser context. */
Table_triggers_list(TABLE *table_arg):
record1_field(0), trigger_table(table_arg)
Table_triggers_list(TABLE *table_arg)
:record1_field(0), trigger_table(table_arg),
m_has_unparseable_trigger(false)
{
bzero((char *)bodies, sizeof(bodies));
bzero((char *)trigger_fields, sizeof(trigger_fields));
......@@ -176,6 +198,8 @@ class Table_triggers_list: public Sql_alloc
void mark_fields_used(trg_event_type event);
void set_parse_error_message(char *error_message);
friend class Item_trigger_field;
bool add_tables_and_routines_for_triggers(THD *thd,
......@@ -193,6 +217,16 @@ class Table_triggers_list: public Sql_alloc
const char *new_db_name,
LEX_STRING *old_table_name,
LEX_STRING *new_table_name);
bool check_for_broken_triggers()
{
if (m_has_unparseable_trigger)
{
my_message(ER_PARSE_ERROR, m_parse_error_message, MYF(0));
return true;
}
return false;
}
};
extern const LEX_STRING trg_action_time_type_names[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment