66
78
static void add_load_option(string &str, const char *option,
67
79
const char *option_value);
68
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
69
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);
71
83
static void field_escape(string &in, const char *from);
72
static bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
73
quick= 1, extended_insert= 1,
74
lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
75
opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
76
opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0,
77
opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0,
78
opt_set_charset=0, opt_dump_date=1,
79
opt_autocommit=0,opt_disable_keys=1,opt_xml=0,
80
opt_delete_master_logs=0, tty_password=0,
81
opt_single_transaction=0, opt_comments= 0, opt_compact= 0,
82
opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0,
83
opt_complete_insert= 0, opt_drop_database= 0,
85
opt_routines=0, opt_tz_utc=1,
87
opt_include_master_host_port= 0,
89
opt_alltspcs=0, opt_notspcs= 0;
90
static bool debug_info_flag= 0, debug_check_flag= 0;
91
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
92
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;
93
124
static string insert_pat;
94
static char *opt_password=0,*current_user=0,
95
*current_host=0,*path=0,*fields_terminated=0,
96
*lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
97
*where=0, *order_by=0,
98
*opt_compatible_mode_str= 0,
100
*log_error_file= NULL;
101
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;
102
139
static char compatible_mode_normal_str[255];
103
/* Server supports character_set_results session variable? */
104
static bool server_supports_switching_charsets= true;
105
140
static uint32_t opt_compatible_mode= 0;
106
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
107
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
108
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
109
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
110
static uint opt_drizzle_port= 0, opt_master_data;
111
static uint opt_slave_data;
112
static uint my_end_arg;
113
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;
114
144
static string extended_row;
115
145
FILE *md_result_file= 0;
116
FILE *stderror_file=0;
118
static uint opt_protocol= DRIZZLE_PROTOCOL_TCP;
121
Constant for detection of default value of default_charset.
122
If default_charset is equal to drizzle_universal_client_charset, then
123
it is the default value which assigned at the very beginning of main().
125
static const char *drizzle_universal_client_charset=
126
DRIZZLE_UNIVERSAL_CLIENT_CHARSET;
127
static char *default_charset;
128
static const CHARSET_INFO *charset_info= &my_charset_latin1;
129
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
130
/* have we seen any VIEWs during table scanning? */
146
FILE *stderror_file= 0;
148
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
132
150
const char *compatible_mode_names[]=
134
152
"MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
135
153
"MAXDB", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS",
139
157
#define MASK_ANSI_QUOTES \
163
181
"Dump all the tablespaces.",
164
182
(char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
166
{"no-tablespaces", 'y',
167
"Do not dump any tablespace information.",
168
(char**) &opt_notspcs, (char**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
170
184
{"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
171
185
(char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
173
187
{"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
174
188
(char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
176
{"add-locks", OPT_LOCKS, "Add locks around insert statements.",
177
(char**) &opt_lock, (char**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
179
190
{"allow-keywords", OPT_KEYWORDS,
180
191
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
181
192
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
182
{"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
183
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
184
(char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
186
{"character-sets-dir", OPT_CHARSETS_DIR,
187
"Directory where character sets are.", (char**) &charsets_dir,
188
(char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
189
193
{"comments", 'i', "Write additional information.",
190
194
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
191
195
1, 0, 0, 0, 0, 0},
217
221
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
218
222
(char**) &debug_info_flag, (char**) &debug_info_flag,
219
223
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
220
{"default-character-set", OPT_DEFAULT_CHARSET,
221
"Set the default character set.", (char**) &default_charset,
222
(char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
223
224
{"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
224
225
(char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
226
{"delete-master-logs", OPT_DELETE_MASTER_LOGS,
227
"Delete logs on master after backup. This automatically enables --master-data.",
228
(char**) &opt_delete_master_logs, (char**) &opt_delete_master_logs, 0,
229
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
230
227
{"disable-keys", 'K',
231
"'/*!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,
232
229
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
233
{"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
234
"This causes the binary log position and filename of the master to be "
235
"appended to the dumped data output. Setting the value to 1, will print"
236
"it as a CHANGE MASTER command in the dumped data output; if equal"
237
" to 2, that command will be prefixed with a comment symbol. "
238
"This option will turn --lock-all-tables on, unless "
239
"--single-transaction is specified too (in which case a "
240
"global read lock is only taken a short time at the beginning of the dump "
241
"- don't forget to read about --single-transaction below). In all cases "
242
"any action on logs will happen at the exact moment of the dump."
243
"Option automatically turns --lock-tables off.",
244
(char**) &opt_slave_data, (char**) &opt_slave_data, 0,
245
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
246
{"events", 'E', "Dump events.",
247
(char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
248
NO_ARG, 0, 0, 0, 0, 0, 0},
249
230
{"extended-insert", 'e',
250
231
"Allows utilization of the new, much faster INSERT syntax.",
251
232
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
261
242
(char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
262
243
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
263
244
(char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
264
{"first-slave", 'x', "Deprecated, renamed to --lock-all-tables.",
265
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
267
245
{"flush-logs", 'F', "Flush logs file in server before starting dump. "
268
246
"Note that if you dump many databases at once (using the option "
269
247
"--databases= or --all-databases), the logs will be flushed for "
270
248
"each database dumped. The exception is when using --lock-all-tables "
272
249
"in this case the logs will be flushed only once, corresponding "
273
250
"to the moment all tables are locked. So if you want your dump and "
274
251
"the log flush to happen at the same exact moment you should use "
275
"--lock-all-tables or --master-data with --flush-logs",
252
"--lock-all-tables or --flush-logs",
276
253
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
278
{"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
279
"after dumping the DRIZZLE database. This option should be used any "
280
"time the dump contains the DRIZZLE database and any other database "
281
"that depends on the data in the DRIZZLE database for proper restore. ",
282
(char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
284
255
{"force", 'f', "Continue even if we get an sql-error.",
285
256
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
286
257
0, 0, 0, 0, 0, 0},
313
278
"dump. Automatically turns --single-transaction and --lock-tables off.",
314
279
(char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
315
280
0, 0, 0, 0, 0, 0},
316
{"lock-tables", 'l', "Lock all tables for read.", (char**) &lock_tables,
317
(char**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
318
{"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.",
319
(char**) &log_error_file, (char**) &log_error_file, 0, GET_STR,
320
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
321
{"master-data", OPT_MASTER_DATA,
322
"This causes the binary log position and filename to be appended to the "
323
"output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
324
" to 2, that command will be prefixed with a comment symbol. "
325
"This option will turn --lock-all-tables on, unless "
326
"--single-transaction is specified too (in which case a "
327
"global read lock is only taken a short time at the beginning of the dump "
328
"- don't forget to read about --single-transaction below). In all cases "
329
"any action on logs will happen at the exact moment of the dump."
330
"Option automatically turns --lock-tables off.",
331
(char**) &opt_master_data, (char**) &opt_master_data, 0,
332
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
333
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
334
(char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
335
GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
336
(int64_t) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
337
{"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
338
(char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
339
GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
340
MALLOC_OVERHEAD-1024, 1024, 0},
341
281
{"no-autocommit", OPT_AUTOCOMMIT,
342
282
"Wrap tables with autocommit/commit statements.",
343
283
(char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
344
284
0, 0, 0, 0, 0, 0},
345
285
{"no-create-db", 'n',
346
"'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.}.",
347
287
(char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
349
289
{"no-create-info", 't', "Don't write table creation info.",
360
300
{"order-by-primary", OPT_ORDER_BY_PRIMARY,
361
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.",
362
302
(char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
364
304
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
365
305
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
366
{"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
367
(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},
369
308
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
370
309
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
371
310
{"quote-names",'Q', "Quote table and column names with backticks (`).",
380
319
{"routines", 'R', "Dump stored routines (functions and procedures).",
381
320
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
382
321
NO_ARG, 0, 0, 0, 0, 0, 0},
383
{"set-charset", OPT_SET_CHARSET,
384
"Add 'SET NAMES default_character_set' to the output.",
385
(char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
387
{"set-variable", 'O',
388
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
389
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
391
Note that the combination --single-transaction --master-data
392
will give bullet-proof binlog position only if server >=4.1.3. That's the
393
old "FLUSH TABLES WITH READ LOCK does not block commit" fixed bug.
395
322
{"single-transaction", OPT_TRANSACTION,
396
323
"Creates a consistent snapshot by dumping all tables in a single "
397
324
"transaction. Works ONLY for tables stored in storage engines which "
398
325
"support multiversioning (currently only InnoDB does); the dump is NOT "
399
326
"guaranteed to be consistent for other storage engines. "
400
327
"While a --single-transaction dump is in process, to ensure a valid "
401
"dump file (correct table contents and binary log position), no other "
328
"dump file (correct table contents), no other "
402
329
"connection should use the following statements: ALTER TABLE, DROP "
403
330
"TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
404
331
"isolated from them. Option automatically turns off --lock-tables.",
415
342
(char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
416
343
{"tables", OPT_TABLES, "Overrides option --databases (-B).",
417
344
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
418
{"tz-utc", OPT_TZ_UTC,
419
"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.",
420
(char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
421
#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},
422
348
{"user", 'u', "User for login if not current user.",
423
349
(char**) ¤t_user, (char**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
424
350
0, 0, 0, 0, 0, 0},
426
351
{"verbose", 'v', "Print info about the various stages.",
427
352
(char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
428
353
{"version",'V', "Output version information and exit.", 0, 0, 0,
487
412
static void check_io(FILE *file)
489
414
if (ferror(file))
490
die(EX_EOF, "Got errno %d on write", errno);
415
die(EX_EOF, _("Got errno %d on write"), errno);
493
418
static void print_version(void)
495
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
496
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);
497
422
} /* print_version */
500
425
static void short_usage_sub(void)
502
printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
503
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"),
505
printf("OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname);
430
printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), my_progname);
509
434
static void usage(void)
512
puts("By Igor Romanenko, Monty, Jani & Sinisa");
513
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");
514
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"));
515
440
short_usage_sub();
516
print_defaults("my",load_default_groups);
441
print_defaults("drizzle",load_default_groups);
517
442
my_print_help(my_long_options);
518
443
my_print_variables(my_long_options);
545
470
if (opt_comments)
547
472
fprintf(sql_file,
548
"-- DRIZZLE dump %s Distrib %s, for %s (%s)\n--\n",
549
DUMP_VERSION, drizzle_get_client_info(),
550
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);
551
475
fprintf(sql_file, "-- Host: %s Database: %s\n",
552
476
current_host ? current_host : "localhost", db_name ? db_name :
554
478
fputs("-- ------------------------------------------------------\n",
556
480
fprintf(sql_file, "-- Server version\t%s\n",
557
drizzle_get_server_info(&drizzle_connection));
481
drizzle_con_server_version(&dcon));
559
483
if (opt_set_charset)
560
484
fprintf(sql_file,
561
"\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;"
562
"\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;"
563
"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
564
"\n/*!40101 SET NAMES %s */;\n",default_charset);
568
fprintf(sql_file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
569
fprintf(sql_file, "/*!40103 SET TIME_ZONE='+00:00' */;\n");
485
"\nSET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;\n");
574
489
fprintf(md_result_file,"\
575
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n\
576
/*!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\
579
494
check_io(sql_file);
627
533
static void free_table_ent(char *key)
629
my_free(key, MYF(0));
633
static uchar* get_table_key(const char *entry, size_t *length,
634
bool not_used __attribute__((unused)))
539
static unsigned char* get_table_key(const char *entry, size_t *length, bool)
636
541
*length= strlen(entry);
637
return (uchar*) entry;
542
return (unsigned char*) entry;
642
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;
649
char *start=argument;
650
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
651
opt_password=my_strdup(argument,MYF(MY_FAE));
652
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' */
654
start[1]=0; /* Cut length of argument */
593
/* Cut length of argument */
661
if (!(md_result_file= my_fopen(argument, O_WRONLY | FILE_BINARY,
604
if (!(md_result_file= fopen(argument, "w")))
676
618
a crash even if the input destination buffer is large enough
677
619
to hold the output.
679
die(EX_USAGE, "Input filename too long: %s", argument);
621
die(EX_USAGE, _("Input filename too long: %s"), argument);
683
625
case 'V': print_version(); exit(0);
686
extended_insert= opt_drop= opt_lock=
628
extended_insert= opt_drop=
687
629
opt_disable_keys= opt_autocommit= opt_create_db= 0;
693
case (int) OPT_MASTER_DATA:
694
if (!argument) /* work like in old versions */
695
opt_master_data= DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL;
697
case (int) OPT_DRIZZLEDUMP_SLAVE_DATA:
698
if (!argument) /* work like in old versions */
699
opt_slave_data= DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL;
701
635
case (int) OPT_OPTIMIZE:
702
extended_insert= opt_drop= opt_lock= quick= create_options=
703
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;
705
639
case (int) OPT_SKIP_OPTIMIZATION:
706
extended_insert= opt_drop= opt_lock= quick= create_options=
707
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;
709
643
case (int) OPT_COMPACT:
712
opt_comments= opt_drop= opt_disable_keys= opt_lock= 0;
646
opt_comments= opt_drop= opt_disable_keys= 0;
713
647
opt_set_charset= 0;
715
649
case (int) OPT_TABLES:
772
701
static int get_options(int *argc, char ***argv)
775
const DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
777
opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
778
opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
780
705
md_result_file= stdout;
781
load_defaults("my",load_default_groups,argc,argv);
706
load_defaults("drizzle",load_default_groups,argc,argv);
782
707
defaults_argv= *argv;
784
709
if (hash_init(&ignore_table, charset_info, 16, 0, 0,
785
710
(hash_get_key) get_table_key,
786
711
(hash_free_key) free_table_ent, 0))
788
/* Don't copy internal log tables */
789
if (my_hash_insert(&ignore_table,
790
(uchar*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
791
my_hash_insert(&ignore_table,
792
(uchar*) my_strdup("mysql.schema", MYF(MY_WME))) ||
793
my_hash_insert(&ignore_table,
794
(uchar*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
795
my_hash_insert(&ignore_table,
796
(uchar*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
797
my_hash_insert(&ignore_table,
798
(uchar*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
799
my_hash_insert(&ignore_table,
800
(uchar*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
803
714
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
804
715
return(ho_error);
806
*drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
807
*drizzle_params->p_net_buffer_length= opt_net_buffer_length;
808
717
if (debug_info_flag)
809
718
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
810
719
if (debug_check_flag)
811
720
my_end_arg= MY_CHECK_ERROR;
814
opt_lock=0; /* Can't have lock with delayed */
815
722
if (!path && (enclosed || opt_enclosed || escaped || lines_terminated ||
816
723
fields_terminated))
819
"%s: You must use option --tab with --fields-...\n", my_progname);
726
_("%s: You must use option --tab with --fields-...\n"), my_progname);
820
727
return(EX_USAGE);
823
/* We don't delete master logs if slave data option */
826
opt_lock_all_tables= !opt_single_transaction;
828
opt_delete_master_logs= 0;
831
/* Ensure consistency of the set of binlog & locking options */
832
if (opt_delete_master_logs && !opt_master_data)
833
opt_master_data= DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL;
834
730
if (opt_single_transaction && opt_lock_all_tables)
836
fprintf(stderr, "%s: You can't use --single-transaction and "
837
"--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);
838
734
return(EX_USAGE);
842
opt_lock_all_tables= !opt_single_transaction;
845
if (opt_single_transaction || opt_lock_all_tables)
847
736
if (enclosed && opt_enclosed)
849
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);
850
739
return(EX_USAGE);
852
741
if ((opt_databases || opt_alldbs) && path)
855
"%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"),
857
746
return(EX_USAGE);
859
if (strcmp(default_charset, charset_info->csname) &&
860
!(charset_info= get_charset_by_csname(default_charset,
861
MY_CS_PRIMARY, MYF(MY_WME))))
863
748
if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs))
868
753
if (tty_password)
869
opt_password=get_tty_password(NullS);
754
opt_password=client_get_tty_password(NULL);
871
756
} /* get_options */
966
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,
969
if (drizzle_query(drizzle_con, query) ||
970
(res && !((*res)= drizzle_store_result(drizzle_con))))
972
maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
973
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);
981
Switch charset for results to some specified charset. If the server does not
982
support character_set_results variable, nothing can be done here. As for
983
whether something should be done here, future new callers of this function
984
should be aware that the server lacking the facility of switching charsets is
987
@note If the server lacks support, then nothing is changed and no error
988
condition is returned.
990
@returns whether there was an error or not
992
static int switch_character_set_results(DRIZZLE *drizzle, const char *cs_name)
994
char query_buffer[QUERY_LENGTH];
997
/* Server lacks facility. This is not an error, by arbitrary decision . */
998
if (!server_supports_switching_charsets)
1001
query_length= snprintf(query_buffer,
1002
sizeof (query_buffer),
1003
"SET SESSION character_set_results = '%s'",
1004
(const char *) cs_name);
1006
return drizzle_real_query(drizzle, query_buffer, query_length);
1010
901
Open a new .sql file to dump the table or view into
1061
952
static int connect_to_db(char *host, char *user,char *passwd)
1063
char buff[20+FN_REFLEN];
1066
verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1067
drizzle_create(&drizzle_connection);
1069
drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NullS);
1071
drizzle_options(&drizzle_connection,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
1072
drizzle_options(&drizzle_connection, DRIZZLE_SET_CHARSET_NAME, default_charset);
1073
if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
1074
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)
1077
DB_error(&drizzle_connection, "when trying to connect");
964
DB_error(NULL, ret, "when trying to connect");
1080
if (drizzle_get_server_version(&drizzle_connection) < 40100)
1082
/* Don't dump SET NAMES with a pre-4.1 server (bug#7997). */
1085
/* Don't switch charsets for 4.1 and earlier. (bug#34192). */
1086
server_supports_switching_charsets= false;
1089
set time_zone to UTC to allow dumping date types between servers with
1090
different time zone settings
1094
snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1095
if (drizzle_query_with_error_report(drizzle, 0, buff))
1099
969
} /* connect_to_db */
1432
1304
table_type - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW"
1433
1305
ignore_flag - what we must particularly ignore - see IGNORE_ defines above
1306
num_fields - number of fields in the table
1436
number of fields in table, 0 if error
1309
true if success, false if error
1439
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)
1442
1315
bool init=0, delayed, write_data, complete_insert;
1443
uint64_t num_fields;
1444
1316
char *result_table, *opt_quoted_table;
1445
1317
const char *insert_option;
1446
char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3];
1447
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];
1448
1322
FILE *sql_file= md_result_file;
1450
DRIZZLE_RES *result;
1323
drizzle_result_st result;
1453
1326
*ignore_flag= check_if_ignore_table(table, table_type);
1456
1329
if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED))
1459
verbose_msg("-- Warning: Unable to use delayed inserts for table '%s' "
1460
"because it's of type %s\n", table, table_type);
1332
verbose_msg(_("-- Warning: Unable to use delayed inserts for table '%s' "
1333
"because it's of type %s\n"), table, table_type);
1463
1336
complete_insert= 0;
1464
1337
if ((write_data= !(*ignore_flag & IGNORE_DATA)))
1466
1339
complete_insert= opt_complete_insert;
1470
1343
insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " :
1471
1344
delayed ? " DELAYED " : opt_ignore ? " IGNORE " : "");
1473
verbose_msg("-- Retrieving table structure for table %s...\n", table);
1475
len= snprintf(query_buff, sizeof(query_buff),
1476
"SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
1477
(opt_quoted || opt_keywords));
1346
verbose_msg(_("-- Retrieving table structure for table %s...\n"), table);
1479
1348
result_table= quote_name(table, table_buff, 1);
1480
1349
opt_quoted_table= quote_name(table, table_buff2, 0);
1482
1351
if (opt_order_by_primary)
1484
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
1485
1354
order_by= primary_key_fields(result_table);
1488
if (!opt_xml && !drizzle_query_with_error_report(drizzle, 0, query_buff))
1490
1359
/* using SHOW CREATE statement */
1491
1360
if (!opt_no_create_info)
1493
1362
/* Make an sql-file, if path was given iow. option -T was given */
1494
1363
char buff[20+FN_REFLEN];
1495
const DRIZZLE_FIELD *field;
1364
const drizzle_column_st *column;
1497
1366
snprintf(buff, sizeof(buff), "show create table %s", result_table);
1499
if (switch_character_set_results(drizzle, "binary") ||
1500
drizzle_query_with_error_report(drizzle, &result, buff) ||
1501
switch_character_set_results(drizzle, default_charset))
1368
if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1506
1373
if (!(sql_file= open_sql_file_for_table(table)))
1375
drizzle_result_free(&result);
1509
1379
write_header(sql_file, db);
1511
1381
if (!opt_xml && opt_comments)
1513
if (strcmp (table_type, "VIEW") == 0) /* view */
1514
fprintf(sql_file, "\n--\n-- Temporary table structure for view %s\n--\n\n",
1517
1383
fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n",
1519
1385
check_io(sql_file);
1524
Even if the "table" is a view, we do a DROP TABLE here. The
1525
view-specific code below fills in the DROP VIEW.
1390
Even if the "table" is a view, we do a DROP TABLE here.
1527
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
1392
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table);
1529
1393
check_io(sql_file);
1532
field= drizzle_fetch_field_direct(result, 0);
1533
if (strcmp(field->name, "View") == 0)
1535
char *scv_buff= NULL;
1537
verbose_msg("-- It's a view, create dummy table for view\n");
1539
/* save "show create" statement for later */
1540
if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1541
scv_buff= my_strdup(scv_buff, MYF(0));
1543
drizzle_free_result(result);
1546
Create a table with the same name as the view and with columns of
1547
the same name in order to satisfy views that depend on this view.
1548
The table will be removed when the actual view is created.
1550
The properties of each column, aside from the data type, are not
1551
preserved in this temporary table, because they are not necessary.
1553
This will not be necessary once we can determine dependencies
1554
between views and can simply dump them in the appropriate order.
1556
snprintf(query_buff, sizeof(query_buff),
1557
"SHOW FIELDS FROM %s", result_table);
1558
if (switch_character_set_results(drizzle, "binary") ||
1559
drizzle_query_with_error_report(drizzle, &result, query_buff) ||
1560
switch_character_set_results(drizzle, default_charset))
1563
View references invalid or privileged table/col/fun (err 1356),
1564
so we cannot create a stand-in table. Be defensive and dump
1565
a comment with the view's 'show create' statement. (Bug #17371)
1568
if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1569
fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1571
my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1576
my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1578
if (drizzle_num_rows(result))
1583
We have already dropped any table of the same name above, so
1584
here we just drop the view.
1587
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
1593
"SET @saved_cs_client = @@character_set_client;\n"
1594
"SET character_set_client = utf8;\n"
1595
"/*!50001 CREATE TABLE %s (\n",
1599
Get first row, following loop will prepend comma - keeps from
1600
having to know if the row being printed is last to determine if
1601
there should be a _trailing_ comma.
1604
row= drizzle_fetch_row(result);
1606
fprintf(sql_file, " %s %s", quote_name(row[0], name_buff, 0),
1609
while((row= drizzle_fetch_row(result)))
1611
/* col name, col type */
1612
fprintf(sql_file, ",\n %s %s",
1613
quote_name(row[0], name_buff, 0), row[1]);
1617
"SET character_set_client = @saved_cs_client;\n");
1622
drizzle_free_result(result);
1625
my_fclose(sql_file, MYF(MY_WME));
1631
row= drizzle_fetch_row(result);
1634
"SET @saved_cs_client = @@character_set_client;\n"
1635
"SET character_set_client = utf8;\n"
1637
"SET character_set_client = @saved_cs_client;\n",
1396
column= drizzle_column_index(&result, 0);
1398
row= drizzle_row_next(&result);
1400
fprintf(sql_file, "%s;\n", row[1]);
1640
1402
check_io(sql_file);
1641
drizzle_free_result(result);
1403
drizzle_result_free(&result);
1643
1406
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1645
if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1409
if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
1648
my_fclose(sql_file, MYF(MY_WME));
1786
1553
check_io(sql_file);
1789
num_fields= drizzle_num_rows(result);
1790
drizzle_free_result(result);
1556
*num_fields= drizzle_result_row_count(&result);
1557
drizzle_result_free(&result);
1791
1559
if (!opt_no_create_info)
1793
1561
/* Make an sql-file, if path was given iow. option -T was given */
1794
1562
char buff[20+FN_REFLEN];
1795
uint keynr,primary_key;
1563
uint32_t keynr,primary_key;
1796
1564
snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1797
if (drizzle_query_with_error_report(drizzle, &result, buff))
1565
if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1799
if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
1802
fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1805
fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1806
my_progname, result_table, drizzle_error(drizzle));
1567
fprintf(stderr, _("%s: Can't get keys for table %s\n"),
1568
my_progname, result_table);
1808
my_fclose(sql_file, MYF(MY_WME));
1812
1574
/* Find first which key is primary key */
1814
1576
primary_key=INT_MAX;
1815
while ((row= drizzle_fetch_row(result)))
1577
while ((row= drizzle_row_next(&result)))
1817
1579
if (atoi(row[3]) == 1)
1866
1628
fputs("\n)",sql_file);
1867
1629
check_io(sql_file);
1870
1631
/* Get DRIZZLE specific create options */
1871
1632
if (create_options)
1873
char show_name_buff[NAME_LEN*2+2+24];
1634
char show_name_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE*2+2+24];
1875
1636
/* Check memory for quote_for_like() */
1876
1637
snprintf(buff, sizeof(buff), "show table status like %s",
1877
1638
quote_for_like(table, show_name_buff));
1879
if (drizzle_query_with_error_report(drizzle, &result, buff))
1640
if (!drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1881
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
1882
{ /* If old DRIZZLE version */
1883
verbose_msg("-- Warning: Couldn't get status information for " \
1884
"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"),
1887
else if (!(row= drizzle_fetch_row(result)))
1890
"Error: Couldn't read status information for table %s (%s)\n",
1891
result_table,drizzle_error(drizzle));
1896
print_xml_row(sql_file, "options", result, &row);
1899
fputs("/*!",sql_file);
1900
print_value(sql_file,result,row,"engine=","Engine",0);
1901
print_value(sql_file,result,row,"","Create_options",0);
1902
print_value(sql_file,result,row,"comment=","Comment",1);
1903
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);
1907
drizzle_free_result(result); /* Is always safe to free */
1911
1667
fputs(";\n", sql_file);
2011
1766
static void dump_table(char *table, char *db)
2013
1768
char ignore_flag;
2014
char buf[200], table_buff[NAME_LEN+3];
1769
char table_buff[DRIZZLE_MAX_TABLE_SIZE+3];
2015
1770
string query_string;
2016
char table_type[NAME_LEN];
2017
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;
2019
uint32_t rownr, row_break, total_length, init_length;
2022
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;
2027
1783
Make sure you get the create table info before the following check for
2028
1784
--no-data flag below. Otherwise, the create table info won't be printed.
2030
num_fields= get_table_structure(table, db, table_type, &ignore_flag);
2033
The "table" could be a view. If so, we don't do anything here.
2035
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);
2038
1792
/* Check --no-data flag */
2039
1793
if (opt_no_data)
2041
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"),
2050
1804
if (ignore_flag & IGNORE_DATA)
2052
verbose_msg("-- Warning: Skipping data for table '%s' because " \
2053
"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);
2056
1810
/* Check that there are any fields in the table */
2057
1811
if (num_fields == 0)
2059
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"),
2065
Check --skip-events flag: it is not enough to skip creation of events
2066
discarding SHOW CREATE EVENT statements generation. The myslq.event
2067
table data should be skipped too.
2069
if (!opt_events && !my_strcasecmp(&my_charset_latin1, db, "mysql") &&
2070
!my_strcasecmp(&my_charset_latin1, table, "event"))
2072
verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2076
1818
result_table= quote_name(table,table_buff, 1);
2077
1819
opt_quoted_table= quote_name(table, table_buff2, 0);
2079
verbose_msg("-- Sending SELECT query...\n");
1821
verbose_msg(_("-- Sending SELECT query...\n"));
2081
1823
query_string.clear();
2082
1824
query_string.reserve(1024);
2174
1917
fputs("\n", md_result_file);
2175
1918
check_io(md_result_file);
2177
if (drizzle_query_with_error_report(drizzle, 0, query_string.c_str()))
2179
DB_error(drizzle, "when retrieving data from server");
2183
res=drizzle_use_result(drizzle);
2185
res=drizzle_store_result(drizzle);
2188
DB_error(drizzle, "when retrieving data from server");
1920
if (drizzleclient_query_with_error_report(&dcon, &result,
1921
query_string.c_str(), quick))
2192
verbose_msg("-- Retrieving rows...\n");
2193
if (drizzle_num_fields(res) != num_fields)
1926
verbose_msg(_("-- Retrieving rows...\n"));
1927
if (drizzle_result_column_count(&result) != num_fields)
2195
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"),
2196
1930
my_progname, result_table);
2197
1931
error= EX_CONSCHECK;
1932
drizzle_result_free(&result);
2203
fprintf(md_result_file,"LOCK TABLES %s WRITE;\n", opt_quoted_table);
2204
check_io(md_result_file);
2206
1936
/* Moved disable keys to after lock per bug 15977 */
2207
1937
if (opt_disable_keys)
2209
fprintf(md_result_file, "/*!40000 ALTER TABLE %s DISABLE KEYS */;\n",
1939
fprintf(md_result_file, "ALTER TABLE %s DISABLE KEYS;\n",
2210
1940
opt_quoted_table);
2211
1941
check_io(md_result_file);
2214
total_length= opt_net_buffer_length; /* Force row break */
1944
total_length= DRIZZLE_MAX_LINE_LENGTH; /* Force row break */
2217
init_length=(uint) insert_pat.length()+4;
1947
init_length=(uint32_t) insert_pat.length()+4;
2219
1949
print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
2221
1951
if (opt_autocommit)
2223
1953
fprintf(md_result_file, "set autocommit=0;\n");
2224
1954
check_io(md_result_file);
2227
while ((row= drizzle_fetch_row(res)))
2230
uint32_t *lengths= drizzle_fetch_lengths(res);
1967
drizzle_row_free(&result, row);
1969
row= drizzle_row_buffer(&result, &ret);
1970
if (ret != DRIZZLE_RETURN_OK)
1973
_("%s: Error reading rows for table: %s (%d:%s) ! Aborting.\n"),
1974
my_progname, result_table, ret, drizzle_con_error(&dcon));
1975
drizzle_result_free(&result);
1980
row= drizzle_row_next(&result);
1985
lengths= drizzle_row_field_sizes(&result);
1988
if ((rownr % show_progress_size) == 0)
1990
verbose_msg(_("-- %"PRIu32" of ~%"PRIu64" rows dumped for table %s\n"), rownr, total_rows, opt_quoted_table);
2232
1992
if (!extended_insert && !opt_xml)
2234
1994
fputs(insert_pat.c_str(),md_result_file);
2235
1995
check_io(md_result_file);
2237
drizzle_field_seek(res,0);
1997
drizzle_column_seek(&result,0);
2543
2290
int init_dumping_tables(char *qdatabase)
2547
2292
if (!opt_create_db)
2549
2294
char qbuf[256];
2551
DRIZZLE_RES *dbinfo;
2296
drizzle_result_st result;
2297
drizzle_return_t ret;
2553
2299
snprintf(qbuf, sizeof(qbuf),
2554
2300
"SHOW CREATE DATABASE IF NOT EXISTS %s",
2557
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);
2559
2309
/* Old server version, dump generic CREATE DATABASE */
2560
2310
if (opt_drop_database)
2561
2311
fprintf(md_result_file,
2562
"\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2312
"\nDROP DATABASE IF EXISTS %s;\n",
2564
2314
fprintf(md_result_file,
2565
"\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n",
2315
"\nCREATE DATABASE IF NOT EXISTS %s;\n",
2570
if (opt_drop_database)
2571
fprintf(md_result_file,
2572
"\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2574
row = drizzle_fetch_row(dbinfo);
2320
if (drizzle_result_buffer(&result) == DRIZZLE_RETURN_OK)
2577
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]);
2579
drizzle_free_result(dbinfo);
2332
drizzle_result_free(&result);
2633
2391
static int dump_all_tables_in_db(char *database)
2637
char table_buff[NAME_LEN*2+3];
2638
char hash_key[2*NAME_LEN+2]; /* "db.tablename" */
2394
char hash_key[DRIZZLE_MAX_DB_SIZE+DRIZZLE_MAX_TABLE_SIZE+2]; /* "db.tablename" */
2639
2395
char *afterdot;
2640
int using_mysql_db= my_strcasecmp(&my_charset_latin1, database, "mysql");
2643
afterdot= stpcpy(hash_key, database);
2396
drizzle_result_st result;
2397
drizzle_return_t ret;
2399
afterdot= strcpy(hash_key, database) + strlen(database);
2644
2400
*afterdot++= '.';
2646
2402
if (init_dumping(database, init_dumping_tables))
2649
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
2405
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NULL);
2653
query= "LOCK TABLES ";
2654
for (numrows= 0 ; (table= getTableName(1)) ; )
2408
if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
2409
ret != DRIZZLE_RETURN_OK)
2656
char *end= stpcpy(afterdot, table);
2657
if (include_table((uchar*) hash_key,end - hash_key))
2660
query.append( quote_name(table, table_buff, 1));
2661
query.append( " READ /*!32311 LOCAL */,");
2411
DB_error(&result, ret, _("when doing refresh"));
2412
/* We shall continue here, if --force was given */
2664
if (numrows && drizzle_real_query(drizzle, query.c_str(), query.length()-1))
2665
DB_error(drizzle, "when using LOCK TABLES");
2666
/* We shall continue here, if --force was given */
2671
if (drizzle_refresh(drizzle, REFRESH_LOG))
2672
DB_error(drizzle, "when doing refresh");
2673
/* We shall continue here, if --force was given */
2415
drizzle_result_free(&result);
2675
2417
while ((table= getTableName(0)))
2677
char *end= stpcpy(afterdot, table);
2678
if (include_table((uchar*) hash_key, end - hash_key))
2419
char *end= strcpy(afterdot, table) + strlen(table);
2420
if (include_table((unsigned char*) hash_key, end - hash_key))
2680
2422
dump_table(table,database);
2681
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2723
2460
snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2724
2461
quote_for_like(old_table_name, show_name_buff));
2726
if (drizzle_query_with_error_report(drizzle, 0, query))
2463
if (drizzleclient_query_with_error_report(&dcon, &result, query, false))
2729
if ((table_res= drizzle_store_result(drizzle)))
2466
num_rows= drizzle_result_row_count(&result);
2731
uint64_t num_rows= drizzle_num_rows(table_res);
2737
TODO: Return all matching rows
2739
row= drizzle_fetch_row(table_res);
2740
lengths= drizzle_fetch_lengths(table_res);
2741
name= strmake_root(root, row[0], lengths[0]);
2743
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);
2749
2484
static int dump_selected_tables(char *db, char **table_names, int tables)
2751
char table_buff[NAME_LEN*2+3];
2752
string lock_tables_query;
2754
2487
char **dump_tables, **pos, **end;
2488
drizzle_result_st result;
2489
drizzle_return_t ret;
2757
2492
if (init_dumping(db, init_dumping_tables))
2782
2510
free_root(&root, MYF(0));
2784
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);
2785
2513
/* We shall countinue here, if --force was given */
2792
if (drizzle_real_query(drizzle, lock_tables_query.c_str(),
2793
lock_tables_query.length()-1))
2797
free_root(&root, MYF(0));
2799
DB_error(drizzle, "when doing LOCK TABLES");
2800
/* We shall countinue here, if --force was given */
2803
2518
if (flush_logs)
2805
if (drizzle_refresh(drizzle, REFRESH_LOG))
2520
if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
2521
ret != DRIZZLE_RETURN_OK)
2807
2523
if (!ignore_errors)
2808
2524
free_root(&root, MYF(0));
2809
DB_error(drizzle, "when doing refresh");
2525
DB_error(&result, ret, _("when doing refresh"));
2526
/* We shall countinue here, if --force was given */
2811
/* We shall countinue here, if --force was given */
2529
drizzle_result_free(&result);
2814
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
2532
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
2816
2534
/* Dump each selected table */
2817
2535
for (pos= dump_tables; pos < end; pos++)
2818
2536
dump_table(*pos, db);
2820
2538
free_root(&root, MYF(0));
2821
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2825
2543
fputs("</database>\n", md_result_file);
2826
2544
check_io(md_result_file);
2829
VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2831
2547
} /* dump_selected_tables */
2834
static int do_show_master_status(DRIZZLE *drizzle_con)
2837
DRIZZLE_RES *master;
2838
const char *comment_prefix=
2839
(opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2840
if (drizzle_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2846
row= drizzle_fetch_row(master);
2847
if (row && row[0] && row[1])
2849
/* SHOW MASTER STATUS reports file and position */
2851
fprintf(md_result_file,
2852
"\n--\n-- Position to start replication or point-in-time "
2853
"recovery from\n--\n\n");
2854
fprintf(md_result_file,
2855
"%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n",
2856
comment_prefix, row[0], row[1]);
2857
check_io(md_result_file);
2859
else if (!ignore_errors)
2861
/* SHOW MASTER STATUS reports nothing and --force is not enabled */
2862
my_printf_error(0, "Error: Binlogging on server not active",
2864
drizzle_free_result(master);
2865
maybe_exit(EX_DRIZZLEERR);
2868
drizzle_free_result(master);
2873
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
2876
/* We need to check if the slave sql is running in the first place */
2877
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2881
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2884
/* if SLAVE SQL is not running, we don't stop it */
2885
if (!strcmp(row[11],"No"))
2887
drizzle_free_result(slave);
2888
/* Silently assume that they don't have the slave running */
2893
drizzle_free_result(slave);
2895
/* now, stop slave if running */
2896
if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2902
static int add_stop_slave(void)
2905
fprintf(md_result_file,
2906
"\n--\n-- stop slave statement to make a recovery dump)\n--\n\n");
2907
fprintf(md_result_file, "STOP SLAVE;\n");
2911
static int add_slave_statements(void)
2914
fprintf(md_result_file,
2915
"\n--\n-- start slave statement to make a recovery dump)\n--\n\n");
2916
fprintf(md_result_file, "START SLAVE;\n");
2920
static int do_show_slave_status(DRIZZLE *drizzle_con)
2923
const char *comment_prefix=
2924
(opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2925
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2929
/* SHOW SLAVE STATUS reports nothing and --force is not enabled */
2930
my_printf_error(0, "Error: Slave not set up", MYF(0));
2936
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2937
if (row && row[9] && row[21])
2939
/* SHOW MASTER STATUS reports file and position */
2941
fprintf(md_result_file,
2942
"\n--\n-- Position to start replication or point-in-time "
2943
"recovery from (the master of this slave)\n--\n\n");
2945
fprintf(md_result_file, "%sCHANGE MASTER TO ", comment_prefix);
2947
if (opt_include_master_host_port)
2950
fprintf(md_result_file, "MASTER_HOST='%s', ", row[1]);
2952
fprintf(md_result_file, "MASTER_PORT='%s', ", row[3]);
2954
fprintf(md_result_file,
2955
"MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", row[9], row[21]);
2957
check_io(md_result_file);
2959
drizzle_free_result(slave);
2964
static int do_start_slave_sql(DRIZZLE *drizzle_con)
2967
/* We need to check if the slave sql is stopped in the first place */
2968
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2972
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2975
/* if SLAVE SQL is not running, we don't start it */
2976
if (!strcmp(row[11],"Yes"))
2978
drizzle_free_result(slave);
2979
/* Silently assume that they don't have the slave running */
2984
drizzle_free_result(slave);
2986
/* now, start slave if stopped */
2987
if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
2989
my_printf_error(0, "Error: Unable to start slave", MYF(0));
2997
static int do_flush_tables_read_lock(DRIZZLE *drizzle_con)
2549
static int do_flush_tables_read_lock(drizzle_con_st *drizzle_con)
3000
2552
We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
3005
2557
update starts between the two FLUSHes, we have that bad stall.
3008
( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
3009
drizzle_query_with_error_report(drizzle_con, 0,
3010
"FLUSH TABLES WITH READ LOCK") );
3014
static int do_unlock_tables(DRIZZLE *drizzle_con)
3016
return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
3019
static int get_bin_log_name(DRIZZLE *drizzle_con,
3020
char* buff_log_name, uint buff_len)
3025
if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
3026
!(res= drizzle_store_result(drizzle)))
3029
if (!(row= drizzle_fetch_row(res)))
3031
drizzle_free_result(res);
3035
Only one row is returned, and the first column is the name of the
3038
strmake(buff_log_name, row[0], buff_len - 1);
3040
drizzle_free_result(res);
3044
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
3047
string str= "PURGE BINARY LOGS TO '";
3048
str.append(log_name);
3050
err = drizzle_query_with_error_report(drizzle_con, 0, str.c_str());
3055
static int start_transaction(DRIZZLE *drizzle_con)
3058
We use BEGIN for old servers. --single-transaction --master-data will fail
3059
on old servers, but that's ok as it was already silently broken (it didn't
3060
do a consistent read, so better tell people frankly, with the error).
3062
We want the first consistent read to be used for all tables to dump so we
3063
need the REPEATABLE READ level (not anything lower, for example READ
3064
COMMITTED would give one new consistent read per dumped table).
3066
if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
3068
fprintf(stderr, "-- %s: the combination of --single-transaction and "
3069
"--master-data requires a DRIZZLE server version of at least 4.1 "
3070
"(current server's version is %s). %s\n",
3071
ignore_errors ? "Warning" : "Error",
3072
drizzle_con->server_version ? drizzle_con->server_version : "unknown",
3073
ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3075
exit(EX_DRIZZLEERR);
3078
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,
3079
2573
"SET SESSION TRANSACTION ISOLATION "
3080
"LEVEL REPEATABLE READ") ||
3081
drizzle_query_with_error_report(drizzle_con, 0,
2574
"LEVEL REPEATABLE READ", false) ||
2575
drizzleclient_query_with_error_report(drizzle_con, 0,
3082
2576
"START TRANSACTION "
3083
"/*!40100 WITH CONSISTENT SNAPSHOT */"));
2577
"WITH CONSISTENT SNAPSHOT", false));
3087
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
3088
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)
3090
2584
const char *end= x + length;
3091
2585
uint32_t found= 0;
3093
2587
char buff[255];
3095
2589
*err_pos= 0; /* No error yet */
3183
2702
char result= IGNORE_NONE;
3184
2703
char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3185
DRIZZLE_RES *res= NULL;
2704
const char *number_of_rows= NULL;
2705
drizzle_result_st res;
3189
2708
/* Check memory for quote_for_like() */
3190
2709
assert(2*sizeof(table_name) < sizeof(show_name_buff));
3191
2710
snprintf(buff, sizeof(buff), "show table status like %s",
3192
2711
quote_for_like(table_name, show_name_buff));
3193
if (drizzle_query_with_error_report(drizzle, &res, buff))
2712
if (drizzleclient_query_with_error_report(&dcon, &res, buff, false))
3195
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
3196
{ /* If old DRIZZLE version */
3197
verbose_msg("-- Warning: Couldn't get status information for "
3198
"table %s (%s)\n", table_name, drizzle_error(drizzle));
3199
return(result); /* assume table is ok */
3202
if (!(row= drizzle_fetch_row(res)))
2716
if (!(row= drizzle_row_next(&res)))
3204
2718
fprintf(stderr,
3205
"Error: Couldn't read status information for table %s (%s)\n",
3206
table_name, drizzle_error(drizzle));
3207
drizzle_free_result(res);
2719
_("Error: Couldn't read status information for table %s\n"),
2721
drizzle_result_free(&res);
3208
2722
return(result); /* assume table is ok */
3211
strmake(table_type, "VIEW", NAME_LEN-1);
3215
If the table type matches any of these, we do support delayed inserts.
3216
Note: we do not want to skip dumping this table if if is not one of
3217
these types, but we do want to use delayed inserts in the dump if
3218
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
3220
strmake(table_type, row[1], NAME_LEN-1);
2738
strncpy(table_type, row[1], DRIZZLE_MAX_TABLE_SIZE-1);
3221
2739
if (opt_delayed)
3223
2741
if (strcmp(table_type,"MyISAM") &&
3224
strcmp(table_type,"ISAM") &&
3225
2742
strcmp(table_type,"ARCHIVE") &&
3226
2743
strcmp(table_type,"HEAP") &&
3227
2744
strcmp(table_type,"MEMORY"))
3228
2745
result= IGNORE_INSERT_DELAYED;
3232
If these two types, we do want to skip dumping the table
3235
(!my_strcasecmp(&my_charset_latin1, table_type, "MRG_MyISAM") ||
3236
!strcmp(table_type,"MRG_ISAM")))
3237
result= IGNORE_DATA;
3239
drizzle_free_result(res);
2748
drizzle_result_free(&res);
3240
2749
return(result);
3262
2771
static char *primary_key_fields(const char *table_name)
3264
DRIZZLE_RES *res= NULL;
2773
drizzle_result_st res;
2774
drizzle_return_t ret;
3266
2776
/* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3267
char show_keys_buff[15 + NAME_LEN * 2 + 3];
3268
uint result_length= 0;
2777
char show_keys_buff[15 + DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
2778
uint32_t result_length= 0;
3269
2779
char *result= 0;
3270
char buff[NAME_LEN * 2 + 3];
2780
char buff[DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
3271
2781
char *quoted_field;
3273
2783
snprintf(show_keys_buff, sizeof(show_keys_buff),
3274
2784
"SHOW KEYS FROM %s", table_name);
3275
if (drizzle_query(drizzle, show_keys_buff) ||
3276
!(res= drizzle_store_result(drizzle)))
3278
fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3279
" records are NOT sorted (%s)\n",
3280
table_name, drizzle_error(drizzle));
3281
/* 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));
3305
2833
/* result (terminating \0 is already in result_length) */
3306
result= (char *)my_malloc(result_length + 10, MYF(MY_WME));
2834
result= (char *)malloc(result_length + 10);
3309
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);
3312
drizzle_data_seek(res, 0);
3313
row= drizzle_fetch_row(res);
2841
drizzle_row_seek(&res, 0);
2842
row= drizzle_row_next(&res);
3314
2843
quoted_field= quote_name(row[4], buff, 0);
3315
end= stpcpy(result, quoted_field);
3316
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)
3318
2847
quoted_field= quote_name(row[4], buff, 0);
3319
end= strxmov(end, ",", quoted_field, NullS);
2848
end+= sprintf(end,",%s",quoted_field);
3325
drizzle_free_result(res);
2852
drizzle_result_free(&res);
3331
2857
int main(int argc, char **argv)
3333
char bin_log_name[FN_REFLEN];
3335
MY_INIT("mysqldump");
2860
MY_INIT("drizzledump");
2861
drizzle_result_st result;
3337
2863
compatible_mode_normal_str[0]= 0;
3338
default_charset= (char *)drizzle_universal_client_charset;
3339
2864
memset(&ignore_table, 0, sizeof(ignore_table));
3341
2866
exit_code= get_options(&argc, &argv);