diff options
author | Sergei Golubchik <serg@mariadb.org> | 2019-04-18 10:14:40 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2019-04-24 16:06:54 +0200 |
commit | ed866e930185d9b0118f5ecd0e199e2588b803fb (patch) | |
tree | c9b836a78a38d9c21fc637c6d75b17c9d6764105 /client | |
parent | 3db6de33b2b47a3c31bc8f8deb721abe0c5b0e1c (diff) | |
download | mariadb-git-ed866e930185d9b0118f5ecd0e199e2588b803fb.tar.gz |
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.
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqldump.c | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index f67e52c1b12..f00d1188502 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -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) |