diff options
author | unknown <msvensson@neptunus.(none)> | 2005-06-16 15:58:17 +0200 |
---|---|---|
committer | unknown <msvensson@neptunus.(none)> | 2005-06-16 15:58:17 +0200 |
commit | 1f86e13cbb558fa93bc5da7b731e4bf3b013dfd4 (patch) | |
tree | bb1b4b5532d642aad77e15b75bad27d2d6029e9a /client/mysqldump.c | |
parent | d340c0f52b17f3dddd492d7ef366cfd62c86e297 (diff) | |
download | mariadb-git-1f86e13cbb558fa93bc5da7b731e4bf3b013dfd4.tar.gz |
BUG#10927 mysqldump: Can't reload dump with view that consist of other view
- Create a small dummy table that will take care of the problem of creating a view dependent of another view which hasn't yet been created.
client/mysqldump.c:
Create a dummy table for the view. ie. a table which has the
same columns as the view should have. This table is dropped
just before the view is created. The table is used to handle the
case where a view references another view, which hasn't yet been
created(during the load of the dump).
mysql-test/r/mysqldump.result:
Add tests for bug#10927
mysql-test/t/mysqldump.test:
Add tests for bug#10927
Diffstat (limited to 'client/mysqldump.c')
-rw-r--r-- | client/mysqldump.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index 907b6233590..6b7923fcd93 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1212,7 +1212,54 @@ static uint get_table_structure(char *table, char *db) if (strcmp(field->name, "View") == 0) { if (verbose) - fprintf(stderr, "-- It's a view, skipped\n"); + fprintf(stderr, "-- It's a view, create dummy table for view\n"); + + mysql_free_result(tableRes); + + /* Create a dummy table for the view. ie. a table which has the + same columns as the view should have. This table is dropped + just before the view is created. The table is used to handle the + case where a view references another view, which hasn't yet been + created(during the load of the dump). BUG#10927 */ + + /* Create temp table by selecting from the view */ + my_snprintf(query_buff, sizeof(query_buff), + "create temporary table %s select * from %s where 1=0", + result_table, result_table); + if (mysql_query_with_error_report(sock, 0, query_buff)) + { + safe_exit(EX_MYSQLERR); + DBUG_RETURN(0); + } + + /* Get CREATE statement for the temp table */ + my_snprintf(query_buff, sizeof(query_buff), "show create table %s", + result_table); + if (mysql_query_with_error_report(sock, 0, query_buff)) + { + safe_exit(EX_MYSQLERR); + DBUG_RETURN(0); + } + tableRes= mysql_store_result(sock); + row= mysql_fetch_row(tableRes); + + if (opt_drop) + fprintf(sql_file, "DROP VIEW IF EXISTS %s;\n",opt_quoted_table); + + /* Print CREATE statement but remove TEMPORARY */ + fprintf(sql_file, "CREATE %s;\n", row[1]+17); + check_io(sql_file); + + mysql_free_result(tableRes); + + /* Drop the temp table */ + my_snprintf(buff, sizeof(buff), + "DROP TEMPORARY TABLE %s", result_table); + if (mysql_query_with_error_report(sock, 0, buff)) + { + safe_exit(EX_MYSQLERR); + DBUG_RETURN(0); + } was_views= 1; DBUG_RETURN(0); } @@ -2752,6 +2799,7 @@ static my_bool get_view_structure(char *table, char* db) } if (opt_drop) { + fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table); fprintf(sql_file, "DROP VIEW IF EXISTS %s;\n", opt_quoted_table); check_io(sql_file); } |