73
70
char **err_pos, uint *err_len);
75
72
static void field_escape(string &in, const char *from);
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;
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,
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;
97
92
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
98
static DRIZZLE drizzle_connection, *drizzle= 0;
93
static DRIZZLE drizzle_connection,*drizzle=0;
99
94
static string insert_pat;
100
static char *opt_password= NULL, *current_user= NULL,
101
*current_host= NULL, *path= NULL, *fields_terminated= NULL,
102
*lines_terminated= NULL, *enclosed= NULL, *opt_enclosed= NULL,
104
*where= NULL, *order_by= NULL,
105
*opt_compatible_mode_str= NULL,
107
static char **defaults_argv= NULL;
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;
108
103
static char compatible_mode_normal_str[255];
104
/* Server supports character_set_results session variable? */
105
static bool server_supports_switching_charsets= true;
109
106
static uint32_t opt_compatible_mode= 0;
110
107
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
111
108
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
112
109
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
113
110
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
114
static uint32_t opt_drizzle_port= 0;
115
static uint opt_master_data;
111
static uint opt_drizzle_port= 0, opt_master_data;
116
112
static uint opt_slave_data;
117
113
static uint my_end_arg;
118
static int first_error= 0;
114
static int first_error=0;
119
115
static string extended_row;
120
116
FILE *md_result_file= 0;
121
FILE *stderror_file= 0;
117
FILE *stderror_file=0;
124
120
Constant for detection of default value of default_charset.
164
162
"Dump all the tablespaces.",
165
163
(char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
165
{"no-tablespaces", 'y',
166
"Do not dump any tablespace information.",
167
(char**) &opt_notspcs, (char**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
167
169
{"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
168
170
(char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
240
242
"Option automatically turns --lock-tables off.",
241
243
(char**) &opt_slave_data, (char**) &opt_slave_data, 0,
242
244
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
245
{"events", 'E', "Dump events.",
246
(char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
247
NO_ARG, 0, 0, 0, 0, 0, 0},
243
248
{"extended-insert", 'e',
244
249
"Allows utilization of the new, much faster INSERT syntax.",
245
250
(char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
269
274
"--lock-all-tables or --master-data with --flush-logs",
270
275
(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,
272
283
{"force", 'f', "Continue even if we get an sql-error.",
273
284
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
274
285
0, 0, 0, 0, 0, 0},
303
314
0, 0, 0, 0, 0, 0},
304
315
{"lock-tables", 'l', "Lock all tables for read.", (char**) &lock_tables,
305
316
(char**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
317
{"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.",
318
(char**) &log_error_file, (char**) &log_error_file, 0, GET_STR,
319
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
306
320
{"master-data", OPT_MASTER_DATA,
307
321
"This causes the binary log position and filename to be appended to the "
308
322
"output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
345
359
{"order-by-primary", OPT_ORDER_BY_PRIMARY,
346
360
"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.",
347
361
(char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
349
363
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
350
364
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
351
{"port", 'p', "Port number to use for connection.",
352
0, 0, 0, GET_UINT, REQUIRED_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,
353
368
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
354
369
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
355
370
{"quote-names",'Q', "Quote table and column names with backticks (`).",
364
379
{"routines", 'R', "Dump stored routines (functions and procedures).",
365
380
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
366
381
NO_ARG, 0, 0, 0, 0, 0, 0},
382
{"set-variable", 'O',
383
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
384
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
368
386
Note that the combination --single-transaction --master-data
369
387
will give bullet-proof binlog position only if server >=4.1.3. That's the
590
static unsigned char* get_table_key(const char *entry, size_t *length, bool)
608
static unsigned char* get_table_key(const char *entry, size_t *length,
609
bool not_used __attribute__((unused)))
592
611
*length= strlen(entry);
593
612
return (unsigned char*) entry;
598
bool get_one_option(int optid, const struct my_option *, char *argument)
617
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
601
uint64_t temp_drizzle_port= 0;
605
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
606
/* if there is an alpha character this is not a valid port */
607
if (strlen(endchar) != 0)
609
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
612
/* If the port number is > 65535 it is not a valid port
613
* This also helps with potential data loss casting unsigned long to a
615
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
617
fprintf(stderr, _("Value supplied for port is not valid.\n"));
622
opt_drizzle_port= (uint32_t) temp_drizzle_port;
628
char *start= argument;
631
opt_password= strdup(argument);
632
if (opt_password == NULL)
634
fprintf(stderr, "Memory allocation error while copying password. "
640
/* Overwriting password with 'x' */
624
char *start=argument;
626
opt_password=my_strdup(argument,MYF(MY_FAE));
627
while (*argument) *argument++= 'x'; /* Destroy argument */
645
/* Cut length of argument */
629
start[1]=0; /* Cut length of argument */
656
636
if (!(md_result_file= my_fopen(argument, O_WRONLY,
775
753
opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
777
755
md_result_file= stdout;
778
load_defaults("drizzle",load_default_groups,argc,argv);
756
load_defaults("my",load_default_groups,argc,argv);
779
757
defaults_argv= *argv;
781
759
if (hash_init(&ignore_table, charset_info, 16, 0, 0,
782
760
(hash_get_key) get_table_key,
783
761
(hash_free_key) free_table_ent, 0))
763
/* Don't copy internal log tables */
764
if (my_hash_insert(&ignore_table,
765
(unsigned char*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
766
my_hash_insert(&ignore_table,
767
(unsigned char*) my_strdup("mysql.schema", MYF(MY_WME))) ||
768
my_hash_insert(&ignore_table,
769
(unsigned char*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
770
my_hash_insert(&ignore_table,
771
(unsigned char*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
772
my_hash_insert(&ignore_table,
773
(unsigned char*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
774
my_hash_insert(&ignore_table,
775
(unsigned char*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
786
778
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
787
779
return(ho_error);
956
Switch charset for results to some specified charset. If the server does not
957
support character_set_results variable, nothing can be done here. As for
958
whether something should be done here, future new callers of this function
959
should be aware that the server lacking the facility of switching charsets is
962
@note If the server lacks support, then nothing is changed and no error
963
condition is returned.
965
@returns whether there was an error or not
967
static int switch_character_set_results(DRIZZLE *drizzle, const char *cs_name)
969
char query_buffer[QUERY_LENGTH];
972
/* Server lacks facility. This is not an error, by arbitrary decision . */
973
if (!server_supports_switching_charsets)
976
query_length= snprintf(query_buffer,
977
sizeof (query_buffer),
978
"SET SESSION character_set_results = '%s'",
979
(const char *) cs_name);
981
return drizzle_real_query(drizzle, query_buffer, query_length);
963
985
Open a new .sql file to dump the table or view into
1362
1384
table_type - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW"
1363
1385
ignore_flag - what we must particularly ignore - see IGNORE_ defines above
1364
num_fields - number of fields in the table
1367
true if success, false if error
1388
number of fields in table, 0 if error
1370
static bool get_table_structure(char *table, char *db, char *table_type,
1371
char *ignore_flag, uint64_t *num_fields)
1391
static uint get_table_structure(char *table, char *db, char *table_type,
1373
1394
bool init=0, delayed, write_data, complete_insert;
1395
uint64_t num_fields;
1374
1396
char *result_table, *opt_quoted_table;
1375
1397
const char *insert_option;
1376
1398
char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3];
1455
1484
field= drizzle_fetch_field_direct(result, 0);
1485
if (strcmp(field->name, "View") == 0)
1487
char *scv_buff= NULL;
1489
verbose_msg("-- It's a view, create dummy table for view\n");
1491
/* save "show create" statement for later */
1492
if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1493
scv_buff= my_strdup(scv_buff, MYF(0));
1495
drizzle_free_result(result);
1498
Create a table with the same name as the view and with columns of
1499
the same name in order to satisfy views that depend on this view.
1500
The table will be removed when the actual view is created.
1502
The properties of each column, aside from the data type, are not
1503
preserved in this temporary table, because they are not necessary.
1505
This will not be necessary once we can determine dependencies
1506
between views and can simply dump them in the appropriate order.
1508
snprintf(query_buff, sizeof(query_buff),
1509
"SHOW FIELDS FROM %s", result_table);
1510
if (switch_character_set_results(drizzle, "binary") ||
1511
drizzle_query_with_error_report(drizzle, &result, query_buff) ||
1512
switch_character_set_results(drizzle, default_charset))
1515
View references invalid or privileged table/col/fun (err 1356),
1516
so we cannot create a stand-in table. Be defensive and dump
1517
a comment with the view's 'show create' statement. (Bug #17371)
1520
if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1521
fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1530
if (drizzle_num_rows(result))
1535
We have already dropped any table of the same name above, so
1536
here we just drop the view.
1539
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
1545
"/*!50001 CREATE TABLE %s (\n",
1549
Get first row, following loop will prepend comma - keeps from
1550
having to know if the row being printed is last to determine if
1551
there should be a _trailing_ comma.
1554
row= drizzle_fetch_row(result);
1556
fprintf(sql_file, " %s %s", quote_name(row[0], name_buff, 0),
1559
while((row= drizzle_fetch_row(result)))
1561
/* col name, col type */
1562
fprintf(sql_file, ",\n %s %s",
1563
quote_name(row[0], name_buff, 0), row[1]);
1565
fprintf(sql_file, "\n) */;\n");
1569
drizzle_free_result(result);
1572
my_fclose(sql_file, MYF(MY_WME));
1457
1578
row= drizzle_fetch_row(result);
3008
3148
drizzle_free_result(res);
3009
3149
return(result); /* assume table is ok */
3013
If the table type matches any of these, we do support delayed inserts.
3014
Note: we do not want to skip dumping this table if if is not one of
3015
these types, but we do want to use delayed inserts in the dump if
3016
the table type is _NOT_ one of these types
3152
strmake(table_type, "VIEW", NAME_LEN-1);
3156
If the table type matches any of these, we do support delayed inserts.
3157
Note: we do not want to skip dumping this table if if is not one of
3158
these types, but we do want to use delayed inserts in the dump if
3159
the table type is _NOT_ one of these types
3019
strncpy(table_type, row[1], NAME_LEN-1);
3161
strmake(table_type, row[1], NAME_LEN-1);
3020
3162
if (opt_delayed)
3022
3164
if (strcmp(table_type,"MyISAM") &&
3165
strcmp(table_type,"ISAM") &&
3023
3166
strcmp(table_type,"ARCHIVE") &&
3024
3167
strcmp(table_type,"HEAP") &&
3025
3168
strcmp(table_type,"MEMORY"))
3026
3169
result= IGNORE_INSERT_DELAYED;
3173
If these two types, we do want to skip dumping the table
3176
(!my_strcasecmp(&my_charset_utf8_general_ci, table_type, "MRG_MyISAM") ||
3177
!strcmp(table_type,"MRG_ISAM")))
3178
result= IGNORE_DATA;
3029
3180
drizzle_free_result(res);
3030
3181
return(result);