Commit ed866e93 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-19182 mysqldump not always handling SHOW CREATE TRIGGER failures correctly

only use SHOW TRIGGERS on old (< 5.1.21) servers, otherwise
always use SHOW CREATE TRIGGER and don't fallback.
parent 3db6de33
......@@ -3262,7 +3262,7 @@ static void dump_trigger_old(FILE *sql_file, MYSQL_RES *show_triggers_rs,
char name_buff[NAME_LEN * 4 + 3];
const char *xml_msg= "\nWarning! mysqldump being run against old server "
"that does not\nsupport 'SHOW CREATE TRIGGERS' "
"that does not\nsupport 'SHOW CREATE TRIGGER' "
"statement. Skipping..\n";
DBUG_ENTER("dump_trigger_old");
......@@ -3413,12 +3413,14 @@ static int dump_triggers_for_table(char *table_name, char *db_name)
char db_cl_name[MY_CS_NAME_SIZE];
int ret= TRUE;
/* Servers below 5.1.21 do not support SHOW CREATE TRIGGER */
const int use_show_create_trigger= mysql_get_server_version(mysql) >= 50121;
DBUG_ENTER("dump_triggers_for_table");
DBUG_PRINT("enter", ("db: %s, table_name: %s", db_name, table_name));
if (path && !(sql_file= open_sql_file_for_table(table_name,
O_WRONLY | O_APPEND)))
if (path &&
!(sql_file= open_sql_file_for_table(table_name, O_WRONLY | O_APPEND)))
DBUG_RETURN(1);
/* Do not use ANSI_QUOTES on triggers in dump */
......@@ -3434,11 +3436,15 @@ static int dump_triggers_for_table(char *table_name, char *db_name)
/* Get list of triggers. */
my_snprintf(query_buff, sizeof(query_buff),
"SELECT TRIGGER_NAME FROM INFORMATION_SCHEMA.TRIGGERS "
"WHERE EVENT_OBJECT_SCHEMA = DATABASE() AND "
"EVENT_OBJECT_TABLE = %s",
quote_for_equal(table_name, name_buff));
if (use_show_create_trigger)
my_snprintf(query_buff, sizeof(query_buff),
"SELECT TRIGGER_NAME FROM INFORMATION_SCHEMA.TRIGGERS "
"WHERE EVENT_OBJECT_SCHEMA = DATABASE() AND "
"EVENT_OBJECT_TABLE = %s",
quote_for_equal(table_name, name_buff));
else
my_snprintf(query_buff, sizeof(query_buff), "SHOW TRIGGERS LIKE %s",
quote_for_like(table_name, name_buff));
if (mysql_query_with_error_report(mysql, &show_triggers_rs, query_buff))
goto done;
......@@ -3454,35 +3460,28 @@ static int dump_triggers_for_table(char *table_name, char *db_name)
while ((row= mysql_fetch_row(show_triggers_rs)))
{
my_snprintf(query_buff, sizeof (query_buff),
"SHOW CREATE TRIGGER %s",
quote_name(row[0], name_buff, TRUE));
if (mysql_query(mysql, query_buff))
if (use_show_create_trigger)
{
/*
mysqldump is being run against old server, that does not support
SHOW CREATE TRIGGER statement. We should use SHOW TRIGGERS output.
MYSQL_RES *show_create_trigger_rs;
NOTE: the dump may be incorrect, as old SHOW TRIGGERS does not
provide all the necessary information to restore trigger properly.
*/
my_snprintf(query_buff, sizeof (query_buff), "SHOW CREATE TRIGGER %s",
quote_name(row[0], name_buff, TRUE));
dump_trigger_old(sql_file, show_triggers_rs, &row, table_name);
}
else
{
MYSQL_RES *show_create_trigger_rs= mysql_store_result(mysql);
int error= (!show_create_trigger_rs ||
dump_trigger(sql_file, show_create_trigger_rs, db_name,
db_cl_name));
mysql_free_result(show_create_trigger_rs);
if (error)
if (mysql_query_with_error_report(mysql, &show_create_trigger_rs,
query_buff))
goto done;
else
{
int error= (!show_create_trigger_rs ||
dump_trigger(sql_file, show_create_trigger_rs, db_name,
db_cl_name));
mysql_free_result(show_create_trigger_rs);
if (error)
goto done;
}
}
else
dump_trigger_old(sql_file, show_triggers_rs, &row, table_name);
}
if (opt_xml)
......
......@@ -2,3 +2,7 @@ CREATE DATABASE mysqldump_30126;
USE mysqldump_30126;
CREATE TABLE t1 (c1 int);
DROP DATABASE mysqldump_30126;
use test;
create table t1 (a int);
create trigger tr after insert on t1 for each row set @a=1;
drop table t1;
......@@ -15,3 +15,16 @@ CREATE TABLE t1 (c1 int);
DROP DATABASE mysqldump_30126;
--remove_file $file
use test;
#
# MDEV-19182 mysqldump not always handling SHOW CREATE TRIGGER failures correctly
#
create table t1 (a int);
create trigger tr after insert on t1 for each row set @a=1;
let $datadir=`select @@datadir`;
move_file $datadir/test/tr.TRN $datadir/test/tr-1.TRN;
error 2;
exec $MYSQL_DUMP test t1 >/dev/null;
move_file $datadir/test/tr-1.TRN $datadir/test/tr.TRN;
drop table t1;
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