Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
5a43a31e
Commit
5a43a31e
authored
Oct 14, 2016
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mysqldump: comments and identifiers with new lines
don't let identifiers with new lines to break a comment
parent
01b39b7b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
207 additions
and
17 deletions
+207
-17
client/mysqldump.c
client/mysqldump.c
+43
-17
mysql-test/r/mysqldump-nl.result
mysql-test/r/mysqldump-nl.result
+126
-0
mysql-test/t/mysqldump-nl.test
mysql-test/t/mysqldump-nl.test
+38
-0
No files found.
client/mysqldump.c
View file @
5a43a31e
...
@@ -547,9 +547,7 @@ static int dump_all_tablespaces();
...
@@ -547,9 +547,7 @@ static int dump_all_tablespaces();
static
int
dump_tablespaces_for_tables
(
char
*
db
,
char
**
table_names
,
int
tables
);
static
int
dump_tablespaces_for_tables
(
char
*
db
,
char
**
table_names
,
int
tables
);
static
int
dump_tablespaces_for_databases
(
char
**
databases
);
static
int
dump_tablespaces_for_databases
(
char
**
databases
);
static
int
dump_tablespaces
(
char
*
ts_where
);
static
int
dump_tablespaces
(
char
*
ts_where
);
static
void
print_comment
(
FILE
*
sql_file
,
my_bool
is_error
,
const
char
*
format
,
static
void
print_comment
(
FILE
*
,
my_bool
,
const
char
*
,
...);
...);
/*
/*
Print the supplied message if in verbose mode
Print the supplied message if in verbose mode
...
@@ -627,6 +625,30 @@ static void short_usage(FILE *f)
...
@@ -627,6 +625,30 @@ static void short_usage(FILE *f)
}
}
/** returns a string fixed to be safely printed inside a -- comment
that is, any new line in it gets prefixed with --
*/
static
const
char
*
fix_for_comment
(
const
char
*
ident
)
{
static
char
buf
[
1024
];
char
c
,
*
s
=
buf
;
while
((
c
=
*
s
++=
*
ident
++
))
{
if
(
s
>=
buf
+
sizeof
(
buf
)
-
10
)
{
strmov
(
s
,
"..."
);
break
;
}
if
(
c
==
'\n'
)
s
=
strmov
(
s
,
"-- "
);
}
return
buf
;
}
static
void
write_header
(
FILE
*
sql_file
,
char
*
db_name
)
static
void
write_header
(
FILE
*
sql_file
,
char
*
db_name
)
{
{
if
(
opt_xml
)
if
(
opt_xml
)
...
@@ -649,8 +671,8 @@ static void write_header(FILE *sql_file, char *db_name)
...
@@ -649,8 +671,8 @@ static void write_header(FILE *sql_file, char *db_name)
DUMP_VERSION
,
MYSQL_SERVER_VERSION
,
SYSTEM_TYPE
,
DUMP_VERSION
,
MYSQL_SERVER_VERSION
,
SYSTEM_TYPE
,
MACHINE_TYPE
);
MACHINE_TYPE
);
print_comment
(
sql_file
,
0
,
"-- Host: %s Database: %s
\n
"
,
print_comment
(
sql_file
,
0
,
"-- Host: %s Database: %s
\n
"
,
current_host
?
current_host
:
"localhost"
,
fix_for_comment
(
current_host
?
current_host
:
"localhost"
)
,
db_name
?
db_name
:
""
);
fix_for_comment
(
db_name
?
db_name
:
""
)
);
print_comment
(
sql_file
,
0
,
print_comment
(
sql_file
,
0
,
"-- ------------------------------------------------------
\n
"
"-- ------------------------------------------------------
\n
"
);
);
...
@@ -2094,7 +2116,8 @@ static uint dump_events_for_db(char *db)
...
@@ -2094,7 +2116,8 @@ static uint dump_events_for_db(char *db)
/* nice comments */
/* nice comments */
print_comment
(
sql_file
,
0
,
print_comment
(
sql_file
,
0
,
"
\n
--
\n
-- Dumping events for database '%s'
\n
--
\n
"
,
db
);
"
\n
--
\n
-- Dumping events for database '%s'
\n
--
\n
"
,
fix_for_comment
(
db
));
/*
/*
not using "mysql_query_with_error_report" because we may have not
not using "mysql_query_with_error_report" because we may have not
...
@@ -2307,7 +2330,8 @@ static uint dump_routines_for_db(char *db)
...
@@ -2307,7 +2330,8 @@ static uint dump_routines_for_db(char *db)
/* nice comments */
/* nice comments */
print_comment
(
sql_file
,
0
,
print_comment
(
sql_file
,
0
,
"
\n
--
\n
-- Dumping routines for database '%s'
\n
--
\n
"
,
db
);
"
\n
--
\n
-- Dumping routines for database '%s'
\n
--
\n
"
,
fix_for_comment
(
db
));
/*
/*
not using "mysql_query_with_error_report" because we may have not
not using "mysql_query_with_error_report" because we may have not
...
@@ -2580,11 +2604,11 @@ static uint get_table_structure(char *table, char *db, char *table_type,
...
@@ -2580,11 +2604,11 @@ static uint get_table_structure(char *table, char *db, char *table_type,
if
(
strcmp
(
table_type
,
"VIEW"
)
==
0
)
/* view */
if
(
strcmp
(
table_type
,
"VIEW"
)
==
0
)
/* view */
print_comment
(
sql_file
,
0
,
print_comment
(
sql_file
,
0
,
"
\n
--
\n
-- Temporary table structure for view %s
\n
--
\n\n
"
,
"
\n
--
\n
-- Temporary table structure for view %s
\n
--
\n\n
"
,
result_table
);
fix_for_comment
(
result_table
)
);
else
else
print_comment
(
sql_file
,
0
,
print_comment
(
sql_file
,
0
,
"
\n
--
\n
-- Table structure for table %s
\n
--
\n\n
"
,
"
\n
--
\n
-- Table structure for table %s
\n
--
\n\n
"
,
result_table
);
fix_for_comment
(
result_table
)
);
if
(
opt_drop
)
if
(
opt_drop
)
{
{
...
@@ -2826,7 +2850,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
...
@@ -2826,7 +2850,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
print_comment
(
sql_file
,
0
,
print_comment
(
sql_file
,
0
,
"
\n
--
\n
-- Table structure for table %s
\n
--
\n\n
"
,
"
\n
--
\n
-- Table structure for table %s
\n
--
\n\n
"
,
result_table
);
fix_for_comment
(
result_table
)
);
if
(
opt_drop
)
if
(
opt_drop
)
fprintf
(
sql_file
,
"DROP TABLE IF EXISTS %s;
\n
"
,
result_table
);
fprintf
(
sql_file
,
"DROP TABLE IF EXISTS %s;
\n
"
,
result_table
);
if
(
!
opt_xml
)
if
(
!
opt_xml
)
...
@@ -3530,21 +3554,21 @@ static void dump_table(char *table, char *db)
...
@@ -3530,21 +3554,21 @@ static void dump_table(char *table, char *db)
{
{
print_comment
(
md_result_file
,
0
,
print_comment
(
md_result_file
,
0
,
"
\n
--
\n
-- Dumping data for table %s
\n
--
\n
"
,
"
\n
--
\n
-- Dumping data for table %s
\n
--
\n
"
,
result_table
);
fix_for_comment
(
result_table
)
);
dynstr_append_checked
(
&
query_string
,
"SELECT /*!40001 SQL_NO_CACHE */ * FROM "
);
dynstr_append_checked
(
&
query_string
,
"SELECT /*!40001 SQL_NO_CACHE */ * FROM "
);
dynstr_append_checked
(
&
query_string
,
result_table
);
dynstr_append_checked
(
&
query_string
,
result_table
);
if
(
where
)
if
(
where
)
{
{
print_comment
(
md_result_file
,
0
,
"-- WHERE: %s
\n
"
,
where
);
print_comment
(
md_result_file
,
0
,
"-- WHERE: %s
\n
"
,
fix_for_comment
(
where
)
);
dynstr_append_checked
(
&
query_string
,
" WHERE "
);
dynstr_append_checked
(
&
query_string
,
" WHERE "
);
dynstr_append_checked
(
&
query_string
,
where
);
dynstr_append_checked
(
&
query_string
,
where
);
}
}
if
(
order_by
)
if
(
order_by
)
{
{
print_comment
(
md_result_file
,
0
,
"-- ORDER BY: %s
\n
"
,
order_by
);
print_comment
(
md_result_file
,
0
,
"-- ORDER BY: %s
\n
"
,
fix_for_comment
(
order_by
)
);
dynstr_append_checked
(
&
query_string
,
" ORDER BY "
);
dynstr_append_checked
(
&
query_string
,
" ORDER BY "
);
dynstr_append_checked
(
&
query_string
,
order_by
);
dynstr_append_checked
(
&
query_string
,
order_by
);
...
@@ -4053,7 +4077,7 @@ static int dump_tablespaces(char* ts_where)
...
@@ -4053,7 +4077,7 @@ static int dump_tablespaces(char* ts_where)
if
(
first
)
if
(
first
)
{
{
print_comment
(
md_result_file
,
0
,
"
\n
--
\n
-- Logfile group: %s
\n
--
\n
"
,
print_comment
(
md_result_file
,
0
,
"
\n
--
\n
-- Logfile group: %s
\n
--
\n
"
,
row
[
0
]
);
fix_for_comment
(
row
[
0
])
);
fprintf
(
md_result_file
,
"
\n
CREATE"
);
fprintf
(
md_result_file
,
"
\n
CREATE"
);
}
}
...
@@ -4122,7 +4146,8 @@ static int dump_tablespaces(char* ts_where)
...
@@ -4122,7 +4146,8 @@ static int dump_tablespaces(char* ts_where)
first
=
1
;
first
=
1
;
if
(
first
)
if
(
first
)
{
{
print_comment
(
md_result_file
,
0
,
"
\n
--
\n
-- Tablespace: %s
\n
--
\n
"
,
row
[
0
]);
print_comment
(
md_result_file
,
0
,
"
\n
--
\n
-- Tablespace: %s
\n
--
\n
"
,
fix_for_comment
(
row
[
0
]));
fprintf
(
md_result_file
,
"
\n
CREATE"
);
fprintf
(
md_result_file
,
"
\n
CREATE"
);
}
}
else
else
...
@@ -4326,7 +4351,8 @@ static int init_dumping(char *database, int init_func(char*))
...
@@ -4326,7 +4351,8 @@ static int init_dumping(char *database, int init_func(char*))
char
*
qdatabase
=
quote_name
(
database
,
quoted_database_buf
,
opt_quoted
);
char
*
qdatabase
=
quote_name
(
database
,
quoted_database_buf
,
opt_quoted
);
print_comment
(
md_result_file
,
0
,
print_comment
(
md_result_file
,
0
,
"
\n
--
\n
-- Current Database: %s
\n
--
\n
"
,
qdatabase
);
"
\n
--
\n
-- Current Database: %s
\n
--
\n
"
,
fix_for_comment
(
qdatabase
));
/* Call the view or table specific function */
/* Call the view or table specific function */
init_func
(
qdatabase
);
init_func
(
qdatabase
);
...
@@ -5356,7 +5382,7 @@ static my_bool get_view_structure(char *table, char* db)
...
@@ -5356,7 +5382,7 @@ static my_bool get_view_structure(char *table, char* db)
print_comment
(
sql_file
,
0
,
print_comment
(
sql_file
,
0
,
"
\n
--
\n
-- Final view structure for view %s
\n
--
\n\n
"
,
"
\n
--
\n
-- Final view structure for view %s
\n
--
\n\n
"
,
result_table
);
fix_for_comment
(
result_table
)
);
/* Table might not exist if this view was dumped with --tab. */
/* Table might not exist if this view was dumped with --tab. */
fprintf
(
sql_file
,
"/*!50001 DROP TABLE IF EXISTS %s*/;
\n
"
,
opt_quoted_table
);
fprintf
(
sql_file
,
"/*!50001 DROP TABLE IF EXISTS %s*/;
\n
"
,
opt_quoted_table
);
...
...
mysql-test/r/mysqldump-nl.result
0 → 100644
View file @
5a43a31e
create database `mysqltest1
1tsetlqsym`;
use `mysqltest1
1tsetlqsym`;
create table `t1
1t` (`foobar
raboof` int);
create view `v1
1v` as select * from `t1
1t`;
create procedure sp() select * from `v1
1v`;
flush tables;
use test;
--
-- Current Database: `mysqltest1
-- 1tsetlqsym`
--
/*!40000 DROP DATABASE IF EXISTS `mysqltest1
1tsetlqsym`*/;
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mysqltest1
1tsetlqsym` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `mysqltest1
1tsetlqsym`;
--
-- Table structure for table `t1
-- 1t`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t1
1t` (
`foobar
raboof` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `t1
-- 1t`
--
--
-- Temporary table structure for view `v1
-- 1v`
--
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE TABLE `v1
1v` (
`foobar
raboof` tinyint NOT NULL
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
--
-- Dumping routines for database 'mysqltest1
-- 1tsetlqsym'
--
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp`()
select * from `v1
1v` ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
--
-- Current Database: `mysqltest1
-- 1tsetlqsym`
--
USE `mysqltest1
1tsetlqsym`;
--
-- Final view structure for view `v1
-- 1v`
--
/*!50001 DROP TABLE IF EXISTS `v1
1v`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = latin1 */;
/*!50001 SET character_set_results = latin1 */;
/*!50001 SET collation_connection = latin1_swedish_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `v1
1v` AS select `t1
1t`.`foobar
raboof` AS `foobar
raboof` from `t1
1t` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
show tables from `mysqltest1
1tsetlqsym`;
Tables_in_mysqltest1
1tsetlqsym
t1
1t
v1
1v
drop database `mysqltest1
1tsetlqsym`;
mysql-test/t/mysqldump-nl.test
0 → 100644
View file @
5a43a31e
#
# New lines in identifiers
#
# embedded server doesn't support external clients
--
source
include
/
not_embedded
.
inc
# cmd.exe doesn't like new lines on the command line
--
source
include
/
not_windows
.
inc
create
database
`mysqltest1
1tsetlqsym`
;
use
`mysqltest1
1tsetlqsym`
;
create
table
`t1
1t`
(
`foobar
raboof`
int
);
create
view
`v1
1v`
as
select
*
from
`t1
1t`
;
create
procedure
sp
()
select
*
from
`v1
1v`
;
flush
tables
;
use
test
;
exec
$MYSQL_DUMP
--
compact
--
comment
--
routines
--
add
-
drop
-
database
--
databases
'mysqltest1
1tsetlqsym'
;
exec
$MYSQL_DUMP
--
compact
--
comment
--
routines
--
add
-
drop
-
database
--
databases
'mysqltest1
1tsetlqsym'
|
$MYSQL
;
show
tables
from
`mysqltest1
1tsetlqsym`
;
drop
database
`mysqltest1
1tsetlqsym`
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment