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
14742557
Commit
14742557
authored
Oct 31, 2003
by
ram@gw.mysql.r18.ru
Browse files
Options
Browse Files
Download
Plain Diff
Merge rkalimullin@bk-internal.mysql.com:/home/bk/mysql-4.1
into gw.mysql.r18.ru:/usr/home/ram/work/4.1.wl1279
parents
f29ed575
0a357809
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
133 additions
and
47 deletions
+133
-47
client/mysqldump.c
client/mysqldump.c
+133
-47
No files found.
client/mysqldump.c
View file @
14742557
...
...
@@ -68,6 +68,13 @@
/* Size of buffer for dump's select query */
#define QUERY_LENGTH 1536
#define print_xml_tag(out_file, sbeg, sval, send) \
{ \
fputs(sbeg, out_file); \
print_quoted_xml(out_file, sval, 0); \
fputs(send, out_file); \
}
static
char
*
add_load_option
(
char
*
ptr
,
const
char
*
object
,
const
char
*
statement
);
static
ulong
find_set
(
TYPELIB
*
lib
,
const
char
*
x
,
uint
length
,
...
...
@@ -298,7 +305,7 @@ static int init_dumping(char *);
static
int
dump_databases
(
char
**
);
static
int
dump_all_databases
();
static
char
*
quote_name
(
const
char
*
name
,
char
*
buff
,
my_bool
force
);
static
void
print_quoted_xml
(
FILE
*
output
,
char
*
fname
,
char
*
str
,
uint
len
);
static
void
print_quoted_xml
(
FILE
*
output
,
char
*
str
,
ulong
len
);
static
void
print_version
(
void
)
{
...
...
@@ -339,8 +346,8 @@ static void write_header(FILE *sql_file, char *db_name)
{
if
(
opt_xml
)
{
fp
rintf
(
sql_file
,
"<?xml version=
\"
1.0
\"
?>
\n
"
);
fp
rintf
(
sql_file
,
"<mysqldump>
\n
"
);
fp
uts
(
"<?xml version=
\"
1.0
\"
?>
\n
"
,
sql_file
);
fp
uts
(
"<mysqldump>
\n
"
,
sql_file
);
}
else
{
...
...
@@ -366,7 +373,7 @@ static void write_header(FILE *sql_file, char *db_name)
static
void
write_footer
(
FILE
*
sql_file
)
{
if
(
opt_xml
)
fp
rintf
(
sql_file
,
"</mysqldump>"
);
fp
uts
(
"</mysqldump>"
,
sql_file
);
else
{
fprintf
(
md_result_file
,
"
\n
\
...
...
@@ -651,6 +658,29 @@ static char *quote_name(const char *name, char *buff, my_bool force)
}
/* quote_name */
void
print_xml_row
(
FILE
*
xml_file
,
const
char
*
row_name
,
MYSQL_RES
*
tableRes
,
MYSQL_ROW
*
row
)
{
uint
i
;
MYSQL_FIELD
*
field
;
ulong
*
lengths
=
mysql_fetch_lengths
(
tableRes
);
fprintf
(
xml_file
,
"
\t\t
<%s"
,
row_name
);
mysql_field_seek
(
tableRes
,
0
);
for
(
i
=
0
;
(
field
=
mysql_fetch_field
(
tableRes
));
i
++
)
{
if
((
*
row
)[
i
]
&&
(
*
row
)[
i
][
0
])
{
fputs
(
" "
,
xml_file
);
print_quoted_xml
(
xml_file
,
field
->
name
,
0
);
fputs
(
"=
\"
"
,
xml_file
);
print_quoted_xml
(
xml_file
,
(
*
row
)[
i
],
lengths
[
i
]);
fputs
(
"
\"
"
,
xml_file
);
}
}
fputs
(
" />
\n
"
,
xml_file
);
}
/*
getStructure -- retrievs database structure, prints out corresponding
CREATE statement and fills out insert_pat.
...
...
@@ -680,7 +710,7 @@ static uint getTableStructure(char *table, char* db)
sprintf
(
insert_pat
,
"SET OPTION SQL_QUOTE_SHOW_CREATE=%d"
,
(
opt_quoted
||
opt_keywords
));
result_table
=
quote_name
(
table
,
table_buff
,
1
);
opt_quoted_table
=
quote_name
(
table
,
table_buff2
,
0
);
if
(
!
mysql_query
(
sock
,
insert_pat
))
if
(
!
opt_xml
&&
!
mysql_query
(
sock
,
insert_pat
))
{
/* using SHOW CREATE statement */
if
(
!
tFlag
)
...
...
@@ -735,7 +765,6 @@ static uint getTableStructure(char *table, char* db)
}
write_header
(
sql_file
,
db
);
}
if
(
!
opt_xml
)
fprintf
(
sql_file
,
"
\n
--
\n
-- Table structure for table %s
\n
--
\n\n
"
,
result_table
);
if
(
opt_drop
)
...
...
@@ -743,7 +772,6 @@ static uint getTableStructure(char *table, char* db)
tableRes
=
mysql_store_result
(
sock
);
row
=
mysql_fetch_row
(
tableRes
);
if
(
!
opt_xml
)
fprintf
(
sql_file
,
"%s;
\n
"
,
row
[
1
]);
mysql_free_result
(
tableRes
);
}
...
...
@@ -818,7 +846,10 @@ static uint getTableStructure(char *table, char* db)
result_table
);
if
(
opt_drop
)
fprintf
(
sql_file
,
"DROP TABLE IF EXISTS %s;
\n
"
,
result_table
);
if
(
!
opt_xml
)
fprintf
(
sql_file
,
"CREATE TABLE %s (
\n
"
,
result_table
);
else
print_xml_tag
(
sql_file
,
"
\t
<table_structure name=
\"
"
,
table
,
"
\"
>
\n
"
);
}
if
(
cFlag
)
sprintf
(
insert_pat
,
"INSERT %sINTO %s ("
,
delayed
,
result_table
);
...
...
@@ -835,7 +866,7 @@ static uint getTableStructure(char *table, char* db)
ulong
*
lengths
=
mysql_fetch_lengths
(
tableRes
);
if
(
init
)
{
if
(
!
tFlag
)
if
(
!
opt_xml
&&
!
tFlag
)
fputs
(
",
\n
"
,
sql_file
);
if
(
cFlag
)
strpos
=
strmov
(
strpos
,
", "
);
...
...
@@ -845,6 +876,12 @@ static uint getTableStructure(char *table, char* db)
strpos
=
strmov
(
strpos
,
quote_name
(
row
[
SHOW_FIELDNAME
],
name_buff
,
0
));
if
(
!
tFlag
)
{
if
(
opt_xml
)
{
print_xml_row
(
sql_file
,
"field"
,
tableRes
,
&
row
);
continue
;
}
if
(
opt_keywords
)
fprintf
(
sql_file
,
" %s.%s %s"
,
result_table
,
quote_name
(
row
[
SHOW_FIELDNAME
],
name_buff
,
0
),
...
...
@@ -906,6 +943,12 @@ static uint getTableStructure(char *table, char* db)
keynr
=
0
;
while
((
row
=
mysql_fetch_row
(
tableRes
)))
{
if
(
opt_xml
)
{
print_xml_row
(
sql_file
,
"key"
,
tableRes
,
&
row
);
continue
;
}
if
(
atoi
(
row
[
3
])
==
1
)
{
if
(
keynr
++
)
...
...
@@ -924,14 +967,26 @@ static uint getTableStructure(char *table, char* db)
if
(
row
[
7
])
fprintf
(
sql_file
,
" (%s)"
,
row
[
7
]);
/* Sub key */
}
if
(
!
opt_xml
)
{
if
(
keynr
)
putc
(
')'
,
sql_file
);
fputs
(
"
\n
)"
,
sql_file
);
}
/* Get MySQL specific create options */
if
(
create_options
)
{
sprintf
(
buff
,
"show table status like %s"
,
result_table
);
ulong
len
=
strlen
(
table
);
char
*
tmp
=
(
char
*
)
my_malloc
(
len
*
2
+
1
,
MYF
(
MY_WME
));
if
(
!
tmp
)
{
ignore_errors
=
0
;
safe_exit
(
EX_MYSQLERR
);
}
mysql_real_escape_string
(
&
mysql_connection
,
tmp
,
table
,
len
);
sprintf
(
buff
,
"show table status like
\"
%s
\"
"
,
tmp
);
my_free
(
tmp
,
MYF
(
MY_WME
));
if
(
mysql_query
(
sock
,
buff
))
{
if
(
mysql_errno
(
sock
)
!=
ER_PARSE_ERROR
)
...
...
@@ -950,6 +1005,12 @@ static uint getTableStructure(char *table, char* db)
result_table
,
mysql_error
(
sock
));
}
else
{
if
(
opt_xml
)
{
print_xml_row
(
sql_file
,
"options"
,
tableRes
,
&
row
);
}
else
{
fputs
(
"/*!"
,
sql_file
);
print_value
(
sql_file
,
tableRes
,
row
,
"type="
,
"Type"
,
0
);
...
...
@@ -957,9 +1018,13 @@ static uint getTableStructure(char *table, char* db)
print_value
(
sql_file
,
tableRes
,
row
,
"comment="
,
"Comment"
,
1
);
fputs
(
" */"
,
sql_file
);
}
}
mysql_free_result
(
tableRes
);
/* Is always safe to free */
}
if
(
!
opt_xml
)
fputs
(
";
\n
"
,
sql_file
);
else
fputs
(
"
\t
</table_structure>
\n
"
,
sql_file
);
}
}
if
(
cFlag
)
...
...
@@ -1127,7 +1192,9 @@ static void dumpTable(uint numFields, char *table)
rownr
=
0
;
init_length
=
(
uint
)
strlen
(
insert_pat
)
+
4
;
if
(
opt_xml
)
fprintf
(
md_result_file
,
"
\t
<table name=
\"
%s
\"
>
\n
"
,
table
);
{
print_xml_tag
(
md_result_file
,
"
\t
<table_data name=
\"
"
,
table
,
"
\"
>
\n
"
);
}
if
(
opt_autocommit
)
fprintf
(
md_result_file
,
"set autocommit=0;
\n
"
);
...
...
@@ -1142,7 +1209,7 @@ static void dumpTable(uint numFields, char *table)
mysql_field_seek
(
res
,
0
);
if
(
opt_xml
)
fp
rintf
(
md_result_file
,
"
\t
<row>
\n
"
);
fp
uts
(
"
\t
<row>
\n
"
,
md_result_file
);
for
(
i
=
0
;
i
<
mysql_num_fields
(
res
);
i
++
)
{
...
...
@@ -1207,8 +1274,12 @@ static void dumpTable(uint numFields, char *table)
if
(
!
IS_NUM_FIELD
(
field
))
{
if
(
opt_xml
)
print_quoted_xml
(
md_result_file
,
field
->
name
,
row
[
i
],
lengths
[
i
]);
{
print_xml_tag
(
md_result_file
,
"
\t\t
<field name=
\"
"
,
field
->
name
,
"
\"
>"
);
print_quoted_xml
(
md_result_file
,
row
[
i
],
lengths
[
i
]);
fputs
(
"</field>
\n
"
,
md_result_file
);
}
else
unescape
(
md_result_file
,
row
[
i
],
lengths
[
i
]);
}
...
...
@@ -1217,9 +1288,13 @@ static void dumpTable(uint numFields, char *table)
/* change any strings ("inf","nan",..) into NULL */
char
*
ptr
=
row
[
i
];
if
(
opt_xml
)
fprintf
(
md_result_file
,
"
\t\t
<field name=
\"
%s
\"
>%s</field>
\n
"
,
field
->
name
,
!
my_isalpha
(
charset_info
,
*
ptr
)
?
ptr
:
"NULL"
);
{
print_xml_tag
(
md_result_file
,
"
\t\t
<field name=
\"
"
,
field
->
name
,
"
\"
>"
);
fputs
(
!
my_isalpha
(
charset_info
,
*
ptr
)
?
ptr
:
"NULL"
,
md_result_file
);
fputs
(
"</field>
\n
"
,
md_result_file
);
}
else
fputs
((
!
my_isalpha
(
charset_info
,
*
ptr
))
?
ptr
:
"NULL"
,
md_result_file
);
...
...
@@ -1228,8 +1303,10 @@ static void dumpTable(uint numFields, char *table)
else
{
if
(
opt_xml
)
fprintf
(
md_result_file
,
"
\t\t
<field name=
\"
%s
\"
>%s</field>
\n
"
,
field
->
name
,
"NULL"
);
{
print_xml_tag
(
md_result_file
,
"
\t\t
<field name=
\"
"
,
field
->
name
,
"
\"
>NULL</field>
\n
"
);
}
else
fputs
(
"NULL"
,
md_result_file
);
}
...
...
@@ -1237,7 +1314,7 @@ static void dumpTable(uint numFields, char *table)
}
if
(
opt_xml
)
fp
rintf
(
md_result_file
,
"
\t
</row>
\n
"
);
fp
uts
(
"
\t
</row>
\n
"
,
md_result_file
);
if
(
extended_insert
)
{
...
...
@@ -1267,7 +1344,7 @@ static void dumpTable(uint numFields, char *table)
/* XML - close table tag and supress regular output */
if
(
opt_xml
)
fp
rintf
(
md_result_file
,
"
\t
</table>
\n
"
);
fp
uts
(
"
\t
</table_data>
\n
"
,
md_result_file
);
else
if
(
extended_insert
&&
row_break
)
fputs
(
";
\n
"
,
md_result_file
);
/* If not empty table */
fflush
(
md_result_file
);
...
...
@@ -1295,25 +1372,30 @@ static void dumpTable(uint numFields, char *table)
}
/* dumpTable */
static
void
print_quoted_xml
(
FILE
*
output
,
char
*
fname
,
char
*
str
,
uint
len
)
static
void
print_quoted_xml
(
FILE
*
output
,
char
*
str
,
ulong
len
)
{
const
char
*
end
;
const
char
*
end
=
str
+
(
len
?
len
:
strlen
(
str
))
;
fprintf
(
output
,
"
\t\t
<field name=
\"
%s
\"
>"
,
fname
);
for
(
end
=
str
+
len
;
str
!=
end
;
str
++
)
for
(;
str
!=
end
;
str
++
)
{
if
(
*
str
==
'<'
)
switch
(
*
str
)
{
case
'<'
:
fputs
(
"<"
,
output
);
else
if
(
*
str
==
'>'
)
break
;
case
'>'
:
fputs
(
">"
,
output
);
else
if
(
*
str
==
'&'
)
break
;
case
'&'
:
fputs
(
"&"
,
output
);
else
if
(
*
str
==
'\"'
)
break
;
case
'\"'
:
fputs
(
"""
,
output
);
else
break
;
default:
fputc
(
*
str
,
output
);
break
;
}
}
fprintf
(
output
,
"</field>
\n
"
);
}
static
char
*
getTableName
(
int
reset
)
...
...
@@ -1434,7 +1516,9 @@ static int dump_all_tables_in_db(char *database)
if
(
init_dumping
(
database
))
return
1
;
if
(
opt_xml
)
fprintf
(
md_result_file
,
"<database name=
\"
%s
\"
>
\n
"
,
database
);
{
print_xml_tag
(
md_result_file
,
"<database name=
\"
"
,
database
,
"
\"
>
\n
"
);
}
if
(
lock_tables
)
{
DYNAMIC_STRING
query
;
...
...
@@ -1462,7 +1546,7 @@ static int dump_all_tables_in_db(char *database)
dumpTable
(
numrows
,
table
);
}
if
(
opt_xml
)
fp
rintf
(
md_result_file
,
"</database>
\n
"
);
fp
uts
(
"</database>
\n
"
,
md_result_file
);
if
(
lock_tables
)
mysql_query
(
sock
,
"UNLOCK_TABLES"
);
return
0
;
...
...
@@ -1500,7 +1584,9 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
/* We shall countinue here, if --force was given */
}
if
(
opt_xml
)
fprintf
(
md_result_file
,
"<database name=
\"
%s
\"
>
\n
"
,
db
);
{
print_xml_tag
(
md_result_file
,
"<database name=
\"
"
,
db
,
"
\"
>
\n
"
);
}
for
(;
tables
>
0
;
tables
--
,
table_names
++
)
{
numrows
=
getTableStructure
(
*
table_names
,
db
);
...
...
@@ -1508,7 +1594,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
dumpTable
(
numrows
,
*
table_names
);
}
if
(
opt_xml
)
fp
rintf
(
md_result_file
,
"</database>
\n
"
);
fp
uts
(
"</database>
\n
"
,
md_result_file
);
if
(
lock_tables
)
mysql_query
(
sock
,
"UNLOCK_TABLES"
);
return
0
;
...
...
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