78
74
#define IGNORE_DATA 0x01 /* don't dump data for this table */
79
75
#define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
82
static bool use_drizzle_protocol= false;
83
static bool quick= true;
84
static bool ignore_errors= false;
85
static bool flush_logs= false;
86
static bool opt_keywords= false;
87
static bool opt_compress= false;
88
static bool opt_delayed= false;
89
static bool create_options= true;
90
static bool opt_quoted= false;
91
bool opt_databases= false;
92
bool opt_alldbs= false;
93
static bool opt_lock_all_tables= false;
94
static bool opt_set_charset= false;
95
static bool opt_dump_date= true;
96
static bool opt_autocommit= false;
97
static bool opt_single_transaction= false;
98
static bool opt_comments;
99
static bool opt_compact;
100
static bool opt_order_by_primary=false;
101
bool opt_ignore= false;
102
static bool opt_complete_insert= false;
103
static bool opt_drop_database;
104
static bool opt_alltspcs= false;
105
bool opt_no_create_info;
106
bool opt_no_data= false;
107
bool opt_create_db= false;
108
bool opt_disable_keys= true;
109
bool extended_insert= true;
110
bool opt_replace_into= false;
112
uint32_t show_progress_size= 0;
113
//static uint64_t total_rows= 0;
114
static string insert_pat;
115
//static char *order_by= NULL;
116
static uint32_t opt_drizzle_port= 0;
117
static int first_error= 0;
118
static string extended_row;
77
static void add_load_option(DYNAMIC_STRING *str, const char *option,
78
const char *option_value);
79
static ulong find_set(TYPELIB *lib, const char *x, uint length,
80
char **err_pos, uint *err_len);
82
static void field_escape(DYNAMIC_STRING* in, const char *from);
83
static bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
84
quick= 1, extended_insert= 1,
85
lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
86
opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
87
opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0,
88
opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0,
89
opt_set_charset=0, opt_dump_date=1,
90
opt_autocommit=0,opt_disable_keys=1,opt_xml=0,
91
opt_delete_master_logs=0, tty_password=0,
92
opt_single_transaction=0, opt_comments= 0, opt_compact= 0,
93
opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0,
94
opt_complete_insert= 0, opt_drop_database= 0,
96
opt_routines=0, opt_tz_utc=1,
98
opt_include_master_host_port= 0,
100
opt_alltspcs=0, opt_notspcs= 0;
101
static bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
102
static ulong opt_max_allowed_packet, opt_net_buffer_length;
103
static DRIZZLE drizzle_connection,*drizzle=0;
104
static DYNAMIC_STRING insert_pat;
105
static char *opt_password=0,*current_user=0,
106
*current_host=0,*path=0,*fields_terminated=0,
107
*lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
108
*where=0, *order_by=0,
109
*opt_compatible_mode_str= 0,
111
*log_error_file= NULL;
112
static char **defaults_argv= 0;
113
static char compatible_mode_normal_str[255];
114
/* Server supports character_set_results session variable? */
115
static bool server_supports_switching_charsets= true;
116
static ulong opt_compatible_mode= 0;
117
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
118
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
119
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
120
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
121
static uint opt_drizzle_port= 0, opt_master_data;
122
static uint opt_slave_data;
123
static uint my_end_arg;
124
static int first_error=0;
125
static DYNAMIC_STRING extended_row;
119
126
FILE *md_result_file= 0;
120
FILE *stderror_file= 0;
121
std::vector<DrizzleDumpDatabase*> database_store;
122
DrizzleDumpConnection* db_connection;
123
DrizzleDumpConnection* destination_connection;
131
int opt_destination= DESTINATION_STDOUT;
132
std::string opt_destination_host;
133
uint16_t opt_destination_port;
134
std::string opt_destination_user;
135
std::string opt_destination_password;
136
std::string opt_destination_database;
138
const string progname= "drizzledump";
153
//static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
155
boost::unordered_set<string> ignore_table;
157
void maybe_exit(int error);
127
FILE *stderror_file=0;
129
static uint opt_protocol= DRIZZLE_PROTOCOL_TCP;
132
Dynamic_string wrapper functions. In this file use these
133
wrappers, they will terminate the process if there is
134
an allocation failure.
136
static void init_dynamic_string_checked(DYNAMIC_STRING *str, const char *init_str,
137
uint init_alloc, uint alloc_increment);
138
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src);
139
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str);
140
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
142
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size);
144
Constant for detection of default value of default_charset.
145
If default_charset is equal to drizzle_universal_client_charset, then
146
it is the default value which assigned at the very beginning of main().
148
static const char *drizzle_universal_client_charset=
149
MYSQL_UNIVERSAL_CLIENT_CHARSET;
150
static char *default_charset;
151
static CHARSET_INFO *charset_info= &my_charset_latin1;
152
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
153
/* have we seen any VIEWs during table scanning? */
155
const char *compatible_mode_names[]=
157
"MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
158
"MAXDB", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS",
162
#define MASK_ANSI_QUOTES \
164
(1<<2) | /* POSTGRESQL */\
165
(1<<3) | /* ORACLE */\
166
(1<<4) | /* MSSQL */\
168
(1<<6) | /* MAXDB */\
171
TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
172
"", compatible_mode_names, NULL};
176
static struct my_option my_long_options[] =
178
{"all", 'a', "Deprecated. Use --create-options instead.",
179
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
181
{"all-databases", 'A',
182
"Dump all the databases. This will be same as --databases with all databases selected.",
183
(char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
185
{"all-tablespaces", 'Y',
186
"Dump all the tablespaces.",
187
(char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
189
{"no-tablespaces", 'y',
190
"Do not dump any tablespace information.",
191
(char**) &opt_notspcs, (char**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
193
{"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
194
(char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
196
{"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
197
(char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
199
{"add-locks", OPT_LOCKS, "Add locks around insert statements.",
200
(char**) &opt_lock, (char**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
202
{"allow-keywords", OPT_KEYWORDS,
203
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
204
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
205
{"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
206
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
207
(char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
209
{"character-sets-dir", OPT_CHARSETS_DIR,
210
"Directory where character sets are.", (char**) &charsets_dir,
211
(char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
212
{"comments", 'i', "Write additional information.",
213
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
215
{"compatible", OPT_COMPATIBLE,
216
"Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires DRIZZLE server version 4.1.0 or higher. This option is ignored with earlier server versions.",
217
(char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
218
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
219
{"compact", OPT_COMPACT,
220
"Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks",
221
(char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
223
{"complete-insert", 'c', "Use complete insert statements.",
224
(char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
225
NO_ARG, 0, 0, 0, 0, 0, 0},
226
{"compress", 'C', "Use compression in server/client protocol.",
227
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
229
{"create-options", OPT_CREATE_OPTIONS,
230
"Include all DRIZZLE specific create options.",
231
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
234
"To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output.",
235
(char**) &opt_databases, (char**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
237
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
238
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
239
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
240
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
241
(char**) &debug_info_flag, (char**) &debug_info_flag,
242
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
243
{"default-character-set", OPT_DEFAULT_CHARSET,
244
"Set the default character set.", (char**) &default_charset,
245
(char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
246
{"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
247
(char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
249
{"delete-master-logs", OPT_DELETE_MASTER_LOGS,
250
"Delete logs on master after backup. This automatically enables --master-data.",
251
(char**) &opt_delete_master_logs, (char**) &opt_delete_master_logs, 0,
252
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
253
{"disable-keys", 'K',
254
"'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (char**) &opt_disable_keys,
255
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
256
{"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
257
"This causes the binary log position and filename of the master to be "
258
"appended to the dumped data output. Setting the value to 1, will print"
259
"it as a CHANGE MASTER command in the dumped data output; if equal"
260
" to 2, that command will be prefixed with a comment symbol. "
261
"This option will turn --lock-all-tables on, unless "
262
"--single-transaction is specified too (in which case a "
263
"global read lock is only taken a short time at the beginning of the dump "
264
"- don't forget to read about --single-transaction below). In all cases "
265
"any action on logs will happen at the exact moment of the dump."
266
"Option automatically turns --lock-tables off.",
267
(char**) &opt_slave_data, (char**) &opt_slave_data, 0,
268
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
269
{"events", 'E', "Dump events.",
270
(char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
271
NO_ARG, 0, 0, 0, 0, 0, 0},
272
{"extended-insert", 'e',
273
"Allows utilization of the new, much faster INSERT syntax.",
274
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
276
{"fields-terminated-by", OPT_FTB,
277
"Fields in the textfile are terminated by ...", (char**) &fields_terminated,
278
(char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
279
{"fields-enclosed-by", OPT_ENC,
280
"Fields in the importfile are enclosed by ...", (char**) &enclosed,
281
(char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
282
{"fields-optionally-enclosed-by", OPT_O_ENC,
283
"Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
284
(char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
285
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
286
(char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
287
{"first-slave", 'x', "Deprecated, renamed to --lock-all-tables.",
288
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
290
{"flush-logs", 'F', "Flush logs file in server before starting dump. "
291
"Note that if you dump many databases at once (using the option "
292
"--databases= or --all-databases), the logs will be flushed for "
293
"each database dumped. The exception is when using --lock-all-tables "
295
"in this case the logs will be flushed only once, corresponding "
296
"to the moment all tables are locked. So if you want your dump and "
297
"the log flush to happen at the same exact moment you should use "
298
"--lock-all-tables or --master-data with --flush-logs",
299
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
301
{"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
302
"after dumping the DRIZZLE database. This option should be used any "
303
"time the dump contains the DRIZZLE database and any other database "
304
"that depends on the data in the DRIZZLE database for proper restore. ",
305
(char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
307
{"force", 'f', "Continue even if we get an sql-error.",
308
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
310
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
311
NO_ARG, 0, 0, 0, 0, 0, 0},
312
{"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, "
313
"VARBINARY, BLOB) in hexadecimal format.",
314
(char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
315
{"host", 'h', "Connect to host.", (char**) ¤t_host,
316
(char**) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
317
{"ignore-table", OPT_IGNORE_TABLE,
318
"Do not dump the specified table. To specify more than one table to ignore, "
319
"use the directive multiple times, once for each table. Each table must "
320
"be specified with both database and table names, e.g. --ignore-table=database.table",
321
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
322
{"include-master-host-port", OPT_DRIZZLEDUMP_INCLUDE_MASTER_HOST_PORT,
323
"Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
324
(char**) &opt_include_master_host_port,
325
(char**) &opt_include_master_host_port,
328
{"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
329
(char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
331
{"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
332
(char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
333
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
334
{"lock-all-tables", 'x', "Locks all tables across all databases. This "
335
"is achieved by taking a global read lock for the duration of the whole "
336
"dump. Automatically turns --single-transaction and --lock-tables off.",
337
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
339
{"lock-tables", 'l', "Lock all tables for read.", (char**) &lock_tables,
340
(char**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
341
{"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.",
342
(char**) &log_error_file, (char**) &log_error_file, 0, GET_STR,
343
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
344
{"master-data", OPT_MASTER_DATA,
345
"This causes the binary log position and filename to be appended to the "
346
"output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
347
" to 2, that command will be prefixed with a comment symbol. "
348
"This option will turn --lock-all-tables on, unless "
349
"--single-transaction is specified too (in which case a "
350
"global read lock is only taken a short time at the beginning of the dump "
351
"- don't forget to read about --single-transaction below). In all cases "
352
"any action on logs will happen at the exact moment of the dump."
353
"Option automatically turns --lock-tables off.",
354
(char**) &opt_master_data, (char**) &opt_master_data, 0,
355
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
356
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
357
(char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
358
GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
359
(int64_t) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
360
{"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
361
(char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
362
GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
363
MALLOC_OVERHEAD-1024, 1024, 0},
364
{"no-autocommit", OPT_AUTOCOMMIT,
365
"Wrap tables with autocommit/commit statements.",
366
(char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
368
{"no-create-db", 'n',
369
"'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
370
(char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
372
{"no-create-info", 't', "Don't write table creation info.",
373
(char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
374
NO_ARG, 0, 0, 0, 0, 0, 0},
375
{"no-data", 'd', "No row information.", (char**) &opt_no_data,
376
(char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
377
{"no-set-names", 'N',
378
"Deprecated. Use --skip-set-charset instead.",
379
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
380
{"opt", OPT_OPTIMIZE,
381
"Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt.",
382
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
383
{"order-by-primary", OPT_ORDER_BY_PRIMARY,
384
"Sorts each table's rows by primary key, or first unique key, if such a key exists. Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer.",
385
(char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
387
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
388
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
389
{"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
390
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
392
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
393
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
394
{"quote-names",'Q', "Quote table and column names with backticks (`).",
395
(char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
397
{"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
398
(char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
401
"Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed).",
402
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
403
{"routines", 'R', "Dump stored routines (functions and procedures).",
404
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
405
NO_ARG, 0, 0, 0, 0, 0, 0},
406
{"set-charset", OPT_SET_CHARSET,
407
"Add 'SET NAMES default_character_set' to the output.",
408
(char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
410
{"set-variable", 'O',
411
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
412
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
414
Note that the combination --single-transaction --master-data
415
will give bullet-proof binlog position only if server >=4.1.3. That's the
416
old "FLUSH TABLES WITH READ LOCK does not block commit" fixed bug.
418
{"single-transaction", OPT_TRANSACTION,
419
"Creates a consistent snapshot by dumping all tables in a single "
420
"transaction. Works ONLY for tables stored in storage engines which "
421
"support multiversioning (currently only InnoDB does); the dump is NOT "
422
"guaranteed to be consistent for other storage engines. "
423
"While a --single-transaction dump is in process, to ensure a valid "
424
"dump file (correct table contents and binary log position), no other "
425
"connection should use the following statements: ALTER TABLE, DROP "
426
"TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
427
"isolated from them. Option automatically turns off --lock-tables.",
428
(char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
429
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
430
{"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.",
431
(char**) &opt_dump_date, (char**) &opt_dump_date, 0,
432
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
433
{"skip-opt", OPT_SKIP_OPTIMIZATION,
434
"Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
435
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
437
"Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if mysqldump is run on the same machine as the mysqld daemon.",
438
(char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
439
{"tables", OPT_TABLES, "Overrides option --databases (-B).",
440
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
441
{"tz-utc", OPT_TZ_UTC,
442
"SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones.",
443
(char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
444
#ifndef DONT_ALLOW_USER_CHANGE
445
{"user", 'u', "User for login if not current user.",
446
(char**) ¤t_user, (char**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
449
{"verbose", 'v', "Print info about the various stages.",
450
(char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
451
{"version",'V', "Output version information and exit.", 0, 0, 0,
452
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
453
{"where", 'w', "Dump only selected records; QUOTES mandatory!",
454
(char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
455
{"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
456
NO_ARG, 0, 0, 0, 0, 0, 0},
457
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
460
static const char *load_default_groups[]= { "drizzledump","client",0 };
462
static void maybe_exit(int error);
158
463
static void die(int error, const char* reason, ...);
159
static void write_header(char *db_name);
160
static int dump_selected_tables(const string &db, const vector<string> &table_names);
161
static int dump_databases(const vector<string> &db_names);
464
static void maybe_die(int error, const char* reason, ...);
465
static void write_header(FILE *sql_file, char *db_name);
466
static void print_value(FILE *file, DRIZZLE_RES *result, DRIZZLE_ROW row,
467
const char *prefix,const char *name,
469
static int dump_selected_tables(char *db, char **table_names, int tables);
470
static int dump_all_tables_in_db(char *db);
471
static int init_dumping_tables(char *);
472
static int init_dumping(char *, int init_func(char*));
473
static int dump_databases(char **);
162
474
static int dump_all_databases(void);
163
int get_server_type();
164
void dump_all_tables(void);
165
void generate_dump(void);
166
void generate_dump_db(void);
168
void dump_all_tables(void)
170
std::vector<DrizzleDumpDatabase*>::iterator i;
171
for (i= database_store.begin(); i != database_store.end(); ++i)
173
if (not (*i)->populateTables())
174
maybe_exit(EX_DRIZZLEERR);
178
void generate_dump(void)
180
std::vector<DrizzleDumpDatabase*>::iterator i;
182
cout << endl << "SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;" << endl;
186
cout << endl << "SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;"
187
<< endl << "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;" << endl;
189
for (i= database_store.begin(); i != database_store.end(); ++i)
191
DrizzleDumpDatabase *database= *i;
197
cout << "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;"
198
<< endl << "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;" << endl;
201
cout << "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;" << endl;
204
void generate_dump_db(void)
206
std::vector<DrizzleDumpDatabase*>::iterator i;
207
DrizzleStringBuf sbuf(1024);
208
destination_connection= new DrizzleDumpConnection(opt_destination_host,
209
opt_destination_port, opt_destination_user, opt_destination_password,
211
sbuf.setConnection(destination_connection);
212
std::ostream sout(&sbuf);
214
sout << "SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;" << endl;
218
sout << "SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;" << endl;
219
sout << "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;" << endl;
222
for (i= database_store.begin(); i != database_store.end(); ++i)
224
DrizzleDumpDatabase *database= *i;
230
sout << "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;" << endl;
231
sout << "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;" << endl;
234
sout << "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;" << endl;
475
static char *quote_name(const char *name, char *buff, bool force);
476
char check_if_ignore_table(const char *table_name, char *table_type);
477
static char *primary_key_fields(const char *table_name);
480
Print the supplied message if in verbose mode
485
... variable number of parameters
487
static void verbose_msg(const char *fmt, ...)
496
vfprintf(stderr, fmt, args);
238
503
exit with message if ferror(file)
245
510
static void check_io(FILE *file)
247
512
if (ferror(file))
248
die(EX_EOF, _("Got errno %d on write"), errno);
251
static void write_header(char *db_name)
253
if ((not opt_compact) and (opt_comments))
255
cout << "-- drizzledump " << VERSION << " libdrizzle "
256
<< drizzle_version() << ", for " << HOST_VENDOR << "-" << HOST_OS
257
<< " (" << HOST_CPU << ")" << endl << "--" << endl;
258
cout << "-- Host: " << current_host << " Database: " << db_name << endl;
259
cout << "-- ------------------------------------------------------" << endl;
260
cout << "-- Server version\t" << db_connection->getServerVersion();
261
if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
262
cout << " (MySQL server)";
263
else if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_DRIZZLE_FOUND)
264
cout << " (Drizzle server)";
265
cout << endl << endl;
513
die(EX_EOF, "Got errno %d on write", errno);
516
static void print_version(void)
518
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
519
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
520
} /* print_version */
523
static void short_usage_sub(void)
525
printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
526
printf("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n",
528
printf("OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname);
532
static void usage(void)
535
puts("By Igor Romanenko, Monty, Jani & Sinisa");
536
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
537
puts("Dumping definition and data DRIZZLE database or table");
539
print_defaults("my",load_default_groups);
540
my_print_help(my_long_options);
541
my_print_variables(my_long_options);
545
static void short_usage(void)
548
printf("For more options, use %s --help\n", my_progname);
551
static void write_header(FILE *sql_file, char *db_name)
555
fputs("<?xml version=\"1.0\"?>\n", sql_file);
557
Schema reference. Allows use of xsi:nil for NULL values and
558
xsi:type to define an element's data type.
560
fputs("<drizzledump ", sql_file);
561
fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
563
fputs(">\n", sql_file);
566
else if (!opt_compact)
571
"-- DRIZZLE dump %s Distrib %s, for %s (%s)\n--\n",
572
DUMP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
573
fprintf(sql_file, "-- Host: %s Database: %s\n",
574
current_host ? current_host : "localhost", db_name ? db_name :
576
fputs("-- ------------------------------------------------------\n",
578
fprintf(sql_file, "-- Server version\t%s\n",
579
drizzle_get_server_info(&drizzle_connection));
583
"\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;"
584
"\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;"
585
"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
586
"\n/*!40101 SET NAMES %s */;\n",default_charset);
590
fprintf(sql_file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
591
fprintf(sql_file, "/*!40103 SET TIME_ZONE='+00:00' */;\n");
596
fprintf(md_result_file,"\
597
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n\
598
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n\
267
603
} /* write_header */
270
606
static void write_footer(FILE *sql_file)
610
fputs("</drizzledump>\n", sql_file);
613
else if (!opt_compact)
616
fprintf(sql_file,"/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n");
620
fprintf(md_result_file,"\
621
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n\
622
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n");
626
"/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n"
627
"/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n"
628
"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
630
"/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
631
fputs("\n", sql_file);
274
632
if (opt_comments)
276
634
if (opt_dump_date)
278
boost::posix_time::ptime time(boost::posix_time::second_clock::local_time());
637
get_date(time_str, GETDATE_DATE_TIME, 0);
279
638
fprintf(sql_file, "-- Dump completed on %s\n",
280
boost::posix_time::to_simple_string(time).c_str());
283
642
fprintf(sql_file, "-- Dump completed\n");
343
927
vsnprintf(buffer, sizeof(buffer), fmt_reason, args);
346
fprintf(stderr, "%s: %s\n", progname.c_str(), buffer);
930
fprintf(stderr, "%s: %s\n", my_progname, buffer);
349
933
ignore_errors= 0; /* force the exit */
350
934
maybe_exit(error_num);
939
Prints out an error message and maybe kills the process.
943
error_num - process return value
944
fmt_reason - a format string for use by vsnprintf.
945
... - variable arguments for above fmt_reason string
948
This call prints out the formatted error message to stderr and then
949
terminates the process, unless the --force command line option is used.
951
This call should be used for non-fatal errors (such as database
952
errors) that the code may still be able to continue to the next unit
956
static void maybe_die(int error_num, const char* fmt_reason, ...)
960
va_start(args,fmt_reason);
961
vsnprintf(buffer, sizeof(buffer), fmt_reason, args);
964
fprintf(stderr, "%s: %s\n", my_progname, buffer);
967
maybe_exit(error_num);
973
Sends a query to server, optionally reads result, prints error message if
977
drizzle_query_with_error_report()
978
drizzle_con connection to use
979
res if non zero, result will be put there with
980
drizzle_store_result()
981
query query to send to server
984
0 query sending and (if res!=0) result reading went ok
988
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
991
if (drizzle_query(drizzle_con, query) ||
992
(res && !((*res)= drizzle_store_result(drizzle_con))))
994
maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
995
query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
1003
Switch charset for results to some specified charset. If the server does not
1004
support character_set_results variable, nothing can be done here. As for
1005
whether something should be done here, future new callers of this function
1006
should be aware that the server lacking the facility of switching charsets is
1009
@note If the server lacks support, then nothing is changed and no error
1010
condition is returned.
1012
@returns whether there was an error or not
1014
static int switch_character_set_results(DRIZZLE *drizzle, const char *cs_name)
1016
char query_buffer[QUERY_LENGTH];
1017
size_t query_length;
1019
/* Server lacks facility. This is not an error, by arbitrary decision . */
1020
if (!server_supports_switching_charsets)
1023
query_length= snprintf(query_buffer,
1024
sizeof (query_buffer),
1025
"SET SESSION character_set_results = '%s'",
1026
(const char *) cs_name);
1028
return drizzle_real_query(drizzle, query_buffer, query_length);
1032
Open a new .sql file to dump the table or view into
1035
open_sql_file_for_table
1036
name name of the table or view
1039
0 Failed to open file
1040
> 0 Handle of the open file
1042
static FILE* open_sql_file_for_table(const char* table)
1045
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
1046
convert_dirname(tmp_path,path,NullS);
1047
res= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
1048
O_WRONLY, MYF(MY_WME));
353
1053
static void free_resources(void)
355
1055
if (md_result_file && md_result_file != stdout)
356
fclose(md_result_file);
357
opt_password.erase();
1056
my_fclose(md_result_file, MYF(0));
1057
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
1058
if (hash_inited(&ignore_table))
1059
hash_free(&ignore_table);
1060
if (extended_insert)
1061
dynstr_free(&extended_row);
1062
if (insert_pat_inited)
1063
dynstr_free(&insert_pat);
1065
free_defaults(defaults_argv);
361
void maybe_exit(int error)
1070
static void maybe_exit(int error)
363
1072
if (!first_error)
364
1073
first_error= error;
365
1074
if (ignore_errors)
367
delete db_connection;
368
if (destination_connection)
369
delete destination_connection;
1077
drizzle_close(drizzle);
370
1078
free_resources();
1084
db_connect -- connects to the host and selects DB.
1087
static int connect_to_db(char *host, char *user,char *passwd)
1089
char buff[20+FN_REFLEN];
1092
verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1093
drizzle_create(&drizzle_connection);
1095
drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NullS);
1097
drizzle_options(&drizzle_connection,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
1098
drizzle_options(&drizzle_connection, DRIZZLE_SET_CHARSET_NAME, default_charset);
1099
if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
1100
NULL,opt_drizzle_port, NULL,
1103
DB_error(&drizzle_connection, "when trying to connect");
1106
if (drizzle_get_server_version(&drizzle_connection) < 40100)
1108
/* Don't dump SET NAMES with a pre-4.1 server (bug#7997). */
1111
/* Don't switch charsets for 4.1 and earlier. (bug#34192). */
1112
server_supports_switching_charsets= false;
1115
set time_zone to UTC to allow dumping date types between servers with
1116
different time zone settings
1120
snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1121
if (drizzle_query_with_error_report(drizzle, 0, buff))
1125
} /* connect_to_db */
1129
** dbDisconnect -- disconnects from the host.
1131
static void dbDisconnect(char *host)
1133
verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost");
1134
drizzle_close(drizzle);
1135
} /* dbDisconnect */
1138
static void unescape(FILE *file,char *pos,uint length)
1142
if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1143
die(EX_DRIZZLEERR, "Couldn't allocate memory");
1145
drizzle_real_escape_string(&drizzle_connection, tmp, pos, length);
1150
my_free(tmp, MYF(MY_WME));
1155
static bool test_if_special_chars(const char *str)
1157
for ( ; *str ; str++)
1158
if (!my_isvar(charset_info,*str) && *str != '$')
1161
} /* test_if_special_chars */
1166
quote_name(name, buff, force)
1168
Quotes char string, taking into account compatible mode
1172
name Unquoted string containing that which will be quoted
1173
buff The buffer that contains the quoted value, also returned
1174
force Flag to make it ignore 'test_if_special_chars'
1181
static char *quote_name(const char *name, char *buff, bool force)
1184
char qtype= (opt_compatible_mode & MASK_ANSI_QUOTES) ? '\"' : '`';
1186
if (!force && !opt_quoted && !test_if_special_chars(name))
1187
return (char*) name;
1202
Quote a table name so it can be used in "SHOW TABLES LIKE <tabname>"
1206
name name of the table
1207
buff quoted name of the table
1210
Quote \, _, ' and % characters
1212
Note: Because DRIZZLE uses the C escape syntax in strings
1213
(for example, '\n' to represent newline), you must double
1214
any '\' that you use in your LIKE strings. For example, to
1215
search for '\n', specify it as '\\n'. To search for '\', specify
1216
it as '\\\\' (the backslashes are stripped once by the parser
1217
and another time when the pattern match is done, leaving a
1218
single backslash to be matched).
1220
Example: "t\1" => "t\\\\1"
1223
static char *quote_for_like(const char *name, char *buff)
1235
else if (*name == '\'' || *name == '_' || *name == '%')
1246
Quote and print a string.
1250
xml_file - output file
1251
str - string to print
1255
Quote '<' '>' '&' '\"' chars and print a string to the xml_file.
1258
static void print_quoted_xml(FILE *xml_file, const char *str, ulong len)
1262
for (end= str + len; str != end; str++)
1266
fputs("<", xml_file);
1269
fputs(">", xml_file);
1272
fputs("&", xml_file);
1275
fputs(""", xml_file);
1278
fputc(*str, xml_file);
1287
Print xml tag. Optionally add attribute(s).
1290
print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name,
1291
..., attribute_name_n, attribute_value_n, NullS)
1292
xml_file - output file
1293
sbeg - line beginning
1294
line_end - line ending
1295
tag_name - XML tag name.
1296
first_attribute_name - tag and first attribute
1297
first_attribute_value - (Implied) value of first attribute
1298
attribute_name_n - attribute n
1299
attribute_value_n - value of attribute n
1302
Print XML tag with any number of attribute="value" pairs to the xml_file.
1305
sbeg<tag_name first_attribute_name="first_attribute_value" ...
1306
attribute_name_n="attribute_value_n">send
1308
Additional arguments must be present in attribute/value pairs.
1309
The last argument should be the null character pointer.
1310
All attribute_value arguments MUST be NULL terminated strings.
1311
All attribute_value arguments will be quoted before output.
1314
static void print_xml_tag(FILE * xml_file, const char* sbeg,
1315
const char* line_end,
1316
const char* tag_name,
1317
const char* first_attribute_name, ...)
1320
const char *attribute_name, *attribute_value;
1322
fputs(sbeg, xml_file);
1323
fputc('<', xml_file);
1324
fputs(tag_name, xml_file);
1326
va_start(arg_list, first_attribute_name);
1327
attribute_name= first_attribute_name;
1328
while (attribute_name != NullS)
1330
attribute_value= va_arg(arg_list, char *);
1331
assert(attribute_value != NullS);
1333
fputc(' ', xml_file);
1334
fputs(attribute_name, xml_file);
1335
fputc('\"', xml_file);
1337
print_quoted_xml(xml_file, attribute_value, strlen(attribute_value));
1338
fputc('\"', xml_file);
1340
attribute_name= va_arg(arg_list, char *);
1344
fputc('>', xml_file);
1345
fputs(line_end, xml_file);
1351
Print xml tag with for a field that is null
1354
print_xml_null_tag()
1355
xml_file - output file
1356
sbeg - line beginning
1357
stag_atr - tag and attribute
1358
sval - value of attribute
1359
line_end - line ending
1362
Print tag with one attribute to the xml_file. Format is:
1363
<stag_atr="sval" xsi:nil="true"/>
1365
sval MUST be a NULL terminated string.
1366
sval string will be qouted before output.
1369
static void print_xml_null_tag(FILE * xml_file, const char* sbeg,
1370
const char* stag_atr, const char* sval,
1371
const char* line_end)
1373
fputs(sbeg, xml_file);
1374
fputs("<", xml_file);
1375
fputs(stag_atr, xml_file);
1376
fputs("\"", xml_file);
1377
print_quoted_xml(xml_file, sval, strlen(sval));
1378
fputs("\" xsi:nil=\"true\" />", xml_file);
1379
fputs(line_end, xml_file);
1385
Print xml tag with many attributes.
1389
xml_file - output file
1390
row_name - xml tag name
1391
tableRes - query result
1395
Print tag with many attribute to the xml_file. Format is:
1396
\t\t<row_name Atr1="Val1" Atr2="Val2"... />
1398
All atributes and values will be quoted before output.
1401
static void print_xml_row(FILE *xml_file, const char *row_name,
1402
DRIZZLE_RES *tableRes, DRIZZLE_ROW *row)
1405
DRIZZLE_FIELD *field;
1406
uint32_t *lengths= drizzle_fetch_lengths(tableRes);
1408
fprintf(xml_file, "\t\t<%s", row_name);
1410
drizzle_field_seek(tableRes, 0);
1411
for (i= 0; (field= drizzle_fetch_field(tableRes)); i++)
1415
fputc(' ', xml_file);
1416
print_quoted_xml(xml_file, field->name, field->name_length);
1417
fputs("=\"", xml_file);
1418
print_quoted_xml(xml_file, (*row)[i], lengths[i]);
1419
fputc('"', xml_file);
1423
fputs(" />\n", xml_file);
1429
Print hex value for blob data.
1433
output_file - output file
1434
str - string to print
1438
Print hex value for blob data.
1441
static void print_blob_as_hex(FILE *output_file, const char *str, ulong len)
1443
/* sakaik got the idea to to provide blob's in hex notation. */
1444
const char *ptr= str, *end= ptr + len;
1445
for (; ptr < end ; ptr++)
1446
fprintf(output_file, "%02X", *((uchar *)ptr));
1447
check_io(output_file);
1451
get_table_structure -- retrievs database structure, prints out corresponding
1452
CREATE statement and fills out insert_pat if the table is the type we will
1458
table_type - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW"
1459
ignore_flag - what we must particularly ignore - see IGNORE_ defines above
1462
number of fields in table, 0 if error
1465
static uint get_table_structure(char *table, char *db, char *table_type,
1468
bool init=0, delayed, write_data, complete_insert;
1469
uint64_t num_fields;
1470
char *result_table, *opt_quoted_table;
1471
const char *insert_option;
1472
char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3];
1473
char table_buff2[NAME_LEN*2+3], query_buff[QUERY_LENGTH];
1474
FILE *sql_file= md_result_file;
1476
DRIZZLE_RES *result;
1479
*ignore_flag= check_if_ignore_table(table, table_type);
1481
delayed= opt_delayed;
1482
if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED))
1485
verbose_msg("-- Warning: Unable to use delayed inserts for table '%s' "
1486
"because it's of type %s\n", table, table_type);
1490
if ((write_data= !(*ignore_flag & IGNORE_DATA)))
1492
complete_insert= opt_complete_insert;
1493
if (!insert_pat_inited)
1495
insert_pat_inited= 1;
1496
init_dynamic_string_checked(&insert_pat, "", 1024, 1024);
1499
dynstr_set_checked(&insert_pat, "");
1502
insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " :
1503
delayed ? " DELAYED " : opt_ignore ? " IGNORE " : "");
1505
verbose_msg("-- Retrieving table structure for table %s...\n", table);
1507
len= snprintf(query_buff, sizeof(query_buff),
1508
"SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
1509
(opt_quoted || opt_keywords));
1511
result_table= quote_name(table, table_buff, 1);
1512
opt_quoted_table= quote_name(table, table_buff2, 0);
1514
if (opt_order_by_primary)
1516
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
1517
order_by= primary_key_fields(result_table);
1520
if (!opt_xml && !drizzle_query_with_error_report(drizzle, 0, query_buff))
1522
/* using SHOW CREATE statement */
1523
if (!opt_no_create_info)
1525
/* Make an sql-file, if path was given iow. option -T was given */
1526
char buff[20+FN_REFLEN];
1527
DRIZZLE_FIELD *field;
1529
snprintf(buff, sizeof(buff), "show create table %s", result_table);
1531
if (switch_character_set_results(drizzle, "binary") ||
1532
drizzle_query_with_error_report(drizzle, &result, buff) ||
1533
switch_character_set_results(drizzle, default_charset))
1538
if (!(sql_file= open_sql_file_for_table(table)))
1541
write_header(sql_file, db);
1543
if (!opt_xml && opt_comments)
1545
if (strcmp (table_type, "VIEW") == 0) /* view */
1546
fprintf(sql_file, "\n--\n-- Temporary table structure for view %s\n--\n\n",
1549
fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n",
1556
Even if the "table" is a view, we do a DROP TABLE here. The
1557
view-specific code below fills in the DROP VIEW.
1559
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
1564
field= drizzle_fetch_field_direct(result, 0);
1565
if (strcmp(field->name, "View") == 0)
1567
char *scv_buff= NULL;
1569
verbose_msg("-- It's a view, create dummy table for view\n");
1571
/* save "show create" statement for later */
1572
if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1573
scv_buff= my_strdup(scv_buff, MYF(0));
1575
drizzle_free_result(result);
1578
Create a table with the same name as the view and with columns of
1579
the same name in order to satisfy views that depend on this view.
1580
The table will be removed when the actual view is created.
1582
The properties of each column, aside from the data type, are not
1583
preserved in this temporary table, because they are not necessary.
1585
This will not be necessary once we can determine dependencies
1586
between views and can simply dump them in the appropriate order.
1588
snprintf(query_buff, sizeof(query_buff),
1589
"SHOW FIELDS FROM %s", result_table);
1590
if (switch_character_set_results(drizzle, "binary") ||
1591
drizzle_query_with_error_report(drizzle, &result, query_buff) ||
1592
switch_character_set_results(drizzle, default_charset))
1595
View references invalid or privileged table/col/fun (err 1356),
1596
so we cannot create a stand-in table. Be defensive and dump
1597
a comment with the view's 'show create' statement. (Bug #17371)
1600
if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1601
fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1603
my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1608
my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1610
if (drizzle_num_rows(result))
1615
We have already dropped any table of the same name above, so
1616
here we just drop the view.
1619
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
1625
"SET @saved_cs_client = @@character_set_client;\n"
1626
"SET character_set_client = utf8;\n"
1627
"/*!50001 CREATE TABLE %s (\n",
1631
Get first row, following loop will prepend comma - keeps from
1632
having to know if the row being printed is last to determine if
1633
there should be a _trailing_ comma.
1636
row= drizzle_fetch_row(result);
1638
fprintf(sql_file, " %s %s", quote_name(row[0], name_buff, 0),
1641
while((row= drizzle_fetch_row(result)))
1643
/* col name, col type */
1644
fprintf(sql_file, ",\n %s %s",
1645
quote_name(row[0], name_buff, 0), row[1]);
1649
"SET character_set_client = @saved_cs_client;\n");
1654
drizzle_free_result(result);
1657
my_fclose(sql_file, MYF(MY_WME));
1663
row= drizzle_fetch_row(result);
1666
"SET @saved_cs_client = @@character_set_client;\n"
1667
"SET character_set_client = utf8;\n"
1669
"SET character_set_client = @saved_cs_client;\n",
1673
drizzle_free_result(result);
1675
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1677
if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1680
my_fclose(sql_file, MYF(MY_WME));
1685
If write_data is true, then we build up insert statements for
1686
the table's data. Note: in subsequent lines of code, this test
1687
will have to be performed each time we are appending to
1692
if (opt_replace_into)
1693
dynstr_append_checked(&insert_pat, "REPLACE ");
1695
dynstr_append_checked(&insert_pat, "INSERT ");
1696
dynstr_append_checked(&insert_pat, insert_option);
1697
dynstr_append_checked(&insert_pat, "INTO ");
1698
dynstr_append_checked(&insert_pat, opt_quoted_table);
1699
if (complete_insert)
1701
dynstr_append_checked(&insert_pat, " (");
1705
dynstr_append_checked(&insert_pat, " VALUES ");
1706
if (!extended_insert)
1707
dynstr_append_checked(&insert_pat, "(");
1711
while ((row= drizzle_fetch_row(result)))
1713
if (complete_insert)
1717
dynstr_append_checked(&insert_pat, ", ");
1720
dynstr_append_checked(&insert_pat,
1721
quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1724
num_fields= drizzle_num_rows(result);
1725
drizzle_free_result(result);
1729
verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
1730
my_progname, drizzle_error(drizzle));
1732
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1734
if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1737
/* Make an sql-file, if path was given iow. option -T was given */
1738
if (!opt_no_create_info)
1742
if (!(sql_file= open_sql_file_for_table(table)))
1744
write_header(sql_file, db);
1746
if (!opt_xml && opt_comments)
1747
fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n",
1750
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", result_table);
1752
fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
1754
print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table,
1761
if (opt_replace_into)
1762
dynstr_append_checked(&insert_pat, "REPLACE ");
1764
dynstr_append_checked(&insert_pat, "INSERT ");
1765
dynstr_append_checked(&insert_pat, insert_option);
1766
dynstr_append_checked(&insert_pat, "INTO ");
1767
dynstr_append_checked(&insert_pat, result_table);
1768
if (complete_insert)
1769
dynstr_append_checked(&insert_pat, " (");
1772
dynstr_append_checked(&insert_pat, " VALUES ");
1773
if (!extended_insert)
1774
dynstr_append_checked(&insert_pat, "(");
1778
while ((row= drizzle_fetch_row(result)))
1780
uint32_t *lengths= drizzle_fetch_lengths(result);
1783
if (!opt_xml && !opt_no_create_info)
1785
fputs(",\n",sql_file);
1788
if (complete_insert)
1789
dynstr_append_checked(&insert_pat, ", ");
1792
if (complete_insert)
1793
dynstr_append_checked(&insert_pat,
1794
quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1795
if (!opt_no_create_info)
1799
print_xml_row(sql_file, "field", result, &row);
1804
fprintf(sql_file, " %s.%s %s", result_table,
1805
quote_name(row[SHOW_FIELDNAME],name_buff, 0),
1808
fprintf(sql_file, " %s %s", quote_name(row[SHOW_FIELDNAME],
1811
if (row[SHOW_DEFAULT])
1813
fputs(" DEFAULT ", sql_file);
1814
unescape(sql_file, row[SHOW_DEFAULT], lengths[SHOW_DEFAULT]);
1816
if (!row[SHOW_NULL][0])
1817
fputs(" NOT NULL", sql_file);
1818
if (row[SHOW_EXTRA][0])
1819
fprintf(sql_file, " %s",row[SHOW_EXTRA]);
1823
num_fields= drizzle_num_rows(result);
1824
drizzle_free_result(result);
1825
if (!opt_no_create_info)
1827
/* Make an sql-file, if path was given iow. option -T was given */
1828
char buff[20+FN_REFLEN];
1829
uint keynr,primary_key;
1830
snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1831
if (drizzle_query_with_error_report(drizzle, &result, buff))
1833
if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
1836
fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1839
fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1840
my_progname, result_table, drizzle_error(drizzle));
1842
my_fclose(sql_file, MYF(MY_WME));
1846
/* Find first which key is primary key */
1848
primary_key=INT_MAX;
1849
while ((row= drizzle_fetch_row(result)))
1851
if (atoi(row[3]) == 1)
1854
#ifdef FORCE_PRIMARY_KEY
1855
if (atoi(row[1]) == 0 && primary_key == INT_MAX)
1858
if (!strcmp(row[2],"PRIMARY"))
1865
drizzle_data_seek(result,0);
1867
while ((row= drizzle_fetch_row(result)))
1871
print_xml_row(sql_file, "key", result, &row);
1875
if (atoi(row[3]) == 1)
1878
putc(')', sql_file);
1879
if (atoi(row[1])) /* Test if duplicate key */
1880
/* Duplicate allowed */
1881
fprintf(sql_file, ",\n KEY %s (",quote_name(row[2],name_buff,0));
1882
else if (keynr == primary_key)
1883
fputs(",\n PRIMARY KEY (",sql_file); /* First UNIQUE is primary */
1885
fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff,
1889
putc(',', sql_file);
1890
fputs(quote_name(row[4], name_buff, 0), sql_file);
1892
fprintf(sql_file, " (%s)",row[7]); /* Sub key */
1895
drizzle_free_result(result);
1899
putc(')', sql_file);
1900
fputs("\n)",sql_file);
1904
/* Get DRIZZLE specific create options */
1907
char show_name_buff[NAME_LEN*2+2+24];
1909
/* Check memory for quote_for_like() */
1910
snprintf(buff, sizeof(buff), "show table status like %s",
1911
quote_for_like(table, show_name_buff));
1913
if (drizzle_query_with_error_report(drizzle, &result, buff))
1915
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
1916
{ /* If old DRIZZLE version */
1917
verbose_msg("-- Warning: Couldn't get status information for " \
1918
"table %s (%s)\n", result_table,drizzle_error(drizzle));
1921
else if (!(row= drizzle_fetch_row(result)))
1924
"Error: Couldn't read status information for table %s (%s)\n",
1925
result_table,drizzle_error(drizzle));
1930
print_xml_row(sql_file, "options", result, &row);
1933
fputs("/*!",sql_file);
1934
print_value(sql_file,result,row,"engine=","Engine",0);
1935
print_value(sql_file,result,row,"","Create_options",0);
1936
print_value(sql_file,result,row,"comment=","Comment",1);
1937
fputs(" */",sql_file);
1941
drizzle_free_result(result); /* Is always safe to free */
1945
fputs(";\n", sql_file);
1947
fputs("\t</table_structure>\n", sql_file);
1951
if (complete_insert)
1953
dynstr_append_checked(&insert_pat, ") VALUES ");
1954
if (!extended_insert)
1955
dynstr_append_checked(&insert_pat, "(");
1957
if (sql_file != md_result_file)
1959
fputs("\n", sql_file);
1960
write_footer(sql_file);
1961
my_fclose(sql_file, MYF(MY_WME));
1963
return((uint) num_fields);
1964
} /* get_table_structure */
1966
static void add_load_option(DYNAMIC_STRING *str, const char *option,
1967
const char *option_value)
1971
/* Null value means we don't add this option. */
1975
dynstr_append_checked(str, option);
1977
if (strncmp(option_value, "0x", sizeof("0x")-1) == 0)
1979
/* It's a hex constant, don't escape */
1980
dynstr_append_checked(str, option_value);
1984
/* char constant; escape */
1985
field_escape(str, option_value);
1991
Allow the user to specify field terminator strings like:
1992
"'", "\", "\\" (escaped backslash), "\t" (tab), "\n" (newline)
1993
This is done by doubling ' and add a end -\ if needed to avoid
1994
syntax errors from the SQL parser.
1997
static void field_escape(DYNAMIC_STRING* in, const char *from)
1999
uint end_backslashes= 0;
2001
dynstr_append_checked(in, "'");
2005
dynstr_append_mem_checked(in, from, 1);
2008
end_backslashes^=1; /* find odd number of backslashes */
2011
if (*from == '\'' && !end_backslashes)
2013
/* We want a duplicate of "'" for DRIZZLE */
2014
dynstr_append_checked(in, "\'");
2020
/* Add missing backslashes if user has specified odd number of backs.*/
2021
if (end_backslashes)
2022
dynstr_append_checked(in, "\\");
2024
dynstr_append_checked(in, "'");
2034
dump_table saves database contents as a series of INSERT statements.
2045
static void dump_table(char *table, char *db)
2048
char buf[200], table_buff[NAME_LEN+3];
2049
DYNAMIC_STRING query_string;
2050
char table_type[NAME_LEN];
2051
char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
2053
ulong rownr, row_break, total_length, init_length;
2056
DRIZZLE_FIELD *field;
2061
Make sure you get the create table info before the following check for
2062
--no-data flag below. Otherwise, the create table info won't be printed.
2064
num_fields= get_table_structure(table, db, table_type, &ignore_flag);
2067
The "table" could be a view. If so, we don't do anything here.
2069
if (strcmp(table_type, "VIEW") == 0)
2072
/* Check --no-data flag */
2075
verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
2081
If the table type is a merge table or any type that has to be
2082
_completely_ ignored and no data dumped
2084
if (ignore_flag & IGNORE_DATA)
2086
verbose_msg("-- Warning: Skipping data for table '%s' because " \
2087
"it's of type %s\n", table, table_type);
2090
/* Check that there are any fields in the table */
2091
if (num_fields == 0)
2093
verbose_msg("-- Skipping dump data for table '%s', it has no fields\n",
2099
Check --skip-events flag: it is not enough to skip creation of events
2100
discarding SHOW CREATE EVENT statements generation. The myslq.event
2101
table data should be skipped too.
2103
if (!opt_events && !my_strcasecmp(&my_charset_latin1, db, "mysql") &&
2104
!my_strcasecmp(&my_charset_latin1, table, "event"))
2106
verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2110
result_table= quote_name(table,table_buff, 1);
2111
opt_quoted_table= quote_name(table, table_buff2, 0);
2113
verbose_msg("-- Sending SELECT query...\n");
2115
init_dynamic_string_checked(&query_string, "", 1024, 1024);
2119
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
2122
Convert the path to native os format
2123
and resolve to the full filepath.
2125
convert_dirname(tmp_path,path,NullS);
2126
my_load_path(tmp_path, tmp_path, NULL);
2127
fn_format(filename, table, tmp_path, ".txt", MYF(MY_UNPACK_FILENAME));
2129
/* Must delete the file that 'INTO OUTFILE' will write to */
2130
my_delete(filename, MYF(0));
2132
/* convert to a unix path name to stick into the query */
2133
to_unix_path(filename);
2135
/* now build the query string */
2137
dynstr_append_checked(&query_string, "SELECT * INTO OUTFILE '");
2138
dynstr_append_checked(&query_string, filename);
2139
dynstr_append_checked(&query_string, "'");
2141
if (fields_terminated || enclosed || opt_enclosed || escaped)
2142
dynstr_append_checked(&query_string, " FIELDS");
2144
add_load_option(&query_string, " TERMINATED BY ", fields_terminated);
2145
add_load_option(&query_string, " ENCLOSED BY ", enclosed);
2146
add_load_option(&query_string, " OPTIONALLY ENCLOSED BY ", opt_enclosed);
2147
add_load_option(&query_string, " ESCAPED BY ", escaped);
2148
add_load_option(&query_string, " LINES TERMINATED BY ", lines_terminated);
2150
dynstr_append_checked(&query_string, " FROM ");
2151
dynstr_append_checked(&query_string, result_table);
2155
dynstr_append_checked(&query_string, " WHERE ");
2156
dynstr_append_checked(&query_string, where);
2161
dynstr_append_checked(&query_string, " ORDER BY ");
2162
dynstr_append_checked(&query_string, order_by);
2165
if (drizzle_real_query(drizzle, query_string.str, query_string.length))
2167
DB_error(drizzle, "when executing 'SELECT INTO OUTFILE'");
2168
dynstr_free(&query_string);
2174
if (!opt_xml && opt_comments)
2176
fprintf(md_result_file,"\n--\n-- Dumping data for table %s\n--\n",
2178
check_io(md_result_file);
2181
dynstr_append_checked(&query_string, "SELECT * FROM ");
2182
dynstr_append_checked(&query_string, result_table);
2186
if (!opt_xml && opt_comments)
2188
fprintf(md_result_file, "-- WHERE: %s\n", where);
2189
check_io(md_result_file);
2192
dynstr_append_checked(&query_string, " WHERE ");
2193
dynstr_append_checked(&query_string, where);
2197
if (!opt_xml && opt_comments)
2199
fprintf(md_result_file, "-- ORDER BY: %s\n", order_by);
2200
check_io(md_result_file);
2202
dynstr_append_checked(&query_string, " ORDER BY ");
2203
dynstr_append_checked(&query_string, order_by);
2206
if (!opt_xml && !opt_compact)
2208
fputs("\n", md_result_file);
2209
check_io(md_result_file);
2211
if (drizzle_query_with_error_report(drizzle, 0, query_string.str))
2213
DB_error(drizzle, "when retrieving data from server");
2217
res=drizzle_use_result(drizzle);
2219
res=drizzle_store_result(drizzle);
2222
DB_error(drizzle, "when retrieving data from server");
2226
verbose_msg("-- Retrieving rows...\n");
2227
if (drizzle_num_fields(res) != num_fields)
2229
fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n",
2230
my_progname, result_table);
2231
error= EX_CONSCHECK;
2237
fprintf(md_result_file,"LOCK TABLES %s WRITE;\n", opt_quoted_table);
2238
check_io(md_result_file);
2240
/* Moved disable keys to after lock per bug 15977 */
2241
if (opt_disable_keys)
2243
fprintf(md_result_file, "/*!40000 ALTER TABLE %s DISABLE KEYS */;\n",
2245
check_io(md_result_file);
2248
total_length= opt_net_buffer_length; /* Force row break */
2251
init_length=(uint) insert_pat.length+4;
2253
print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
2257
fprintf(md_result_file, "set autocommit=0;\n");
2258
check_io(md_result_file);
2261
while ((row= drizzle_fetch_row(res)))
2264
uint32_t *lengths= drizzle_fetch_lengths(res);
2266
if (!extended_insert && !opt_xml)
2268
fputs(insert_pat.str,md_result_file);
2269
check_io(md_result_file);
2271
drizzle_field_seek(res,0);
2275
fputs("\t<row>\n", md_result_file);
2276
check_io(md_result_file);
2279
for (i= 0; i < drizzle_num_fields(res); i++)
2282
ulong length= lengths[i];
2284
if (!(field= drizzle_fetch_field(res)))
2286
"Not enough fields from table %s! Aborting.\n",
2290
63 is my_charset_bin. If charsetnr is not 63,
2291
we have not a BLOB but a TEXT column.
2292
we'll dump in hex only BLOB columns.
2294
is_blob= (opt_hex_blob && field->charsetnr == 63 &&
2295
(field->type == MYSQL_TYPE_STRING ||
2296
field->type == MYSQL_TYPE_VARCHAR ||
2297
field->type == MYSQL_TYPE_BLOB)) ? 1 : 0;
2298
if (extended_insert && !opt_xml)
2301
dynstr_set_checked(&extended_row,"(");
2303
dynstr_append_checked(&extended_row,",");
2309
if (!IS_NUM_FIELD(field))
2312
"length * 2 + 2" is OK for both HEX and non-HEX modes:
2313
- In HEX mode we need exactly 2 bytes per character
2314
plus 2 bytes for '0x' prefix.
2315
- In non-HEX mode we need up to 2 bytes per character,
2316
plus 2 bytes for leading and trailing '\'' characters.
2317
Also we need to reserve 1 byte for terminating '\0'.
2319
dynstr_realloc_checked(&extended_row,length * 2 + 2 + 1);
2320
if (opt_hex_blob && is_blob)
2322
dynstr_append_checked(&extended_row, "0x");
2323
extended_row.length+= drizzle_hex_string(extended_row.str +
2324
extended_row.length,
2326
assert(extended_row.length+1 <= extended_row.max_length);
2327
/* drizzle_hex_string() already terminated string by '\0' */
2328
assert(extended_row.str[extended_row.length] == '\0');
2332
dynstr_append_checked(&extended_row,"'");
2333
extended_row.length +=
2334
drizzle_real_escape_string(&drizzle_connection,
2335
&extended_row.str[extended_row.length],
2337
extended_row.str[extended_row.length]='\0';
2338
dynstr_append_checked(&extended_row,"'");
2343
/* change any strings ("inf", "-inf", "nan") into NULL */
2345
if (my_isalpha(charset_info, *ptr) || (*ptr == '-' &&
2346
my_isalpha(charset_info, ptr[1])))
2347
dynstr_append_checked(&extended_row, "NULL");
2350
dynstr_append_checked(&extended_row, ptr);
2355
dynstr_append_checked(&extended_row,"''");
2358
dynstr_append_checked(&extended_row,"NULL");
2364
fputc(',', md_result_file);
2365
check_io(md_result_file);
2369
if (!IS_NUM_FIELD(field))
2373
if (opt_hex_blob && is_blob && length)
2375
/* Define xsi:type="xs:hexBinary" for hex encoded data */
2376
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2377
field->name, "xsi:type=", "xs:hexBinary", NullS);
2378
print_blob_as_hex(md_result_file, row[i], length);
2382
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2383
field->name, NullS);
2384
print_quoted_xml(md_result_file, row[i], length);
2386
fputs("</field>\n", md_result_file);
2388
else if (opt_hex_blob && is_blob && length)
2390
fputs("0x", md_result_file);
2391
print_blob_as_hex(md_result_file, row[i], length);
2394
unescape(md_result_file, row[i], length);
2398
/* change any strings ("inf", "-inf", "nan") into NULL */
2402
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2403
field->name, NullS);
2404
fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
2406
fputs("</field>\n", md_result_file);
2408
else if (my_isalpha(charset_info, *ptr) ||
2409
(*ptr == '-' && my_isalpha(charset_info, ptr[1])))
2410
fputs("NULL", md_result_file);
2412
fputs(ptr, md_result_file);
2417
/* The field value is NULL */
2419
fputs("NULL", md_result_file);
2421
print_xml_null_tag(md_result_file, "\t\t", "field name=",
2424
check_io(md_result_file);
2430
fputs("\t</row>\n", md_result_file);
2431
check_io(md_result_file);
2434
if (extended_insert)
2437
dynstr_append_checked(&extended_row,")");
2438
row_length= 2 + extended_row.length;
2439
if (total_length + row_length < opt_net_buffer_length)
2441
total_length+= row_length;
2442
fputc(',',md_result_file); /* Always row break */
2443
fputs(extended_row.str,md_result_file);
2448
fputs(";\n", md_result_file);
2449
row_break=1; /* This is first row */
2451
fputs(insert_pat.str,md_result_file);
2452
fputs(extended_row.str,md_result_file);
2453
total_length= row_length+init_length;
2455
check_io(md_result_file);
2459
fputs(");\n", md_result_file);
2460
check_io(md_result_file);
2464
/* XML - close table tag and supress regular output */
2466
fputs("\t</table_data>\n", md_result_file);
2467
else if (extended_insert && row_break)
2468
fputs(";\n", md_result_file); /* If not empty table */
2469
fflush(md_result_file);
2470
check_io(md_result_file);
2471
if (drizzle_errno(drizzle))
2473
snprintf(buf, sizeof(buf),
2474
"%s: Error %d: %s when dumping table %s at row: %ld\n",
2476
drizzle_errno(drizzle),
2477
drizzle_error(drizzle),
2481
error= EX_CONSCHECK;
2485
/* Moved enable keys to before unlock per bug 15977 */
2486
if (opt_disable_keys)
2488
fprintf(md_result_file,"/*!40000 ALTER TABLE %s ENABLE KEYS */;\n",
2490
check_io(md_result_file);
2494
fputs("UNLOCK TABLES;\n", md_result_file);
2495
check_io(md_result_file);
2499
fprintf(md_result_file, "commit;\n");
2500
check_io(md_result_file);
2502
drizzle_free_result(res);
2504
dynstr_free(&query_string);
2508
dynstr_free(&query_string);
2514
static char *getTableName(int reset)
2516
static DRIZZLE_RES *res= NULL;
2521
if (!(res= drizzle_list_tables(drizzle,NullS)))
2524
if ((row= drizzle_fetch_row(res)))
2525
return((char*) row[0]);
2528
drizzle_data_seek(res,0); /* We want to read again */
2531
drizzle_free_result(res);
2535
} /* getTableName */
374
2538
static int dump_all_databases()
377
drizzle_result_st *tableres;
2541
DRIZZLE_RES *tableres;
380
DrizzleDumpDatabase *database;
383
std::cerr << _("-- Retrieving database structures...") << std::endl;
385
/* Blocking the MySQL privilege tables too because we can't import them due to bug#646187 */
386
if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
387
query= "SELECT SCHEMA_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME NOT IN ('information_schema', 'performance_schema', 'mysql')";
389
query= "SELECT SCHEMA_NAME, DEFAULT_COLLATION_NAME FROM DATA_DICTIONARY.SCHEMAS WHERE SCHEMA_NAME NOT IN ('information_schema','data_dictionary')";
391
tableres= db_connection->query(query);
392
while ((row= drizzle_row_next(tableres)))
2544
if (drizzle_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
2546
while ((row= drizzle_fetch_row(tableres)))
394
std::string database_name(row[0]);
395
if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
396
database= new DrizzleDumpDatabaseMySQL(database_name, db_connection);
398
database= new DrizzleDumpDatabaseDrizzle(database_name, db_connection);
400
database->setCollate(row[1]);
401
database_store.push_back(database);
2548
if (dump_all_tables_in_db(row[0]))
403
db_connection->freeResult(tableres);
406
2553
/* dump_all_databases */
409
static int dump_databases(const vector<string> &db_names)
2556
static int dump_databases(char **db_names)
413
DrizzleDumpDatabase *database;
415
for (vector<string>::const_iterator it= db_names.begin(); it != db_names.end(); ++it)
2562
for (db= db_names ; *db ; db++)
418
if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
419
database= new DrizzleDumpDatabaseMySQL(temp, db_connection);
421
database= new DrizzleDumpDatabaseDrizzle(temp, db_connection);
422
database_store.push_back(database);
2564
if (dump_all_tables_in_db(*db))
425
2568
} /* dump_databases */
427
static int dump_selected_tables(const string &db, const vector<string> &table_names)
429
DrizzleDumpDatabase *database;
431
if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
432
database= new DrizzleDumpDatabaseMySQL(db, db_connection);
434
database= new DrizzleDumpDatabaseDrizzle(db, db_connection);
436
if (not database->populateTables(table_names))
439
maybe_exit(EX_DRIZZLEERR);
442
database_store.push_back(database);
2572
Table Specific database initalization.
2576
qdatabase quoted name of the database
2583
int init_dumping_tables(char *qdatabase)
2591
DRIZZLE_RES *dbinfo;
2593
snprintf(qbuf, sizeof(qbuf),
2594
"SHOW CREATE DATABASE IF NOT EXISTS %s",
2597
if (drizzle_query(drizzle, qbuf) || !(dbinfo = drizzle_store_result(drizzle)))
2599
/* Old server version, dump generic CREATE DATABASE */
2600
if (opt_drop_database)
2601
fprintf(md_result_file,
2602
"\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2604
fprintf(md_result_file,
2605
"\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n",
2610
if (opt_drop_database)
2611
fprintf(md_result_file,
2612
"\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2614
row = drizzle_fetch_row(dbinfo);
2617
fprintf(md_result_file,"\n%s;\n",row[1]);
2619
drizzle_free_result(dbinfo);
2623
} /* init_dumping_tables */
2626
static int init_dumping(char *database, int init_func(char*))
2628
if (drizzle_get_server_version(drizzle) >= 50003 &&
2629
!my_strcasecmp(&my_charset_latin1, database, "information_schema"))
2632
if (drizzle_select_db(drizzle, database))
2634
DB_error(drizzle, "when selecting the database");
2635
return 1; /* If --force */
2637
if (!path && !opt_xml)
2639
if (opt_databases || opt_alldbs)
2642
length of table name * 2 (if name contains quotes), 2 quotes and 0
2644
char quoted_database_buf[NAME_LEN*2+3];
2645
char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
2648
fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase);
2649
check_io(md_result_file);
2652
/* Call the view or table specific function */
2653
init_func(qdatabase);
2655
fprintf(md_result_file,"\nUSE %s;\n", qdatabase);
2656
check_io(md_result_file);
2659
if (extended_insert)
2660
init_dynamic_string_checked(&extended_row, "", 1024, 1024);
2662
} /* init_dumping */
2665
/* Return 1 if we should copy the table */
2667
static bool include_table(const uchar *hash_key, size_t len)
2669
return !hash_search(&ignore_table, hash_key, len);
2673
static int dump_all_tables_in_db(char *database)
2677
char table_buff[NAME_LEN*2+3];
2678
char hash_key[2*NAME_LEN+2]; /* "db.tablename" */
2680
int using_mysql_db= my_strcasecmp(&my_charset_latin1, database, "mysql");
2683
afterdot= strmov(hash_key, database);
2686
if (init_dumping(database, init_dumping_tables))
2689
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
2692
DYNAMIC_STRING query;
2693
init_dynamic_string_checked(&query, "LOCK TABLES ", 256, 1024);
2694
for (numrows= 0 ; (table= getTableName(1)) ; )
2696
char *end= strmov(afterdot, table);
2697
if (include_table((uchar*) hash_key,end - hash_key))
2700
dynstr_append_checked(&query, quote_name(table, table_buff, 1));
2701
dynstr_append_checked(&query, " READ /*!32311 LOCAL */,");
2704
if (numrows && drizzle_real_query(drizzle, query.str, query.length-1))
2705
DB_error(drizzle, "when using LOCK TABLES");
2706
/* We shall continue here, if --force was given */
2707
dynstr_free(&query);
2711
if (drizzle_refresh(drizzle, REFRESH_LOG))
2712
DB_error(drizzle, "when doing refresh");
2713
/* We shall continue here, if --force was given */
2715
while ((table= getTableName(0)))
2717
char *end= strmov(afterdot, table);
2718
if (include_table((uchar*) hash_key, end - hash_key))
2720
dump_table(table,database);
2721
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2727
fputs("</database>\n", md_result_file);
2728
check_io(md_result_file);
2731
VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2732
if (flush_privileges && using_mysql_db == 0)
2734
fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2735
fprintf(md_result_file,"\n/*! FLUSH PRIVILEGES */;\n");
2738
} /* dump_all_tables_in_db */
2742
get_actual_table_name -- executes a SHOW TABLES LIKE '%s' to get the actual
2743
table name from the server for the table name given on the command line.
2744
we do this because the table name given on the command line may be a
2745
different case (e.g. T1 vs t1)
2748
pointer to the table name
2752
static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
2755
DRIZZLE_RES *table_res;
2757
char query[50 + 2*NAME_LEN];
2758
char show_name_buff[FN_REFLEN];
2761
/* Check memory for quote_for_like() */
2762
assert(2*sizeof(old_table_name) < sizeof(show_name_buff));
2763
snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2764
quote_for_like(old_table_name, show_name_buff));
2766
if (drizzle_query_with_error_report(drizzle, 0, query))
2769
if ((table_res= drizzle_store_result(drizzle)))
2771
uint64_t num_rows= drizzle_num_rows(table_res);
2777
TODO: Return all matching rows
2779
row= drizzle_fetch_row(table_res);
2780
lengths= drizzle_fetch_lengths(table_res);
2781
name= strmake_root(root, row[0], lengths[0]);
2783
drizzle_free_result(table_res);
2789
static int dump_selected_tables(char *db, char **table_names, int tables)
2791
char table_buff[NAME_LEN*2+3];
2792
DYNAMIC_STRING lock_tables_query;
2794
char **dump_tables, **pos, **end;
2797
if (init_dumping(db, init_dumping_tables))
2800
init_alloc_root(&root, 8192, 0);
2801
if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
2802
die(EX_EOM, "alloc_root failure.");
2804
init_dynamic_string_checked(&lock_tables_query, "LOCK TABLES ", 256, 1024);
2805
for (; tables > 0 ; tables-- , table_names++)
2807
/* the table name passed on commandline may be wrong case */
2808
if ((*pos= get_actual_table_name(*table_names, &root)))
2810
/* Add found table name to lock_tables_query */
2813
dynstr_append_checked(&lock_tables_query, quote_name(*pos, table_buff, 1));
2814
dynstr_append_checked(&lock_tables_query, " READ /*!32311 LOCAL */,");
2822
dynstr_free(&lock_tables_query);
2823
free_root(&root, MYF(0));
2825
maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names);
2826
/* We shall countinue here, if --force was given */
2833
if (drizzle_real_query(drizzle, lock_tables_query.str,
2834
lock_tables_query.length-1))
2838
dynstr_free(&lock_tables_query);
2839
free_root(&root, MYF(0));
2841
DB_error(drizzle, "when doing LOCK TABLES");
2842
/* We shall countinue here, if --force was given */
2845
dynstr_free(&lock_tables_query);
2848
if (drizzle_refresh(drizzle, REFRESH_LOG))
2851
free_root(&root, MYF(0));
2852
DB_error(drizzle, "when doing refresh");
2854
/* We shall countinue here, if --force was given */
2857
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
2859
/* Dump each selected table */
2860
for (pos= dump_tables; pos < end; pos++)
2861
dump_table(*pos, db);
2863
free_root(&root, MYF(0));
2864
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2868
fputs("</database>\n", md_result_file);
2869
check_io(md_result_file);
2872
VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
445
2874
} /* dump_selected_tables */
447
static int do_flush_tables_read_lock()
2877
static int do_show_master_status(DRIZZLE *drizzle_con)
2880
DRIZZLE_RES *master;
2881
const char *comment_prefix=
2882
(opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2883
if (drizzle_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2889
row= drizzle_fetch_row(master);
2890
if (row && row[0] && row[1])
2892
/* SHOW MASTER STATUS reports file and position */
2894
fprintf(md_result_file,
2895
"\n--\n-- Position to start replication or point-in-time "
2896
"recovery from\n--\n\n");
2897
fprintf(md_result_file,
2898
"%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n",
2899
comment_prefix, row[0], row[1]);
2900
check_io(md_result_file);
2902
else if (!ignore_errors)
2904
/* SHOW MASTER STATUS reports nothing and --force is not enabled */
2905
my_printf_error(0, "Error: Binlogging on server not active",
2907
drizzle_free_result(master);
2908
maybe_exit(EX_DRIZZLEERR);
2911
drizzle_free_result(master);
2916
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
2919
/* We need to check if the slave sql is running in the first place */
2920
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2924
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2927
/* if SLAVE SQL is not running, we don't stop it */
2928
if (!strcmp(row[11],"No"))
2930
drizzle_free_result(slave);
2931
/* Silently assume that they don't have the slave running */
2936
drizzle_free_result(slave);
2938
/* now, stop slave if running */
2939
if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2945
static int add_stop_slave(void)
2948
fprintf(md_result_file,
2949
"\n--\n-- stop slave statement to make a recovery dump)\n--\n\n");
2950
fprintf(md_result_file, "STOP SLAVE;\n");
2954
static int add_slave_statements(void)
2957
fprintf(md_result_file,
2958
"\n--\n-- start slave statement to make a recovery dump)\n--\n\n");
2959
fprintf(md_result_file, "START SLAVE;\n");
2963
static int do_show_slave_status(DRIZZLE *drizzle_con)
2966
const char *comment_prefix=
2967
(opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2968
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2972
/* SHOW SLAVE STATUS reports nothing and --force is not enabled */
2973
my_printf_error(0, "Error: Slave not set up", MYF(0));
2979
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2980
if (row && row[9] && row[21])
2982
/* SHOW MASTER STATUS reports file and position */
2984
fprintf(md_result_file,
2985
"\n--\n-- Position to start replication or point-in-time "
2986
"recovery from (the master of this slave)\n--\n\n");
2988
fprintf(md_result_file, "%sCHANGE MASTER TO ", comment_prefix);
2990
if (opt_include_master_host_port)
2993
fprintf(md_result_file, "MASTER_HOST='%s', ", row[1]);
2995
fprintf(md_result_file, "MASTER_PORT='%s', ", row[3]);
2997
fprintf(md_result_file,
2998
"MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", row[9], row[21]);
3000
check_io(md_result_file);
3002
drizzle_free_result(slave);
3007
static int do_start_slave_sql(DRIZZLE *drizzle_con)
3010
/* We need to check if the slave sql is stopped in the first place */
3011
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
3015
DRIZZLE_ROW row= drizzle_fetch_row(slave);
3018
/* if SLAVE SQL is not running, we don't start it */
3019
if (!strcmp(row[11],"Yes"))
3021
drizzle_free_result(slave);
3022
/* Silently assume that they don't have the slave running */
3027
drizzle_free_result(slave);
3029
/* now, start slave if stopped */
3030
if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
3032
my_printf_error(0, "Error: Unable to start slave", MYF(0));
3040
static int do_flush_tables_read_lock(DRIZZLE *drizzle_con)
450
3043
We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
451
3044
will wait but will not stall the whole mysqld, and when the long update is
452
3045
done the FLUSH TABLES WITH READ LOCK will start and succeed quickly. So,
453
FLUSH TABLES is to lower the probability of a stage where both drizzled
3046
FLUSH TABLES is to lower the probability of a stage where both mysqldump
454
3047
and most client connections are stalled. Of course, if a second long
455
3048
update starts between the two FLUSHes, we have that bad stall.
458
db_connection->queryNoResult("FLUSH TABLES");
459
db_connection->queryNoResult("FLUSH TABLES WITH READ LOCK");
464
static int do_unlock_tables()
466
db_connection->queryNoResult("UNLOCK TABLES");
470
static int start_transaction()
472
db_connection->queryNoResult("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ");
473
db_connection->queryNoResult("START TRANSACTION WITH CONSISTENT SNAPSHOT");
3051
( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
3052
drizzle_query_with_error_report(drizzle_con, 0,
3053
"FLUSH TABLES WITH READ LOCK") );
3057
static int do_unlock_tables(DRIZZLE *drizzle_con)
3059
return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
3062
static int get_bin_log_name(DRIZZLE *drizzle_con,
3063
char* buff_log_name, uint buff_len)
3068
if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
3069
!(res= drizzle_store_result(drizzle)))
3072
if (!(row= drizzle_fetch_row(res)))
3074
drizzle_free_result(res);
3078
Only one row is returned, and the first column is the name of the
3081
strmake(buff_log_name, row[0], buff_len - 1);
3083
drizzle_free_result(res);
3087
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
3091
init_dynamic_string_checked(&str, "PURGE BINARY LOGS TO '", 1024, 1024);
3092
dynstr_append_checked(&str, log_name);
3093
dynstr_append_checked(&str, "'");
3094
err = drizzle_query_with_error_report(drizzle_con, 0, str.str);
3100
static int start_transaction(DRIZZLE *drizzle_con)
3103
We use BEGIN for old servers. --single-transaction --master-data will fail
3104
on old servers, but that's ok as it was already silently broken (it didn't
3105
do a consistent read, so better tell people frankly, with the error).
3107
We want the first consistent read to be used for all tables to dump so we
3108
need the REPEATABLE READ level (not anything lower, for example READ
3109
COMMITTED would give one new consistent read per dumped table).
3111
if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
3113
fprintf(stderr, "-- %s: the combination of --single-transaction and "
3114
"--master-data requires a DRIZZLE server version of at least 4.1 "
3115
"(current server's version is %s). %s\n",
3116
ignore_errors ? "Warning" : "Error",
3117
drizzle_con->server_version ? drizzle_con->server_version : "unknown",
3118
ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3120
exit(EX_DRIZZLEERR);
3123
return (drizzle_query_with_error_report(drizzle_con, 0,
3124
"SET SESSION TRANSACTION ISOLATION "
3125
"LEVEL REPEATABLE READ") ||
3126
drizzle_query_with_error_report(drizzle_con, 0,
3127
"START TRANSACTION "
3128
"/*!40100 WITH CONSISTENT SNAPSHOT */"));
3132
static ulong find_set(TYPELIB *lib, const char *x, uint length,
3133
char **err_pos, uint *err_len)
3135
const char *end= x + length;
3140
*err_pos= 0; /* No error yet */
3141
while (end > x && my_isspace(charset_info, end[-1]))
3147
const char *start= x;
3150
const char *pos= start;
3153
for (; pos != end && *pos != ','; pos++) ;
3154
var_len= (uint) (pos - start);
3155
strmake(buff, start, min(sizeof(buff), var_len));
3156
find= find_type(buff, lib, var_len);
3159
*err_pos= (char*) start;
3163
found|= ((int64_t) 1 << (find - 1));
3173
/* Print a value with a prefix on file */
3174
static void print_value(FILE *file, DRIZZLE_RES *result, DRIZZLE_ROW row,
3175
const char *prefix, const char *name,
3178
DRIZZLE_FIELD *field;
3179
drizzle_field_seek(result, 0);
3181
for ( ; (field= drizzle_fetch_field(result)) ; row++)
3183
if (!strcmp(field->name,name))
3185
if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
3188
fputs(prefix, file);
3190
unescape(file,row[0],(uint) strlen(row[0]));
3192
fputs(row[0], file);
3198
return; /* This shouldn't happen */
3205
Check if we the table is one of the table types that should be ignored:
3206
MRG_ISAM, MRG_MYISAM, if opt_delayed, if that table supports delayed inserts.
3207
If the table should be altogether ignored, it returns a true, false if it
3208
should not be ignored. If the user has selected to use INSERT DELAYED, it
3209
sets the value of the bool pointer supports_delayed_inserts to 0 if not
3210
supported, 1 if it is supported.
3214
check_if_ignore_table()
3215
table_name Table name to check
3216
table_type Type of table
3219
drizzle Drizzle connection
3220
verbose Write warning messages
3223
char (bit value) See IGNORE_ values at top
3226
char check_if_ignore_table(const char *table_name, char *table_type)
3228
char result= IGNORE_NONE;
3229
char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3230
DRIZZLE_RES *res= NULL;
3234
/* Check memory for quote_for_like() */
3235
assert(2*sizeof(table_name) < sizeof(show_name_buff));
3236
snprintf(buff, sizeof(buff), "show table status like %s",
3237
quote_for_like(table_name, show_name_buff));
3238
if (drizzle_query_with_error_report(drizzle, &res, buff))
3240
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
3241
{ /* If old DRIZZLE version */
3242
verbose_msg("-- Warning: Couldn't get status information for "
3243
"table %s (%s)\n", table_name, drizzle_error(drizzle));
3244
return(result); /* assume table is ok */
3247
if (!(row= drizzle_fetch_row(res)))
3250
"Error: Couldn't read status information for table %s (%s)\n",
3251
table_name, drizzle_error(drizzle));
3252
drizzle_free_result(res);
3253
return(result); /* assume table is ok */
3256
strmake(table_type, "VIEW", NAME_LEN-1);
3260
If the table type matches any of these, we do support delayed inserts.
3261
Note: we do not want to skip dumping this table if if is not one of
3262
these types, but we do want to use delayed inserts in the dump if
3263
the table type is _NOT_ one of these types
3265
strmake(table_type, row[1], NAME_LEN-1);
3268
if (strcmp(table_type,"MyISAM") &&
3269
strcmp(table_type,"ISAM") &&
3270
strcmp(table_type,"ARCHIVE") &&
3271
strcmp(table_type,"HEAP") &&
3272
strcmp(table_type,"MEMORY"))
3273
result= IGNORE_INSERT_DELAYED;
3277
If these two types, we do want to skip dumping the table
3280
(!my_strcasecmp(&my_charset_latin1, table_type, "MRG_MyISAM") ||
3281
!strcmp(table_type,"MRG_ISAM")))
3282
result= IGNORE_DATA;
3284
drizzle_free_result(res);
3290
Get string of comma-separated primary key field names
3293
char *primary_key_fields(const char *table_name)
3294
RETURNS pointer to allocated buffer (must be freed by caller)
3295
table_name quoted table name
3298
Use SHOW KEYS FROM table_name, allocate a buffer to hold the
3299
field names, and then build that string and return the pointer
3302
Returns NULL if there is no PRIMARY or UNIQUE key on the table,
3303
or if there is some failure. It is better to continue to dump
3304
the table unsorted, rather than exit without dumping the data.
3307
static char *primary_key_fields(const char *table_name)
3309
DRIZZLE_RES *res= NULL;
3311
/* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3312
char show_keys_buff[15 + NAME_LEN * 2 + 3];
3313
uint result_length= 0;
3315
char buff[NAME_LEN * 2 + 3];
3318
snprintf(show_keys_buff, sizeof(show_keys_buff),
3319
"SHOW KEYS FROM %s", table_name);
3320
if (drizzle_query(drizzle, show_keys_buff) ||
3321
!(res= drizzle_store_result(drizzle)))
3323
fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3324
" records are NOT sorted (%s)\n",
3325
table_name, drizzle_error(drizzle));
3326
/* Don't exit, because it's better to print out unsorted records */
3331
* Figure out the length of the ORDER BY clause result.
3332
* Note that SHOW KEYS is ordered: a PRIMARY key is always the first
3333
* row, and UNIQUE keys come before others. So we only need to check
3334
* the first key, not all keys.
3336
if ((row= drizzle_fetch_row(res)) && atoi(row[1]) == 0)
3341
quoted_field= quote_name(row[4], buff, 0);
3342
result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3343
} while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1);
3346
/* Build the ORDER BY clause result */
3350
/* result (terminating \0 is already in result_length) */
3351
result= my_malloc(result_length + 10, MYF(MY_WME));
3354
fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
3357
drizzle_data_seek(res, 0);
3358
row= drizzle_fetch_row(res);
3359
quoted_field= quote_name(row[4], buff, 0);
3360
end= strmov(result, quoted_field);
3361
while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
3363
quoted_field= quote_name(row[4], buff, 0);
3364
end= strxmov(end, ",", quoted_field, NullS);
3370
drizzle_free_result(res);
3376
The following functions are wrappers for the dynamic string functions
3377
and if they fail, the wrappers will terminate the current process.
3380
#define DYNAMIC_STR_ERROR_MSG "Couldn't perform DYNAMIC_STRING operation"
3382
static void init_dynamic_string_checked(DYNAMIC_STRING *str, const char *init_str,
3383
uint init_alloc, uint alloc_increment)
3385
if (init_dynamic_string(str, init_str, init_alloc, alloc_increment))
3386
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3389
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src)
3391
if (dynstr_append(dest, src))
3392
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3395
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str)
3397
if (dynstr_set(str, init_str))
3398
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3401
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
3404
if (dynstr_append_mem(str, append, length))
3405
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3408
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size)
3410
if (dynstr_realloc(str, additional_size))
3411
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
477
3415
int main(int argc, char **argv)
3417
char bin_log_name[FN_REFLEN];
483
po::options_description commandline_options(N_("Options used only in command line"));
484
commandline_options.add_options()
485
("all-databases,A", po::value<bool>(&opt_alldbs)->default_value(false)->zero_tokens(),
486
N_("Dump all the databases. This will be same as --databases with all databases selected."))
487
("all-tablespaces,Y", po::value<bool>(&opt_alltspcs)->default_value(false)->zero_tokens(),
488
N_("Dump all the tablespaces."))
489
("complete-insert,c", po::value<bool>(&opt_complete_insert)->default_value(false)->zero_tokens(),
490
N_("Use complete insert statements."))
491
("compress,C", po::value<bool>(&opt_compress)->default_value(false)->zero_tokens(),
492
N_("Use compression in server/client protocol."))
493
("flush-logs,F", po::value<bool>(&flush_logs)->default_value(false)->zero_tokens(),
494
N_("Flush logs file in server before starting dump. Note that if you dump many databases at once (using the option --databases= or --all-databases), the logs will be flushed for each database dumped. The exception is when using --lock-all-tables in this case the logs will be flushed only once, corresponding to the moment all tables are locked. So if you want your dump and the log flush to happen at the same exact moment you should use --lock-all-tables or --flush-logs"))
495
("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
496
N_("Continue even if we get an sql-error."))
497
("help,?", N_("Display this help message and exit."))
498
("lock-all-tables,x", po::value<bool>(&opt_lock_all_tables)->default_value(false)->zero_tokens(),
499
N_("Locks all tables across all databases. This is achieved by taking a global read lock for the duration of the whole dump. Automatically turns --single-transaction and --lock-tables off."))
500
("order-by-primary", po::value<bool>(&opt_order_by_primary)->default_value(false)->zero_tokens(),
501
N_("Sorts each table's rows by primary key, or first unique key, if such a key exists. Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer."))
502
("single-transaction", po::value<bool>(&opt_single_transaction)->default_value(false)->zero_tokens(),
503
N_("Creates a consistent snapshot by dumping all tables in a single transaction. Works ONLY for tables stored in storage engines which support multiversioning (currently only InnoDB does); the dump is NOT guaranteed to be consistent for other storage engines. While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents), no other connection should use the following statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not isolated from them. Option automatically turns off --lock-tables."))
504
("opt", N_("Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt."))
506
N_("Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys."))
507
("tables", N_("Overrides option --databases (-B)."))
508
("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(10000),
509
N_("Number of rows before each output progress report (requires --verbose)."))
510
("verbose,v", po::value<bool>(&verbose)->default_value(false)->zero_tokens(),
511
N_("Print info about the various stages."))
512
("version,V", N_("Output version information and exit."))
513
("skip-comments", N_("Turn off Comments"))
514
("skip-create", N_("Turn off create-options"))
515
("skip-extended-insert", N_("Turn off extended-insert"))
516
("skip-dump-date",N_( "Turn off dump date at the end of the output"))
517
("no-defaults", N_("Do not read from the configuration files"))
520
po::options_description dump_options(N_("Options specific to the drizzle client"));
521
dump_options.add_options()
522
("add-drop-database", po::value<bool>(&opt_drop_database)->default_value(false)->zero_tokens(),
523
N_("Add a 'DROP DATABASE' before each create."))
524
("skip-drop-table", N_("Do not add a 'drop table' before each create."))
525
("allow-keywords", po::value<bool>(&opt_keywords)->default_value(false)->zero_tokens(),
526
N_("Allow creation of column names that are keywords."))
527
("compact", po::value<bool>(&opt_compact)->default_value(false)->zero_tokens(),
528
N_("Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks"))
529
("databases,B", po::value<bool>(&opt_databases)->default_value(false)->zero_tokens(),
530
N_("To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output."))
531
("delayed-insert", po::value<bool>(&opt_delayed)->default_value(false)->zero_tokens(),
532
N_("Insert rows with INSERT DELAYED;"))
533
("skip-disable-keys,K",
534
N_("'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will not be put in the output."))
535
("ignore-table", po::value<string>(),
536
N_("Do not dump the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table. Each table must be specified with both database and table names, e.g. --ignore-table=database.table"))
537
("insert-ignore", po::value<bool>(&opt_ignore)->default_value(false)->zero_tokens(),
538
N_("Insert rows with INSERT IGNORE."))
539
("lines-terminated-by", po::value<string>(&lines_terminated)->default_value(""),
540
N_("Lines in the i.file are terminated by ..."))
541
("no-autocommit", po::value<bool>(&opt_autocommit)->default_value(false)->zero_tokens(),
542
N_("Wrap tables with autocommit/commit statements."))
543
("no-create-db,n", po::value<bool>(&opt_create_db)->default_value(false)->zero_tokens(),
544
N_("'CREATE DATABASE IF NOT EXISTS db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given."))
545
("no-create-info,t", po::value<bool>(&opt_no_create_info)->default_value(false)->zero_tokens(),
546
N_("Don't write table creation info."))
547
("no-data,d", po::value<bool>(&opt_no_data)->default_value(false)->zero_tokens(),
548
N_("No row information."))
549
("no-set-names,N", N_("Deprecated. Use --skip-set-charset instead."))
550
("set-charset", po::value<bool>(&opt_set_charset)->default_value(false)->zero_tokens(),
551
N_("Enable set-name"))
552
("slow", N_("Buffer query instead of dumping directly to stdout."))
553
("replace", po::value<bool>(&opt_replace_into)->default_value(false)->zero_tokens(),
554
N_("Use REPLACE INTO instead of INSERT INTO."))
555
("result-file,r", po::value<string>(),
556
N_("Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed)."))
557
("destination-type", po::value<string>()->default_value("stdout"),
558
N_("Where to send output to (stdout|database"))
559
("destination-host", po::value<string>(&opt_destination_host)->default_value("localhost"),
560
N_("Hostname for destination db server (requires --destination=database)"))
561
("destination-port", po::value<uint16_t>(&opt_destination_port)->default_value(3306),
562
N_("Port number for destination db server (requires --destination=database)"))
563
("destination-user", po::value<string>(&opt_destination_user),
564
N_("User name for destination db server (resquires --destination=database)"))
565
("destination-password", po::value<string>(&opt_destination_password),
566
N_("Password for destination db server (requires --destination=database)"))
567
("destination-database", po::value<string>(&opt_destination_database),
568
N_("The database in the destination db server (requires --destination=database, not for use with --all-databases)"))
571
po::options_description client_options(N_("Options specific to the client"));
572
client_options.add_options()
573
("host,h", po::value<string>(¤t_host)->default_value("localhost"),
574
N_("Connect to host."))
575
("password,P", po::value<string>(&password)->default_value(PASSWORD_SENTINEL),
576
N_("Password to use when connecting to server. If password is not given it's solicited on the tty."))
577
("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
578
N_("Port number to use for connection."))
579
("user,u", po::value<string>(¤t_user)->default_value(""),
580
N_("User for login if not current user."))
581
("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
582
N_("The protocol of connection (mysql or drizzle)."))
585
po::options_description hidden_options(N_("Hidden Options"));
586
hidden_options.add_options()
587
("database-used", po::value<vector<string> >(), N_("Used to select the database"))
588
("Table-used", po::value<vector<string> >(), N_("Used to select the tables"))
591
po::options_description all_options(N_("Allowed Options + Hidden Options"));
592
all_options.add(commandline_options).add(dump_options).add(client_options).add(hidden_options);
594
po::options_description long_options(N_("Allowed Options"));
595
long_options.add(commandline_options).add(dump_options).add(client_options);
597
std::string system_config_dir_dump(SYSCONFDIR);
598
system_config_dir_dump.append("/drizzle/drizzledump.cnf");
600
std::string system_config_dir_client(SYSCONFDIR);
601
system_config_dir_client.append("/drizzle/client.cnf");
603
std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
605
po::positional_options_description p;
606
p.add("database-used", 1);
607
p.add("Table-used",-1);
609
md_result_file= stdout;
611
po::variables_map vm;
613
// Disable allow_guessing
614
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
616
po::store(po::command_line_parser(argc, argv).style(style).
617
options(all_options).positional(p).
618
extra_parser(parse_password_arg).run(), vm);
620
if (! vm.count("no-defaults"))
622
std::string user_config_dir_dump(user_config_dir);
623
user_config_dir_dump.append("/drizzle/drizzledump.cnf");
625
std::string user_config_dir_client(user_config_dir);
626
user_config_dir_client.append("/drizzle/client.cnf");
628
ifstream user_dump_ifs(user_config_dir_dump.c_str());
629
po::store(parse_config_file(user_dump_ifs, dump_options), vm);
631
ifstream user_client_ifs(user_config_dir_client.c_str());
632
po::store(parse_config_file(user_client_ifs, client_options), vm);
634
ifstream system_dump_ifs(system_config_dir_dump.c_str());
635
po::store(parse_config_file(system_dump_ifs, dump_options), vm);
637
ifstream system_client_ifs(system_config_dir_client.c_str());
638
po::store(parse_config_file(system_client_ifs, client_options), vm);
643
if ((not vm.count("database-used") && not vm.count("Table-used")
644
&& not opt_alldbs && path.empty())
645
|| (vm.count("help")) || vm.count("version"))
647
printf(_("Drizzledump %s build %s, for %s-%s (%s)\n"),
648
drizzle_version(), VERSION, HOST_VENDOR, HOST_OS, HOST_CPU);
649
if (vm.count("version"))
652
puts(_("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"));
653
puts(_("Dumps definitions and data from a Drizzle database server"));
654
printf(_("Usage: %s [OPTIONS] database [tables]\n"), progname.c_str());
655
printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
657
printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), progname.c_str());
658
cout << long_options;
659
if (vm.count("help"))
665
/* Inverted Booleans */
667
opt_drop= (vm.count("skip-drop-table")) ? false : true;
668
opt_comments= (vm.count("skip-comments")) ? false : true;
669
extended_insert= (vm.count("skip-extended-insert")) ? false : true;
670
opt_dump_date= (vm.count("skip-dump-date")) ? false : true;
671
opt_disable_keys= (vm.count("skip-disable-keys")) ? false : true;
672
quick= (vm.count("slow")) ? false : true;
673
opt_quoted= (vm.count("skip-quote-names")) ? false : true;
675
if (vm.count("protocol"))
677
std::transform(opt_protocol.begin(), opt_protocol.end(),
678
opt_protocol.begin(), ::tolower);
680
if (not opt_protocol.compare("mysql"))
681
use_drizzle_protocol=false;
682
else if (not opt_protocol.compare("drizzle"))
683
use_drizzle_protocol=true;
686
cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
691
if (vm.count("port"))
693
/* If the port number is > 65535 it is not a valid port
694
* This also helps with potential data loss casting unsigned long to a
697
if (opt_drizzle_port > 65535)
699
fprintf(stderr, _("Value supplied for port is not valid.\n"));
704
if(vm.count("password"))
706
if (!opt_password.empty())
707
opt_password.erase();
708
if (password == PASSWORD_SENTINEL)
714
opt_password= password;
723
if (vm.count("result-file"))
725
if (!(md_result_file= fopen(vm["result-file"].as<string>().c_str(), "w")))
729
if (vm.count("no-set-names"))
739
if (vm.count("skip-opt"))
741
extended_insert= opt_drop= quick= create_options= 0;
742
opt_disable_keys= opt_set_charset= 0;
747
opt_comments= opt_drop= opt_disable_keys= 0;
753
extended_insert= opt_drop= quick= create_options= 1;
754
opt_disable_keys= opt_set_charset= 1;
757
if (vm.count("tables"))
759
opt_databases= false;
762
if (vm.count("ignore-table"))
764
if (!strchr(vm["ignore-table"].as<string>().c_str(), '.'))
766
fprintf(stderr, _("Illegal use of option --ignore-table=<database>.<table>\n"));
767
exit(EXIT_ARGUMENT_INVALID);
769
string tmpptr(vm["ignore-table"].as<string>());
770
ignore_table.insert(tmpptr);
773
if (vm.count("skip-create"))
775
opt_create_db= opt_no_create_info= create_options= false;
778
exit_code= get_options();
3419
MY_INIT("mysqldump");
3421
compatible_mode_normal_str[0]= 0;
3422
default_charset= (char *)drizzle_universal_client_charset;
3423
bzero((char*) &ignore_table, sizeof(ignore_table));
3425
exit_code= get_options(&argc, &argv);
781
3428
free_resources();
782
3429
exit(exit_code);
785
db_connection = new DrizzleDumpConnection(current_host, opt_drizzle_port,
786
current_user, opt_password, use_drizzle_protocol);
788
if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
789
db_connection->queryNoResult("SET NAMES 'utf8'");
791
if (vm.count("destination-type"))
793
string tmp_destination(vm["destination-type"].as<string>());
794
if (tmp_destination.compare("database") == 0)
795
opt_destination= DESTINATION_DB;
796
else if (tmp_destination.compare("stdout") == 0)
797
opt_destination= DESTINATION_STDOUT;
799
exit(EXIT_ARGUMENT_INVALID);
803
if (path.empty() && vm.count("database-used"))
805
string database_used= *vm["database-used"].as< vector<string> >().begin();
806
write_header((char *)database_used.c_str());
809
if ((opt_lock_all_tables) && do_flush_tables_read_lock())
811
if (opt_single_transaction && start_transaction())
813
if (opt_lock_all_tables)
814
db_connection->queryNoResult("FLUSH LOGS");
815
if (opt_single_transaction && do_unlock_tables()) /* unlock but no commit! */
3434
if(!(stderror_file= freopen(log_error_file, "a+", stderr)))
3437
exit(EX_DRIZZLEERR);
3441
if (connect_to_db(current_host, current_user, opt_password))
3444
exit(EX_DRIZZLEERR);
3447
write_header(md_result_file, *argv);
3449
if (opt_slave_data && do_stop_slave_sql(drizzle))
3452
if ((opt_lock_all_tables || opt_master_data) &&
3453
do_flush_tables_read_lock(drizzle))
3455
if (opt_single_transaction && start_transaction(drizzle))
3457
if (opt_delete_master_logs)
3459
if (drizzle_refresh(drizzle, REFRESH_LOG) ||
3460
get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
3464
if (opt_lock_all_tables || opt_master_data)
3466
if (flush_logs && drizzle_refresh(drizzle, REFRESH_LOG))
3468
flush_logs= 0; /* not anymore; that would not be sensible */
3470
/* Add 'STOP SLAVE to beginning of dump */
3471
if (opt_slave_apply && add_stop_slave())
3473
if (opt_master_data && do_show_master_status(drizzle))
3475
if (opt_slave_data && do_show_slave_status(drizzle))
3477
if (opt_single_transaction && do_unlock_tables(drizzle)) /* unlock but no commit! */
820
3482
dump_all_databases();
823
if (vm.count("database-used") && vm.count("Table-used") && ! opt_databases)
3484
else if (argc > 1 && !opt_databases)
825
string database_used= *vm["database-used"].as< vector<string> >().begin();
826
3486
/* Only one database and selected table(s) */
827
dump_selected_tables(database_used, vm["Table-used"].as< vector<string> >());
830
if (vm.count("Table-used") && opt_databases)
834
vector<string> database_used= vm["database-used"].as< vector<string> >();
835
vector<string> table_used= vm["Table-used"].as< vector<string> >();
837
for (vector<string>::iterator it= table_used.begin();
838
it != table_used.end();
841
database_used.insert(database_used.end(), *it);
843
dump_databases(database_used);
848
if (vm.count("database-used") && ! vm.count("Table-used"))
850
dump_databases(vm["database-used"].as< vector<string> >());
853
if (opt_destination == DESTINATION_STDOUT)
3487
dump_selected_tables(*argv, (argv + 1), (argc - 1));
3491
dump_databases(argv);
3494
/* if --dump-slave , start the slave sql thread */
3495
if (opt_slave_data && do_start_slave_sql(drizzle))
3498
/* add 'START SLAVE' to end of dump */
3499
if (opt_slave_apply && add_slave_statements())
858
3502
/* ensure dumped data flushed */
859
3503
if (md_result_file && fflush(md_result_file))