2009-09-23 23:32:31 +02:00
|
|
|
#ifndef SQL_TRIGGER_INCLUDED
|
|
|
|
#define SQL_TRIGGER_INCLUDED
|
|
|
|
|
2011-07-04 01:25:49 +02:00
|
|
|
/*
|
2011-11-21 18:13:14 +01:00
|
|
|
Copyright (c) 2004, 2011, Oracle and/or its affiliates.
|
2005-07-09 19:51:59 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2005-07-09 19:51:59 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2011-06-30 17:46:53 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
2005-07-09 19:51:59 +02:00
|
|
|
|
2015-10-23 11:31:18 +02:00
|
|
|
#include <mysqld_error.h>
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
/* Forward declarations */
|
|
|
|
|
|
|
|
class Item_trigger_field;
|
|
|
|
class sp_head;
|
|
|
|
class sp_name;
|
|
|
|
class Query_tables_list;
|
|
|
|
struct TABLE_LIST;
|
|
|
|
class Query_tables_list;
|
|
|
|
|
|
|
|
/** Event on which trigger is invoked. */
|
|
|
|
enum trg_event_type
|
|
|
|
{
|
|
|
|
TRG_EVENT_INSERT= 0,
|
|
|
|
TRG_EVENT_UPDATE= 1,
|
|
|
|
TRG_EVENT_DELETE= 2,
|
|
|
|
TRG_EVENT_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
#include "table.h" /* GRANT_INFO */
|
|
|
|
|
|
|
|
/*
|
|
|
|
We need this two enums here instead of sql_lex.h because
|
|
|
|
at least one of them is used by Item_trigger_field interface.
|
|
|
|
|
|
|
|
Time when trigger is invoked (i.e. before or after row actually
|
|
|
|
inserted/updated/deleted).
|
|
|
|
*/
|
|
|
|
enum trg_action_time_type
|
|
|
|
{
|
|
|
|
TRG_ACTION_BEFORE= 0, TRG_ACTION_AFTER= 1, TRG_ACTION_MAX
|
|
|
|
};
|
|
|
|
|
2016-10-02 14:35:08 +02:00
|
|
|
enum trigger_order_type
|
|
|
|
{
|
|
|
|
TRG_ORDER_NONE= 0,
|
|
|
|
TRG_ORDER_FOLLOWS= 1,
|
|
|
|
TRG_ORDER_PRECEDES= 2
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct st_trg_execution_order
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
FOLLOWS or PRECEDES as specified in the CREATE TRIGGER statement.
|
|
|
|
*/
|
|
|
|
enum trigger_order_type ordering_clause;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Trigger name referenced in the FOLLOWS/PRECEDES clause of the
|
|
|
|
CREATE TRIGGER statement.
|
|
|
|
*/
|
|
|
|
LEX_STRING anchor_trigger_name;
|
|
|
|
};
|
2005-07-09 19:51:59 +02:00
|
|
|
|
2004-09-07 14:29:46 +02:00
|
|
|
|
2016-10-02 14:35:08 +02:00
|
|
|
class Table_triggers_list;
|
|
|
|
|
|
|
|
/**
|
|
|
|
The trigger object
|
2004-09-07 14:29:46 +02:00
|
|
|
*/
|
2005-08-15 17:15:12 +02:00
|
|
|
|
2016-10-02 14:35:08 +02:00
|
|
|
class Trigger :public Sql_alloc
|
2004-09-07 14:29:46 +02:00
|
|
|
{
|
2016-10-02 14:35:08 +02:00
|
|
|
public:
|
|
|
|
Trigger(Table_triggers_list *base_arg, sp_head *code):
|
|
|
|
base(base_arg), body(code), next(0), trigger_fields(0), action_order(0)
|
|
|
|
{
|
|
|
|
bzero((char *)&subject_table_grants, sizeof(subject_table_grants));
|
|
|
|
}
|
|
|
|
~Trigger();
|
|
|
|
Table_triggers_list *base;
|
|
|
|
sp_head *body;
|
|
|
|
Trigger *next; /* Next trigger of same type */
|
|
|
|
|
2007-10-16 22:11:50 +02:00
|
|
|
/**
|
2006-07-01 23:51:10 +02:00
|
|
|
Heads of the lists linking items for all fields used in triggers
|
|
|
|
grouped by event and action_time.
|
|
|
|
*/
|
2016-10-02 14:35:08 +02:00
|
|
|
Item_trigger_field *trigger_fields;
|
|
|
|
LEX_STRING name;
|
|
|
|
LEX_STRING on_table_name; /* Raw table name */
|
|
|
|
LEX_STRING definition;
|
|
|
|
LEX_STRING definer;
|
|
|
|
|
|
|
|
/* Character sets used */
|
|
|
|
LEX_STRING client_cs_name;
|
|
|
|
LEX_STRING connection_cl_name;
|
|
|
|
LEX_STRING db_cl_name;
|
|
|
|
|
|
|
|
GRANT_INFO subject_table_grants;
|
|
|
|
ulonglong sql_mode;
|
|
|
|
/* Store create time. Can't be mysql_time_t as this holds also sub seconds */
|
|
|
|
ulonglong create_time;
|
|
|
|
trg_event_type event;
|
|
|
|
trg_action_time_type action_time;
|
|
|
|
uint action_order;
|
|
|
|
|
|
|
|
bool is_fields_updated_in_trigger(MY_BITMAP *used_fields);
|
|
|
|
void get_trigger_info(LEX_STRING *stmt, LEX_STRING *body,
|
|
|
|
LEX_STRING *definer);
|
|
|
|
/* Functions executed over each active trigger */
|
|
|
|
bool change_on_table_name(void* param_arg);
|
|
|
|
bool change_table_name(void* param_arg);
|
|
|
|
bool add_to_file_list(void* param_arg);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef bool (Trigger::*Triggers_processor)(void *arg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
This class holds all information about triggers of table.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Table_triggers_list: public Sql_alloc
|
|
|
|
{
|
|
|
|
friend class Trigger;
|
|
|
|
|
|
|
|
/* Points to first trigger for a certain type */
|
|
|
|
Trigger *triggers[TRG_EVENT_MAX][TRG_ACTION_MAX];
|
2015-11-14 22:51:54 +01:00
|
|
|
/**
|
|
|
|
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;
|
2007-10-16 22:11:50 +02:00
|
|
|
/**
|
2005-05-24 20:19:33 +02:00
|
|
|
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).
|
2004-09-07 14:29:46 +02:00
|
|
|
*/
|
2005-05-24 20:19:33 +02:00
|
|
|
Field **record1_field;
|
2007-10-16 22:11:50 +02:00
|
|
|
/**
|
2005-05-24 20:19:33 +02:00
|
|
|
During execution of trigger new_field and old_field should point to the
|
|
|
|
array of fields representing new or old version of row correspondingly
|
|
|
|
(so it can point to TABLE::field or to Tale_triggers_list::record1_field)
|
|
|
|
*/
|
|
|
|
Field **new_field;
|
2004-09-07 14:29:46 +02:00
|
|
|
Field **old_field;
|
2006-12-14 23:51:37 +01:00
|
|
|
|
2005-05-24 20:19:33 +02:00
|
|
|
/* TABLE instance for which this triggers list object was created */
|
2006-12-14 23:51:37 +01:00
|
|
|
TABLE *trigger_table;
|
2005-11-10 20:25:03 +01:00
|
|
|
|
2011-06-10 05:52:39 +02:00
|
|
|
/**
|
|
|
|
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];
|
2016-10-02 14:35:08 +02:00
|
|
|
uint count; /* Number of triggers */
|
2011-06-10 05:52:39 +02:00
|
|
|
|
2004-09-07 14:29:46 +02:00
|
|
|
public:
|
2007-10-16 22:11:50 +02:00
|
|
|
/**
|
2004-09-07 14:29:46 +02:00
|
|
|
Field responsible for storing triggers definitions in file.
|
|
|
|
It have to be public because we are using it directly from parser.
|
|
|
|
*/
|
|
|
|
List<LEX_STRING> definitions_list;
|
2007-10-16 22:11:50 +02:00
|
|
|
/**
|
2005-07-28 21:39:11 +02:00
|
|
|
List of sql modes for triggers
|
|
|
|
*/
|
|
|
|
List<ulonglong> definition_modes_list;
|
2016-10-02 14:35:08 +02:00
|
|
|
/** Create times for triggers */
|
|
|
|
List<ulonglong> create_times;
|
2004-09-07 14:29:46 +02:00
|
|
|
|
2005-11-10 20:25:03 +01:00
|
|
|
List<LEX_STRING> definers_list;
|
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
/* Character set context, used for parsing and executing triggers. */
|
|
|
|
|
|
|
|
List<LEX_STRING> client_cs_names;
|
|
|
|
List<LEX_STRING> connection_cl_names;
|
|
|
|
List<LEX_STRING> db_cl_names;
|
|
|
|
|
|
|
|
/* End of character ser context. */
|
|
|
|
|
2011-06-10 09:20:15 +02:00
|
|
|
Table_triggers_list(TABLE *table_arg)
|
2015-11-14 22:51:54 +01:00
|
|
|
:record0_field(0), extra_null_bitmap(0), record1_field(0),
|
|
|
|
trigger_table(table_arg),
|
2016-10-02 14:35:08 +02:00
|
|
|
m_has_unparseable_trigger(false), count(0)
|
2004-09-07 14:29:46 +02:00
|
|
|
{
|
2016-10-02 14:35:08 +02:00
|
|
|
bzero((char *) triggers, sizeof(triggers));
|
2004-09-07 14:29:46 +02:00
|
|
|
}
|
|
|
|
~Table_triggers_list();
|
|
|
|
|
2006-08-24 16:48:26 +02:00
|
|
|
bool create_trigger(THD *thd, TABLE_LIST *table, String *stmt_query);
|
|
|
|
bool drop_trigger(THD *thd, TABLE_LIST *table, String *stmt_query);
|
2004-09-07 14:29:46 +02:00
|
|
|
bool process_triggers(THD *thd, trg_event_type event,
|
2005-05-24 20:19:33 +02:00
|
|
|
trg_action_time_type time_type,
|
2005-08-15 17:15:12 +02:00
|
|
|
bool old_row_is_record1);
|
2016-10-02 14:35:08 +02:00
|
|
|
void empty_lists();
|
|
|
|
bool create_lists_needed_for_files(MEM_ROOT *root);
|
|
|
|
bool save_trigger_file(THD *thd, const char *db, const char *table_name);
|
2004-09-07 14:29:46 +02:00
|
|
|
|
|
|
|
static bool check_n_load(THD *thd, const char *db, const char *table_name,
|
2005-07-19 18:06:49 +02:00
|
|
|
TABLE *table, bool names_only);
|
|
|
|
static bool drop_all_triggers(THD *thd, char *db, char *table_name);
|
2006-02-24 21:50:36 +01:00
|
|
|
static bool change_table_name(THD *thd, const char *db,
|
2010-09-16 11:11:13 +02:00
|
|
|
const char *old_alias,
|
2006-02-24 21:50:36 +01:00
|
|
|
const char *old_table,
|
|
|
|
const char *new_db,
|
|
|
|
const char *new_table);
|
2016-10-02 14:35:08 +02:00
|
|
|
void add_trigger(trg_event_type event_type,
|
|
|
|
trg_action_time_type action_time,
|
|
|
|
trigger_order_type ordering_clause,
|
|
|
|
LEX_STRING *anchor_trigger_name,
|
|
|
|
Trigger *trigger);
|
|
|
|
Trigger *get_trigger(trg_event_type event_type,
|
|
|
|
trg_action_time_type action_time)
|
|
|
|
{
|
|
|
|
return triggers[event_type][action_time];
|
|
|
|
}
|
|
|
|
/* Simpler version of the above, to avoid casts in the code */
|
|
|
|
Trigger *get_trigger(uint event_type, uint action_time)
|
|
|
|
{
|
|
|
|
return get_trigger((trg_event_type) event_type,
|
|
|
|
(trg_action_time_type) action_time);
|
|
|
|
}
|
|
|
|
|
2007-04-04 12:50:39 +02:00
|
|
|
bool has_triggers(trg_event_type event_type,
|
|
|
|
trg_action_time_type action_time)
|
|
|
|
{
|
2016-10-02 14:35:08 +02:00
|
|
|
return get_trigger(event_type,action_time) != 0;
|
2007-04-04 12:50:39 +02:00
|
|
|
}
|
2004-11-12 15:04:07 +01:00
|
|
|
bool has_delete_triggers()
|
|
|
|
{
|
2016-10-02 14:35:08 +02:00
|
|
|
return (has_triggers(TRG_EVENT_DELETE,TRG_ACTION_BEFORE) ||
|
|
|
|
has_triggers(TRG_EVENT_DELETE,TRG_ACTION_AFTER));
|
2004-11-12 15:04:07 +01:00
|
|
|
}
|
|
|
|
|
2006-07-06 11:33:23 +02:00
|
|
|
void mark_fields_used(trg_event_type event);
|
2006-07-01 23:51:10 +02:00
|
|
|
|
2011-06-10 05:52:39 +02:00
|
|
|
void set_parse_error_message(char *error_message);
|
|
|
|
|
2004-09-07 14:29:46 +02:00
|
|
|
friend class Item_trigger_field;
|
2009-12-08 15:13:12 +01:00
|
|
|
|
|
|
|
bool add_tables_and_routines_for_triggers(THD *thd,
|
|
|
|
Query_tables_list *prelocking_ctx,
|
|
|
|
TABLE_LIST *table_list);
|
2004-11-24 10:24:02 +01:00
|
|
|
|
2015-11-14 22:51:54 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-10-02 14:35:08 +02:00
|
|
|
Trigger *find_trigger(const LEX_STRING *name, bool remove_from_list);
|
|
|
|
|
|
|
|
Trigger* for_all_triggers(Triggers_processor func, void *arg);
|
|
|
|
|
2004-11-24 10:24:02 +01:00
|
|
|
private:
|
2015-11-14 22:51:54 +01:00
|
|
|
bool prepare_record_accessors(TABLE *table);
|
2016-10-02 14:35:08 +02:00
|
|
|
Trigger *change_table_name_in_trignames(const char *old_db_name,
|
|
|
|
const char *new_db_name,
|
|
|
|
LEX_STRING *new_table_name,
|
|
|
|
Trigger *trigger);
|
2006-02-24 21:50:36 +01:00
|
|
|
bool change_table_name_in_triggers(THD *thd,
|
2009-01-14 15:50:51 +01:00
|
|
|
const char *old_db_name,
|
|
|
|
const char *new_db_name,
|
2006-02-24 21:50:36 +01:00
|
|
|
LEX_STRING *old_table_name,
|
|
|
|
LEX_STRING *new_table_name);
|
2011-06-10 05:52:39 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2004-09-07 14:29:46 +02:00
|
|
|
};
|
2005-07-19 18:06:49 +02:00
|
|
|
|
2015-11-14 22:51:54 +01:00
|
|
|
inline Field **TABLE::field_to_fill()
|
|
|
|
{
|
|
|
|
return triggers && triggers->nullable_fields() ? triggers->nullable_fields()
|
|
|
|
: field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-14 17:23:55 +02:00
|
|
|
bool add_table_for_trigger(THD *thd,
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
const sp_name *trg_name,
|
2007-06-14 17:23:55 +02:00
|
|
|
bool continue_if_not_exist,
|
|
|
|
TABLE_LIST **table);
|
|
|
|
|
|
|
|
void build_trn_path(THD *thd, const sp_name *trg_name, LEX_STRING *trn_path);
|
|
|
|
|
|
|
|
bool check_trn_exists(const LEX_STRING *trn_path);
|
|
|
|
|
|
|
|
bool load_table_name_for_trigger(THD *thd,
|
|
|
|
const sp_name *trg_name,
|
|
|
|
const LEX_STRING *trn_path,
|
|
|
|
LEX_STRING *tbl_name);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
|
|
|
|
|
|
|
|
extern const char * const TRG_EXT;
|
|
|
|
extern const char * const TRN_EXT;
|
2007-06-14 17:23:55 +02:00
|
|
|
|
2009-09-23 23:32:31 +02:00
|
|
|
#endif /* SQL_TRIGGER_INCLUDED */
|