mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Bug#17371: Unable to dump a schema with invalid views
'show create' works even on views that are short of a base-table (this throw a warning though, like you would expect). Unfortunately, this is not what mysqldump uses; it creates stand-in tables and hence requests 'show fields' on the view which fails with missing base-tables. The --force option prevents the dump from stopping at this point; furthermore this patch dumps a comment showing create for the offending view for better diagnostics. This solution was confirmed by submitter as solving their/clients' problem. Problem might become non-issue once mysqldump no longer creates stand-in tables. client/mysqldump.c: Dump a comment showing create for a view if we can't show fields for it for better diagnostics. mysql-test/r/mysqldump.result: add test for #17371 - be defensive. if we can't do a full dump on a view (incl. 'show fields' for a stand-in table), at least create a comment with the 'show create' info when --force is given. mysql-test/t/mysqldump.test: add test for #17371 - be defensive. if we can't do a full dump on a view (incl. 'show fields' for a stand-in table), at least create a comment with the 'show create' info when --force is given.
This commit is contained in:
@ -1494,9 +1494,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);
|
||||
|
||||
/*
|
||||
@ -1514,9 +1520,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)))
|
||||
{
|
||||
|
@ -2731,3 +2731,12 @@ p CREATE DEFINER=`root`@`localhost` PROCEDURE `p`()
|
||||
select 42
|
||||
drop function f;
|
||||
drop procedure p;
|
||||
create table t1 ( id serial );
|
||||
create view v1 as select * from t1;
|
||||
drop table t1;
|
||||
mysqldump {
|
||||
|
||||
-- failed on view `v1`: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t1`.`id` AS `id` from `t1`
|
||||
|
||||
} mysqldump
|
||||
drop view v1;
|
||||
|
@ -1143,3 +1143,16 @@ show create procedure p;
|
||||
drop function f;
|
||||
drop procedure p;
|
||||
|
||||
#
|
||||
# Bug #17371 Unable to dump a schema with invalid views
|
||||
#
|
||||
#
|
||||
create table t1 ( id serial );
|
||||
create view v1 as select * from t1;
|
||||
drop table t1;
|
||||
# mysqldump gets 1356 from server, but gives us 2
|
||||
--echo mysqldump {
|
||||
--error 2
|
||||
--exec $MYSQL_DUMP --force -N --compact --skip-comments test
|
||||
--echo } mysqldump
|
||||
drop view v1;
|
||||
|
Reference in New Issue
Block a user