1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-22200 maridb-dump add --header option

fix quoting
This commit is contained in:
Sergei Golubchik
2022-10-26 14:54:53 +02:00
parent ad7631bdce
commit 768a10d02a
3 changed files with 30 additions and 29 deletions

View File

@ -2112,17 +2112,16 @@ static my_bool test_if_special_chars(const char *str)
name Unquoted string containing that which will be quoted name Unquoted string containing that which will be quoted
buff The buffer that contains the quoted value, also returned buff The buffer that contains the quoted value, also returned
force Flag to make it ignore 'test_if_special_chars' force Flag to make it ignore 'test_if_special_chars'
quote_c Charater to use as the enclosing quote
Returns Returns
A pointer to the quoted string, or the original string if nothing has A pointer to the quoted string, or the original string if nothing has
changed. changed.
*/ */
static char *quote(const char *name, char *buff, my_bool force, char quote_c) static char *quote_name(const char *name, char *buff, my_bool force)
{ {
char *to= buff; char *to= buff;
char qtype= (opt_compatible_mode & MASK_ANSI_QUOTES) ? '\"' : quote_c; char qtype= (opt_compatible_mode & MASK_ANSI_QUOTES) ? '\"' : '`';
if (!force && !opt_quoted && !test_if_special_chars(name)) if (!force && !opt_quoted && !test_if_special_chars(name))
return (char*) name; return (char*) name;
@ -2136,29 +2135,7 @@ static char *quote(const char *name, char *buff, my_bool force, char quote_c)
to[0]= qtype; to[0]= qtype;
to[1]= 0; to[1]= 0;
return buff; return buff;
} /* quote */ } /* quote_name */
/*
quote_name(name, buff, force)
quote() with the ` character
*/
static char *quote_name(const char *name, char *buff, my_bool force)
{
return quote(name, buff, force, '`');
}
/*
quote_string(name, buff, force)
quote() with the ' character
*/
static char *quote_string(const char *name, char *buff)
{
return quote(name, buff, 0, '\'');
}
/* /*
@ -3429,7 +3406,7 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
quote_name(row[SHOW_FIELDNAME], name_buff, 0)); quote_name(row[SHOW_FIELDNAME], name_buff, 0));
if (opt_header) if (opt_header)
dynstr_append_checked(&select_field_names_for_header, dynstr_append_checked(&select_field_names_for_header,
quote_string(row[SHOW_FIELDNAME], name_buff)); quote_for_equal(row[SHOW_FIELDNAME], name_buff));
} }
init=0; init=0;
/* /*
@ -3534,7 +3511,7 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
quote_name(row[SHOW_FIELDNAME], name_buff, 0)); quote_name(row[SHOW_FIELDNAME], name_buff, 0));
if (opt_header) if (opt_header)
dynstr_append_checked(&select_field_names_for_header, dynstr_append_checked(&select_field_names_for_header,
quote_string(row[SHOW_FIELDNAME], name_buff)); quote_for_equal(row[SHOW_FIELDNAME], name_buff));
init=1; init=1;
} }
init=0; init=0;

View File

@ -45,7 +45,18 @@ course_id name description num_years escape_çÇÁá!#%"';5 Course 1 Course Desc
# Dump header and data rows into outfile with several options above combined # Dump header and data rows into outfile with several options above combined
# #
'course_id','name','description','num_years','escape_çÇÁá!#%"\'';'5','Course 1','Course Description 1','3',\N; 'course_id','name','description','num_years','escape_çÇÁá!#%"\'';'5','Course 1','Course Description 1','3',\N;
'course_id','name','description','num_years','escape_çÇÁá!#%"\'';'5','Course 1','Course Description 1','3',\N;INSERT INTO `courses` VALUES (4, 'Course 2', 'Course Description 2', 4, NULL); 'course_id','name','description','num_years','escape_çÇÁá!#%"\'';'5','Course 1','Course Description 1','3',\N;
#
# --skip-quote-names
#
course_id name description num_years escape_çÇÁá!#%"'
5 Course 1 Course Description 1 3 \N
#
# --compatible=ansi
#
course_id name description num_years escape_çÇÁá!#%"'
5 Course 1 Course Description 1 3 \N
INSERT INTO `courses` VALUES (4, 'Course 2', 'Course Description 2', 4, NULL);
INSERT INTO `courses` VALUES (3, 'Course 3', 'Course Description 3', 3, NULL); INSERT INTO `courses` VALUES (3, 'Course 3', 'Course Description 3', 3, NULL);
INSERT INTO `courses` VALUES (2, 'Course 4', 'Course Description 4', 5, NULL); INSERT INTO `courses` VALUES (2, 'Course 4', 'Course Description 4', 5, NULL);
INSERT INTO `courses` VALUES (1, 'Course 5', 'Course Description 5', 3, NULL); INSERT INTO `courses` VALUES (1, 'Course 5', 'Course Description 5', 3, NULL);

View File

@ -58,6 +58,19 @@ INSERT INTO `courses` VALUES (5, 'Course 1', 'Course Description 1', 3, NULL);
--exec $MYSQL_DUMP -u root --tab $MYSQLTEST_VARDIR/ --header --fields-terminated-by , --fields-optionally-enclosed-by \' --lines-terminated-by \; test --exec $MYSQL_DUMP -u root --tab $MYSQLTEST_VARDIR/ --header --fields-terminated-by , --fields-optionally-enclosed-by \' --lines-terminated-by \; test
--cat_file $MYSQLTEST_VARDIR/courses.txt --cat_file $MYSQLTEST_VARDIR/courses.txt
--echo
--echo #
--echo # --skip-quote-names
--echo #
--exec $MYSQL_DUMP -u root --tab $MYSQLTEST_VARDIR/ --header --skip-quote-names test
--cat_file $MYSQLTEST_VARDIR/courses.txt
--echo #
--echo # --compatible=ansi
--echo #
--exec $MYSQL_DUMP -u root --tab $MYSQLTEST_VARDIR/ --header --compatible=ansi test
--cat_file $MYSQLTEST_VARDIR/courses.txt
INSERT INTO `courses` VALUES (4, 'Course 2', 'Course Description 2', 4, NULL); INSERT INTO `courses` VALUES (4, 'Course 2', 'Course Description 2', 4, NULL);
INSERT INTO `courses` VALUES (3, 'Course 3', 'Course Description 3', 3, NULL); INSERT INTO `courses` VALUES (3, 'Course 3', 'Course Description 3', 3, NULL);
INSERT INTO `courses` VALUES (2, 'Course 4', 'Course Description 4', 5, NULL); INSERT INTO `courses` VALUES (2, 'Course 4', 'Course Description 4', 5, NULL);