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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
9aaadae2
Commit
9aaadae2
authored
20 years ago
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge bk-internal.mysql.com:/home/bk/mysql-4.1
into mysql.com:/home/kostja/mysql/mysql-4.1-root
parents
1f65c22c
eadea645
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
0 deletions
+103
-0
client/mysqldump.c
client/mysqldump.c
+103
-0
No files found.
client/mysqldump.c
View file @
9aaadae2
...
...
@@ -55,6 +55,7 @@
#define EX_MYSQLERR 2
#define EX_CONSCHECK 3
#define EX_EOM 4
#define EX_EOF 5
/* ferror for output file was got */
/* index into 'show fields from table' */
...
...
@@ -332,6 +333,23 @@ static const char *check_if_ignore_table(const char *table_name);
#include <help_start.h>
/*
exit with message if ferror(file)
SYNOPSIS
check_io()
file - checked file
*/
void
check_io
(
FILE
*
file
)
{
if
(
ferror
(
file
))
{
fprintf
(
stderr
,
"%s: Got errno %d on write
\n
"
,
my_progname
,
errno
);
safe_exit
(
EX_EOF
);
}
}
static
void
print_version
(
void
)
{
printf
(
"%s Ver %s Distrib %s, for %s (%s)
\n
"
,
my_progname
,
DUMP_VERSION
,
...
...
@@ -378,6 +396,7 @@ static void write_header(FILE *sql_file, char *db_name)
{
fputs
(
"<?xml version=
\"
1.0
\"
?>
\n
"
,
sql_file
);
fputs
(
"<mysqldump>
\n
"
,
sql_file
);
check_io
(
sql_file
);
}
else
if
(
!
opt_compact
)
{
...
...
@@ -409,6 +428,7 @@ static void write_header(FILE *sql_file, char *db_name)
"/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=
\"
%s%s%s
\"
*/;
\n
"
,
path
?
""
:
"NO_AUTO_VALUE_ON_ZERO"
,
compatible_mode_normal_str
[
0
]
==
0
?
""
:
","
,
compatible_mode_normal_str
);
check_io
(
sql_file
);
}
}
/* write_header */
...
...
@@ -416,7 +436,10 @@ static void write_header(FILE *sql_file, char *db_name)
static
void
write_footer
(
FILE
*
sql_file
)
{
if
(
opt_xml
)
{
fputs
(
"</mysqldump>
\n
"
,
sql_file
);
check_io
(
sql_file
);
}
else
if
(
!
opt_compact
)
{
fprintf
(
sql_file
,
"
\n
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
\n
"
);
...
...
@@ -432,6 +455,7 @@ static void write_footer(FILE *sql_file)
"/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
\n
"
"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
\n
"
);
fputs
(
"
\n
"
,
sql_file
);
check_io
(
sql_file
);
}
}
/* write_footer */
...
...
@@ -725,6 +749,7 @@ static void unescape(FILE *file,char *pos,uint length)
fputc
(
'\''
,
file
);
fputs
(
tmp
,
file
);
fputc
(
'\''
,
file
);
check_io
(
file
);
my_free
(
tmp
,
MYF
(
MY_WME
));
DBUG_VOID_RETURN
;
}
/* unescape */
...
...
@@ -816,6 +841,7 @@ static void print_quoted_xml(FILE *xml_file, const char *str, ulong len)
break
;
}
}
check_io
(
xml_file
);
}
...
...
@@ -849,6 +875,7 @@ static void print_xml_tag1(FILE * xml_file, const char* sbeg,
print_quoted_xml
(
xml_file
,
sval
,
strlen
(
sval
));
fputs
(
"
\"
>"
,
xml_file
);
fputs
(
send
,
xml_file
);
check_io
(
xml_file
);
}
...
...
@@ -877,6 +904,7 @@ static void print_xml_row(FILE *xml_file, const char *row_name,
ulong
*
lengths
=
mysql_fetch_lengths
(
tableRes
);
fprintf
(
xml_file
,
"
\t\t
<%s"
,
row_name
);
check_io
(
xml_file
);
mysql_field_seek
(
tableRes
,
0
);
for
(
i
=
0
;
(
field
=
mysql_fetch_field
(
tableRes
));
i
++
)
{
...
...
@@ -887,9 +915,11 @@ static void print_xml_row(FILE *xml_file, const char *row_name,
fputs
(
"=
\"
"
,
xml_file
);
print_quoted_xml
(
xml_file
,
(
*
row
)[
i
],
lengths
[
i
]);
fputc
(
'"'
,
xml_file
);
check_io
(
xml_file
);
}
}
fputs
(
" />
\n
"
,
xml_file
);
check_io
(
xml_file
);
}
/*
...
...
@@ -956,14 +986,21 @@ static uint getTableStructure(char *table, char* db)
write_header
(
sql_file
,
db
);
}
if
(
!
opt_xml
&&
opt_comments
)
{
fprintf
(
sql_file
,
"
\n
--
\n
-- Table structure for table %s
\n
--
\n\n
"
,
result_table
);
check_io
(
sql_file
);
}
if
(
opt_drop
)
{
fprintf
(
sql_file
,
"DROP TABLE IF EXISTS %s;
\n
"
,
opt_quoted_table
);
check_io
(
sql_file
);
}
tableRes
=
mysql_store_result
(
sock
);
row
=
mysql_fetch_row
(
tableRes
);
fprintf
(
sql_file
,
"%s;
\n
"
,
row
[
1
]);
check_io
(
sql_file
);
mysql_free_result
(
tableRes
);
}
sprintf
(
insert_pat
,
"show fields from %s"
,
result_table
);
...
...
@@ -1043,6 +1080,7 @@ static uint getTableStructure(char *table, char* db)
fprintf
(
sql_file
,
"CREATE TABLE %s (
\n
"
,
result_table
);
else
print_xml_tag1
(
sql_file
,
"
\t
"
,
"table_structure name="
,
table
,
"
\n
"
);
check_io
(
sql_file
);
}
if
(
cFlag
)
sprintf
(
insert_pat
,
"INSERT %sINTO %s ("
,
delayed
,
result_table
);
...
...
@@ -1060,7 +1098,10 @@ static uint getTableStructure(char *table, char* db)
if
(
init
)
{
if
(
!
opt_xml
&&
!
tFlag
)
{
fputs
(
",
\n
"
,
sql_file
);
check_io
(
sql_file
);
}
if
(
cFlag
)
strpos
=
strmov
(
strpos
,
", "
);
}
...
...
@@ -1092,6 +1133,7 @@ static uint getTableStructure(char *table, char* db)
fputs
(
" NOT NULL"
,
sql_file
);
if
(
row
[
SHOW_EXTRA
][
0
])
fprintf
(
sql_file
,
" %s"
,
row
[
SHOW_EXTRA
]);
check_io
(
sql_file
);
}
}
numFields
=
(
uint
)
mysql_num_rows
(
tableRes
);
...
...
@@ -1160,12 +1202,14 @@ static uint getTableStructure(char *table, char* db)
fputs
(
quote_name
(
row
[
4
],
name_buff
,
0
),
sql_file
);
if
(
row
[
7
])
fprintf
(
sql_file
,
" (%s)"
,
row
[
7
]);
/* Sub key */
check_io
(
sql_file
);
}
if
(
!
opt_xml
)
{
if
(
keynr
)
putc
(
')'
,
sql_file
);
fputs
(
"
\n
)"
,
sql_file
);
check_io
(
sql_file
);
}
/* Get MySQL specific create options */
...
...
@@ -1204,6 +1248,7 @@ static uint getTableStructure(char *table, char* db)
print_value
(
sql_file
,
tableRes
,
row
,
""
,
"Create_options"
,
0
);
print_value
(
sql_file
,
tableRes
,
row
,
"comment="
,
"Comment"
,
1
);
fputs
(
" */"
,
sql_file
);
check_io
(
sql_file
);
}
}
mysql_free_result
(
tableRes
);
/* Is always safe to free */
...
...
@@ -1212,6 +1257,7 @@ static uint getTableStructure(char *table, char* db)
fputs
(
";
\n
"
,
sql_file
);
else
fputs
(
"
\t
</table_structure>
\n
"
,
sql_file
);
check_io
(
sql_file
);
}
}
if
(
cFlag
)
...
...
@@ -1365,19 +1411,28 @@ static void dumpTable(uint numFields, char *table)
else
{
if
(
!
opt_xml
&&
opt_comments
)
{
fprintf
(
md_result_file
,
"
\n
--
\n
-- Dumping data for table %s
\n
--
\n
"
,
result_table
);
check_io
(
md_result_file
);
}
sprintf
(
query
,
"SELECT /*!40001 SQL_NO_CACHE */ * FROM %s"
,
result_table
);
if
(
where
)
{
if
(
!
opt_xml
&&
opt_comments
)
{
fprintf
(
md_result_file
,
"-- WHERE: %s
\n
"
,
where
);
check_io
(
md_result_file
);
}
query
=
alloc_query_str
((
ulong
)
(
strlen
(
where
)
+
strlen
(
query
)
+
10
));
strxmov
(
query
,
query_buf
,
" WHERE "
,
where
,
NullS
);
}
if
(
!
opt_xml
&&
!
opt_compact
)
{
fputs
(
"
\n
"
,
md_result_file
);
check_io
(
md_result_file
);
}
if
(
mysql_query
(
sock
,
query
))
{
DBerror
(
sock
,
"when retrieving data from server"
);
...
...
@@ -1405,10 +1460,16 @@ static void dumpTable(uint numFields, char *table)
}
if
(
opt_disable_keys
)
{
fprintf
(
md_result_file
,
"
\n
/*!40000 ALTER TABLE %s DISABLE KEYS */;
\n
"
,
opt_quoted_table
);
check_io
(
md_result_file
);
}
if
(
opt_lock
)
{
fprintf
(
md_result_file
,
"LOCK TABLES %s WRITE;
\n
"
,
opt_quoted_table
);
check_io
(
md_result_file
);
}
total_length
=
opt_net_buffer_length
;
/* Force row break */
row_break
=
0
;
...
...
@@ -1418,7 +1479,10 @@ static void dumpTable(uint numFields, char *table)
print_xml_tag1
(
md_result_file
,
"
\t
"
,
"table_data name="
,
table
,
"
\n
"
);
if
(
opt_autocommit
)
{
fprintf
(
md_result_file
,
"set autocommit=0;
\n
"
);
check_io
(
md_result_file
);
}
while
((
row
=
mysql_fetch_row
(
res
)))
{
...
...
@@ -1426,11 +1490,17 @@ static void dumpTable(uint numFields, char *table)
ulong
*
lengths
=
mysql_fetch_lengths
(
res
);
rownr
++
;
if
(
!
extended_insert
&&
!
opt_xml
)
{
fputs
(
insert_pat
,
md_result_file
);
check_io
(
md_result_file
);
}
mysql_field_seek
(
res
,
0
);
if
(
opt_xml
)
{
fputs
(
"
\t
<row>
\n
"
,
md_result_file
);
check_io
(
md_result_file
);
}
for
(
i
=
0
;
i
<
mysql_num_fields
(
res
);
i
++
)
{
...
...
@@ -1503,7 +1573,10 @@ static void dumpTable(uint numFields, char *table)
else
{
if
(
i
&&
!
opt_xml
)
{
fputc
(
','
,
md_result_file
);
check_io
(
md_result_file
);
}
if
(
row
[
i
])
{
if
(
!
IS_NUM_FIELD
(
field
))
...
...
@@ -1546,11 +1619,15 @@ static void dumpTable(uint numFields, char *table)
}
else
fputs
(
"NULL"
,
md_result_file
);
check_io
(
md_result_file
);
}
}
if
(
opt_xml
)
{
fputs
(
"
\t
</row>
\n
"
,
md_result_file
);
check_io
(
md_result_file
);
}
if
(
extended_insert
)
{
...
...
@@ -1573,9 +1650,13 @@ static void dumpTable(uint numFields, char *table)
fputs
(
extended_row
.
str
,
md_result_file
);
total_length
=
row_length
+
init_length
;
}
check_io
(
md_result_file
);
}
else
if
(
!
opt_xml
)
{
fputs
(
");
\n
"
,
md_result_file
);
check_io
(
md_result_file
);
}
}
/* XML - close table tag and supress regular output */
...
...
@@ -1584,6 +1665,7 @@ static void dumpTable(uint numFields, char *table)
else
if
(
extended_insert
&&
row_break
)
fputs
(
";
\n
"
,
md_result_file
);
/* If not empty table */
fflush
(
md_result_file
);
check_io
(
md_result_file
);
if
(
mysql_errno
(
sock
))
{
sprintf
(
query
,
"%s: Error %d: %s when dumping table %s at row: %ld
\n
"
,
...
...
@@ -1597,12 +1679,21 @@ static void dumpTable(uint numFields, char *table)
goto
err
;
}
if
(
opt_lock
)
{
fputs
(
"UNLOCK TABLES;
\n
"
,
md_result_file
);
check_io
(
md_result_file
);
}
if
(
opt_disable_keys
)
{
fprintf
(
md_result_file
,
"/*!40000 ALTER TABLE %s ENABLE KEYS */;
\n
"
,
opt_quoted_table
);
check_io
(
md_result_file
);
}
if
(
opt_autocommit
)
{
fprintf
(
md_result_file
,
"commit;
\n
"
);
check_io
(
md_result_file
);
}
mysql_free_result
(
res
);
if
(
query
!=
query_buf
)
my_free
(
query
,
MYF
(
MY_ALLOW_ZERO_PTR
));
...
...
@@ -1693,7 +1784,10 @@ static int init_dumping(char *database)
char
quoted_database_buf
[
64
*
2
+
3
];
char
*
qdatabase
=
quote_name
(
database
,
quoted_database_buf
,
opt_quoted
);
if
(
opt_comments
)
{
fprintf
(
md_result_file
,
"
\n
--
\n
-- Current Database: %s
\n
--
\n
"
,
qdatabase
);
check_io
(
md_result_file
);
}
if
(
!
opt_create_db
)
{
char
qbuf
[
256
];
...
...
@@ -1720,6 +1814,7 @@ static int init_dumping(char *database)
}
}
fprintf
(
md_result_file
,
"
\n
USE %s;
\n
"
,
qdatabase
);
check_io
(
md_result_file
);
}
}
if
(
extended_insert
&&
init_dynamic_string
(
&
extended_row
,
""
,
1024
,
1024
))
...
...
@@ -1766,7 +1861,10 @@ static int dump_all_tables_in_db(char *database)
dumpTable
(
numrows
,
table
);
}
if
(
opt_xml
)
{
fputs
(
"</database>
\n
"
,
md_result_file
);
check_io
(
md_result_file
);
}
if
(
lock_tables
)
mysql_query
(
sock
,
"UNLOCK TABLES"
);
return
0
;
...
...
@@ -1812,7 +1910,10 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
dumpTable
(
numrows
,
*
table_names
);
}
if
(
opt_xml
)
{
fputs
(
"</database>
\n
"
,
md_result_file
);
check_io
(
md_result_file
);
}
if
(
lock_tables
)
mysql_query
(
sock
,
"UNLOCK TABLES"
);
return
0
;
...
...
@@ -1881,6 +1982,7 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
unescape
(
file
,
row
[
0
],(
uint
)
strlen
(
row
[
0
]));
else
fputs
(
row
[
0
],
file
);
check_io
(
file
);
return
;
}
}
...
...
@@ -2020,6 +2122,7 @@ int main(int argc, char **argv)
fprintf
(
md_result_file
,
"CHANGE MASTER TO MASTER_LOG_FILE='%s', \
MASTER_LOG_POS=%s ;
\n
"
,
row
[
0
],
row
[
1
]);
check_io
(
md_result_file
);
}
mysql_free_result
(
master
);
}
...
...
This diff is collapsed.
Click to expand it.
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