67
78
static void add_load_option(string &str, const char *option,
68
79
const char *option_value);
69
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
70
char **err_pos, uint *err_len);
80
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
81
char **err_pos, uint32_t *err_len);
72
83
static void field_escape(string &in, const char *from);
73
static bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
74
quick= 1, extended_insert= 1,
75
lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
76
opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
77
opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0,
78
opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0,
79
opt_set_charset=0, opt_dump_date=1,
80
opt_autocommit=0,opt_disable_keys=1,opt_xml=0,
81
opt_delete_master_logs=0, tty_password=0,
82
opt_single_transaction=0, opt_comments= 0, opt_compact= 0,
83
opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0,
84
opt_complete_insert= 0, opt_drop_database= 0,
86
opt_routines=0, opt_tz_utc=1,
88
opt_include_master_host_port= 0,
90
opt_alltspcs=0, opt_notspcs= 0;
91
static bool debug_info_flag= 0, debug_check_flag= 0;
92
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
93
static DRIZZLE drizzle_connection,*drizzle=0;
84
static bool verbose= false;
85
static bool opt_no_create_info= false;
86
static bool opt_no_data= false;
87
static bool quick= true;
88
static bool extended_insert= true;
89
static bool ignore_errors= false;
90
static bool flush_logs= false;
91
static bool opt_drop= true;
92
static bool opt_keywords= false;
93
static bool opt_compress= false;
94
static bool opt_delayed= false;
95
static bool create_options= true;
96
static bool opt_quoted= false;
97
static bool opt_databases= false;
98
static bool opt_alldbs= false;
99
static bool opt_create_db= false;
100
static bool opt_lock_all_tables= false;
101
static bool opt_set_charset= false;
102
static bool opt_dump_date= true;
103
static bool opt_autocommit= false;
104
static bool opt_disable_keys= true;
105
static bool opt_xml= false;
106
static bool tty_password= false;
107
static bool opt_single_transaction= false;
108
static bool opt_comments= false;
109
static bool opt_compact= false;
110
static bool opt_hex_blob= false;
111
static bool opt_order_by_primary=false;
112
static bool opt_ignore= false;
113
static bool opt_complete_insert= false;
114
static bool opt_drop_database= false;
115
static bool opt_replace_into= false;
116
static bool opt_routines= false;
117
static bool opt_alltspcs= false;
118
static bool debug_info_flag= false;
119
static bool debug_check_flag= false;
120
static uint32_t show_progress_size= 0;
121
static uint64_t total_rows= 0;
122
static drizzle_st drizzle;
123
static drizzle_con_st dcon;
94
124
static string insert_pat;
95
static char *opt_password=0,*current_user=0,
96
*current_host=0,*path=0,*fields_terminated=0,
97
*lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
98
*where=0, *order_by=0,
99
*opt_compatible_mode_str= 0,
101
*log_error_file= NULL;
102
static char **defaults_argv= 0;
125
static char *opt_password= NULL;
126
static char *current_user= NULL;
127
static char *current_host= NULL;
128
static char *path= NULL;
129
static char *fields_terminated= NULL;
130
static char *lines_terminated= NULL;
131
static char *enclosed= NULL;
132
static char *opt_enclosed= NULL;
133
static char *escaped= NULL;
134
static char *where= NULL;
135
static char *order_by= NULL;
136
static char *opt_compatible_mode_str= NULL;
137
static char *err_ptr= NULL;
138
static char **defaults_argv= NULL;
103
139
static char compatible_mode_normal_str[255];
104
/* Server supports character_set_results session variable? */
105
static bool server_supports_switching_charsets= true;
106
140
static uint32_t opt_compatible_mode= 0;
107
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
108
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
109
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
110
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
111
static uint opt_drizzle_port= 0, opt_master_data;
112
static uint opt_slave_data;
113
static uint my_end_arg;
114
static int first_error=0;
141
static uint32_t opt_drizzle_port= 0;
142
static uint32_t my_end_arg;
143
static int first_error= 0;
115
144
static string extended_row;
116
145
FILE *md_result_file= 0;
117
FILE *stderror_file=0;
146
FILE *stderror_file= 0;
120
Constant for detection of default value of default_charset.
121
If default_charset is equal to drizzle_universal_client_charset, then
122
it is the default value which assigned at the very beginning of main().
124
static const char *drizzle_universal_client_charset=
125
DRIZZLE_UNIVERSAL_CLIENT_CHARSET;
126
static char *default_charset;
127
148
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
128
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
129
/* have we seen any VIEWs during table scanning? */
131
150
const char *compatible_mode_names[]=
133
152
"MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
162
181
"Dump all the tablespaces.",
163
182
(char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
165
{"no-tablespaces", 'y',
166
"Do not dump any tablespace information.",
167
(char**) &opt_notspcs, (char**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
169
184
{"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
170
185
(char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
172
187
{"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
173
188
(char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
175
{"add-locks", OPT_LOCKS, "Add locks around insert statements.",
176
(char**) &opt_lock, (char**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
178
190
{"allow-keywords", OPT_KEYWORDS,
179
191
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
180
192
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
181
{"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
182
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
183
(char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
185
{"character-sets-dir", OPT_CHARSETS_DIR,
186
"Directory where character sets are.", (char**) &charsets_dir,
187
(char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
188
193
{"comments", 'i', "Write additional information.",
189
194
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
190
195
1, 0, 0, 0, 0, 0},
216
221
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
217
222
(char**) &debug_info_flag, (char**) &debug_info_flag,
218
223
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
219
{"default-character-set", OPT_DEFAULT_CHARSET,
220
"Set the default character set.", (char**) &default_charset,
221
(char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
222
224
{"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
223
225
(char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
225
{"delete-master-logs", OPT_DELETE_MASTER_LOGS,
226
"Delete logs on master after backup. This automatically enables --master-data.",
227
(char**) &opt_delete_master_logs, (char**) &opt_delete_master_logs, 0,
228
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
229
227
{"disable-keys", 'K',
230
"'/*!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,
228
"'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.", (char**) &opt_disable_keys,
231
229
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
232
{"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
233
"This causes the binary log position and filename of the master to be "
234
"appended to the dumped data output. Setting the value to 1, will print"
235
"it as a CHANGE MASTER command in the dumped data output; if equal"
236
" to 2, that command will be prefixed with a comment symbol. "
237
"This option will turn --lock-all-tables on, unless "
238
"--single-transaction is specified too (in which case a "
239
"global read lock is only taken a short time at the beginning of the dump "
240
"- don't forget to read about --single-transaction below). In all cases "
241
"any action on logs will happen at the exact moment of the dump."
242
"Option automatically turns --lock-tables off.",
243
(char**) &opt_slave_data, (char**) &opt_slave_data, 0,
244
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
245
{"events", 'E', "Dump events.",
246
(char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
247
NO_ARG, 0, 0, 0, 0, 0, 0},
248
230
{"extended-insert", 'e',
249
231
"Allows utilization of the new, much faster INSERT syntax.",
250
232
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
260
242
(char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
261
243
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
262
244
(char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
263
{"first-slave", 'x', "Deprecated, renamed to --lock-all-tables.",
264
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
266
245
{"flush-logs", 'F', "Flush logs file in server before starting dump. "
267
246
"Note that if you dump many databases at once (using the option "
268
247
"--databases= or --all-databases), the logs will be flushed for "
269
248
"each database dumped. The exception is when using --lock-all-tables "
271
249
"in this case the logs will be flushed only once, corresponding "
272
250
"to the moment all tables are locked. So if you want your dump and "
273
251
"the log flush to happen at the same exact moment you should use "
274
"--lock-all-tables or --master-data with --flush-logs",
252
"--lock-all-tables or --flush-logs",
275
253
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
277
{"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
278
"after dumping the DRIZZLE database. This option should be used any "
279
"time the dump contains the DRIZZLE database and any other database "
280
"that depends on the data in the DRIZZLE database for proper restore. ",
281
(char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
283
255
{"force", 'f', "Continue even if we get an sql-error.",
284
256
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
285
257
0, 0, 0, 0, 0, 0},
312
278
"dump. Automatically turns --single-transaction and --lock-tables off.",
313
279
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
314
280
0, 0, 0, 0, 0, 0},
315
{"lock-tables", 'l', "Lock all tables for read.", (char**) &lock_tables,
316
(char**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
317
{"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.",
318
(char**) &log_error_file, (char**) &log_error_file, 0, GET_STR,
319
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
320
{"master-data", OPT_MASTER_DATA,
321
"This causes the binary log position and filename to be appended to the "
322
"output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
323
" to 2, that command will be prefixed with a comment symbol. "
324
"This option will turn --lock-all-tables on, unless "
325
"--single-transaction is specified too (in which case a "
326
"global read lock is only taken a short time at the beginning of the dump "
327
"- don't forget to read about --single-transaction below). In all cases "
328
"any action on logs will happen at the exact moment of the dump."
329
"Option automatically turns --lock-tables off.",
330
(char**) &opt_master_data, (char**) &opt_master_data, 0,
331
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
332
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
333
(char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
334
GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
335
(int64_t) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
336
{"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
337
(char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
338
GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
339
MALLOC_OVERHEAD-1024, 1024, 0},
340
281
{"no-autocommit", OPT_AUTOCOMMIT,
341
282
"Wrap tables with autocommit/commit statements.",
342
283
(char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
343
284
0, 0, 0, 0, 0, 0},
344
285
{"no-create-db", 'n',
345
"'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.}.",
286
"'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.}.",
346
287
(char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
348
289
{"no-create-info", 't', "Don't write table creation info.",
359
300
{"order-by-primary", OPT_ORDER_BY_PRIMARY,
360
301
"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.",
361
302
(char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
363
304
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
364
305
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
365
{"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
366
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
306
{"port", 'p', "Port number to use for connection.",
307
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
368
308
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
369
309
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
370
310
{"quote-names",'Q', "Quote table and column names with backticks (`).",
379
319
{"routines", 'R', "Dump stored routines (functions and procedures).",
380
320
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
381
321
NO_ARG, 0, 0, 0, 0, 0, 0},
382
{"set-charset", OPT_SET_CHARSET,
383
"Add 'SET NAMES default_character_set' to the output.",
384
(char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
386
{"set-variable", 'O',
387
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
388
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
390
Note that the combination --single-transaction --master-data
391
will give bullet-proof binlog position only if server >=4.1.3. That's the
392
old "FLUSH TABLES WITH READ LOCK does not block commit" fixed bug.
394
322
{"single-transaction", OPT_TRANSACTION,
395
323
"Creates a consistent snapshot by dumping all tables in a single "
396
324
"transaction. Works ONLY for tables stored in storage engines which "
397
325
"support multiversioning (currently only InnoDB does); the dump is NOT "
398
326
"guaranteed to be consistent for other storage engines. "
399
327
"While a --single-transaction dump is in process, to ensure a valid "
400
"dump file (correct table contents and binary log position), no other "
328
"dump file (correct table contents), no other "
401
329
"connection should use the following statements: ALTER TABLE, DROP "
402
330
"TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
403
331
"isolated from them. Option automatically turns off --lock-tables.",
414
342
(char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
415
343
{"tables", OPT_TABLES, "Overrides option --databases (-B).",
416
344
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
417
{"tz-utc", OPT_TZ_UTC,
418
"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.",
419
(char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
420
#ifndef DONT_ALLOW_USER_CHANGE
345
{"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of rows before each output progress report (requires --verbose)."),
346
(char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
347
10000, 0, 0, 0, 0, 0},
421
348
{"user", 'u', "User for login if not current user.",
422
349
(char**) ¤t_user, (char**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
423
350
0, 0, 0, 0, 0, 0},
425
351
{"verbose", 'v', "Print info about the various stages.",
426
352
(char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
427
353
{"version",'V', "Output version information and exit.", 0, 0, 0,
486
412
static void check_io(FILE *file)
488
414
if (ferror(file))
489
die(EX_EOF, "Got errno %d on write", errno);
415
die(EX_EOF, _("Got errno %d on write"), errno);
492
418
static void print_version(void)
494
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
495
drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
420
printf(_("%s Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), my_progname,
421
VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
496
422
} /* print_version */
499
425
static void short_usage_sub(void)
501
printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
502
printf("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n",
427
printf(_("Usage: %s [OPTIONS] database [tables]\n"), my_progname);
428
printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
504
printf("OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname);
430
printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), my_progname);
508
434
static void usage(void)
511
puts("By Igor Romanenko, Monty, Jani & Sinisa");
512
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");
513
puts("Dumping definition and data DRIZZLE database or table");
438
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"));
439
puts(_("Dumps definitions and data from a Drizzle database server"));
514
440
short_usage_sub();
515
print_defaults("my",load_default_groups);
441
print_defaults("drizzle",load_default_groups);
516
442
my_print_help(my_long_options);
517
443
my_print_variables(my_long_options);
544
470
if (opt_comments)
546
472
fprintf(sql_file,
547
"-- DRIZZLE dump %s Distrib %s, for %s (%s)\n--\n",
548
DUMP_VERSION, drizzle_get_client_info(),
549
SYSTEM_TYPE, MACHINE_TYPE);
473
"-- drizzledump %s libdrizzle %s, for %s-%s (%s)\n--\n",
474
VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
550
475
fprintf(sql_file, "-- Host: %s Database: %s\n",
551
476
current_host ? current_host : "localhost", db_name ? db_name :
553
478
fputs("-- ------------------------------------------------------\n",
555
480
fprintf(sql_file, "-- Server version\t%s\n",
556
drizzle_get_server_info(&drizzle_connection));
481
drizzle_con_server_version(&dcon));
558
483
if (opt_set_charset)
559
484
fprintf(sql_file,
560
"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
561
"\n/*!40101 SET NAMES %s */;\n",default_charset);
565
fprintf(sql_file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
566
fprintf(sql_file, "/*!40103 SET TIME_ZONE='+00:00' */;\n");
485
"\nSET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;\n");
571
489
fprintf(md_result_file,"\
572
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n\
573
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n\
490
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;\n\
491
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\n\
576
494
check_io(sql_file);
628
static unsigned char* get_table_key(const char *entry, size_t *length,
629
bool not_used __attribute__((unused)))
539
static unsigned char* get_table_key(const char *entry, size_t *length, bool)
631
541
*length= strlen(entry);
632
542
return (unsigned char*) entry;
637
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
546
bool get_one_option(int optid, const struct my_option *, char *argument)
549
uint64_t temp_drizzle_port= 0;
553
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
554
/* if there is an alpha character this is not a valid port */
555
if (strlen(endchar) != 0)
557
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
560
/* If the port number is > 65535 it is not a valid port
561
* This also helps with potential data loss casting unsigned long to a
563
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
565
fprintf(stderr, _("Value supplied for port is not valid.\n"));
570
opt_drizzle_port= (uint32_t) temp_drizzle_port;
644
char *start=argument;
646
opt_password=my_strdup(argument,MYF(MY_FAE));
647
while (*argument) *argument++= 'x'; /* Destroy argument */
576
char *start= argument;
579
opt_password= strdup(argument);
580
if (opt_password == NULL)
582
fprintf(stderr, _("Memory allocation error while copying password. "
588
/* Overwriting password with 'x' */
649
start[1]=0; /* Cut length of argument */
593
/* Cut length of argument */
656
if (!(md_result_file= my_fopen(argument, O_WRONLY | FILE_BINARY,
604
if (!(md_result_file= fopen(argument, "w")))
671
618
a crash even if the input destination buffer is large enough
672
619
to hold the output.
674
die(EX_USAGE, "Input filename too long: %s", argument);
621
die(EX_USAGE, _("Input filename too long: %s"), argument);
678
625
case 'V': print_version(); exit(0);
681
extended_insert= opt_drop= opt_lock=
628
extended_insert= opt_drop=
682
629
opt_disable_keys= opt_autocommit= opt_create_db= 0;
688
case (int) OPT_MASTER_DATA:
689
if (!argument) /* work like in old versions */
690
opt_master_data= DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL;
692
case (int) OPT_DRIZZLEDUMP_SLAVE_DATA:
693
if (!argument) /* work like in old versions */
694
opt_slave_data= DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL;
696
635
case (int) OPT_OPTIMIZE:
697
extended_insert= opt_drop= opt_lock= quick= create_options=
698
opt_disable_keys= lock_tables= opt_set_charset= 1;
636
extended_insert= opt_drop= quick= create_options=
637
opt_disable_keys= opt_set_charset= 1;
700
639
case (int) OPT_SKIP_OPTIMIZATION:
701
extended_insert= opt_drop= opt_lock= quick= create_options=
702
opt_disable_keys= lock_tables= opt_set_charset= 0;
640
extended_insert= opt_drop= quick= create_options=
641
opt_disable_keys= opt_set_charset= 0;
704
643
case (int) OPT_COMPACT:
707
opt_comments= opt_drop= opt_disable_keys= opt_lock= 0;
646
opt_comments= opt_drop= opt_disable_keys= 0;
708
647
opt_set_charset= 0;
710
649
case (int) OPT_TABLES:
767
701
static int get_options(int *argc, char ***argv)
770
const DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
772
opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
773
opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
775
705
md_result_file= stdout;
776
load_defaults("my",load_default_groups,argc,argv);
706
load_defaults("drizzle",load_default_groups,argc,argv);
777
707
defaults_argv= *argv;
779
709
if (hash_init(&ignore_table, charset_info, 16, 0, 0,
780
710
(hash_get_key) get_table_key,
781
711
(hash_free_key) free_table_ent, 0))
783
/* Don't copy internal log tables */
784
if (my_hash_insert(&ignore_table,
785
(unsigned char*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
786
my_hash_insert(&ignore_table,
787
(unsigned char*) my_strdup("mysql.schema", MYF(MY_WME))) ||
788
my_hash_insert(&ignore_table,
789
(unsigned char*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
790
my_hash_insert(&ignore_table,
791
(unsigned char*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
792
my_hash_insert(&ignore_table,
793
(unsigned char*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
794
my_hash_insert(&ignore_table,
795
(unsigned char*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
798
714
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
799
715
return(ho_error);
801
*drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
802
*drizzle_params->p_net_buffer_length= opt_net_buffer_length;
803
717
if (debug_info_flag)
804
718
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
805
719
if (debug_check_flag)
806
720
my_end_arg= MY_CHECK_ERROR;
809
opt_lock=0; /* Can't have lock with delayed */
810
722
if (!path && (enclosed || opt_enclosed || escaped || lines_terminated ||
811
723
fields_terminated))
814
"%s: You must use option --tab with --fields-...\n", my_progname);
726
_("%s: You must use option --tab with --fields-...\n"), my_progname);
815
727
return(EX_USAGE);
818
/* We don't delete master logs if slave data option */
821
opt_lock_all_tables= !opt_single_transaction;
823
opt_delete_master_logs= 0;
826
/* Ensure consistency of the set of binlog & locking options */
827
if (opt_delete_master_logs && !opt_master_data)
828
opt_master_data= DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL;
829
730
if (opt_single_transaction && opt_lock_all_tables)
831
fprintf(stderr, "%s: You can't use --single-transaction and "
832
"--lock-all-tables at the same time.\n", my_progname);
732
fprintf(stderr, _("%s: You can't use --single-transaction and "
733
"--lock-all-tables at the same time.\n"), my_progname);
833
734
return(EX_USAGE);
837
opt_lock_all_tables= !opt_single_transaction;
840
if (opt_single_transaction || opt_lock_all_tables)
842
736
if (enclosed && opt_enclosed)
844
fprintf(stderr, "%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n", my_progname);
738
fprintf(stderr, _("%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n"), my_progname);
845
739
return(EX_USAGE);
847
741
if ((opt_databases || opt_alldbs) && path)
850
"%s: --databases or --all-databases can't be used with --tab.\n",
744
_("%s: --databases or --all-databases can't be used with --tab.\n"),
852
746
return(EX_USAGE);
854
if (strcmp(default_charset, charset_info->csname) &&
855
!(charset_info= get_charset_by_csname(default_charset,
856
MY_CS_PRIMARY, MYF(MY_WME))))
858
748
if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs))
863
753
if (tty_password)
864
opt_password=get_tty_password(NULL);
754
opt_password=client_get_tty_password(NULL);
866
756
} /* get_options */
961
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
860
static int drizzleclient_query_with_error_report(drizzle_con_st *con,
861
drizzle_result_st *result,
862
const char *query_str,
964
if (drizzle_query(drizzle_con, query) ||
965
(res && !((*res)= drizzle_store_result(drizzle_con))))
967
maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
968
query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
865
drizzle_return_t ret;
867
if (drizzle_query_str(con, result, query_str, &ret) == NULL ||
868
ret != DRIZZLE_RETURN_OK)
870
if (ret == DRIZZLE_RETURN_ERROR_CODE)
872
maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
873
query_str, drizzle_result_error(result),
874
drizzle_result_error_code(result));
875
drizzle_result_free(result);
879
maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
880
query_str, drizzle_con_error(con), ret);
886
ret= drizzle_column_buffer(result);
888
ret= drizzle_result_buffer(result);
889
if (ret != DRIZZLE_RETURN_OK)
891
drizzle_result_free(result);
892
maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
893
query_str, drizzle_con_error(con), ret);
976
Switch charset for results to some specified charset. If the server does not
977
support character_set_results variable, nothing can be done here. As for
978
whether something should be done here, future new callers of this function
979
should be aware that the server lacking the facility of switching charsets is
982
@note If the server lacks support, then nothing is changed and no error
983
condition is returned.
985
@returns whether there was an error or not
987
static int switch_character_set_results(DRIZZLE *drizzle, const char *cs_name)
989
char query_buffer[QUERY_LENGTH];
992
/* Server lacks facility. This is not an error, by arbitrary decision . */
993
if (!server_supports_switching_charsets)
996
query_length= snprintf(query_buffer,
997
sizeof (query_buffer),
998
"SET SESSION character_set_results = '%s'",
999
(const char *) cs_name);
1001
return drizzle_real_query(drizzle, query_buffer, query_length);
1005
901
Open a new .sql file to dump the table or view into
1056
952
static int connect_to_db(char *host, char *user,char *passwd)
1058
char buff[20+FN_REFLEN];
1061
verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1062
drizzle_create(&drizzle_connection);
1064
drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NULL);
1065
if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
1066
NULL,opt_drizzle_port, NULL,
954
drizzle_return_t ret;
956
verbose_msg(_("-- Connecting to %s...\n"), host ? host : "localhost");
957
drizzle_create(&drizzle);
958
drizzle_con_create(&drizzle, &dcon);
959
drizzle_con_set_tcp(&dcon, host, opt_drizzle_port);
960
drizzle_con_set_auth(&dcon, user, passwd);
961
ret= drizzle_con_connect(&dcon);
962
if (ret != DRIZZLE_RETURN_OK)
1069
DB_error(&drizzle_connection, "when trying to connect");
964
DB_error(NULL, ret, "when trying to connect");
1072
if (drizzle_get_server_version(&drizzle_connection) < 40100)
1074
/* Don't dump SET NAMES with a pre-4.1 server (bug#7997). */
1077
/* Don't switch charsets for 4.1 and earlier. (bug#34192). */
1078
server_supports_switching_charsets= false;
1081
set time_zone to UTC to allow dumping date types between servers with
1082
different time zone settings
1086
snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1087
if (drizzle_query_with_error_report(drizzle, 0, buff))
1091
969
} /* connect_to_db */
1424
1304
table_type - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW"
1425
1305
ignore_flag - what we must particularly ignore - see IGNORE_ defines above
1306
num_fields - number of fields in the table
1428
number of fields in table, 0 if error
1309
true if success, false if error
1431
static uint get_table_structure(char *table, char *db, char *table_type,
1312
static bool get_table_structure(char *table, char *db, char *table_type,
1313
char *ignore_flag, uint64_t *num_fields)
1434
1315
bool init=0, delayed, write_data, complete_insert;
1435
uint64_t num_fields;
1436
1316
char *result_table, *opt_quoted_table;
1437
1317
const char *insert_option;
1438
char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3];
1439
char table_buff2[NAME_LEN*2+3], query_buff[QUERY_LENGTH];
1318
char name_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE+3];
1319
char table_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE*2+3];
1320
char table_buff2[DRIZZLE_MAX_TABLE_SIZE*2+3];
1321
char query_buff[QUERY_LENGTH];
1440
1322
FILE *sql_file= md_result_file;
1442
DRIZZLE_RES *result;
1323
drizzle_result_st result;
1445
1326
*ignore_flag= check_if_ignore_table(table, table_type);
1477
1354
order_by= primary_key_fields(result_table);
1480
if (!opt_xml && !drizzle_query_with_error_report(drizzle, 0, query_buff))
1482
1359
/* using SHOW CREATE statement */
1483
1360
if (!opt_no_create_info)
1485
1362
/* Make an sql-file, if path was given iow. option -T was given */
1486
1363
char buff[20+FN_REFLEN];
1487
const DRIZZLE_FIELD *field;
1364
const drizzle_column_st *column;
1489
1366
snprintf(buff, sizeof(buff), "show create table %s", result_table);
1491
if (switch_character_set_results(drizzle, "binary") ||
1492
drizzle_query_with_error_report(drizzle, &result, buff) ||
1493
switch_character_set_results(drizzle, default_charset))
1368
if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1498
1373
if (!(sql_file= open_sql_file_for_table(table)))
1375
drizzle_result_free(&result);
1501
1379
write_header(sql_file, db);
1503
1381
if (!opt_xml && opt_comments)
1505
if (strcmp (table_type, "VIEW") == 0) /* view */
1506
fprintf(sql_file, "\n--\n-- Temporary table structure for view %s\n--\n\n",
1509
1383
fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n",
1511
1385
check_io(sql_file);
1516
Even if the "table" is a view, we do a DROP TABLE here. The
1517
view-specific code below fills in the DROP VIEW.
1390
Even if the "table" is a view, we do a DROP TABLE here.
1519
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
1392
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table);
1521
1393
check_io(sql_file);
1524
field= drizzle_fetch_field_direct(result, 0);
1525
if (strcmp(field->name, "View") == 0)
1527
char *scv_buff= NULL;
1529
verbose_msg("-- It's a view, create dummy table for view\n");
1531
/* save "show create" statement for later */
1532
if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1533
scv_buff= my_strdup(scv_buff, MYF(0));
1535
drizzle_free_result(result);
1538
Create a table with the same name as the view and with columns of
1539
the same name in order to satisfy views that depend on this view.
1540
The table will be removed when the actual view is created.
1542
The properties of each column, aside from the data type, are not
1543
preserved in this temporary table, because they are not necessary.
1545
This will not be necessary once we can determine dependencies
1546
between views and can simply dump them in the appropriate order.
1548
snprintf(query_buff, sizeof(query_buff),
1549
"SHOW FIELDS FROM %s", result_table);
1550
if (switch_character_set_results(drizzle, "binary") ||
1551
drizzle_query_with_error_report(drizzle, &result, query_buff) ||
1552
switch_character_set_results(drizzle, default_charset))
1555
View references invalid or privileged table/col/fun (err 1356),
1556
so we cannot create a stand-in table. Be defensive and dump
1557
a comment with the view's 'show create' statement. (Bug #17371)
1560
if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1561
fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1570
if (drizzle_num_rows(result))
1575
We have already dropped any table of the same name above, so
1576
here we just drop the view.
1579
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
1585
"/*!50001 CREATE TABLE %s (\n",
1589
Get first row, following loop will prepend comma - keeps from
1590
having to know if the row being printed is last to determine if
1591
there should be a _trailing_ comma.
1594
row= drizzle_fetch_row(result);
1596
fprintf(sql_file, " %s %s", quote_name(row[0], name_buff, 0),
1599
while((row= drizzle_fetch_row(result)))
1601
/* col name, col type */
1602
fprintf(sql_file, ",\n %s %s",
1603
quote_name(row[0], name_buff, 0), row[1]);
1605
fprintf(sql_file, "\n) */;\n");
1609
drizzle_free_result(result);
1612
my_fclose(sql_file, MYF(MY_WME));
1618
row= drizzle_fetch_row(result);
1396
column= drizzle_column_index(&result, 0);
1398
row= drizzle_row_next(&result);
1620
1400
fprintf(sql_file, "%s;\n", row[1]);
1622
1402
check_io(sql_file);
1623
drizzle_free_result(result);
1403
drizzle_result_free(&result);
1625
1406
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1627
if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1409
if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
1630
my_fclose(sql_file, MYF(MY_WME));
1768
1553
check_io(sql_file);
1771
num_fields= drizzle_num_rows(result);
1772
drizzle_free_result(result);
1556
*num_fields= drizzle_result_row_count(&result);
1557
drizzle_result_free(&result);
1773
1559
if (!opt_no_create_info)
1775
1561
/* Make an sql-file, if path was given iow. option -T was given */
1776
1562
char buff[20+FN_REFLEN];
1777
uint keynr,primary_key;
1563
uint32_t keynr,primary_key;
1778
1564
snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1779
if (drizzle_query_with_error_report(drizzle, &result, buff))
1565
if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1781
if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
1784
fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1787
fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1788
my_progname, result_table, drizzle_error(drizzle));
1567
fprintf(stderr, _("%s: Can't get keys for table %s\n"),
1568
my_progname, result_table);
1790
my_fclose(sql_file, MYF(MY_WME));
1794
1574
/* Find first which key is primary key */
1796
1576
primary_key=INT_MAX;
1797
while ((row= drizzle_fetch_row(result)))
1577
while ((row= drizzle_row_next(&result)))
1799
1579
if (atoi(row[3]) == 1)
1848
1628
fputs("\n)",sql_file);
1849
1629
check_io(sql_file);
1852
1631
/* Get DRIZZLE specific create options */
1853
1632
if (create_options)
1855
char show_name_buff[NAME_LEN*2+2+24];
1634
char show_name_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE*2+2+24];
1857
1636
/* Check memory for quote_for_like() */
1858
1637
snprintf(buff, sizeof(buff), "show table status like %s",
1859
1638
quote_for_like(table, show_name_buff));
1861
if (drizzle_query_with_error_report(drizzle, &result, buff))
1640
if (!drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1863
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
1864
{ /* If old DRIZZLE version */
1865
verbose_msg("-- Warning: Couldn't get status information for " \
1866
"table %s (%s)\n", result_table,drizzle_error(drizzle));
1642
if (!(row= drizzle_row_next(&result)))
1645
_("Error: Couldn't read status information for table %s\n"),
1869
else if (!(row= drizzle_fetch_row(result)))
1872
"Error: Couldn't read status information for table %s (%s)\n",
1873
result_table,drizzle_error(drizzle));
1878
print_xml_row(sql_file, "options", result, &row);
1881
fputs("/*!",sql_file);
1882
print_value(sql_file,result,row,"engine=","Engine",0);
1883
print_value(sql_file,result,row,"","Create_options",0);
1884
print_value(sql_file,result,row,"comment=","Comment",1);
1885
fputs(" */",sql_file);
1651
print_xml_row(sql_file, "options", &result, &row);
1654
fputs("/*!",sql_file);
1655
print_value(sql_file,&result,row,"engine=","Engine",0);
1656
print_value(sql_file,&result,row,"","Create_options",0);
1657
print_value(sql_file,&result,row,"comment=","Comment",1);
1659
fputs(" */",sql_file);
1663
drizzle_result_free(&result);
1889
drizzle_free_result(result); /* Is always safe to free */
1893
1667
fputs(";\n", sql_file);
1993
1766
static void dump_table(char *table, char *db)
1995
1768
char ignore_flag;
1996
char buf[200], table_buff[NAME_LEN+3];
1769
char table_buff[DRIZZLE_MAX_TABLE_SIZE+3];
1997
1770
string query_string;
1998
char table_type[NAME_LEN];
1999
char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
1771
char table_type[DRIZZLE_MAX_TABLE_SIZE];
1772
char *result_table, table_buff2[DRIZZLE_MAX_TABLE_SIZE*2+3], *opt_quoted_table;
2001
uint32_t rownr, row_break, total_length, init_length;
2004
DRIZZLE_FIELD *field;
1774
uint32_t rownr, row_break, total_length, init_length;
1775
uint64_t num_fields= 0;
1776
drizzle_return_t ret;
1777
drizzle_result_st result;
1778
drizzle_column_st *column;
2009
1783
Make sure you get the create table info before the following check for
2010
1784
--no-data flag below. Otherwise, the create table info won't be printed.
2012
num_fields= get_table_structure(table, db, table_type, &ignore_flag);
2015
The "table" could be a view. If so, we don't do anything here.
2017
if (strcmp(table_type, "VIEW") == 0)
1786
if (!get_table_structure(table, db, table_type, &ignore_flag, &num_fields))
1788
maybe_die(EX_TABLE_STATUS, _("Error retrieving table structure for table: \"%s\""), table);
2020
1792
/* Check --no-data flag */
2021
1793
if (opt_no_data)
2023
verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
1795
verbose_msg(_("-- Skipping dump data for table '%s', --no-data was used\n"),
2032
1804
if (ignore_flag & IGNORE_DATA)
2034
verbose_msg("-- Warning: Skipping data for table '%s' because " \
2035
"it's of type %s\n", table, table_type);
1806
verbose_msg(_("-- Warning: Skipping data for table '%s' because " \
1807
"it's of type %s\n"), table, table_type);
2038
1810
/* Check that there are any fields in the table */
2039
1811
if (num_fields == 0)
2041
verbose_msg("-- Skipping dump data for table '%s', it has no fields\n",
1813
verbose_msg(_("-- Skipping dump data for table '%s', it has no fields\n"),
2047
Check --skip-events flag: it is not enough to skip creation of events
2048
discarding SHOW CREATE EVENT statements generation. The myslq.event
2049
table data should be skipped too.
2051
if (!opt_events && !my_strcasecmp(&my_charset_utf8_general_ci, db, "mysql") &&
2052
!my_strcasecmp(&my_charset_utf8_general_ci, table, "event"))
2054
verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2058
1818
result_table= quote_name(table,table_buff, 1);
2059
1819
opt_quoted_table= quote_name(table, table_buff2, 0);
2061
verbose_msg("-- Sending SELECT query...\n");
1821
verbose_msg(_("-- Sending SELECT query...\n"));
2063
1823
query_string.clear();
2064
1824
query_string.reserve(1024);
2156
1917
fputs("\n", md_result_file);
2157
1918
check_io(md_result_file);
2159
if (drizzle_query_with_error_report(drizzle, 0, query_string.c_str()))
2161
DB_error(drizzle, "when retrieving data from server");
2165
res=drizzle_use_result(drizzle);
2167
res=drizzle_store_result(drizzle);
2170
DB_error(drizzle, "when retrieving data from server");
1920
if (drizzleclient_query_with_error_report(&dcon, &result,
1921
query_string.c_str(), quick))
2174
verbose_msg("-- Retrieving rows...\n");
2175
if (drizzle_num_fields(res) != num_fields)
1926
verbose_msg(_("-- Retrieving rows...\n"));
1927
if (drizzle_result_column_count(&result) != num_fields)
2177
fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n",
1929
fprintf(stderr,_("%s: Error in field count for table: %s ! Aborting.\n"),
2178
1930
my_progname, result_table);
2179
1931
error= EX_CONSCHECK;
1932
drizzle_result_free(&result);
2185
fprintf(md_result_file,"LOCK TABLES %s WRITE;\n", opt_quoted_table);
2186
check_io(md_result_file);
2188
1936
/* Moved disable keys to after lock per bug 15977 */
2189
1937
if (opt_disable_keys)
2191
fprintf(md_result_file, "/*!40000 ALTER TABLE %s DISABLE KEYS */;\n",
1939
fprintf(md_result_file, "ALTER TABLE %s DISABLE KEYS;\n",
2192
1940
opt_quoted_table);
2193
1941
check_io(md_result_file);
2196
total_length= opt_net_buffer_length; /* Force row break */
1944
total_length= DRIZZLE_MAX_LINE_LENGTH; /* Force row break */
2199
init_length=(uint) insert_pat.length()+4;
1947
init_length=(uint32_t) insert_pat.length()+4;
2201
1949
print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
2455
2217
static char *getTableName(int reset)
2457
static DRIZZLE_RES *res= NULL;
2219
static drizzle_result_st result;
2220
static bool have_result= false;
2462
if (!(res= drizzle_list_tables(drizzle,NULL)))
2225
if (drizzleclient_query_with_error_report(&dcon, &result, "SHOW TABLES", false))
2465
if ((row= drizzle_fetch_row(res)))
2466
return((char*) row[0]);
2230
if ((row= drizzle_row_next(&result)))
2469
drizzle_data_seek(res,0); /* We want to read again */
2234
drizzle_row_seek(&result, 0);
2472
drizzle_free_result(res);
2237
drizzle_result_free(&result);
2476
2241
} /* getTableName */
2479
2244
static int dump_all_databases()
2482
DRIZZLE_RES *tableres;
2247
drizzle_result_st tableres;
2485
if (drizzle_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
2250
if (drizzleclient_query_with_error_report(&dcon, &tableres, "SHOW DATABASES", false))
2487
while ((row= drizzle_fetch_row(tableres)))
2252
while ((row= drizzle_row_next(&tableres)))
2489
2254
if (dump_all_tables_in_db(row[0]))
2257
drizzle_result_free(&tableres);
2494
2260
/* dump_all_databases */
2524
2290
int init_dumping_tables(char *qdatabase)
2528
2292
if (!opt_create_db)
2530
2294
char qbuf[256];
2532
DRIZZLE_RES *dbinfo;
2296
drizzle_result_st result;
2297
drizzle_return_t ret;
2534
2299
snprintf(qbuf, sizeof(qbuf),
2535
2300
"SHOW CREATE DATABASE IF NOT EXISTS %s",
2538
if (drizzle_query(drizzle, qbuf) || !(dbinfo = drizzle_store_result(drizzle)))
2303
if (drizzle_query_str(&dcon, &result, qbuf, &ret) == NULL ||
2304
ret != DRIZZLE_RETURN_OK)
2306
if (ret == DRIZZLE_RETURN_ERROR_CODE)
2307
drizzle_result_free(&result);
2540
2309
/* Old server version, dump generic CREATE DATABASE */
2541
2310
if (opt_drop_database)
2542
2311
fprintf(md_result_file,
2543
"\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2312
"\nDROP DATABASE IF EXISTS %s;\n",
2545
2314
fprintf(md_result_file,
2546
"\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n",
2315
"\nCREATE DATABASE IF NOT EXISTS %s;\n",
2551
if (opt_drop_database)
2552
fprintf(md_result_file,
2553
"\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2555
row = drizzle_fetch_row(dbinfo);
2320
if (drizzle_result_buffer(&result) == DRIZZLE_RETURN_OK)
2558
fprintf(md_result_file,"\n%s;\n",row[1]);
2322
if (opt_drop_database)
2323
fprintf(md_result_file,
2324
"\nDROP DATABASE IF EXISTS %s;\n",
2326
row = drizzle_row_next(&result);
2327
if (row != NULL && row[1])
2329
fprintf(md_result_file,"\n%s;\n",row[1]);
2560
drizzle_free_result(dbinfo);
2332
drizzle_result_free(&result);
2614
2391
static int dump_all_tables_in_db(char *database)
2618
char table_buff[NAME_LEN*2+3];
2619
char hash_key[2*NAME_LEN+2]; /* "db.tablename" */
2394
char hash_key[DRIZZLE_MAX_DB_SIZE+DRIZZLE_MAX_TABLE_SIZE+2]; /* "db.tablename" */
2620
2395
char *afterdot;
2621
int using_mysql_db= my_strcasecmp(&my_charset_utf8_general_ci, database, "mysql");
2624
afterdot= my_stpcpy(hash_key, database);
2396
drizzle_result_st result;
2397
drizzle_return_t ret;
2399
afterdot= strcpy(hash_key, database) + strlen(database);
2625
2400
*afterdot++= '.';
2627
2402
if (init_dumping(database, init_dumping_tables))
2630
2405
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NULL);
2634
query= "LOCK TABLES ";
2635
for (numrows= 0 ; (table= getTableName(1)) ; )
2408
if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
2409
ret != DRIZZLE_RETURN_OK)
2637
char *end= my_stpcpy(afterdot, table);
2638
if (include_table((unsigned char*) hash_key,end - hash_key))
2641
query.append( quote_name(table, table_buff, 1));
2642
query.append( " READ /*!32311 LOCAL */,");
2411
DB_error(&result, ret, _("when doing refresh"));
2412
/* We shall continue here, if --force was given */
2645
if (numrows && drizzle_real_query(drizzle, query.c_str(), query.length()-1))
2646
DB_error(drizzle, "when using LOCK TABLES");
2647
/* We shall continue here, if --force was given */
2652
if (drizzle_refresh(drizzle, REFRESH_LOG))
2653
DB_error(drizzle, "when doing refresh");
2654
/* We shall continue here, if --force was given */
2415
drizzle_result_free(&result);
2656
2417
while ((table= getTableName(0)))
2658
char *end= my_stpcpy(afterdot, table);
2419
char *end= strcpy(afterdot, table) + strlen(table);
2659
2420
if (include_table((unsigned char*) hash_key, end - hash_key))
2661
2422
dump_table(table,database);
2704
2460
snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2705
2461
quote_for_like(old_table_name, show_name_buff));
2707
if (drizzle_query_with_error_report(drizzle, 0, query))
2463
if (drizzleclient_query_with_error_report(&dcon, &result, query, false))
2710
if ((table_res= drizzle_store_result(drizzle)))
2466
num_rows= drizzle_result_row_count(&result);
2712
uint64_t num_rows= drizzle_num_rows(table_res);
2718
TODO: Return all matching rows
2720
row= drizzle_fetch_row(table_res);
2721
lengths= drizzle_fetch_lengths(table_res);
2722
name= strmake_root(root, row[0], lengths[0]);
2724
drizzle_free_result(table_res);
2472
TODO: Return all matching rows
2474
row= drizzle_row_next(&result);
2475
lengths= drizzle_row_field_sizes(&result);
2476
name= strmake_root(root, row[0], lengths[0]);
2478
drizzle_result_free(&result);
2730
2484
static int dump_selected_tables(char *db, char **table_names, int tables)
2732
char table_buff[NAME_LEN*2+3];
2733
string lock_tables_query;
2735
2487
char **dump_tables, **pos, **end;
2488
drizzle_result_st result;
2489
drizzle_return_t ret;
2738
2492
if (init_dumping(db, init_dumping_tables))
2763
2510
free_root(&root, MYF(0));
2765
maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names);
2512
maybe_die(EX_ILLEGAL_TABLE, _("Couldn't find table: \"%s\""), *table_names);
2766
2513
/* We shall countinue here, if --force was given */
2773
if (drizzle_real_query(drizzle, lock_tables_query.c_str(),
2774
lock_tables_query.length()-1))
2778
free_root(&root, MYF(0));
2780
DB_error(drizzle, "when doing LOCK TABLES");
2781
/* We shall countinue here, if --force was given */
2784
2518
if (flush_logs)
2786
if (drizzle_refresh(drizzle, REFRESH_LOG))
2520
if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
2521
ret != DRIZZLE_RETURN_OK)
2788
2523
if (!ignore_errors)
2789
2524
free_root(&root, MYF(0));
2790
DB_error(drizzle, "when doing refresh");
2525
DB_error(&result, ret, _("when doing refresh"));
2526
/* We shall countinue here, if --force was given */
2792
/* We shall countinue here, if --force was given */
2529
drizzle_result_free(&result);
2795
2532
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
2806
2543
fputs("</database>\n", md_result_file);
2807
2544
check_io(md_result_file);
2810
drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2812
2547
} /* dump_selected_tables */
2815
static int do_show_master_status(DRIZZLE *drizzle_con)
2818
DRIZZLE_RES *master;
2819
const char *comment_prefix=
2820
(opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2821
if (drizzle_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2827
row= drizzle_fetch_row(master);
2828
if (row && row[0] && row[1])
2830
/* SHOW MASTER STATUS reports file and position */
2832
fprintf(md_result_file,
2833
"\n--\n-- Position to start replication or point-in-time "
2834
"recovery from\n--\n\n");
2835
fprintf(md_result_file,
2836
"%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n",
2837
comment_prefix, row[0], row[1]);
2838
check_io(md_result_file);
2840
else if (!ignore_errors)
2842
/* SHOW MASTER STATUS reports nothing and --force is not enabled */
2843
my_printf_error(0, "Error: Binlogging on server not active",
2845
drizzle_free_result(master);
2846
maybe_exit(EX_DRIZZLEERR);
2849
drizzle_free_result(master);
2854
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
2857
/* We need to check if the slave sql is running in the first place */
2858
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2862
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2865
/* if SLAVE SQL is not running, we don't stop it */
2866
if (!strcmp(row[11],"No"))
2868
drizzle_free_result(slave);
2869
/* Silently assume that they don't have the slave running */
2874
drizzle_free_result(slave);
2876
/* now, stop slave if running */
2877
if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2883
static int add_stop_slave(void)
2886
fprintf(md_result_file,
2887
"\n--\n-- stop slave statement to make a recovery dump)\n--\n\n");
2888
fprintf(md_result_file, "STOP SLAVE;\n");
2892
static int add_slave_statements(void)
2895
fprintf(md_result_file,
2896
"\n--\n-- start slave statement to make a recovery dump)\n--\n\n");
2897
fprintf(md_result_file, "START SLAVE;\n");
2901
static int do_show_slave_status(DRIZZLE *drizzle_con)
2904
const char *comment_prefix=
2905
(opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2906
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2910
/* SHOW SLAVE STATUS reports nothing and --force is not enabled */
2911
my_printf_error(0, "Error: Slave not set up", MYF(0));
2917
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2918
if (row && row[9] && row[21])
2920
/* SHOW MASTER STATUS reports file and position */
2922
fprintf(md_result_file,
2923
"\n--\n-- Position to start replication or point-in-time "
2924
"recovery from (the master of this slave)\n--\n\n");
2926
fprintf(md_result_file, "%sCHANGE MASTER TO ", comment_prefix);
2928
if (opt_include_master_host_port)
2931
fprintf(md_result_file, "MASTER_HOST='%s', ", row[1]);
2933
fprintf(md_result_file, "MASTER_PORT='%s', ", row[3]);
2935
fprintf(md_result_file,
2936
"MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", row[9], row[21]);
2938
check_io(md_result_file);
2940
drizzle_free_result(slave);
2945
static int do_start_slave_sql(DRIZZLE *drizzle_con)
2948
/* We need to check if the slave sql is stopped in the first place */
2949
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2953
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2956
/* if SLAVE SQL is not running, we don't start it */
2957
if (!strcmp(row[11],"Yes"))
2959
drizzle_free_result(slave);
2960
/* Silently assume that they don't have the slave running */
2965
drizzle_free_result(slave);
2967
/* now, start slave if stopped */
2968
if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
2970
my_printf_error(0, "Error: Unable to start slave", MYF(0));
2978
static int do_flush_tables_read_lock(DRIZZLE *drizzle_con)
2549
static int do_flush_tables_read_lock(drizzle_con_st *drizzle_con)
2981
2552
We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
2986
2557
update starts between the two FLUSHes, we have that bad stall.
2989
( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
2990
drizzle_query_with_error_report(drizzle_con, 0,
2991
"FLUSH TABLES WITH READ LOCK") );
2995
static int do_unlock_tables(DRIZZLE *drizzle_con)
2997
return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
3000
static int get_bin_log_name(DRIZZLE *drizzle_con,
3001
char* buff_log_name, uint buff_len)
3006
if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
3007
!(res= drizzle_store_result(drizzle)))
3010
if (!(row= drizzle_fetch_row(res)))
3012
drizzle_free_result(res);
3016
Only one row is returned, and the first column is the name of the
3019
strmake(buff_log_name, row[0], buff_len - 1);
3021
drizzle_free_result(res);
3025
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
3028
string str= "PURGE BINARY LOGS TO '";
3029
str.append(log_name);
3031
err = drizzle_query_with_error_report(drizzle_con, 0, str.c_str());
3036
static int start_transaction(DRIZZLE *drizzle_con)
3039
We use BEGIN for old servers. --single-transaction --master-data will fail
3040
on old servers, but that's ok as it was already silently broken (it didn't
3041
do a consistent read, so better tell people frankly, with the error).
3043
We want the first consistent read to be used for all tables to dump so we
3044
need the REPEATABLE READ level (not anything lower, for example READ
3045
COMMITTED would give one new consistent read per dumped table).
3047
if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
3049
fprintf(stderr, "-- %s: the combination of --single-transaction and "
3050
"--master-data requires a DRIZZLE server version of at least 4.1 "
3051
"(current server's version is %s). %s\n",
3052
ignore_errors ? "Warning" : "Error",
3053
drizzle_con->server_version ? drizzle_con->server_version : "unknown",
3054
ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3056
exit(EX_DRIZZLEERR);
3059
return (drizzle_query_with_error_report(drizzle_con, 0,
2560
( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES", false) ||
2561
drizzleclient_query_with_error_report(drizzle_con, 0,
2562
"FLUSH TABLES WITH READ LOCK", false) );
2565
static int do_unlock_tables(drizzle_con_st *drizzle_con)
2567
return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES", false);
2570
static int start_transaction(drizzle_con_st *drizzle_con)
2572
return (drizzleclient_query_with_error_report(drizzle_con, 0,
3060
2573
"SET SESSION TRANSACTION ISOLATION "
3061
"LEVEL REPEATABLE READ") ||
3062
drizzle_query_with_error_report(drizzle_con, 0,
2574
"LEVEL REPEATABLE READ", false) ||
2575
drizzleclient_query_with_error_report(drizzle_con, 0,
3063
2576
"START TRANSACTION "
3064
"/*!40100 WITH CONSISTENT SNAPSHOT */"));
2577
"WITH CONSISTENT SNAPSHOT", false));
3068
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
3069
char **err_pos, uint *err_len)
2581
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
2582
char **err_pos, uint32_t *err_len)
3071
2584
const char *end= x + length;
3072
2585
uint32_t found= 0;
3074
2587
char buff[255];
3076
2589
*err_pos= 0; /* No error yet */
3164
2702
char result= IGNORE_NONE;
3165
2703
char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3166
DRIZZLE_RES *res= NULL;
2704
const char *number_of_rows= NULL;
2705
drizzle_result_st res;
3170
2708
/* Check memory for quote_for_like() */
3171
2709
assert(2*sizeof(table_name) < sizeof(show_name_buff));
3172
2710
snprintf(buff, sizeof(buff), "show table status like %s",
3173
2711
quote_for_like(table_name, show_name_buff));
3174
if (drizzle_query_with_error_report(drizzle, &res, buff))
2712
if (drizzleclient_query_with_error_report(&dcon, &res, buff, false))
3176
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
3177
{ /* If old DRIZZLE version */
3178
verbose_msg("-- Warning: Couldn't get status information for "
3179
"table %s (%s)\n", table_name, drizzle_error(drizzle));
3180
return(result); /* assume table is ok */
3183
if (!(row= drizzle_fetch_row(res)))
2716
if (!(row= drizzle_row_next(&res)))
3185
2718
fprintf(stderr,
3186
"Error: Couldn't read status information for table %s (%s)\n",
3187
table_name, drizzle_error(drizzle));
3188
drizzle_free_result(res);
2719
_("Error: Couldn't read status information for table %s\n"),
2721
drizzle_result_free(&res);
3189
2722
return(result); /* assume table is ok */
3192
strmake(table_type, "VIEW", NAME_LEN-1);
3196
If the table type matches any of these, we do support delayed inserts.
3197
Note: we do not want to skip dumping this table if if is not one of
3198
these types, but we do want to use delayed inserts in the dump if
3199
the table type is _NOT_ one of these types
2726
if ((number_of_rows= fetch_named_row(&res, row, "Rows")) != NULL)
2728
total_rows= strtoul(number_of_rows, NULL, 10);
2732
If the table type matches any of these, we do support delayed inserts.
2733
Note: we do not want to skip dumping this table if if is not one of
2734
these types, but we do want to use delayed inserts in the dump if
2735
the table type is _NOT_ one of these types
3201
strmake(table_type, row[1], NAME_LEN-1);
2738
strncpy(table_type, row[1], DRIZZLE_MAX_TABLE_SIZE-1);
3202
2739
if (opt_delayed)
3204
2741
if (strcmp(table_type,"MyISAM") &&
3205
strcmp(table_type,"ISAM") &&
3206
2742
strcmp(table_type,"ARCHIVE") &&
3207
2743
strcmp(table_type,"HEAP") &&
3208
2744
strcmp(table_type,"MEMORY"))
3209
2745
result= IGNORE_INSERT_DELAYED;
3213
If these two types, we do want to skip dumping the table
3216
(!my_strcasecmp(&my_charset_utf8_general_ci, table_type, "MRG_MyISAM") ||
3217
!strcmp(table_type,"MRG_ISAM")))
3218
result= IGNORE_DATA;
3220
drizzle_free_result(res);
2748
drizzle_result_free(&res);
3221
2749
return(result);
3243
2771
static char *primary_key_fields(const char *table_name)
3245
DRIZZLE_RES *res= NULL;
2773
drizzle_result_st res;
2774
drizzle_return_t ret;
3247
2776
/* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3248
char show_keys_buff[15 + NAME_LEN * 2 + 3];
3249
uint result_length= 0;
2777
char show_keys_buff[15 + DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
2778
uint32_t result_length= 0;
3250
2779
char *result= 0;
3251
char buff[NAME_LEN * 2 + 3];
2780
char buff[DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
3252
2781
char *quoted_field;
3254
2783
snprintf(show_keys_buff, sizeof(show_keys_buff),
3255
2784
"SHOW KEYS FROM %s", table_name);
3256
if (drizzle_query(drizzle, show_keys_buff) ||
3257
!(res= drizzle_store_result(drizzle)))
3259
fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3260
" records are NOT sorted (%s)\n",
3261
table_name, drizzle_error(drizzle));
3262
/* Don't exit, because it's better to print out unsorted records */
2785
if (drizzle_query_str(&dcon, &res, show_keys_buff, &ret) == NULL ||
2786
ret != DRIZZLE_RETURN_OK)
2788
if (ret == DRIZZLE_RETURN_ERROR_CODE)
2790
fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
2791
" records are NOT sorted (%s)\n"),
2792
table_name, drizzle_result_error(&res));
2793
drizzle_result_free(&res);
2797
fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
2798
" records are NOT sorted (%s)\n"),
2799
table_name, drizzle_con_error(&dcon));
2805
if (drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
2807
fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
2808
" records are NOT sorted (%s)\n"),
2809
table_name, drizzle_con_error(&dcon));
3286
2833
/* result (terminating \0 is already in result_length) */
3287
result= (char *)my_malloc(result_length + 10, MYF(MY_WME));
2834
result= (char *)malloc(result_length + 10);
3290
fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
2837
fprintf(stderr, _("Error: Not enough memory to store ORDER BY clause\n"));
2838
drizzle_result_free(&res);
3293
drizzle_data_seek(res, 0);
3294
row= drizzle_fetch_row(res);
2841
drizzle_row_seek(&res, 0);
2842
row= drizzle_row_next(&res);
3295
2843
quoted_field= quote_name(row[4], buff, 0);
3296
end= my_stpcpy(result, quoted_field);
3297
while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
2844
end= strcpy(result, quoted_field) + strlen(quoted_field);
2845
while ((row= drizzle_row_next(&res)) && atoi(row[3]) > 1)
3299
2847
quoted_field= quote_name(row[4], buff, 0);
3300
end= strxmov(end, ",", quoted_field, NULL);
2848
end+= sprintf(end,",%s",quoted_field);
3306
drizzle_free_result(res);
2852
drizzle_result_free(&res);
3312
2857
int main(int argc, char **argv)
3314
char bin_log_name[FN_REFLEN];
3316
MY_INIT("mysqldump");
2860
MY_INIT("drizzledump");
2861
drizzle_result_st result;
3318
2863
compatible_mode_normal_str[0]= 0;
3319
default_charset= (char *)drizzle_universal_client_charset;
3320
2864
memset(&ignore_table, 0, sizeof(ignore_table));
3322
2866
exit_code= get_options(&argc, &argv);
3344
2879
write_header(md_result_file, *argv);
3346
if (opt_slave_data && do_stop_slave_sql(drizzle))
3349
if ((opt_lock_all_tables || opt_master_data) &&
3350
do_flush_tables_read_lock(drizzle))
3352
if (opt_single_transaction && start_transaction(drizzle))
3354
if (opt_delete_master_logs)
3356
if (drizzle_refresh(drizzle, REFRESH_LOG) ||
3357
get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
3361
if (opt_lock_all_tables || opt_master_data)
3363
if (flush_logs && drizzle_refresh(drizzle, REFRESH_LOG))
2881
if ((opt_lock_all_tables) && do_flush_tables_read_lock(&dcon))
2883
if (opt_single_transaction && start_transaction(&dcon))
2885
if (opt_lock_all_tables)
2887
if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))
2889
drizzle_result_free(&result);
3365
2890
flush_logs= 0; /* not anymore; that would not be sensible */
3367
/* Add 'STOP SLAVE to beginning of dump */
3368
if (opt_slave_apply && add_stop_slave())
3370
if (opt_master_data && do_show_master_status(drizzle))
3372
if (opt_slave_data && do_show_slave_status(drizzle))
3374
if (opt_single_transaction && do_unlock_tables(drizzle)) /* unlock but no commit! */
2892
if (opt_single_transaction && do_unlock_tables(&dcon)) /* unlock but no commit! */
3377
2895
if (opt_alldbs)