summaryrefslogtreecommitdiff
path: root/client/mysqldump.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/mysqldump.c')
-rw-r--r--client/mysqldump.c58
1 files changed, 45 insertions, 13 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 6df6a30be31..eadd45b960c 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -1643,9 +1643,15 @@ static uint get_table_structure(char *table, char *db, char *table_type,
field= mysql_fetch_field_direct(result, 0);
if (strcmp(field->name, "View") == 0)
{
+ char *scv_buff = NULL;
+
if (verbose)
fprintf(stderr, "-- It's a view, create dummy table for view\n");
+ /* save "show create" statement for later */
+ if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
+ scv_buff= my_strdup(scv_buff, MYF(0));
+
mysql_free_result(result);
/*
@@ -1663,9 +1669,22 @@ static uint get_table_structure(char *table, char *db, char *table_type,
"SHOW FIELDS FROM %s", result_table);
if (mysql_query_with_error_report(sock, 0, query_buff))
{
+ /*
+ View references invalid or privileged table/col/fun (err 1356),
+ so we cannot create a stand-in table. Be defensive and dump
+ a comment with the view's 'show create' statement. (Bug #17371)
+ */
+
+ if (mysql_errno(sock) == ER_VIEW_INVALID)
+ fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
+
+ my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
+
safe_exit(EX_MYSQLERR);
- DBUG_RETURN(0);
+ DBUG_RETURN(0);
}
+ else
+ my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
if ((result= mysql_store_result(sock)))
{
@@ -1706,6 +1725,9 @@ static uint get_table_structure(char *table, char *db, char *table_type,
}
mysql_free_result(result);
+ if (path)
+ my_fclose(sql_file, MYF(MY_WME));
+
seen_views= 1;
DBUG_RETURN(0);
}
@@ -2363,15 +2385,16 @@ static void dump_table(char *table, char *db)
goto err;
}
- if (opt_disable_keys)
+ if (opt_lock)
{
- fprintf(md_result_file, "\n/*!40000 ALTER TABLE %s DISABLE KEYS */;\n",
- opt_quoted_table);
+ fprintf(md_result_file,"LOCK TABLES %s WRITE;\n", opt_quoted_table);
check_io(md_result_file);
}
- if (opt_lock)
+ /* Moved disable keys to after lock per bug 15977 */
+ if (opt_disable_keys)
{
- fprintf(md_result_file,"LOCK TABLES %s WRITE;\n", opt_quoted_table);
+ fprintf(md_result_file, "/*!40000 ALTER TABLE %s DISABLE KEYS */;\n",
+ opt_quoted_table);
check_io(md_result_file);
}
@@ -2635,17 +2658,19 @@ static void dump_table(char *table, char *db)
error= EX_CONSCHECK;
goto err;
}
- if (opt_lock)
- {
- fputs("UNLOCK TABLES;\n", md_result_file);
- check_io(md_result_file);
- }
+
+ /* Moved enable keys to before unlock per bug 15977 */
if (opt_disable_keys)
{
fprintf(md_result_file,"/*!40000 ALTER TABLE %s ENABLE KEYS */;\n",
opt_quoted_table);
check_io(md_result_file);
}
+ if (opt_lock)
+ {
+ fputs("UNLOCK TABLES;\n", md_result_file);
+ check_io(md_result_file);
+ }
if (opt_autocommit)
{
fprintf(md_result_file, "commit;\n");
@@ -3037,6 +3062,12 @@ static my_bool dump_all_views_in_db(char *database)
uint numrows;
char table_buff[NAME_LEN*2+3];
+ if (mysql_select_db(sock, database))
+ {
+ DB_error(sock, "when selecting the database");
+ return 1;
+ }
+
if (opt_xml)
print_xml_tag1(md_result_file, "", "database name=", database, "\n");
if (lock_tables)
@@ -3698,12 +3729,13 @@ static my_bool get_view_structure(char *table, char* db)
mysql_free_result(table_res);
/* Get the result from "select ... information_schema" */
- if (!(table_res= mysql_store_result(sock)))
+ if (!(table_res= mysql_store_result(sock)) ||
+ !(row= mysql_fetch_row(table_res)))
{
safe_exit(EX_MYSQLERR);
DBUG_RETURN(1);
}
- row= mysql_fetch_row(table_res);
+
lengths= mysql_fetch_lengths(table_res);
/*