67
70
static void add_load_option(string &str, const char *option,
68
71
const char *option_value);
69
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
70
char **err_pos, uint *err_len);
72
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
73
char **err_pos, uint32_t *err_len);
72
75
static void field_escape(string &in, const char *from);
73
static bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
74
quick= 1, extended_insert= 1,
75
lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
76
opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
77
opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0,
78
opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0,
79
opt_set_charset=0, opt_dump_date=1,
80
opt_autocommit=0,opt_disable_keys=1,opt_xml=0,
81
opt_delete_master_logs=0, tty_password=0,
82
opt_single_transaction=0, opt_comments= 0, opt_compact= 0,
83
opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0,
84
opt_complete_insert= 0, opt_drop_database= 0,
86
opt_routines=0, opt_tz_utc=1,
88
opt_include_master_host_port= 0,
90
opt_alltspcs=0, opt_notspcs= 0;
91
static bool debug_info_flag= 0, debug_check_flag= 0;
92
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
93
static DRIZZLE drizzle_connection,*drizzle=0;
76
static bool verbose= false, opt_no_create_info= false, opt_no_data= false,
77
quick= true, extended_insert= true,
78
lock_tables= true, ignore_errors= false, flush_logs= false,
79
opt_drop= true, opt_keywords= false,
80
opt_lock= true, opt_compress= false,
81
opt_delayed= false, create_options= true, opt_quoted= false,
82
opt_databases= false, opt_alldbs= false, opt_create_db= false,
83
opt_lock_all_tables= false,
84
opt_set_charset= false, opt_dump_date= true,
85
opt_autocommit= false, opt_disable_keys= true, opt_xml= false,
86
opt_delete_master_logs= false, tty_password= false,
87
opt_single_transaction= false, opt_comments= false,
88
opt_compact= false, opt_hex_blob= false,
89
opt_order_by_primary=false, opt_ignore= false,
90
opt_complete_insert= false, opt_drop_database= false,
91
opt_replace_into= false,
93
opt_slave_apply= false,
94
opt_include_master_host_port= false,
96
static bool debug_info_flag= false, debug_check_flag= false;
97
static uint32_t opt_max_allowed_packet, opt_net_buffer_length, show_progress_size= 0;
98
static uint64_t total_rows= 0;
99
static DRIZZLE drizzleclient_connection, *drizzle= 0;
94
100
static string insert_pat;
95
static char *opt_password=0,*current_user=0,
96
*current_host=0,*path=0,*fields_terminated=0,
97
*lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
98
*where=0, *order_by=0,
99
*opt_compatible_mode_str= 0,
101
*log_error_file= NULL;
102
static char **defaults_argv= 0;
101
static char *opt_password= NULL, *current_user= NULL,
102
*current_host= NULL, *path= NULL, *fields_terminated= NULL,
103
*lines_terminated= NULL, *enclosed= NULL, *opt_enclosed= NULL,
105
*where= NULL, *order_by= NULL,
106
*opt_compatible_mode_str= NULL,
108
static char **defaults_argv= NULL;
103
109
static char compatible_mode_normal_str[255];
104
/* Server supports character_set_results session variable? */
105
static bool server_supports_switching_charsets= true;
106
110
static uint32_t opt_compatible_mode= 0;
107
111
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
108
112
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
109
113
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
110
114
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
111
static uint opt_drizzle_port= 0, opt_master_data;
112
static uint opt_slave_data;
113
static uint my_end_arg;
114
static int first_error=0;
115
static uint32_t opt_drizzle_port= 0;
116
static uint32_t opt_master_data;
117
static uint32_t opt_slave_data;
118
static uint32_t my_end_arg;
119
static int first_error= 0;
115
120
static string extended_row;
116
121
FILE *md_result_file= 0;
117
FILE *stderror_file=0;
122
FILE *stderror_file= 0;
120
125
Constant for detection of default value of default_charset.
242
238
"Option automatically turns --lock-tables off.",
243
239
(char**) &opt_slave_data, (char**) &opt_slave_data, 0,
244
240
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
245
{"events", 'E', "Dump events.",
246
(char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
247
NO_ARG, 0, 0, 0, 0, 0, 0},
248
241
{"extended-insert", 'e',
249
242
"Allows utilization of the new, much faster INSERT syntax.",
250
243
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
274
267
"--lock-all-tables or --master-data with --flush-logs",
275
268
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
277
{"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
278
"after dumping the DRIZZLE database. This option should be used any "
279
"time the dump contains the DRIZZLE database and any other database "
280
"that depends on the data in the DRIZZLE database for proper restore. ",
281
(char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
283
270
{"force", 'f', "Continue even if we get an sql-error.",
284
271
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
285
272
0, 0, 0, 0, 0, 0},
314
301
0, 0, 0, 0, 0, 0},
315
302
{"lock-tables", 'l', "Lock all tables for read.", (char**) &lock_tables,
316
303
(char**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
317
{"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.",
318
(char**) &log_error_file, (char**) &log_error_file, 0, GET_STR,
319
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
320
304
{"master-data", OPT_MASTER_DATA,
321
305
"This causes the binary log position and filename to be appended to the "
322
306
"output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
331
315
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
332
316
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
333
317
(char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
334
GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
318
GET_UINT32, REQUIRED_ARG, 24*1024*1024, 4096,
335
319
(int64_t) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
336
320
{"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
337
321
(char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
338
GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
322
GET_UINT32, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
339
323
MALLOC_OVERHEAD-1024, 1024, 0},
340
324
{"no-autocommit", OPT_AUTOCOMMIT,
341
325
"Wrap tables with autocommit/commit statements.",
342
326
(char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
343
327
0, 0, 0, 0, 0, 0},
344
328
{"no-create-db", 'n',
345
"'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
329
"'CREATE DATABASE IF NOT EXISTS db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
346
330
(char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
348
332
{"no-create-info", 't', "Don't write table creation info.",
359
343
{"order-by-primary", OPT_ORDER_BY_PRIMARY,
360
344
"Sorts each table's rows by primary key, or first unique key, if such a key exists. Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer.",
361
345
(char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
363
347
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
364
348
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
365
{"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
366
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
349
{"port", 'p', "Port number to use for connection.",
350
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
368
351
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
369
352
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
370
353
{"quote-names",'Q', "Quote table and column names with backticks (`).",
379
362
{"routines", 'R', "Dump stored routines (functions and procedures).",
380
363
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
381
364
NO_ARG, 0, 0, 0, 0, 0, 0},
382
{"set-charset", OPT_SET_CHARSET,
383
"Add 'SET NAMES default_character_set' to the output.",
384
(char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
386
{"set-variable", 'O',
387
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
388
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
390
366
Note that the combination --single-transaction --master-data
391
367
will give bullet-proof binlog position only if server >=4.1.3. That's the
414
390
(char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
415
391
{"tables", OPT_TABLES, "Overrides option --databases (-B).",
416
392
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
417
{"tz-utc", OPT_TZ_UTC,
418
"SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones.",
419
(char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
393
{"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of rows before each output progress report (requires --verbose)."),
394
(char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
395
10000, 0, 0, 0, 0, 0},
420
396
#ifndef DONT_ALLOW_USER_CHANGE
421
397
{"user", 'u', "User for login if not current user.",
422
398
(char**) ¤t_user, (char**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
486
463
static void check_io(FILE *file)
488
465
if (ferror(file))
489
die(EX_EOF, "Got errno %d on write", errno);
466
die(EX_EOF, _("Got errno %d on write"), errno);
492
469
static void print_version(void)
494
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
495
drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
471
printf(_("%s Ver %s Distrib %s, for %s (%s)\n"),my_progname,DUMP_VERSION,
472
drizzleclient_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
496
473
} /* print_version */
499
476
static void short_usage_sub(void)
501
printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
502
printf("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n",
478
printf(_("Usage: %s [OPTIONS] database [tables]\n"), my_progname);
479
printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
504
printf("OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname);
481
printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), my_progname);
508
485
static void usage(void)
511
puts("By Igor Romanenko, Monty, Jani & Sinisa");
512
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
513
puts("Dumping definition and data DRIZZLE database or table");
488
puts(_("By Igor Romanenko, Monty, Jani & Sinisa"));
489
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"));
490
puts(_("Dumping definition and data DRIZZLE database or table"));
514
491
short_usage_sub();
515
print_defaults("my",load_default_groups);
492
print_defaults("drizzle",load_default_groups);
516
493
my_print_help(my_long_options);
517
494
my_print_variables(my_long_options);
628
static unsigned char* get_table_key(const char *entry, size_t *length,
629
bool not_used __attribute__((unused)))
592
static unsigned char* get_table_key(const char *entry, size_t *length, bool)
631
594
*length= strlen(entry);
632
595
return (unsigned char*) entry;
637
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
600
bool get_one_option(int optid, const struct my_option *, char *argument)
603
uint64_t temp_drizzle_port= 0;
607
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
608
/* if there is an alpha character this is not a valid port */
609
if (strlen(endchar) != 0)
611
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
614
/* If the port number is > 65535 it is not a valid port
615
* This also helps with potential data loss casting unsigned long to a
617
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
619
fprintf(stderr, _("Value supplied for port is not valid.\n"));
624
opt_drizzle_port= (uint32_t) temp_drizzle_port;
644
char *start=argument;
646
opt_password=my_strdup(argument,MYF(MY_FAE));
647
while (*argument) *argument++= 'x'; /* Destroy argument */
630
char *start= argument;
633
opt_password= strdup(argument);
634
if (opt_password == NULL)
636
fprintf(stderr, _("Memory allocation error while copying password. "
642
/* Overwriting password with 'x' */
649
start[1]=0; /* Cut length of argument */
647
/* Cut length of argument */
656
if (!(md_result_file= my_fopen(argument, O_WRONLY | FILE_BINARY,
658
if (!(md_result_file= fopen(argument, "w")))
767
770
static int get_options(int *argc, char ***argv)
770
const DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
773
const DRIZZLE_PARAMETERS *drizzle_params= drizzleclient_get_parameters();
772
775
opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
773
776
opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
775
778
md_result_file= stdout;
776
load_defaults("my",load_default_groups,argc,argv);
779
load_defaults("drizzle",load_default_groups,argc,argv);
777
780
defaults_argv= *argv;
779
782
if (hash_init(&ignore_table, charset_info, 16, 0, 0,
780
783
(hash_get_key) get_table_key,
781
784
(hash_free_key) free_table_ent, 0))
783
/* Don't copy internal log tables */
784
if (my_hash_insert(&ignore_table,
785
(unsigned char*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
786
my_hash_insert(&ignore_table,
787
(unsigned char*) my_strdup("mysql.schema", MYF(MY_WME))) ||
788
my_hash_insert(&ignore_table,
789
(unsigned char*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
790
my_hash_insert(&ignore_table,
791
(unsigned char*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
792
my_hash_insert(&ignore_table,
793
(unsigned char*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
794
my_hash_insert(&ignore_table,
795
(unsigned char*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
798
787
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
799
788
return(ho_error);
961
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
949
static int drizzleclient_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
962
950
const char *query)
964
if (drizzle_query(drizzle_con, query) ||
965
(res && !((*res)= drizzle_store_result(drizzle_con))))
952
if (drizzleclient_query(drizzle_con, query) ||
953
(res && !((*res)= drizzleclient_store_result(drizzle_con))))
967
maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
968
query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
955
maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
956
query, drizzleclient_error(drizzle_con), drizzleclient_errno(drizzle_con));
976
Switch charset for results to some specified charset. If the server does not
977
support character_set_results variable, nothing can be done here. As for
978
whether something should be done here, future new callers of this function
979
should be aware that the server lacking the facility of switching charsets is
982
@note If the server lacks support, then nothing is changed and no error
983
condition is returned.
985
@returns whether there was an error or not
987
static int switch_character_set_results(DRIZZLE *drizzle, const char *cs_name)
989
char query_buffer[QUERY_LENGTH];
992
/* Server lacks facility. This is not an error, by arbitrary decision . */
993
if (!server_supports_switching_charsets)
996
query_length= snprintf(query_buffer,
997
sizeof (query_buffer),
998
"SET SESSION character_set_results = '%s'",
999
(const char *) cs_name);
1001
return drizzle_real_query(drizzle, query_buffer, query_length);
1005
963
Open a new .sql file to dump the table or view into
1056
1014
static int connect_to_db(char *host, char *user,char *passwd)
1058
char buff[20+FN_REFLEN];
1061
verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1062
drizzle_create(&drizzle_connection);
1016
verbose_msg(_("-- Connecting to %s...\n"), host ? host : "localhost");
1017
drizzleclient_create(&drizzleclient_connection);
1063
1018
if (opt_compress)
1064
drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NULL);
1065
if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
1019
drizzleclient_options(&drizzleclient_connection,DRIZZLE_OPT_COMPRESS,NULL);
1020
if (!(drizzle= drizzleclient_connect(&drizzleclient_connection,host,user,passwd,
1066
1021
NULL,opt_drizzle_port, NULL,
1069
DB_error(&drizzle_connection, "when trying to connect");
1024
DB_error(&drizzleclient_connection, "when trying to connect");
1072
if (drizzle_get_server_version(&drizzle_connection) < 40100)
1074
/* Don't dump SET NAMES with a pre-4.1 server (bug#7997). */
1077
/* Don't switch charsets for 4.1 and earlier. (bug#34192). */
1078
server_supports_switching_charsets= false;
1081
set time_zone to UTC to allow dumping date types between servers with
1082
different time zone settings
1086
snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1087
if (drizzle_query_with_error_report(drizzle, 0, buff))
1091
1029
} /* connect_to_db */
1424
1362
table_type - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW"
1425
1363
ignore_flag - what we must particularly ignore - see IGNORE_ defines above
1364
num_fields - number of fields in the table
1428
number of fields in table, 0 if error
1367
true if success, false if error
1431
static uint get_table_structure(char *table, char *db, char *table_type,
1370
static bool get_table_structure(char *table, char *db, char *table_type,
1371
char *ignore_flag, uint64_t *num_fields)
1434
1373
bool init=0, delayed, write_data, complete_insert;
1435
uint64_t num_fields;
1436
1374
char *result_table, *opt_quoted_table;
1437
1375
const char *insert_option;
1438
1376
char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3];
1439
1377
char table_buff2[NAME_LEN*2+3], query_buff[QUERY_LENGTH];
1440
1378
FILE *sql_file= md_result_file;
1442
1379
DRIZZLE_RES *result;
1443
1380
DRIZZLE_ROW row;
1448
1385
if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED))
1451
verbose_msg("-- Warning: Unable to use delayed inserts for table '%s' "
1452
"because it's of type %s\n", table, table_type);
1388
verbose_msg(_("-- Warning: Unable to use delayed inserts for table '%s' "
1389
"because it's of type %s\n"), table, table_type);
1455
1392
complete_insert= 0;
1456
1393
if ((write_data= !(*ignore_flag & IGNORE_DATA)))
1458
1395
complete_insert= opt_complete_insert;
1462
1399
insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " :
1463
1400
delayed ? " DELAYED " : opt_ignore ? " IGNORE " : "");
1465
verbose_msg("-- Retrieving table structure for table %s...\n", table);
1467
len= snprintf(query_buff, sizeof(query_buff),
1468
"SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
1469
(opt_quoted || opt_keywords));
1402
verbose_msg(_("-- Retrieving table structure for table %s...\n"), table);
1471
1404
result_table= quote_name(table, table_buff, 1);
1472
1405
opt_quoted_table= quote_name(table, table_buff2, 0);
1516
Even if the "table" is a view, we do a DROP TABLE here. The
1517
view-specific code below fills in the DROP VIEW.
1443
Even if the "table" is a view, we do a DROP TABLE here.
1519
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
1445
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table);
1521
1446
check_io(sql_file);
1524
field= drizzle_fetch_field_direct(result, 0);
1525
if (strcmp(field->name, "View") == 0)
1527
char *scv_buff= NULL;
1529
verbose_msg("-- It's a view, create dummy table for view\n");
1531
/* save "show create" statement for later */
1532
if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1533
scv_buff= my_strdup(scv_buff, MYF(0));
1535
drizzle_free_result(result);
1538
Create a table with the same name as the view and with columns of
1539
the same name in order to satisfy views that depend on this view.
1540
The table will be removed when the actual view is created.
1542
The properties of each column, aside from the data type, are not
1543
preserved in this temporary table, because they are not necessary.
1545
This will not be necessary once we can determine dependencies
1546
between views and can simply dump them in the appropriate order.
1548
snprintf(query_buff, sizeof(query_buff),
1549
"SHOW FIELDS FROM %s", result_table);
1550
if (switch_character_set_results(drizzle, "binary") ||
1551
drizzle_query_with_error_report(drizzle, &result, query_buff) ||
1552
switch_character_set_results(drizzle, default_charset))
1555
View references invalid or privileged table/col/fun (err 1356),
1556
so we cannot create a stand-in table. Be defensive and dump
1557
a comment with the view's 'show create' statement. (Bug #17371)
1560
if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1561
fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1570
if (drizzle_num_rows(result))
1575
We have already dropped any table of the same name above, so
1576
here we just drop the view.
1579
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
1585
"/*!50001 CREATE TABLE %s (\n",
1589
Get first row, following loop will prepend comma - keeps from
1590
having to know if the row being printed is last to determine if
1591
there should be a _trailing_ comma.
1594
row= drizzle_fetch_row(result);
1596
fprintf(sql_file, " %s %s", quote_name(row[0], name_buff, 0),
1599
while((row= drizzle_fetch_row(result)))
1601
/* col name, col type */
1602
fprintf(sql_file, ",\n %s %s",
1603
quote_name(row[0], name_buff, 0), row[1]);
1605
fprintf(sql_file, "\n) */;\n");
1609
drizzle_free_result(result);
1612
my_fclose(sql_file, MYF(MY_WME));
1618
row= drizzle_fetch_row(result);
1449
field= drizzleclient_fetch_field_direct(result, 0);
1451
row= drizzleclient_fetch_row(result);
1620
1453
fprintf(sql_file, "%s;\n", row[1]);
1622
1455
check_io(sql_file);
1623
drizzle_free_result(result);
1456
drizzleclient_free_result(result);
1625
1458
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1627
if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1460
if (drizzleclient_query_with_error_report(drizzle, &result, query_buff))
1630
my_fclose(sql_file, MYF(MY_WME));
1768
1601
check_io(sql_file);
1771
num_fields= drizzle_num_rows(result);
1772
drizzle_free_result(result);
1604
*num_fields= drizzleclient_num_rows(result);
1605
drizzleclient_free_result(result);
1773
1606
if (!opt_no_create_info)
1775
1608
/* Make an sql-file, if path was given iow. option -T was given */
1776
1609
char buff[20+FN_REFLEN];
1777
uint keynr,primary_key;
1610
uint32_t keynr,primary_key;
1778
1611
snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1779
if (drizzle_query_with_error_report(drizzle, &result, buff))
1612
if (drizzleclient_query_with_error_report(drizzle, &result, buff))
1781
if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
1614
if (drizzleclient_errno(drizzle) == ER_WRONG_OBJECT)
1783
1616
/* it is VIEW */
1784
1617
fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1785
1618
goto continue_xml;
1787
fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1788
my_progname, result_table, drizzle_error(drizzle));
1620
fprintf(stderr, _("%s: Can't get keys for table %s (%s)\n"),
1621
my_progname, result_table, drizzleclient_error(drizzle));
1790
my_fclose(sql_file, MYF(MY_WME));
1794
1627
/* Find first which key is primary key */
1796
1629
primary_key=INT_MAX;
1797
while ((row= drizzle_fetch_row(result)))
1630
while ((row= drizzleclient_fetch_row(result)))
1799
1632
if (atoi(row[3]) == 1)
1858
1690
snprintf(buff, sizeof(buff), "show table status like %s",
1859
1691
quote_for_like(table, show_name_buff));
1861
if (drizzle_query_with_error_report(drizzle, &result, buff))
1693
if (drizzleclient_query_with_error_report(drizzle, &result, buff))
1863
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
1695
if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
1864
1696
{ /* If old DRIZZLE version */
1865
verbose_msg("-- Warning: Couldn't get status information for " \
1866
"table %s (%s)\n", result_table,drizzle_error(drizzle));
1697
verbose_msg(_("-- Warning: Couldn't get status information for " \
1698
"table %s (%s)\n"), result_table,drizzleclient_error(drizzle));
1869
else if (!(row= drizzle_fetch_row(result)))
1701
else if (!(row= drizzleclient_fetch_row(result)))
1871
1703
fprintf(stderr,
1872
"Error: Couldn't read status information for table %s (%s)\n",
1873
result_table,drizzle_error(drizzle));
1704
_("Error: Couldn't read status information for table %s (%s)\n"),
1705
result_table,drizzleclient_error(drizzle));
2032
1862
if (ignore_flag & IGNORE_DATA)
2034
verbose_msg("-- Warning: Skipping data for table '%s' because " \
2035
"it's of type %s\n", table, table_type);
1864
verbose_msg(_("-- Warning: Skipping data for table '%s' because " \
1865
"it's of type %s\n"), table, table_type);
2038
1868
/* Check that there are any fields in the table */
2039
1869
if (num_fields == 0)
2041
verbose_msg("-- Skipping dump data for table '%s', it has no fields\n",
1871
verbose_msg(_("-- Skipping dump data for table '%s', it has no fields\n"),
2047
Check --skip-events flag: it is not enough to skip creation of events
2048
discarding SHOW CREATE EVENT statements generation. The myslq.event
2049
table data should be skipped too.
2051
if (!opt_events && !my_strcasecmp(&my_charset_utf8_general_ci, db, "mysql") &&
2052
!my_strcasecmp(&my_charset_utf8_general_ci, table, "event"))
2054
verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2058
1876
result_table= quote_name(table,table_buff, 1);
2059
1877
opt_quoted_table= quote_name(table, table_buff2, 0);
2061
verbose_msg("-- Sending SELECT query...\n");
1879
verbose_msg(_("-- Sending SELECT query...\n"));
2063
1881
query_string.clear();
2064
1882
query_string.reserve(1024);
2156
1971
fputs("\n", md_result_file);
2157
1972
check_io(md_result_file);
2159
if (drizzle_query_with_error_report(drizzle, 0, query_string.c_str()))
1974
if (drizzleclient_query_with_error_report(drizzle, 0, query_string.c_str()))
2161
DB_error(drizzle, "when retrieving data from server");
1976
DB_error(drizzle, _("when retrieving data from server"));
2165
res=drizzle_use_result(drizzle);
1980
res=drizzleclient_use_result(drizzle);
2167
res=drizzle_store_result(drizzle);
1982
res=drizzleclient_store_result(drizzle);
2170
DB_error(drizzle, "when retrieving data from server");
1985
DB_error(drizzle, _("when retrieving data from server"));
2174
verbose_msg("-- Retrieving rows...\n");
2175
if (drizzle_num_fields(res) != num_fields)
1989
verbose_msg(_("-- Retrieving rows...\n"));
1990
if (drizzleclient_num_fields(res) != num_fields)
2177
fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n",
1992
fprintf(stderr,_("%s: Error in field count for table: %s ! Aborting.\n"),
2178
1993
my_progname, result_table);
2179
1994
error= EX_CONSCHECK;
2630
2450
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NULL);
2631
2451
if (lock_tables)
2634
query= "LOCK TABLES ";
2453
string query("LOCK TABLES ");
2635
2454
for (numrows= 0 ; (table= getTableName(1)) ; )
2637
char *end= my_stpcpy(afterdot, table);
2456
char *end= strcpy(afterdot, table) + strlen(table);
2638
2457
if (include_table((unsigned char*) hash_key,end - hash_key))
2641
2460
query.append( quote_name(table, table_buff, 1));
2642
query.append( " READ /*!32311 LOCAL */,");
2461
query.append( " READ LOCAL,");
2645
if (numrows && drizzle_real_query(drizzle, query.c_str(), query.length()-1))
2646
DB_error(drizzle, "when using LOCK TABLES");
2464
if (numrows && drizzleclient_real_query(drizzle, query.c_str(), query.length()-1))
2465
DB_error(drizzle, _("when using LOCK TABLES"));
2647
2466
/* We shall continue here, if --force was given */
2650
2469
if (flush_logs)
2652
if (drizzle_refresh(drizzle, REFRESH_LOG))
2653
DB_error(drizzle, "when doing refresh");
2471
if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
2472
DB_error(drizzle, _("when doing refresh"));
2654
2473
/* We shall continue here, if --force was given */
2656
2475
while ((table= getTableName(0)))
2658
char *end= my_stpcpy(afterdot, table);
2477
char *end= strcpy(afterdot, table) + strlen(table);
2659
2478
if (include_table((unsigned char*) hash_key, end - hash_key))
2661
2480
dump_table(table,database);
2947
2761
DRIZZLE_RES *slave;
2948
2762
/* We need to check if the slave sql is stopped in the first place */
2949
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2763
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2953
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2767
DRIZZLE_ROW row= drizzleclient_fetch_row(slave);
2954
2768
if (row && row[11])
2956
2770
/* if SLAVE SQL is not running, we don't start it */
2957
2771
if (!strcmp(row[11],"Yes"))
2959
drizzle_free_result(slave);
2773
drizzleclient_free_result(slave);
2960
2774
/* Silently assume that they don't have the slave running */
2965
drizzle_free_result(slave);
2779
drizzleclient_free_result(slave);
2967
2781
/* now, start slave if stopped */
2968
if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
2782
if (drizzleclient_query_with_error_report(drizzle_con, 0, "START SLAVE"))
2970
my_printf_error(0, "Error: Unable to start slave", MYF(0));
2784
my_printf_error(0, _("Error: Unable to start slave"), MYF(0));
2986
2800
update starts between the two FLUSHes, we have that bad stall.
2989
( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
2990
drizzle_query_with_error_report(drizzle_con, 0,
2803
( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
2804
drizzleclient_query_with_error_report(drizzle_con, 0,
2991
2805
"FLUSH TABLES WITH READ LOCK") );
2995
2809
static int do_unlock_tables(DRIZZLE *drizzle_con)
2997
return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
2811
return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
3000
2814
static int get_bin_log_name(DRIZZLE *drizzle_con,
3001
char* buff_log_name, uint buff_len)
2815
char* buff_log_name, uint32_t buff_len)
3003
2817
DRIZZLE_RES *res;
3004
2818
DRIZZLE_ROW row;
3006
if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
3007
!(res= drizzle_store_result(drizzle)))
2820
if (drizzleclient_query(drizzle_con, "SHOW MASTER STATUS") ||
2821
!(res= drizzleclient_store_result(drizzle)))
3010
if (!(row= drizzle_fetch_row(res)))
2824
if (!(row= drizzleclient_fetch_row(res)))
3012
drizzle_free_result(res);
2826
drizzleclient_free_result(res);
3016
2830
Only one row is returned, and the first column is the name of the
3019
strmake(buff_log_name, row[0], buff_len - 1);
2833
strncpy(buff_log_name, row[0], buff_len - 1);
3021
drizzle_free_result(res);
2835
drizzleclient_free_result(res);
3028
2842
string str= "PURGE BINARY LOGS TO '";
3029
2843
str.append(log_name);
3030
2844
str.append("'");
3031
err = drizzle_query_with_error_report(drizzle_con, 0, str.c_str());
2845
err = drizzleclient_query_with_error_report(drizzle_con, 0, str.c_str());
3036
2850
static int start_transaction(DRIZZLE *drizzle_con)
3039
We use BEGIN for old servers. --single-transaction --master-data will fail
3040
on old servers, but that's ok as it was already silently broken (it didn't
3041
do a consistent read, so better tell people frankly, with the error).
3043
We want the first consistent read to be used for all tables to dump so we
3044
need the REPEATABLE READ level (not anything lower, for example READ
3045
COMMITTED would give one new consistent read per dumped table).
3047
if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
3049
fprintf(stderr, "-- %s: the combination of --single-transaction and "
3050
"--master-data requires a DRIZZLE server version of at least 4.1 "
3051
"(current server's version is %s). %s\n",
3052
ignore_errors ? "Warning" : "Error",
3053
drizzle_con->server_version ? drizzle_con->server_version : "unknown",
3054
ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3056
exit(EX_DRIZZLEERR);
3059
return (drizzle_query_with_error_report(drizzle_con, 0,
2852
return (drizzleclient_query_with_error_report(drizzle_con, 0,
3060
2853
"SET SESSION TRANSACTION ISOLATION "
3061
2854
"LEVEL REPEATABLE READ") ||
3062
drizzle_query_with_error_report(drizzle_con, 0,
2855
drizzleclient_query_with_error_report(drizzle_con, 0,
3063
2856
"START TRANSACTION "
3064
"/*!40100 WITH CONSISTENT SNAPSHOT */"));
2857
"WITH CONSISTENT SNAPSHOT"));
3068
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
3069
char **err_pos, uint *err_len)
2861
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
2862
char **err_pos, uint32_t *err_len)
3071
2864
const char *end= x + length;
3072
2865
uint32_t found= 0;
3074
2867
char buff[255];
3076
2869
*err_pos= 0; /* No error yet */
3164
2981
char result= IGNORE_NONE;
3165
2982
char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
2983
const char *number_of_rows= NULL;
3166
2984
DRIZZLE_RES *res= NULL;
3167
2985
DRIZZLE_ROW row;
3170
2987
/* Check memory for quote_for_like() */
3171
2988
assert(2*sizeof(table_name) < sizeof(show_name_buff));
3172
2989
snprintf(buff, sizeof(buff), "show table status like %s",
3173
2990
quote_for_like(table_name, show_name_buff));
3174
if (drizzle_query_with_error_report(drizzle, &res, buff))
2991
if (drizzleclient_query_with_error_report(drizzle, &res, buff))
3176
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
2993
if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
3177
2994
{ /* If old DRIZZLE version */
3178
verbose_msg("-- Warning: Couldn't get status information for "
3179
"table %s (%s)\n", table_name, drizzle_error(drizzle));
2995
verbose_msg(_("-- Warning: Couldn't get status information for "
2996
"table %s (%s)\n"), table_name, drizzleclient_error(drizzle));
3180
2997
return(result); /* assume table is ok */
3183
if (!(row= drizzle_fetch_row(res)))
3000
if (!(row= drizzleclient_fetch_row(res)))
3185
3002
fprintf(stderr,
3186
"Error: Couldn't read status information for table %s (%s)\n",
3187
table_name, drizzle_error(drizzle));
3188
drizzle_free_result(res);
3003
_("Error: Couldn't read status information for table %s (%s)\n"),
3004
table_name, drizzleclient_error(drizzle));
3005
drizzleclient_free_result(res);
3189
3006
return(result); /* assume table is ok */
3192
strmake(table_type, "VIEW", NAME_LEN-1);
3196
If the table type matches any of these, we do support delayed inserts.
3197
Note: we do not want to skip dumping this table if if is not one of
3198
these types, but we do want to use delayed inserts in the dump if
3199
the table type is _NOT_ one of these types
3010
if ((number_of_rows= fetch_named_row(res, row, "Rows")) != NULL)
3012
total_rows= strtoul(number_of_rows, NULL, 10);
3016
If the table type matches any of these, we do support delayed inserts.
3017
Note: we do not want to skip dumping this table if if is not one of
3018
these types, but we do want to use delayed inserts in the dump if
3019
the table type is _NOT_ one of these types
3201
strmake(table_type, row[1], NAME_LEN-1);
3022
strncpy(table_type, row[1], NAME_LEN-1);
3202
3023
if (opt_delayed)
3204
3025
if (strcmp(table_type,"MyISAM") &&
3205
strcmp(table_type,"ISAM") &&
3206
3026
strcmp(table_type,"ARCHIVE") &&
3207
3027
strcmp(table_type,"HEAP") &&
3208
3028
strcmp(table_type,"MEMORY"))
3209
3029
result= IGNORE_INSERT_DELAYED;
3213
If these two types, we do want to skip dumping the table
3216
(!my_strcasecmp(&my_charset_utf8_general_ci, table_type, "MRG_MyISAM") ||
3217
!strcmp(table_type,"MRG_ISAM")))
3218
result= IGNORE_DATA;
3220
drizzle_free_result(res);
3032
drizzleclient_free_result(res);
3221
3033
return(result);
3246
3058
DRIZZLE_ROW row;
3247
3059
/* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3248
3060
char show_keys_buff[15 + NAME_LEN * 2 + 3];
3249
uint result_length= 0;
3061
uint32_t result_length= 0;
3250
3062
char *result= 0;
3251
3063
char buff[NAME_LEN * 2 + 3];
3252
3064
char *quoted_field;
3254
3066
snprintf(show_keys_buff, sizeof(show_keys_buff),
3255
3067
"SHOW KEYS FROM %s", table_name);
3256
if (drizzle_query(drizzle, show_keys_buff) ||
3257
!(res= drizzle_store_result(drizzle)))
3068
if (drizzleclient_query(drizzle, show_keys_buff) ||
3069
!(res= drizzleclient_store_result(drizzle)))
3259
fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3260
" records are NOT sorted (%s)\n",
3261
table_name, drizzle_error(drizzle));
3071
fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
3072
" records are NOT sorted (%s)\n"),
3073
table_name, drizzleclient_error(drizzle));
3262
3074
/* Don't exit, because it's better to print out unsorted records */
3286
3098
/* result (terminating \0 is already in result_length) */
3287
result= (char *)my_malloc(result_length + 10, MYF(MY_WME));
3099
result= (char *)malloc(result_length + 10);
3290
fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
3102
fprintf(stderr, _("Error: Not enough memory to store ORDER BY clause\n"));
3293
drizzle_data_seek(res, 0);
3294
row= drizzle_fetch_row(res);
3105
drizzleclient_data_seek(res, 0);
3106
row= drizzleclient_fetch_row(res);
3295
3107
quoted_field= quote_name(row[4], buff, 0);
3296
end= my_stpcpy(result, quoted_field);
3297
while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
3108
end= strcpy(result, quoted_field) + strlen(quoted_field);
3109
while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1)
3299
3111
quoted_field= quote_name(row[4], buff, 0);
3300
end= strxmov(end, ",", quoted_field, NULL);
3112
end+= sprintf(end,",%s",quoted_field);
3306
drizzle_free_result(res);
3118
drizzleclient_free_result(res);