diff options
author | unknown <anozdrin/alik@ibm.> | 2007-07-27 18:20:17 +0400 |
---|---|---|
committer | unknown <anozdrin/alik@ibm.> | 2007-07-27 18:20:17 +0400 |
commit | e030b5dcc030e5777ed6260e4a9bb1c135b32aed (patch) | |
tree | 67a0ad62d894ba9e62f87816ac5d66109de254f7 /client | |
parent | 339ea316b938b9b1c2a166c6580bf84333d80a5f (diff) | |
download | mariadb-git-e030b5dcc030e5777ed6260e4a9bb1c135b32aed.tar.gz |
Fix for BUG#30027: mysqldump does not dump views properly.
mysqldump generates view defitions in two stages:
- dump CREATE TABLE statements for the temporary tables. For each view a
temporary table, that has the same structure as the view is created.
- dump DROP TABLE statements for the temporary tables and CREATE VIEW
statements for the view.
This approach is required because views can have dependencies on each other
(a view can use other views). So, they should be created in the particular
order. mysqldump however is not smart enough, so in order to resolve
dependencies it creates temporary tables first of all.
The problem was that mysqldump might have generated incorrect dump for the
temporary table when a view has non-ASCII column name. That happened when
default-character-set is not utf8.
The fix is to:
1. Switch character_set_client for the mysqldump's connection to binary
before issuing SHOW FIELDS statement in order to avoid conversion.
2. Dump switch character_set_client statements to UTF8 and back for
CREATE TABLE statement that is issued to create temporary table.
client/mysqldump.c:
1. Switch character_set_results for mysqldump's connection to
binary before SHOW FIELDS in order to avoid conversion to client
character set.
2. Dump switch character_set_client statements to UTF8 and back
for CREATE TABLE statement.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/t/mysqldump.test:
Test case for BUG#30027.
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqldump.c | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index 0f30ebddacc..6f0e30b8f35 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2174,7 +2174,9 @@ static uint get_table_structure(char *table, char *db, char *table_type, */ my_snprintf(query_buff, sizeof(query_buff), "SHOW FIELDS FROM %s", result_table); - if (mysql_query_with_error_report(mysql, 0, query_buff)) + if (switch_character_set_results(mysql, "binary") || + mysql_query_with_error_report(mysql, &result, query_buff) || + switch_character_set_results(mysql, default_charset)) { /* View references invalid or privileged table/col/fun (err 1356), @@ -2192,43 +2194,50 @@ static uint get_table_structure(char *table, char *db, char *table_type, else my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR)); - if ((result= mysql_store_result(mysql))) + if (mysql_num_rows(result)) { - if (mysql_num_rows(result)) + if (opt_drop) { - if (opt_drop) - { /* - We have already dropped any table of the same name - above, so here we just drop the view. - */ + We have already dropped any table of the same name above, so + here we just drop the view. + */ - fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n", - opt_quoted_table); - check_io(sql_file); - } + fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n", + opt_quoted_table); + check_io(sql_file); + } - fprintf(sql_file, "/*!50001 CREATE TABLE %s (\n", result_table); - /* - Get first row, following loop will prepend comma - keeps - from having to know if the row being printed is last to - determine if there should be a _trailing_ comma. - */ - row= mysql_fetch_row(result); + fprintf(sql_file, + "SET @saved_cs_client = @@character_set_client;\n" + "SET character_set_client = utf8;\n" + "/*!50001 CREATE TABLE %s (\n", + result_table); + + /* + Get first row, following loop will prepend comma - keeps from + having to know if the row being printed is last to determine if + there should be a _trailing_ comma. + */ - fprintf(sql_file, " %s %s", quote_name(row[0], name_buff, 0), - row[1]); + row= mysql_fetch_row(result); - while((row= mysql_fetch_row(result))) - { - /* col name, col type */ - fprintf(sql_file, ",\n %s %s", - quote_name(row[0], name_buff, 0), row[1]); - } - fprintf(sql_file, "\n) */;\n"); - check_io(sql_file); + fprintf(sql_file, " %s %s", quote_name(row[0], name_buff, 0), + row[1]); + + while((row= mysql_fetch_row(result))) + { + /* col name, col type */ + fprintf(sql_file, ",\n %s %s", + quote_name(row[0], name_buff, 0), row[1]); } + fprintf(sql_file, + "\n) */;\n" + "SET character_set_client = @saved_cs_client;\n"); + + check_io(sql_file); } + mysql_free_result(result); if (path) |