~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqldump.c

Removed/replaced DBUG symbols and TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
                      char **err_pos, uint *err_len);
81
81
 
82
82
static void field_escape(DYNAMIC_STRING* in, const char *from);
83
 
static bool  verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
 
83
static my_bool  verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
84
84
                quick= 1, extended_insert= 1,
85
85
                lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
86
86
                opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
98
98
                opt_include_master_host_port= 0,
99
99
                opt_events= 0,
100
100
                opt_alltspcs=0, opt_notspcs= 0;
101
 
static bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
 
101
static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
102
102
static ulong opt_max_allowed_packet, opt_net_buffer_length;
103
103
static MYSQL mysql_connection,*mysql=0;
104
104
static DYNAMIC_STRING insert_pat;
112
112
static char **defaults_argv= 0;
113
113
static char compatible_mode_normal_str[255];
114
114
/* Server supports character_set_results session variable? */
115
 
static bool server_supports_switching_charsets= true;
 
115
static my_bool server_supports_switching_charsets= TRUE;
116
116
static ulong opt_compatible_mode= 0;
117
117
#define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1
118
118
#define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2
126
126
FILE *md_result_file= 0;
127
127
FILE *stderror_file=0;
128
128
 
 
129
#ifdef HAVE_SMEM
 
130
static char *shared_memory_base_name=0;
 
131
#endif
129
132
static uint opt_protocol= MYSQL_PROTOCOL_TCP;
130
133
 
131
134
/*
151
154
static CHARSET_INFO *charset_info= &my_charset_latin1;
152
155
const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
153
156
/* have we seen any VIEWs during table scanning? */
154
 
bool seen_views= 0;
 
