Browse Source

MDEV-37483 mariadb-dump -T doesn't convert table names

use my_charset_filename to build file names from table names.
this guarantees that file name will be always valid for any
table name, no matter what characters it contains and what file name
rules local filesystem has.

mariadb-import now converts back, if possible.
bb-10.6-mdev-36058-hf
Sergei Golubchik 2 months ago
parent
commit
ff12ec86a5
  1. 13
      client/mysqldump.c
  2. 10
      client/mysqlimport.c
  3. 46
      mysql-test/main/mysqldump.result
  4. 42
      mysql-test/main/mysqldump.test

13
client/mysqldump.c

@ -1841,10 +1841,19 @@ static char *cover_definer_clause(const char *stmt_str,
static const char* build_path_for_table(char *to, const char *dir,
const char *table, const char *ext)
{
char tmp_path[FN_REFLEN];
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
convert_dirname(tmp_path, path, NULL);
my_load_path(tmp_path, tmp_path, NULL);
return fn_format(to, table, tmp_path, ext, MYF(MY_UNPACK_FILENAME));
if (check_if_legal_tablename(table))
strxnmov(filename, sizeof(filename) - 1, table, "@@@", NULL);
else
{
uint errors, len;
len= my_convert(filename, sizeof(filename) - 1, &my_charset_filename,
table, (uint32)strlen(table), charset_info, &errors);
filename[len]= 0;
}
return fn_format(to, filename, tmp_path, ext, MYF(MY_UNPACK_FILENAME));
}

10
client/mysqlimport.c

@ -340,6 +340,16 @@ static int write_to_table(char *filename, MYSQL *mysql)
DBUG_PRINT("enter",("filename: %s",filename));
fn_format(tablename, filename, "", "", MYF(MY_REPLACE_DIR | MY_REPLACE_EXT));
if (strchr(tablename, '@'))
{
uint errors, len;
const char *csname= my_default_csname(); /* see MYSQL_SET_CHARSET_NAME */
CHARSET_INFO *cs= get_charset_by_csname(csname, MY_CS_PRIMARY, MYF(0));
len= my_convert(escaped_name, sizeof(escaped_name) - 1, cs, tablename,
(uint32)strlen(tablename), &my_charset_filename, &errors);
if (!errors)
strmake(tablename, escaped_name, len);
}
if (!opt_local_file)
strmov(hard_path,filename);
else

46
mysql-test/main/mysqldump.result

@ -6624,3 +6624,49 @@ SET character_set_client = @saved_cs_client;
drop view `v'1"2`;
drop table t1;
# End of 10.5 tests
#
# MDEV-37483 mariadb-dump -T doesn't convert table names
#
set names latin1;
create database foo;
use foo;
create table `con_schöne_grüße` (a int) select 1 as a;
create table `con` (b int) select 2 as b;
create table `con/bar` (c int) select 3 as c;
create table `con@home` (d int) select 4 as d;
drop database foo;
use test;
con@002fbar.sql
con@002fbar.txt
con@@@.sql
con@@@.txt
con@home.sql
con@home.txt
con_sch@1ine_gr@1o@1je.sql
con_sch@1ine_gr@1o@1je.txt
show tables;
Tables_in_test
con
con/bar
con@home
con_schöne_grüße
test.con: Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
test.con/bar: Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
test.con@home: Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
select * from `con_schöne_grüße`;
a
1
select * from `con`;
b
2
select * from `con/bar`;
c
3
select * from `con@home`;
d
4
drop table `con_schöne_grüße`;
drop table `con`;
drop table `con/bar`;
drop table `con@home`;
# End of 10.6 tests

42
mysql-test/main/mysqldump.test

@ -3035,3 +3035,45 @@ drop view `v'1"2`; # "'
drop table t1;
--echo # End of 10.5 tests
--echo #
--echo # MDEV-37483 mariadb-dump -T doesn't convert table names
--echo #
set names latin1;
create database foo;
use foo;
create table `con_schöne_grüße` (a int) select 1 as a;
create table `con` (b int) select 2 as b;
create table `con/bar` (c int) select 3 as c;
create table `con@home` (d int) select 4 as d;
exec $MYSQL_DUMP foo --tab $MYSQLTEST_VARDIR/tmp;
drop database foo;
use test;
move_file $MYSQLTEST_VARDIR/tmp/con@0040home.sql $MYSQLTEST_VARDIR/tmp/con@home.sql;
move_file $MYSQLTEST_VARDIR/tmp/con@0040home.txt $MYSQLTEST_VARDIR/tmp/con@home.txt;
list_files $MYSQLTEST_VARDIR/tmp con*;
exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/con@@@.sql;
exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/con@002fbar.sql;
exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/con_sch@1ine_gr@1o@1je.sql;
exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/con@home.sql;
show tables;
exec $MYSQL_IMPORT test $MYSQLTEST_VARDIR/tmp/con@@@.txt;
exec $MYSQL_IMPORT test $MYSQLTEST_VARDIR/tmp/con@002fbar.txt;
if (`select @@version like '10.6.%'`) {
# utf8 console output on Windows is fixed in MDEV-26713, until then
--disable_result_log
}
exec $MYSQL_IMPORT test $MYSQLTEST_VARDIR/tmp/con_sch@1ine_gr@1o@1je.txt;
--enable_result_log
exec $MYSQL_IMPORT test $MYSQLTEST_VARDIR/tmp/con@home.txt;
select * from `con_schöne_grüße`;
select * from `con`;
select * from `con/bar`;
select * from `con@home`;
drop table `con_schöne_grüße`;
drop table `con`;
drop table `con/bar`;
drop table `con@home`;
--echo # End of 10.6 tests
Loading…
Cancel
Save