157
my_bool seen_views= 0;
155
158
const char *compatible_mode_names[]=
156
159
{
157
160
  "MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
176
179
static struct my_option my_long_options[] =
177
180
{
178
181
  {"all", 'a', "Deprecated. Use --create-options instead.",
179
 
   (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
 
182
   (uchar**) &create_options, (uchar**) &create_options, 0, GET_BOOL, NO_ARG, 1,
180
183
   0, 0, 0, 0, 0},
181
184
  {"all-databases", 'A',
182
185
   "Dump all the databases. This will be same as --databases with all databases selected.",
183
 
   (char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
186
   (uchar**) &opt_alldbs, (uchar**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
184
187
   0, 0},
185
188
  {"all-tablespaces", 'Y',
186
189
   "Dump all the tablespaces.",
187
 
   (char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
190
   (uchar**) &opt_alltspcs, (uchar**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
188
191
   0, 0},
189
192
  {"no-tablespaces", 'y',
190
193
   "Do not dump any tablespace information.",
191
 
   (char**) &opt_notspcs, (char**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
194
   (uchar**) &opt_notspcs, (uchar**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
192
195
   0, 0},
193
196
  {"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
194
 
   (char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
197
   (uchar**) &opt_drop_database, (uchar**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
195
198
   0},
196
199
  {"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
197
 
   (char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
 
200
   (uchar**) &opt_drop, (uchar**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
198
201
   0},
199
202
  {"add-locks", OPT_LOCKS, "Add locks around insert statements.",
200
 
   (char**) &opt_lock, (char**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
 
203
   (uchar**) &opt_lock, (uchar**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
201
204
   0},
202
205
  {"allow-keywords", OPT_KEYWORDS,
203
 
   "Allow creation of column names that are keywords.", (char**) &opt_keywords,
204
 
   (char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
206
   "Allow creation of column names that are keywords.", (uchar**) &opt_keywords,
 
207
   (uchar**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
205
208
  {"apply-slave-statements", OPT_MYSQLDUMP_SLAVE_APPLY,
206
209
   "Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
207
 
   (char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
 
210
   (uchar**) &opt_slave_apply, (uchar**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
208
211
   0, 0, 0, 0, 0, 0},
209
212
  {"character-sets-dir", OPT_CHARSETS_DIR,
210
 
   "Directory where character sets are.", (char**) &charsets_dir,
211
 
   (char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
213
   "Directory where character sets are.", (uchar**) &charsets_dir,
 
214
   (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
212
215
  {"comments", 'i', "Write additional information.",
213
 
   (char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
 
216
   (uchar**) &opt_comments, (uchar**) &opt_comments, 0, GET_BOOL, NO_ARG,
214
217
   1, 0, 0, 0, 0, 0},
215
218
  {"compatible", OPT_COMPATIBLE,
216
219
   "Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires MySQL server version 4.1.0 or higher. This option is ignored with earlier server versions.",
217
 
   (char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
 
220
   (uchar**) &opt_compatible_mode_str, (uchar**) &opt_compatible_mode_str, 0,
218
221
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
219
222
  {"compact", OPT_COMPACT,
220
223
   "Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs.  Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks",
221
 
   (char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
224
   (uchar**) &opt_compact, (uchar**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
222
225
   0, 0},
223
226
  {"complete-insert", 'c', "Use complete insert statements.",
224
 
   (char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
 
227
   (uchar**) &opt_complete_insert, (uchar**) &opt_complete_insert, 0, GET_BOOL,
225
228
   NO_ARG, 0, 0, 0, 0, 0, 0},
226
229
  {"compress", 'C', "Use compression in server/client protocol.",
227
 
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
230
   (uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
228
231
   0, 0, 0},
229
232
  {"create-options", OPT_CREATE_OPTIONS,
230
233
   "Include all MySQL specific create options.",
231
 
   (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
 
234
   (uchar**) &create_options, (uchar**) &create_options, 0, GET_BOOL, NO_ARG, 1,
232
235
   0, 0, 0, 0, 0},
233
236
  {"databases", 'B',
234
237
   "To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output.",
235
 
   (char**) &opt_databases, (char**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
 
238
   (uchar**) &opt_databases, (uchar**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
236
239
   0, 0, 0, 0},
 
240
#ifdef DBUG_OFF
 
241
  {"debug", '#', "This is a non-debug version. Catch this and exit",
 
242
   0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
243
#else
 
244
  {"debug", '#', "Output debug log", (uchar**) &default_dbug_option,
 
245
   (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
246
#endif
237
247
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
238
 
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
248
   (uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
239
249
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
240
250
  {"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
241
 
   (char**) &debug_info_flag, (char**) &debug_info_flag,
 
251
   (uchar**) &debug_info_flag, (uchar**) &debug_info_flag,
242
252
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
243
253
  {"default-character-set", OPT_DEFAULT_CHARSET,
244
 
   "Set the default character set.", (char**) &default_charset,
245
 
   (char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
254
   "Set the default character set.", (uchar**) &default_charset,
 
255
   (uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
246
256
  {"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
247
 
   (char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
257
   (uchar**) &opt_delayed, (uchar**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
248
258
   0, 0},
249
259
  {"delete-master-logs", OPT_DELETE_MASTER_LOGS,
250
260
   "Delete logs on master after backup. This automatically enables --master-data.",
251
 
   (char**) &opt_delete_master_logs, (char**) &opt_delete_master_logs, 0,
 
261
   (uchar**) &opt_delete_master_logs, (uchar**) &opt_delete_master_logs, 0,
252
262
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
253
263
  {"disable-keys", 'K',
254
 
   "'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (char**) &opt_disable_keys,
255
 
   (char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
264
   "'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (uchar**) &opt_disable_keys,
 
265
   (uchar**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
256
266
  {"dump-slave", OPT_MYSQLDUMP_SLAVE_DATA,
257
267
   "This causes the binary log position and filename of the master to be "
258
268
   "appended to the dumped data output. Setting the value to 1, will print"
264
274
   "- don't forget to read about --single-transaction below). In all cases "
265
275
   "any action on logs will happen at the exact moment of the dump."
266
276
   "Option automatically turns --lock-tables off.",
267
 
   (char**) &opt_slave_data, (char**) &opt_slave_data, 0,
 
277
   (uchar**) &opt_slave_data, (uchar**) &opt_slave_data, 0,
268
278
   GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
269
279
  {"events", 'E', "Dump events.",
270
 
     (char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
 
280
     (uchar**) &opt_events, (uchar**) &opt_events, 0, GET_BOOL,
271
281
     NO_ARG, 0, 0, 0, 0, 0, 0},
272
282
  {"extended-insert", 'e',
273
283
   "Allows utilization of the new, much faster INSERT syntax.",
274
 
   (char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
 
284
   (uchar**) &extended_insert, (uchar**) &extended_insert, 0, GET_BOOL, NO_ARG,
275
285
   1, 0, 0, 0, 0, 0},
276
286
  {"fields-terminated-by", OPT_FTB,
277
 
   "Fields in the textfile are terminated by ...", (char**) &fields_terminated,
278
 
   (char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
287
   "Fields in the textfile are terminated by ...", (uchar**) &fields_terminated,
 
288
   (uchar**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
279
289
  {"fields-enclosed-by", OPT_ENC,
280
 
   "Fields in the importfile are enclosed by ...", (char**) &enclosed,
281
 
   (char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
 
290
   "Fields in the importfile are enclosed by ...", (uchar**) &enclosed,
 
291
   (uchar**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
282
292
  {"fields-optionally-enclosed-by", OPT_O_ENC,
283
 
   "Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
284
 
   (char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
 
293
   "Fields in the i.file are opt. enclosed by ...", (uchar**) &opt_enclosed,
 
294
   (uchar**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
285
295
  {"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
286
 
   (char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
296
   (uchar**) &escaped, (uchar**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
287
297
  {"first-slave", 'x', "Deprecated, renamed to --lock-all-tables.",
288
 
   (char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
 
298
   (uchar**) &opt_lock_all_tables, (uchar**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
289
299
   0, 0, 0, 0, 0, 0},
290
300
  {"flush-logs", 'F', "Flush logs file in server before starting dump. "
291
301
   "Note that if you dump many databases at once (using the option "
296
306
   "to the moment all tables are locked. So if you want your dump and "
297
307
   "the log flush to happen at the same exact moment you should use "
298
308
   "--lock-all-tables or --master-data with --flush-logs",
299
 
   (char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
309
   (uchar**) &flush_logs, (uchar**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
300
310
   0, 0},
301
311
  {"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
302
312
   "after dumping the mysql database.  This option should be used any "
303
313
   "time the dump contains the mysql database and any other database "
304
314
   "that depends on the data in the mysql database for proper restore. ",
305
 
   (char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
315
   (uchar**) &flush_privileges, (uchar**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
306
316
   0, 0},
307
317
  {"force", 'f', "Continue even if we get an sql-error.",
308
 
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
 
318
   (uchar**) &ignore_errors, (uchar**) &ignore_errors, 0, GET_BOOL, NO_ARG,
309
319
   0, 0, 0, 0, 0, 0},
310
320
  {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
311
321
   NO_ARG, 0, 0, 0, 0, 0, 0},
312
322
  {"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, "
313
323
    "VARBINARY, BLOB) in hexadecimal format.",
314
 
   (char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
315
 
  {"host", 'h', "Connect to host.", (char**) &current_host,
316
 
   (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
324
   (uchar**) &opt_hex_blob, (uchar**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
325
  {"host", 'h', "Connect to host.", (uchar**) &current_host,
 
326
   (uchar**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
317
327
  {"ignore-table", OPT_IGNORE_TABLE,
318
328
   "Do not dump the specified table. To specify more than one table to ignore, "
319
329
   "use the directive multiple times, once for each table.  Each table must "
321
331
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
322
332
  {"include-master-host-port", OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT,
323
333
   "Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
324
 
   (char**) &opt_include_master_host_port, 
325
 
   (char**) &opt_include_master_host_port, 
 
334
   (uchar**) &opt_include_master_host_port, 
 
335
   (uchar**) &opt_include_master_host_port, 
326
336
   0, GET_BOOL, NO_ARG,
327
337
   0, 0, 0, 0, 0, 0},
328
338
  {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
329
 
   (char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
339
   (uchar**) &opt_ignore, (uchar**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
330
340
   0, 0},
331
341
  {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
332
 
   (char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
 
342
   (uchar**) &lines_terminated, (uchar**) &lines_terminated, 0, GET_STR,
333
343
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
334
344
  {"lock-all-tables", 'x', "Locks all tables across all databases. This "
335
345
   "is achieved by taking a global read lock for the duration of the whole "
336
346
   "dump. Automatically turns --single-transaction and --lock-tables off.",
337
 
   (char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
 
347
   (uchar**) &opt_lock_all_tables, (uchar**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
338
348
   0, 0, 0, 0, 0, 0},
339
 
  {"lock-tables", 'l', "Lock all tables for read.", (char**) &lock_tables,
340
 
   (char**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
349
  {"lock-tables", 'l', "Lock all tables for read.", (uchar**) &lock_tables,
 
350
   (uchar**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
341
351
  {"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.",
342
 
   (char**) &log_error_file, (char**) &log_error_file, 0, GET_STR,
 
352
   (uchar**) &log_error_file, (uchar**) &log_error_file, 0, GET_STR,
343
353
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
344
354
  {"master-data", OPT_MASTER_DATA,
345
355
   "This causes the binary log position and filename to be appended to the "
351
361
   "- don't forget to read about --single-transaction below). In all cases "
352
362
   "any action on logs will happen at the exact moment of the dump."
353
363
   "Option automatically turns --lock-tables off.",
354
 
   (char**) &opt_master_data, (char**) &opt_master_data, 0,
 
364
   (uchar**) &opt_master_data, (uchar**) &opt_master_data, 0,
355
365
   GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
356
366
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
357
 
    (char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
 
367
    (uchar**) &opt_max_allowed_packet, (uchar**) &opt_max_allowed_packet, 0,
358
368
    GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
359
 
   (int64_t) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
 
369
   (longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
360
370
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
361
 
    (char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
 
371
    (uchar**) &opt_net_buffer_length, (uchar**) &opt_net_buffer_length, 0,
362
372
    GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
363
373
   MALLOC_OVERHEAD-1024, 1024, 0},
364
374
  {"no-autocommit", OPT_AUTOCOMMIT,
365
375
   "Wrap tables with autocommit/commit statements.",
366
 
   (char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
 
376
   (uchar**) &opt_autocommit, (uchar**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
367
377
   0, 0, 0, 0, 0, 0},
368
378
  {"no-create-db", 'n',
369
379
   "'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
370
 
   (char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
 
380
   (uchar**) &opt_create_db, (uchar**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
371
381
   0, 0, 0, 0},
372
382
  {"no-create-info", 't', "Don't write table creation info.",
373
 
   (char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
 
383
   (uchar**) &opt_no_create_info, (uchar**) &opt_no_create_info, 0, GET_BOOL,
374
384
   NO_ARG, 0, 0, 0, 0, 0, 0},
375
 
  {"no-data", 'd', "No row information.", (char**) &opt_no_data,
376
 
   (char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
385
  {"no-data", 'd', "No row information.", (uchar**) &opt_no_data,
 
386
   (uchar**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
377
387
  {"no-set-names", 'N',
378
388
   "Deprecated. Use --skip-set-charset instead.",
379
389
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
382
392
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
383
393
  {"order-by-primary", OPT_ORDER_BY_PRIMARY,
384
394
   "Sorts each table's rows by primary key, or first unique key, if such a key exists.  Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer.",
385
 
   (char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
395
   (uchar**) &opt_order_by_primary, (uchar**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
386
396
  {"password", 'p',
387
397
   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
388
398
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
389
 
  {"port", 'P', "Port number to use for connection.", (char**) &opt_mysql_port,
390
 
   (char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
 
399
  {"port", 'P', "Port number to use for connection.", (uchar**) &opt_mysql_port,
 
400
   (uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
391
401
   0},
392
402
  {"quick", 'q', "Don't buffer query, dump directly to stdout.",
393
 
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
403
   (uchar**) &quick, (uchar**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
394
404
  {"quote-names",'Q', "Quote table and column names with backticks (`).",
395
 
   (char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
 
405
   (uchar**) &opt_quoted, (uchar**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
396
406
   0, 0},
397
407
  {"replace", OPT_MYSQL_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
398
 
   (char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
408
   (uchar**) &opt_replace_into, (uchar**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
399
409
   0, 0},
400
410
  {"result-file", 'r',
401
411
   "Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed).",
402
412
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
403
413
  {"routines", 'R', "Dump stored routines (functions and procedures).",
404
 
     (char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
 
414
     (uchar**) &opt_routines, (uchar**) &opt_routines, 0, GET_BOOL,
405
415
     NO_ARG, 0, 0, 0, 0, 0, 0},
406
416
  {"set-charset", OPT_SET_CHARSET,
407
417
   "Add 'SET NAMES default_character_set' to the output.",
408
 
   (char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
 
418
   (uchar**) &opt_set_charset, (uchar**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
409
419
   0, 0, 0, 0, 0},
410
420
  {"set-variable", 'O',
411
421
   "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
412
422
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
423
#ifdef HAVE_SMEM
 
424
  {"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
 
425
   "Base name of shared memory.", (uchar**) &shared_memory_base_name, (uchar**) &shared_memory_base_name,
 
426
   0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
427
#endif
413
428
  /*
414
429
    Note that the combination --single-transaction --master-data
415
430
    will give bullet-proof binlog position only if server >=4.1.3. That's the
425
440
   "connection should use the following statements: ALTER TABLE, DROP "
426
441
   "TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
427
442
   "isolated from them. Option automatically turns off --lock-tables.",
428
 
   (char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
 
443
   (uchar**) &opt_single_transaction, (uchar**) &opt_single_transaction, 0,
429
444
   GET_BOOL, NO_ARG,  0, 0, 0, 0, 0, 0},
430
445
  {"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.",
431
 
   (char**) &opt_dump_date, (char**) &opt_dump_date, 0,
 
446
   (uchar**) &opt_dump_date, (uchar**) &opt_dump_date, 0,
432
447
   GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
433
448
  {"skip-opt", OPT_SKIP_OPTIMIZATION,
434
449
   "Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
435
450
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
436
451
  {"tab",'T',
437
452
   "Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if mysqldump is run on the same machine as the mysqld daemon.",
438
 
   (char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
453
   (uchar**) &path, (uchar**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
439
454
  {"tables", OPT_TABLES, "Overrides option --databases (-B).",
440
455
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
441
456
  {"tz-utc", OPT_TZ_UTC,
442
457
    "SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones.",
443
 
    (char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
458
    (uchar**) &opt_tz_utc, (uchar**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
444
459
#ifndef DONT_ALLOW_USER_CHANGE
445
460
  {"user", 'u', "User for login if not current user.",
446
 
   (char**) &current_user, (char**) &current_user, 0, GET_STR, REQUIRED_ARG,
 
461
   (uchar**) &current_user, (uchar**) &current_user, 0, GET_STR, REQUIRED_ARG,
447
462
   0, 0, 0, 0, 0, 0},
448
463
#endif
449
464
  {"verbose", 'v', "Print info about the various stages.",
450
 
   (char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
465
   (uchar**) &verbose, (uchar**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
451
466
  {"version",'V', "Output version information and exit.", 0, 0, 0,
452
467
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
453
468
  {"where", 'w', "Dump only selected records; QUOTES mandatory!",
454
 
   (char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
469
   (uchar**) &where, (uchar**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
455
470
  {"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
456
471
   NO_ARG, 0, 0, 0, 0, 0, 0},
457
472
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
472
487
static int init_dumping(char *, int init_func(char*));
473
488
static int dump_databases(char **);
474
489
static int dump_all_databases(void);
475
 
static char *quote_name(const char *name, char *buff, bool force);
 
490
static char *quote_name(const char *name, char *buff, my_bool force);
476
491
char check_if_ignore_table(const char *table_name, char *table_type);
477
492
static char *primary_key_fields(const char *table_name);
478
493
 
490
505
static void verbose_msg(const char *fmt, ...)
491
506
{
492
507
  va_list args;
493
 
 
 
508
  DBUG_ENTER("verbose_msg");
494
509
 
495
510
  if (!verbose)
496
 
    return;
 
511
    DBUG_VOID_RETURN;
497
512
 
498
513
  va_start(args, fmt);
499
514
  vfprintf(stderr, fmt, args);
500
515
  va_end(args);
501
516
 
502
 
  return;
 
517
  DBUG_VOID_RETURN;
503
518
}
504
519
 
505
520
/*
659
674
 
660
675
 
661
676
static uchar* get_table_key(const char *entry, size_t *length,
662
 
                            bool not_used __attribute__((unused)))
 
677
                            my_bool not_used __attribute__((unused)))
663
678
{
664
679
  *length= strlen(entry);
665
680
  return (uchar*) entry;
666
681
}
667
682
 
668
683
 
669
 
static bool
 
684
static my_bool
670
685
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
671
686
               char *argument)
672
687
{
708
723
    }
709
724
 
710
725
    break;
 
726
  case '#':
 
727
    DBUG_PUSH(argument ? argument : default_dbug_option);
 
728
    debug_check_flag= 1;
 
729
    break;
711
730
  case 'V': print_version(); exit(0);
712
731
  case 'X':
713
732
    opt_xml= 1;
774
793
        fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
775
794
        exit(1);
776
795
      }
 
796
#if !defined(DBUG_OFF)
 
797
      {
 
798
        uint size_for_sql_mode= 0;
 
799
        const char **ptr;
 
800
        for (ptr= compatible_mode_names; *ptr; ptr++)
 
801
          size_for_sql_mode+= strlen(*ptr);
 
802
        size_for_sql_mode+= sizeof(compatible_mode_names)-1;
 
803
        DBUG_ASSERT(sizeof(compatible_mode_normal_str)>=size_for_sql_mode);
 
804
      }
 
805
#endif
777
806
      mode= opt_compatible_mode;
778
807
      for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++)
779
808
      {
904
933
*/
905
934
static void DB_error(MYSQL *mysql_arg, const char *when)
906
935
{
907
 
 
 
936
  DBUG_ENTER("DB_error");
908
937
  maybe_die(EX_MYSQLERR, "Got error: %d: %s %s",
909
938
          mysql_errno(mysql_arg), mysql_error(mysql_arg), when);
910
 
  return;
 
939
  DBUG_VOID_RETURN;
911
940
}
912
941
 
913
942
 
1024
1053
 
1025
1054
  /* Server lacks facility.  This is not an error, by arbitrary decision . */
1026
1055
  if (!server_supports_switching_charsets)
1027
 
    return false;
 
1056
    return FALSE;
1028
1057
 
1029
1058
  query_length= snprintf(query_buffer,
1030
1059
                         sizeof (query_buffer),
1093
1122
static int connect_to_db(char *host, char *user,char *passwd)
1094
1123
{
1095
1124
  char buff[20+FN_REFLEN];
1096
 
 
 
1125
  DBUG_ENTER("connect_to_db");
1097
1126
 
1098
1127
  verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1099
1128
  mysql_init(&mysql_connection);
1101
1130
    mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS);
1102
1131
  if (opt_protocol)
1103
1132
    mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
 
1133
#ifdef HAVE_SMEM
 
1134
  if (shared_memory_base_name)
 
1135
    mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
 
1136
#endif
1104
1137
  mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
1105
1138
  if (!(mysql= mysql_real_connect(&mysql_connection,host,user,passwd,
1106
1139
                                  NULL,opt_mysql_port, NULL,
1107
1140
                                  0)))
1108
1141
  {
1109
1142
    DB_error(&mysql_connection, "when trying to connect");
1110
 
    return(1);
 
1143
    DBUG_RETURN(1);
1111
1144
  }
1112
1145
  if (mysql_get_server_version(&mysql_connection) < 40100)
1113
1146
  {
1115
1148
    opt_set_charset= 0;
1116
1149
 
1117
1150
    /* Don't switch charsets for 4.1 and earlier.  (bug#34192). */
1118
 
    server_supports_switching_charsets= false;
 
1151
    server_supports_switching_charsets= FALSE;
1119
1152
  } 
1120
1153
  /*
1121
1154
    set time_zone to UTC to allow dumping date types between servers with
1125
1158
  {
1126
1159
    snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1127
1160
    if (mysql_query_with_error_report(mysql, 0, buff))
1128
 
      return(1);
 
1161
      DBUG_RETURN(1);
1129
1162
  }
1130
 
  return(0);
 
1163
  DBUG_RETURN(0);
1131
1164
} /* connect_to_db */
1132
1165
 
1133
1166
 
1144
1177
static void unescape(FILE *file,char *pos,uint length)
1145
1178
{
1146
1179
  char *tmp;
1147
 
 
 
1180
  DBUG_ENTER("unescape");
1148
1181
  if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1149
1182
    die(EX_MYSQLERR, "Couldn't allocate memory");
1150
1183
 
1154
1187
  fputc('\'', file);
1155
1188
  check_io(file);
1156
1189
  my_free(tmp, MYF(MY_WME));
1157
 
  return;
 
1190
  DBUG_VOID_RETURN;
1158
1191
} /* unescape */
1159
1192
 
1160
1193
 
1161
 
static bool test_if_special_chars(const char *str)
 
1194
static my_bool test_if_special_chars(const char *str)
1162
1195
{
 
1196
#if MYSQL_VERSION_ID >= 32300
1163
1197
  for ( ; *str ; str++)
1164
1198
    if (!my_isvar(charset_info,*str) && *str != '$')
1165
1199
      return 1;
 
1200
#endif
1166
1201
  return 0;
1167
1202
} /* test_if_special_chars */
1168
1203
 
1184
1219
  buff                 quoted string
1185
1220
 
1186
1221
*/
1187
 
static char *quote_name(const char *name, char *buff, bool force)
 
1222
static char *quote_name(const char *name, char *buff, my_bool force)
1188
1223
{
1189
1224
  char *to= buff;
1190
1225
  char qtype= (opt_compatible_mode & MASK_ANSI_QUOTES) ? '\"' : '`';
1334
1369
  while (attribute_name != NullS)
1335
1370
  {
1336
1371
    attribute_value= va_arg(arg_list, char *);
1337
 
    assert(attribute_value != NullS);
 
1372
    DBUG_ASSERT(attribute_value != NullS);
1338
1373
 
1339
1374
    fputc(' ', xml_file);
1340
1375
    fputs(attribute_name, xml_file);    
1409
1444
{
1410
1445
  uint i;
1411
1446
  MYSQL_FIELD *field;
1412
 
  uint32_t *lengths= mysql_fetch_lengths(tableRes);
 
1447
  ulong *lengths= mysql_fetch_lengths(tableRes);
1413
1448
 
1414
1449
  fprintf(xml_file, "\t\t<%s", row_name);
1415
1450
  check_io(xml_file);
1471
1506
static uint get_table_structure(char *table, char *db, char *table_type,
1472
1507
                                char *ignore_flag)
1473
1508
{
1474
 
  bool    init=0, delayed, write_data, complete_insert;
1475
 
  uint64_t num_fields;
 
1509
  my_bool    init=0, delayed, write_data, complete_insert;
 
1510
  my_ulonglong num_fields;
1476
1511
  char       *result_table, *opt_quoted_table;
1477
1512
  const char *insert_option;
1478
1513
  char       name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3];
1481
1516
  int        len;
1482
1517
  MYSQL_RES  *result;
1483
1518
  MYSQL_ROW  row;
 
1519
  DBUG_ENTER("get_table_structure");
 
1520
  DBUG_PRINT("enter", ("db: %s  table: %s", db, table));
1484
1521
 
1485
1522
  *ignore_flag= check_if_ignore_table(table, table_type);
1486
1523
 
1537
1574
      if (switch_character_set_results(mysql, "binary") ||
1538
1575
          mysql_query_with_error_report(mysql, &result, buff) ||
1539
1576
          switch_character_set_results(mysql, default_charset))
1540
 
        return(0);
 
1577
        DBUG_RETURN(0);
1541
1578
 
1542
1579
      if (path)
1543
1580
      {
1544
1581
        if (!(sql_file= open_sql_file_for_table(table)))
1545
 
          return(0);
 
1582
          DBUG_RETURN(0);
1546
1583
 
1547
1584
        write_header(sql_file, db);
1548
1585
      }
1608
1645
 
1609
1646
          my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1610
1647
 
1611
 
          return(0);
 
1648
          DBUG_RETURN(0);
1612
1649
        }
1613
1650
        else
1614
1651
          my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1663
1700
          my_fclose(sql_file, MYF(MY_WME));
1664
1701
 
1665
1702
        seen_views= 1;
1666
 
        return(0);
 
1703
        DBUG_RETURN(0);
1667
1704
      }
1668
1705
 
1669
1706
      row= mysql_fetch_row(result);
1684
1721
    {
1685
1722
      if (path)
1686
1723
        my_fclose(sql_file, MYF(MY_WME));
1687
 
      return(0);
 
1724
      DBUG_RETURN(0);
1688
1725
    }
1689
1726
 
1690
1727
    /*
1738
1775
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1739
1776
             result_table);
1740
1777
    if (mysql_query_with_error_report(mysql, &result, query_buff))
1741
 
      return(0);
 
1778
      DBUG_RETURN(0);
1742
1779
 
1743
1780
    /* Make an sql-file, if path was given iow. option -T was given */
1744
1781
    if (!opt_no_create_info)
1746
1783
      if (path)
1747
1784
      {
1748
1785
        if (!(sql_file= open_sql_file_for_table(table)))
1749
 
          return(0);
 
1786
          DBUG_RETURN(0);
1750
1787
        write_header(sql_file, db);
1751
1788
      }
1752
1789
      if (!opt_xml && opt_comments)
1783
1820
 
1784
1821
    while ((row= mysql_fetch_row(result)))
1785
1822
    {
1786
 
      uint32_t *lengths= mysql_fetch_lengths(result);
 
1823
      ulong *lengths= mysql_fetch_lengths(result);
1787
1824
      if (init)
1788
1825
      {
1789
1826
        if (!opt_xml && !opt_no_create_info)
1846
1883
                my_progname, result_table, mysql_error(mysql));
1847
1884
        if (path)
1848
1885
          my_fclose(sql_file, MYF(MY_WME));
1849
 
        return(0);
 
1886
        DBUG_RETURN(0);
1850
1887
      }
1851
1888
 
1852
1889
      /* Find first which key is primary key */
1966
2003
    write_footer(sql_file);
1967
2004
    my_fclose(sql_file, MYF(MY_WME));
1968
2005
  }
1969
 
  return((uint) num_fields);
 
2006
  DBUG_RETURN((uint) num_fields);
1970
2007
} /* get_table_structure */
1971
2008
 
1972
2009
static void add_load_option(DYNAMIC_STRING *str, const char *option,
2061
2098
  MYSQL_RES     *res;
2062
2099
  MYSQL_FIELD   *field;
2063
2100
  MYSQL_ROW     row;
2064
 
 
 
2101
  DBUG_ENTER("dump_table");
2065
2102
 
2066
2103
  /*
2067
2104
    Make sure you get the create table info before the following check for
2073
2110
    The "table" could be a view.  If so, we don't do anything here.
2074
2111
  */
2075
2112
  if (strcmp(table_type, "VIEW") == 0)
2076
 
    return;
 
2113
    DBUG_VOID_RETURN;
2077
2114
 
2078
2115
  /* Check --no-data flag */
2079
2116
  if (opt_no_data)
2080
2117
  {
2081
2118
    verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
2082
2119
                table);
2083
 
    return;
 
2120
    DBUG_VOID_RETURN;
2084
2121
  }
2085
2122
 
 
2123
  DBUG_PRINT("info",
 
2124
             ("ignore_flag: %x  num_fields: %d", (int) ignore_flag,
 
2125
              num_fields));
2086
2126
  /*
2087
2127
    If the table type is a merge table or any type that has to be
2088
2128
     _completely_ ignored and no data dumped
2091
2131
  {
2092
2132
    verbose_msg("-- Warning: Skipping data for table '%s' because " \
2093
2133
                "it's of type %s\n", table, table_type);
2094
 
    return;
 
2134
    DBUG_VOID_RETURN;
2095
2135
  }
2096
2136
  /* Check that there are any fields in the table */
2097
2137
  if (num_fields == 0)
2098
2138
  {
2099
2139
    verbose_msg("-- Skipping dump data for table '%s', it has no fields\n",
2100
2140
                table);
2101
 
    return;
 
2141
    DBUG_VOID_RETURN;
2102
2142
  }
2103
2143
 
2104
2144
  /*
2110
2150
      !my_strcasecmp(&my_charset_latin1, table, "event"))
2111
2151
  {
2112
2152
    verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2113
 
    return;
 
2153
    DBUG_VOID_RETURN;
2114
2154
  }
2115
2155
 
2116
2156
  result_table= quote_name(table,table_buff, 1);
2172
2212
    {
2173
2213
      DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
2174
2214
      dynstr_free(&query_string);
2175
 
      return;
 
2215
      DBUG_VOID_RETURN;
2176
2216
    }
2177
2217
  }
2178
2218
  else
2267
2307
    while ((row= mysql_fetch_row(res)))
2268
2308
    {
2269
2309
      uint i;
2270
 
      uint32_t *lengths= mysql_fetch_lengths(res);
 
2310
      ulong *lengths= mysql_fetch_lengths(res);
2271
2311
      rownr++;
2272
2312
      if (!extended_insert && !opt_xml)
2273
2313
      {
2329
2369
                  extended_row.length+= mysql_hex_string(extended_row.str +
2330
2370
                                                         extended_row.length,
2331
2371
                                                         row[i], length);
2332
 
                  assert(extended_row.length+1 <= extended_row.max_length);
 
2372
                  DBUG_ASSERT(extended_row.length+1 <= extended_row.max_length);
2333
2373
                  /* mysql_hex_string() already terminated string by '\0' */
2334
 
                  assert(extended_row.str[extended_row.length] == '\0');
 
2374
                  DBUG_ASSERT(extended_row.str[extended_row.length] == '\0');
2335
2375
                }
2336
2376
                else
2337
2377
                {
2508
2548
    mysql_free_result(res);
2509
2549
  }
2510
2550
  dynstr_free(&query_string);
2511
 
  return;
 
2551
  DBUG_VOID_RETURN;
2512
2552
 
2513
2553
err:
2514
2554
  dynstr_free(&query_string);
2515
2555
  maybe_exit(error);
2516
 
  return;
 
2556
  DBUG_VOID_RETURN;
2517
2557
} /* dump_table */
2518
2558
 
2519
2559
 
2563
2603
{
2564
2604
  int result=0;
2565
2605
  char **db;
2566
 
 
 
2606
  DBUG_ENTER("dump_databases");
2567
2607
 
2568
2608
  for (db= db_names ; *db ; db++)
2569
2609
  {
2570
2610
    if (dump_all_tables_in_db(*db))
2571
2611
      result=1;
2572
2612
  }
2573
 
  return(result);
 
2613
  DBUG_RETURN(result);
2574
2614
} /* dump_databases */
2575
2615
 
2576
2616
 
2588
2628
 
2589
2629
int init_dumping_tables(char *qdatabase)
2590
2630
{
2591
 
 
 
2631
  DBUG_ENTER("init_dumping_tables");
2592
2632
 
2593
2633
  if (!opt_create_db)
2594
2634
  {
2625
2665
      mysql_free_result(dbinfo);
2626
2666
    }
2627
2667
  }
2628
 
  return(0);
 
2668
  DBUG_RETURN(0);
2629
2669
} /* init_dumping_tables */
2630
2670
 
2631
2671
 
2670
2710
 
2671
2711
/* Return 1 if we should copy the table */
2672
2712
 
2673
 
static bool include_table(const uchar *hash_key, size_t len)
 
2713
static my_bool include_table(const uchar *hash_key, size_t len)
2674
2714
{
2675
2715
  return !hash_search(&ignore_table, hash_key, len);
2676
2716
}
2684
2724
  char hash_key[2*NAME_LEN+2];  /* "db.tablename" */
2685
2725
  char *afterdot;
2686
2726
  int using_mysql_db= my_strcasecmp(&my_charset_latin1, database, "mysql");
2687
 
 
 
2727
  DBUG_ENTER("dump_all_tables_in_db");
2688
2728
 
2689
2729
  afterdot= strmov(hash_key, database);
2690
2730
  *afterdot++= '.';
2691
2731
 
2692
2732
  if (init_dumping(database, init_dumping_tables))
2693
 
    return(1);
 
2733
    DBUG_RETURN(1);
2694
2734
  if (opt_xml)
2695
2735
    print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
2696
2736
  if (lock_tables)
2740
2780
    fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2741
2781
    fprintf(md_result_file,"\n/*! FLUSH PRIVILEGES */;\n");
2742
2782
  }
2743
 
  return(0);
 
2783
  DBUG_RETURN(0);
2744
2784
} /* dump_all_tables_in_db */
2745
2785
 
2746
2786
 
2762
2802
  MYSQL_ROW  row;
2763
2803
  char query[50 + 2*NAME_LEN];
2764
2804
  char show_name_buff[FN_REFLEN];
2765
 
 
 
2805
  DBUG_ENTER("get_actual_table_name");
2766
2806
 
2767
2807
  /* Check memory for quote_for_like() */
2768
 
  assert(2*sizeof(old_table_name) < sizeof(show_name_buff));
 
2808
  DBUG_ASSERT(2*sizeof(old_table_name) < sizeof(show_name_buff));
2769
2809
  snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2770
2810
           quote_for_like(old_table_name, show_name_buff));
2771
2811
 
2774
2814
 
2775
2815
  if ((table_res= mysql_store_result(mysql)))
2776
2816
  {
2777
 
    uint64_t num_rows= mysql_num_rows(table_res);
 
2817
    my_ulonglong num_rows= mysql_num_rows(table_res);
2778
2818
    if (num_rows > 0)
2779
2819
    {
2780
 
      uint32_t *lengths;
 
2820
      ulong *lengths;
2781
2821
      /*
2782
2822
        Return first row
2783
2823
        TODO: Return all matching rows
2788
2828
    }
2789
2829
    mysql_free_result(table_res);
2790
2830
  }
2791
 
  return(name);
 
2831
  DBUG_PRINT("exit", ("new_table_name: %s", name));
 
2832
  DBUG_RETURN(name);
2792
2833
}
2793
2834
 
2794
2835
 
2798
2839
  DYNAMIC_STRING lock_tables_query;
2799
2840
  MEM_ROOT root;
2800
2841
  char **dump_tables, **pos, **end;
2801
 
 
 
2842
  DBUG_ENTER("dump_selected_tables");
2802
2843
 
2803
2844
  if (init_dumping(db, init_dumping_tables))
2804
 
    return(1);
 
2845
    DBUG_RETURN(1);
2805
2846
 
2806
2847
  init_alloc_root(&root, 8192, 0);
2807
2848
  if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
2864
2905
 
2865
2906
  /* Dump each selected table */
2866
2907
  for (pos= dump_tables; pos < end; pos++)
 
2908
  {
 
2909
    DBUG_PRINT("info",("Dumping table %s", *pos));
2867
2910
    dump_table(*pos, db);
 
2911
  }
2868
2912
 
2869
2913
  free_root(&root, MYF(0));
2870
2914
  my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2876
2920
  }
2877
2921
  if (lock_tables)
2878
2922
    VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
2879
 
  return(0);
 
2923
  DBUG_RETURN(0);
2880
2924
} /* dump_selected_tables */
2881
2925
 
2882
2926
 
3166
3210
        *err_len= var_len;
3167
3211
      }
3168
3212
      else
3169
 
        found|= ((int64_t) 1 << (find - 1));
 
3213
        found|= ((longlong) 1 << (find - 1));
3170
3214
      if (pos == end)
3171
3215
        break;
3172
3216
      start= pos + 1;
3210
3254
 
3211
3255
  Check if we the table is one of the table types that should be ignored:
3212
3256
  MRG_ISAM, MRG_MYISAM, if opt_delayed, if that table supports delayed inserts.
3213
 
  If the table should be altogether ignored, it returns a true, false if it
 
3257
  If the table should be altogether ignored, it returns a TRUE, FALSE if it
3214
3258
  should not be ignored. If the user has selected to use INSERT DELAYED, it
3215
3259
  sets the value of the bool pointer supports_delayed_inserts to 0 if not
3216
3260
  supported, 1 if it is supported.
3235
3279
  char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3236
3280
  MYSQL_RES *res= NULL;
3237
3281
  MYSQL_ROW row;
3238
 
 
 
3282
  DBUG_ENTER("check_if_ignore_table");
3239
3283
 
3240
3284
  /* Check memory for quote_for_like() */
3241
 
  assert(2*sizeof(table_name) < sizeof(show_name_buff));
 
3285
  DBUG_ASSERT(2*sizeof(table_name) < sizeof(show_name_buff));
3242
3286
  snprintf(buff, sizeof(buff), "show table status like %s",
3243
3287
           quote_for_like(table_name, show_name_buff));
3244
3288
  if (mysql_query_with_error_report(mysql, &res, buff))
3247
3291
    {                                   /* If old MySQL version */
3248
3292
      verbose_msg("-- Warning: Couldn't get status information for "
3249
3293
                  "table %s (%s)\n", table_name, mysql_error(mysql));
3250
 
      return(result);                       /* assume table is ok */
 
3294
      DBUG_RETURN(result);                       /* assume table is ok */
3251
3295
    }
3252
3296
  }
3253
3297
  if (!(row= mysql_fetch_row(res)))
3256
3300
            "Error: Couldn't read status information for table %s (%s)\n",
3257
3301
            table_name, mysql_error(mysql));
3258
3302
    mysql_free_result(res);
3259
 
    return(result);                         /* assume table is ok */
 
3303
    DBUG_RETURN(result);                         /* assume table is ok */
3260
3304
  }
3261
3305
  if (!(row[1]))
3262
3306
    strmake(table_type, "VIEW", NAME_LEN-1);
3288
3332
      result= IGNORE_DATA;
3289
3333
  }
3290
3334
  mysql_free_result(res);
3291
 
  return(result);
 
3335
  DBUG_RETURN(result);
3292
3336
}
3293
3337
 
3294
3338
 
3516
3560
  if (opt_delete_master_logs && purge_bin_logs_to(mysql, bin_log_name))
3517
3561
    goto err;
3518
3562
 
 
3563
#ifdef HAVE_SMEM
 
3564
  my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
 
3565
#endif
3519
3566
  /*
3520
3567
    No reason to explicitely COMMIT the transaction, neither to explicitely
3521
3568
    UNLOCK TABLES: these will be automatically be done by the server when we