13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* mysqldump.c - Dump a tables contents and format to an ASCII file
16
/* drizzledump.c - Dump a tables contents and format to an ASCII file
18
18
** The author's original notes follow :-
22
22
** WARRANTY: None, expressed, impressed, implied
24
24
** STATUS: Public domain
25
** Adapted and optimized for MySQL by
25
** Adapted and optimized for DRIZZLE by
26
26
** Michael Widenius, Sinisa Milivojevic, Jani Tolonen
27
27
** -w --where added 9/10/98 by Jim Faucette
28
28
** slave code by David Saez Padros <david@ols.es>
31
31
** Andrei Errapart <andreie@no.spam.ee>
32
32
** Tõnu Samuel <tonu@please.do.not.remove.this.spam.ee>
33
33
** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up
34
** and adapted to mysqldump 05/11/01 by Jani Tolonen
34
** and adapted to drizzledump 05/11/01 by Jani Tolonen
35
35
** Added --single-transaction option 06/06/2002 by Peter Zaitsev
36
36
** 10 Jun 2003: SET NAMES and --no-set-names by Alexander Barkov
100
100
opt_alltspcs=0, opt_notspcs= 0;
101
101
static 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
static MYSQL mysql_connection,*mysql=0;
103
static DRIZZLE drizzle_connection,*drizzle=0;
104
104
static DYNAMIC_STRING insert_pat;
105
105
static char *opt_password=0,*current_user=0,
106
106
*current_host=0,*path=0,*fields_terminated=0,
114
114
/* Server supports character_set_results session variable? */
115
115
static bool server_supports_switching_charsets= true;
116
116
static ulong opt_compatible_mode= 0;
117
#define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1
118
#define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2
119
#define MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
120
#define MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL 2
121
static uint opt_mysql_port= 0, opt_master_data;
117
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
118
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
119
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
120
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
121
static uint opt_drizzle_port= 0, opt_master_data;
122
122
static uint opt_slave_data;
123
123
static uint my_end_arg;
124
124
static int first_error=0;
142
142
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size);
144
144
Constant for detection of default value of default_charset.
145
If default_charset is equal to mysql_universal_client_charset, then
145
If default_charset is equal to drizzle_universal_client_charset, then
146
146
it is the default value which assigned at the very beginning of main().
148
static const char *mysql_universal_client_charset=
148
static const char *drizzle_universal_client_charset=
149
149
MYSQL_UNIVERSAL_CLIENT_CHARSET;
150
150
static char *default_charset;
151
151
static CHARSET_INFO *charset_info= &my_charset_latin1;
152
const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
152
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
153
153
/* have we seen any VIEWs during table scanning? */
154
154
bool seen_views= 0;
155
155
const char *compatible_mode_names[]=
202
202
{"allow-keywords", OPT_KEYWORDS,
203
203
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
204
204
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
205
{"apply-slave-statements", OPT_MYSQLDUMP_SLAVE_APPLY,
205
{"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
206
206
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
207
207
(char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
208
208
0, 0, 0, 0, 0, 0},
213
213
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
214
214
1, 0, 0, 0, 0, 0},
215
215
{"compatible", OPT_COMPATIBLE,
216
"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.",
216
"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 DRIZZLE server version 4.1.0 or higher. This option is ignored with earlier server versions.",
217
217
(char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
218
218
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
219
219
{"compact", OPT_COMPACT,
227
227
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
229
229
{"create-options", OPT_CREATE_OPTIONS,
230
"Include all MySQL specific create options.",
230
"Include all DRIZZLE specific create options.",
231
231
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
233
233
{"databases", 'B',
253
253
{"disable-keys", 'K',
254
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
255
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
256
{"dump-slave", OPT_MYSQLDUMP_SLAVE_DATA,
256
{"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
257
257
"This causes the binary log position and filename of the master to be "
258
258
"appended to the dumped data output. Setting the value to 1, will print"
259
259
"it as a CHANGE MASTER command in the dumped data output; if equal"
265
265
"any action on logs will happen at the exact moment of the dump."
266
266
"Option automatically turns --lock-tables off.",
267
267
(char**) &opt_slave_data, (char**) &opt_slave_data, 0,
268
GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
268
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
269
269
{"events", 'E', "Dump events.",
270
270
(char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
271
271
NO_ARG, 0, 0, 0, 0, 0, 0},
299
299
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
301
301
{"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
302
"after dumping the mysql database. This option should be used any "
303
"time the dump contains the mysql database and any other database "
304
"that depends on the data in the mysql database for proper restore. ",
302
"after dumping the DRIZZLE database. This option should be used any "
303
"time the dump contains the DRIZZLE database and any other database "
304
"that depends on the data in the DRIZZLE database for proper restore. ",
305
305
(char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
307
307
{"force", 'f', "Continue even if we get an sql-error.",
319
319
"use the directive multiple times, once for each table. Each table must "
320
320
"be specified with both database and table names, e.g. --ignore-table=database.table",
321
321
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
322
{"include-master-host-port", OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT,
322
{"include-master-host-port", OPT_DRIZZLEDUMP_INCLUDE_MASTER_HOST_PORT,
323
323
"Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
324
324
(char**) &opt_include_master_host_port,
325
325
(char**) &opt_include_master_host_port,
352
352
"any action on logs will happen at the exact moment of the dump."
353
353
"Option automatically turns --lock-tables off.",
354
354
(char**) &opt_master_data, (char**) &opt_master_data, 0,
355
GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
355
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
356
356
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
357
357
(char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
358
358
GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
386
386
{"password", 'p',
387
387
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
388
388
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,
389
{"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
390
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
392
392
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
393
393
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
394
394
{"quote-names",'Q', "Quote table and column names with backticks (`).",
395
395
(char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
397
{"replace", OPT_MYSQL_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
397
{"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
398
398
(char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
400
400
{"result-file", 'r',
457
457
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
460
static const char *load_default_groups[]= { "mysqldump","client",0 };
460
static const char *load_default_groups[]= { "drizzledump","client",0 };
462
462
static void maybe_exit(int error);
463
463
static void die(int error, const char* reason, ...);
464
464
static void maybe_die(int error, const char* reason, ...);
465
465
static void write_header(FILE *sql_file, char *db_name);
466
static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
466
static void print_value(FILE *file, DRIZZLE_RES *result, DRIZZLE_ROW row,
467
467
const char *prefix,const char *name,
468
468
int string_value);
469
469
static int dump_selected_tables(char *db, char **table_names, int tables);
535
535
puts("By Igor Romanenko, Monty, Jani & Sinisa");
536
536
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");
537
puts("Dumping definition and data mysql database or table");
537
puts("Dumping definition and data DRIZZLE database or table");
538
538
short_usage_sub();
539
539
print_defaults("my",load_default_groups);
540
540
my_print_help(my_long_options);
557
557
Schema reference. Allows use of xsi:nil for NULL values and
558
558
xsi:type to define an element's data type.
560
fputs("<mysqldump ", sql_file);
560
fputs("<drizzledump ", sql_file);
561
561
fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
563
563
fputs(">\n", sql_file);
568
568
if (opt_comments)
570
570
fprintf(sql_file,
571
"-- MySQL dump %s Distrib %s, for %s (%s)\n--\n",
571
"-- DRIZZLE dump %s Distrib %s, for %s (%s)\n--\n",
572
572
DUMP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
573
573
fprintf(sql_file, "-- Host: %s Database: %s\n",
574
574
current_host ? current_host : "localhost", db_name ? db_name :
715
715
case (int) OPT_MASTER_DATA:
716
716
if (!argument) /* work like in old versions */
717
opt_master_data= MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL;
717
opt_master_data= DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL;
719
case (int) OPT_MYSQLDUMP_SLAVE_DATA:
719
case (int) OPT_DRIZZLEDUMP_SLAVE_DATA:
720
720
if (!argument) /* work like in old versions */
721
opt_slave_data= MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL;
721
opt_slave_data= DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL;
723
723
case (int) OPT_OPTIMIZE:
724
724
extended_insert= opt_drop= opt_lock= quick= create_options=
794
794
static int get_options(int *argc, char ***argv)
797
MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
797
DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
799
opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
800
opt_net_buffer_length= *mysql_params->p_net_buffer_length;
799
opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
800
opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
802
802
md_result_file= stdout;
803
803
load_defaults("my",load_default_groups,argc,argv);
825
825
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
826
826
return(ho_error);
828
*mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
829
*mysql_params->p_net_buffer_length= opt_net_buffer_length;
828
*drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
829
*drizzle_params->p_net_buffer_length= opt_net_buffer_length;
830
830
if (debug_info_flag)
831
831
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
832
832
if (debug_check_flag)
853
853
/* Ensure consistency of the set of binlog & locking options */
854
854
if (opt_delete_master_logs && !opt_master_data)
855
opt_master_data= MYSQL_OPT_MASTER_DATA_COMMENTED_SQL;
855
opt_master_data= DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL;
856
856
if (opt_single_transaction && opt_lock_all_tables)
858
858
fprintf(stderr, "%s: You can't use --single-transaction and "
897
** DB_error -- prints mysql error message and exits the program.
897
** DB_error -- prints DRIZZLE error message and exits the program.
899
static void DB_error(MYSQL *mysql_arg, const char *when)
899
static void DB_error(DRIZZLE *drizzle_arg, const char *when)
902
maybe_die(EX_MYSQLERR, "Got error: %d: %s %s",
903
mysql_errno(mysql_arg), mysql_error(mysql_arg), when);
902
maybe_die(EX_DRIZZLEERR, "Got error: %d: %s %s",
903
drizzle_errno(drizzle_arg), drizzle_error(drizzle_arg), when);
988
static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res,
988
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
989
989
const char *query)
991
if (mysql_query(mysql_con, query) ||
992
(res && !((*res)= mysql_store_result(mysql_con))))
991
if (drizzle_query(drizzle_con, query) ||
992
(res && !((*res)= drizzle_store_result(drizzle_con))))
994
maybe_die(EX_MYSQLERR, "Couldn't execute '%s': %s (%d)",
995
query, mysql_error(mysql_con), mysql_errno(mysql_con));
994
maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
995
query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
1092
1092
verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1093
mysql_init(&mysql_connection);
1093
drizzle_create(&drizzle_connection);
1094
1094
if (opt_compress)
1095
mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS);
1095
drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NullS);
1096
1096
if (opt_protocol)
1097
mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
1098
mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
1099
if (!(mysql= mysql_real_connect(&mysql_connection,host,user,passwd,
1100
NULL,opt_mysql_port, NULL,
1097
drizzle_options(&drizzle_connection,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
1098
drizzle_options(&drizzle_connection, DRIZZLE_SET_CHARSET_NAME, default_charset);
1099
if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
1100
NULL,opt_drizzle_port, NULL,
1103
DB_error(&mysql_connection, "when trying to connect");
1103
DB_error(&drizzle_connection, "when trying to connect");
1106
if (mysql_get_server_version(&mysql_connection) < 40100)
1106
if (drizzle_get_server_version(&drizzle_connection) < 40100)
1108
1108
/* Don't dump SET NAMES with a pre-4.1 server (bug#7997). */
1109
1109
opt_set_charset= 0;
1142
1142
if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1143
die(EX_MYSQLERR, "Couldn't allocate memory");
1143
die(EX_DRIZZLEERR, "Couldn't allocate memory");
1145
mysql_real_escape_string(&mysql_connection, tmp, pos, length);
1145
drizzle_real_escape_string(&drizzle_connection, tmp, pos, length);
1146
1146
fputc('\'', file);
1147
1147
fputs(tmp, file);
1148
1148
fputc('\'', file);
1210
1210
Quote \, _, ' and % characters
1212
Note: Because MySQL uses the C escape syntax in strings
1212
Note: Because DRIZZLE uses the C escape syntax in strings
1213
1213
(for example, '\n' to represent newline), you must double
1214
1214
any '\' that you use in your LIKE strings. For example, to
1215
1215
search for '\n', specify it as '\\n'. To search for '\', specify
1401
1401
static void print_xml_row(FILE *xml_file, const char *row_name,
1402
MYSQL_RES *tableRes, MYSQL_ROW *row)
1402
DRIZZLE_RES *tableRes, DRIZZLE_ROW *row)
1406
uint32_t *lengths= mysql_fetch_lengths(tableRes);
1405
DRIZZLE_FIELD *field;
1406
uint32_t *lengths= drizzle_fetch_lengths(tableRes);
1408
1408
fprintf(xml_file, "\t\t<%s", row_name);
1409
1409
check_io(xml_file);
1410
mysql_field_seek(tableRes, 0);
1411
for (i= 0; (field= mysql_fetch_field(tableRes)); i++)
1410
drizzle_field_seek(tableRes, 0);
1411
for (i= 0; (field= drizzle_fetch_field(tableRes)); i++)
1517
1517
order_by= primary_key_fields(result_table);
1520
if (!opt_xml && !mysql_query_with_error_report(mysql, 0, query_buff))
1520
if (!opt_xml && !drizzle_query_with_error_report(drizzle, 0, query_buff))
1522
1522
/* using SHOW CREATE statement */
1523
1523
if (!opt_no_create_info)
1525
1525
/* Make an sql-file, if path was given iow. option -T was given */
1526
1526
char buff[20+FN_REFLEN];
1527
DRIZZLE_FIELD *field;
1529
1529
snprintf(buff, sizeof(buff), "show create table %s", result_table);
1531
if (switch_character_set_results(mysql, "binary") ||
1532
mysql_query_with_error_report(mysql, &result, buff) ||
1533
switch_character_set_results(mysql, default_charset))
1531
if (switch_character_set_results(drizzle, "binary") ||
1532
drizzle_query_with_error_report(drizzle, &result, buff) ||
1533
switch_character_set_results(drizzle, default_charset))
1569
1569
verbose_msg("-- It's a view, create dummy table for view\n");
1571
1571
/* save "show create" statement for later */
1572
if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
1572
if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1573
1573
scv_buff= my_strdup(scv_buff, MYF(0));
1575
mysql_free_result(result);
1575
drizzle_free_result(result);
1578
1578
Create a table with the same name as the view and with columns of
1588
1588
snprintf(query_buff, sizeof(query_buff),
1589
1589
"SHOW FIELDS FROM %s", result_table);
1590
if (switch_character_set_results(mysql, "binary") ||
1591
mysql_query_with_error_report(mysql, &result, query_buff) ||
1592
switch_character_set_results(mysql, default_charset))
1590
if (switch_character_set_results(drizzle, "binary") ||
1591
drizzle_query_with_error_report(drizzle, &result, query_buff) ||
1592
switch_character_set_results(drizzle, default_charset))
1595
1595
View references invalid or privileged table/col/fun (err 1356),
1597
1597
a comment with the view's 'show create' statement. (Bug #17371)
1600
if (mysql_errno(mysql) == ER_VIEW_INVALID)
1600
if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1601
1601
fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1603
1603
my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1633
1633
there should be a _trailing_ comma.
1636
row= mysql_fetch_row(result);
1636
row= drizzle_fetch_row(result);
1638
1638
fprintf(sql_file, " %s %s", quote_name(row[0], name_buff, 0),
1641
while((row= mysql_fetch_row(result)))
1641
while((row= drizzle_fetch_row(result)))
1643
1643
/* col name, col type */
1644
1644
fprintf(sql_file, ",\n %s %s",
1672
1672
check_io(sql_file);
1673
mysql_free_result(result);
1673
drizzle_free_result(result);
1675
1675
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1677
if (mysql_query_with_error_report(mysql, &result, query_buff))
1677
if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1680
1680
my_fclose(sql_file, MYF(MY_WME));
1721
1721
quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1724
num_fields= mysql_num_rows(result);
1725
mysql_free_result(result);
1724
num_fields= drizzle_num_rows(result);
1725
drizzle_free_result(result);
1729
1729
verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
1730
my_progname, mysql_error(mysql));
1730
my_progname, drizzle_error(drizzle));
1732
1732
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1734
if (mysql_query_with_error_report(mysql, &result, query_buff))
1734
if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1737
1737
/* Make an sql-file, if path was given iow. option -T was given */
1820
1820
check_io(sql_file);
1823
num_fields= mysql_num_rows(result);
1824
mysql_free_result(result);
1823
num_fields= drizzle_num_rows(result);
1824
drizzle_free_result(result);
1825
1825
if (!opt_no_create_info)
1827
1827
/* Make an sql-file, if path was given iow. option -T was given */
1828
1828
char buff[20+FN_REFLEN];
1829
1829
uint keynr,primary_key;
1830
1830
snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1831
if (mysql_query_with_error_report(mysql, &result, buff))
1831
if (drizzle_query_with_error_report(drizzle, &result, buff))
1833
if (mysql_errno(mysql) == ER_WRONG_OBJECT)
1833
if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
1835
1835
/* it is VIEW */
1836
1836
fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1837
1837
goto continue_xml;
1839
1839
fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1840
my_progname, result_table, mysql_error(mysql));
1840
my_progname, result_table, drizzle_error(drizzle));
1842
1842
my_fclose(sql_file, MYF(MY_WME));
1910
1910
snprintf(buff, sizeof(buff), "show table status like %s",
1911
1911
quote_for_like(table, show_name_buff));
1913
if (mysql_query_with_error_report(mysql, &result, buff))
1913
if (drizzle_query_with_error_report(drizzle, &result, buff))
1915
if (mysql_errno(mysql) != ER_PARSE_ERROR)
1916
{ /* If old MySQL version */
1915
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
1916
{ /* If old DRIZZLE version */
1917
1917
verbose_msg("-- Warning: Couldn't get status information for " \
1918
"table %s (%s)\n", result_table,mysql_error(mysql));
1918
"table %s (%s)\n", result_table,drizzle_error(drizzle));
1921
else if (!(row= mysql_fetch_row(result)))
1921
else if (!(row= drizzle_fetch_row(result)))
1923
1923
fprintf(stderr,
1924
1924
"Error: Couldn't read status information for table %s (%s)\n",
1925
result_table,mysql_error(mysql));
1925
result_table,drizzle_error(drizzle));
2162
2162
dynstr_append_checked(&query_string, order_by);
2165
if (mysql_real_query(mysql, query_string.str, query_string.length))
2165
if (drizzle_real_query(drizzle, query_string.str, query_string.length))
2167
DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
2167
DB_error(drizzle, "when executing 'SELECT INTO OUTFILE'");
2168
2168
dynstr_free(&query_string);
2208
2208
fputs("\n", md_result_file);
2209
2209
check_io(md_result_file);
2211
if (mysql_query_with_error_report(mysql, 0, query_string.str))
2211
if (drizzle_query_with_error_report(drizzle, 0, query_string.str))
2213
DB_error(mysql, "when retrieving data from server");
2213
DB_error(drizzle, "when retrieving data from server");
2217
res=mysql_use_result(mysql);
2217
res=drizzle_use_result(drizzle);
2219
res=mysql_store_result(mysql);
2219
res=drizzle_store_result(drizzle);
2222
DB_error(mysql, "when retrieving data from server");
2222
DB_error(drizzle, "when retrieving data from server");
2226
2226
verbose_msg("-- Retrieving rows...\n");
2227
if (mysql_num_fields(res) != num_fields)
2227
if (drizzle_num_fields(res) != num_fields)
2229
2229
fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n",
2230
2230
my_progname, result_table);
2258
2258
check_io(md_result_file);
2261
while ((row= mysql_fetch_row(res)))
2261
while ((row= drizzle_fetch_row(res)))
2264
uint32_t *lengths= mysql_fetch_lengths(res);
2264
uint32_t *lengths= drizzle_fetch_lengths(res);
2266
2266
if (!extended_insert && !opt_xml)
2268
2268
fputs(insert_pat.str,md_result_file);
2269
2269
check_io(md_result_file);
2271
mysql_field_seek(res,0);
2271
drizzle_field_seek(res,0);
2276
2276
check_io(md_result_file);
2279
for (i= 0; i < mysql_num_fields(res); i++)
2279
for (i= 0; i < drizzle_num_fields(res); i++)
2282
2282
ulong length= lengths[i];
2284
if (!(field= mysql_fetch_field(res)))
2284
if (!(field= drizzle_fetch_field(res)))
2285
2285
die(EX_CONSCHECK,
2286
2286
"Not enough fields from table %s! Aborting.\n",
2320
2320
if (opt_hex_blob && is_blob)
2322
2322
dynstr_append_checked(&extended_row, "0x");
2323
extended_row.length+= mysql_hex_string(extended_row.str +
2323
extended_row.length+= drizzle_hex_string(extended_row.str +
2324
2324
extended_row.length,
2325
2325
row[i], length);
2326
2326
assert(extended_row.length+1 <= extended_row.max_length);
2327
/* mysql_hex_string() already terminated string by '\0' */
2327
/* drizzle_hex_string() already terminated string by '\0' */
2328
2328
assert(extended_row.str[extended_row.length] == '\0');
2332
2332
dynstr_append_checked(&extended_row,"'");
2333
2333
extended_row.length +=
2334
mysql_real_escape_string(&mysql_connection,
2334
drizzle_real_escape_string(&drizzle_connection,
2335
2335
&extended_row.str[extended_row.length],
2336
2336
row[i],length);
2337
2337
extended_row.str[extended_row.length]='\0';
2468
2468
fputs(";\n", md_result_file); /* If not empty table */
2469
2469
fflush(md_result_file);
2470
2470
check_io(md_result_file);
2471
if (mysql_errno(mysql))
2471
if (drizzle_errno(drizzle))
2473
2473
snprintf(buf, sizeof(buf),
2474
2474
"%s: Error %d: %s when dumping table %s at row: %ld\n",
2476
drizzle_errno(drizzle),
2477
drizzle_error(drizzle),
2480
2480
fputs(buf,stderr);
2514
2514
static char *getTableName(int reset)
2516
static MYSQL_RES *res= NULL;
2516
static DRIZZLE_RES *res= NULL;
2521
if (!(res= mysql_list_tables(mysql,NullS)))
2521
if (!(res= drizzle_list_tables(drizzle,NullS)))
2524
if ((row= mysql_fetch_row(res)))
2524
if ((row= drizzle_fetch_row(res)))
2525
2525
return((char*) row[0]);
2528
mysql_data_seek(res,0); /* We want to read again */
2528
drizzle_data_seek(res,0); /* We want to read again */
2531
mysql_free_result(res);
2531
drizzle_free_result(res);
2538
2538
static int dump_all_databases()
2541
MYSQL_RES *tableres;
2541
DRIZZLE_RES *tableres;
2544
if (mysql_query_with_error_report(mysql, &tableres, "SHOW DATABASES"))
2544
if (drizzle_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
2546
while ((row= mysql_fetch_row(tableres)))
2546
while ((row= drizzle_fetch_row(tableres)))
2548
2548
if (dump_all_tables_in_db(row[0]))
2587
2587
if (!opt_create_db)
2589
2589
char qbuf[256];
2591
DRIZZLE_RES *dbinfo;
2593
2593
snprintf(qbuf, sizeof(qbuf),
2594
2594
"SHOW CREATE DATABASE IF NOT EXISTS %s",
2597
if (mysql_query(mysql, qbuf) || !(dbinfo = mysql_store_result(mysql)))
2597
if (drizzle_query(drizzle, qbuf) || !(dbinfo = drizzle_store_result(drizzle)))
2599
2599
/* Old server version, dump generic CREATE DATABASE */
2600
2600
if (opt_drop_database)
2611
2611
fprintf(md_result_file,
2612
2612
"\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2614
row = mysql_fetch_row(dbinfo);
2614
row = drizzle_fetch_row(dbinfo);
2617
2617
fprintf(md_result_file,"\n%s;\n",row[1]);
2619
mysql_free_result(dbinfo);
2619
drizzle_free_result(dbinfo);
2626
2626
static int init_dumping(char *database, int init_func(char*))
2628
if (mysql_get_server_version(mysql) >= 50003 &&
2628
if (drizzle_get_server_version(drizzle) >= 50003 &&
2629
2629
!my_strcasecmp(&my_charset_latin1, database, "information_schema"))
2632
if (mysql_select_db(mysql, database))
2632
if (drizzle_select_db(drizzle, database))
2634
DB_error(mysql, "when selecting the database");
2634
DB_error(drizzle, "when selecting the database");
2635
2635
return 1; /* If --force */
2637
2637
if (!path && !opt_xml)
2701
2701
dynstr_append_checked(&query, " READ /*!32311 LOCAL */,");
2704
if (numrows && mysql_real_query(mysql, query.str, query.length-1))
2705
DB_error(mysql, "when using LOCK TABLES");
2704
if (numrows && drizzle_real_query(drizzle, query.str, query.length-1))
2705
DB_error(drizzle, "when using LOCK TABLES");
2706
2706
/* We shall continue here, if --force was given */
2707
2707
dynstr_free(&query);
2709
2709
if (flush_logs)
2711
if (mysql_refresh(mysql, REFRESH_LOG))
2712
DB_error(mysql, "when doing refresh");
2711
if (drizzle_refresh(drizzle, REFRESH_LOG))
2712
DB_error(drizzle, "when doing refresh");
2713
2713
/* We shall continue here, if --force was given */
2715
2715
while ((table= getTableName(0)))
2728
2728
check_io(md_result_file);
2730
2730
if (lock_tables)
2731
VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
2731
VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2732
2732
if (flush_privileges && using_mysql_db == 0)
2734
2734
fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2763
2763
snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2764
2764
quote_for_like(old_table_name, show_name_buff));
2766
if (mysql_query_with_error_report(mysql, 0, query))
2766
if (drizzle_query_with_error_report(drizzle, 0, query))
2769
if ((table_res= mysql_store_result(mysql)))
2769
if ((table_res= drizzle_store_result(drizzle)))
2771
uint64_t num_rows= mysql_num_rows(table_res);
2771
uint64_t num_rows= drizzle_num_rows(table_res);
2772
2772
if (num_rows > 0)
2774
2774
uint32_t *lengths;
2776
2776
Return first row
2777
2777
TODO: Return all matching rows
2779
row= mysql_fetch_row(table_res);
2780
lengths= mysql_fetch_lengths(table_res);
2779
row= drizzle_fetch_row(table_res);
2780
lengths= drizzle_fetch_lengths(table_res);
2781
2781
name= strmake_root(root, row[0], lengths[0]);
2783
mysql_free_result(table_res);
2783
drizzle_free_result(table_res);
2838
2838
dynstr_free(&lock_tables_query);
2839
2839
free_root(&root, MYF(0));
2841
DB_error(mysql, "when doing LOCK TABLES");
2841
DB_error(drizzle, "when doing LOCK TABLES");
2842
2842
/* We shall countinue here, if --force was given */
2845
2845
dynstr_free(&lock_tables_query);
2846
2846
if (flush_logs)
2848
if (mysql_refresh(mysql, REFRESH_LOG))
2848
if (drizzle_refresh(drizzle, REFRESH_LOG))
2850
2850
if (!ignore_errors)
2851
2851
free_root(&root, MYF(0));
2852
DB_error(mysql, "when doing refresh");
2852
DB_error(drizzle, "when doing refresh");
2854
2854
/* We shall countinue here, if --force was given */
2869
2869
check_io(md_result_file);
2871
2871
if (lock_tables)
2872
VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
2872
VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2874
2874
} /* dump_selected_tables */
2877
static int do_show_master_status(MYSQL *mysql_con)
2877
static int do_show_master_status(DRIZZLE *drizzle_con)
2880
DRIZZLE_RES *master;
2881
2881
const char *comment_prefix=
2882
(opt_master_data == MYSQL_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2883
if (mysql_query_with_error_report(mysql_con, &master, "SHOW MASTER STATUS"))
2882
(opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2883
if (drizzle_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2889
row= mysql_fetch_row(master);
2889
row= drizzle_fetch_row(master);
2890
2890
if (row && row[0] && row[1])
2892
2892
/* SHOW MASTER STATUS reports file and position */
2904
2904
/* SHOW MASTER STATUS reports nothing and --force is not enabled */
2905
2905
my_printf_error(0, "Error: Binlogging on server not active",
2907
mysql_free_result(master);
2908
maybe_exit(EX_MYSQLERR);
2907
drizzle_free_result(master);
2908
maybe_exit(EX_DRIZZLEERR);
2911
mysql_free_result(master);
2911
drizzle_free_result(master);
2916
static int do_stop_slave_sql(MYSQL *mysql_con)
2916
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
2919
2919
/* We need to check if the slave sql is running in the first place */
2920
if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
2920
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2924
MYSQL_ROW row= mysql_fetch_row(slave);
2924
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2925
2925
if (row && row[11])
2927
2927
/* if SLAVE SQL is not running, we don't stop it */
2928
2928
if (!strcmp(row[11],"No"))
2930
mysql_free_result(slave);
2930
drizzle_free_result(slave);
2931
2931
/* Silently assume that they don't have the slave running */
2936
mysql_free_result(slave);
2936
drizzle_free_result(slave);
2938
2938
/* now, stop slave if running */
2939
if (mysql_query_with_error_report(mysql_con, 0, "STOP SLAVE SQL_THREAD"))
2939
if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2963
static int do_show_slave_status(MYSQL *mysql_con)
2963
static int do_show_slave_status(DRIZZLE *drizzle_con)
2966
2966
const char *comment_prefix=
2967
(opt_slave_data == MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2968
if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
2967
(opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2968
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2970
2970
if (!ignore_errors)
3000
3000
check_io(md_result_file);
3002
mysql_free_result(slave);
3002
drizzle_free_result(slave);
3007
static int do_start_slave_sql(MYSQL *mysql_con)
3007
static int do_start_slave_sql(DRIZZLE *drizzle_con)
3010
3010
/* We need to check if the slave sql is stopped in the first place */
3011
if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
3011
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
3015
MYSQL_ROW row= mysql_fetch_row(slave);
3015
DRIZZLE_ROW row= drizzle_fetch_row(slave);
3016
3016
if (row && row[11])
3018
3018
/* if SLAVE SQL is not running, we don't start it */
3019
3019
if (!strcmp(row[11],"Yes"))
3021
mysql_free_result(slave);
3021
drizzle_free_result(slave);
3022
3022
/* Silently assume that they don't have the slave running */
3027
mysql_free_result(slave);
3027
drizzle_free_result(slave);
3029
3029
/* now, start slave if stopped */
3030
if (mysql_query_with_error_report(mysql_con, 0, "START SLAVE"))
3030
if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
3032
3032
my_printf_error(0, "Error: Unable to start slave", MYF(0));
3048
3048
update starts between the two FLUSHes, we have that bad stall.
3051
( mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES") ||
3052
mysql_query_with_error_report(mysql_con, 0,
3051
( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
3052
drizzle_query_with_error_report(drizzle_con, 0,
3053
3053
"FLUSH TABLES WITH READ LOCK") );
3057
static int do_unlock_tables(MYSQL *mysql_con)
3057
static int do_unlock_tables(DRIZZLE *drizzle_con)
3059
return mysql_query_with_error_report(mysql_con, 0, "UNLOCK TABLES");
3059
return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
3062
static int get_bin_log_name(MYSQL *mysql_con,
3062
static int get_bin_log_name(DRIZZLE *drizzle_con,
3063
3063
char* buff_log_name, uint buff_len)
3068
if (mysql_query(mysql_con, "SHOW MASTER STATUS") ||
3069
!(res= mysql_store_result(mysql)))
3068
if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
3069
!(res= drizzle_store_result(drizzle)))
3072
if (!(row= mysql_fetch_row(res)))
3072
if (!(row= drizzle_fetch_row(res)))
3074
mysql_free_result(res);
3074
drizzle_free_result(res);
3081
3081
strmake(buff_log_name, row[0], buff_len - 1);
3083
mysql_free_result(res);
3083
drizzle_free_result(res);
3087
static int purge_bin_logs_to(MYSQL *mysql_con, char* log_name)
3087
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
3089
3089
DYNAMIC_STRING str;
3091
3091
init_dynamic_string_checked(&str, "PURGE BINARY LOGS TO '", 1024, 1024);
3092
3092
dynstr_append_checked(&str, log_name);
3093
3093
dynstr_append_checked(&str, "'");
3094
err = mysql_query_with_error_report(mysql_con, 0, str.str);
3094
err = drizzle_query_with_error_report(drizzle_con, 0, str.str);
3095
3095
dynstr_free(&str);
3100
static int start_transaction(MYSQL *mysql_con)
3100
static int start_transaction(DRIZZLE *drizzle_con)
3103
3103
We use BEGIN for old servers. --single-transaction --master-data will fail
3108
3108
need the REPEATABLE READ level (not anything lower, for example READ
3109
3109
COMMITTED would give one new consistent read per dumped table).
3111
if ((mysql_get_server_version(mysql_con) < 40100) && opt_master_data)
3111
if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
3113
3113
fprintf(stderr, "-- %s: the combination of --single-transaction and "
3114
"--master-data requires a MySQL server version of at least 4.1 "
3114
"--master-data requires a DRIZZLE server version of at least 4.1 "
3115
3115
"(current server's version is %s). %s\n",
3116
3116
ignore_errors ? "Warning" : "Error",
3117
mysql_con->server_version ? mysql_con->server_version : "unknown",
3117
drizzle_con->server_version ? drizzle_con->server_version : "unknown",
3118
3118
ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3119
3119
if (!ignore_errors)
3120
exit(EX_DRIZZLEERR);
3123
return (mysql_query_with_error_report(mysql_con, 0,
3123
return (drizzle_query_with_error_report(drizzle_con, 0,
3124
3124
"SET SESSION TRANSACTION ISOLATION "
3125
3125
"LEVEL REPEATABLE READ") ||
3126
mysql_query_with_error_report(mysql_con, 0,
3126
drizzle_query_with_error_report(drizzle_con, 0,
3127
3127
"START TRANSACTION "
3128
3128
"/*!40100 WITH CONSISTENT SNAPSHOT */"));
3173
3173
/* Print a value with a prefix on file */
3174
static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
3174
static void print_value(FILE *file, DRIZZLE_RES *result, DRIZZLE_ROW row,
3175
3175
const char *prefix, const char *name,
3176
3176
int string_value)
3179
mysql_field_seek(result, 0);
3178
DRIZZLE_FIELD *field;
3179
drizzle_field_seek(result, 0);
3181
for ( ; (field= mysql_fetch_field(result)) ; row++)
3181
for ( ; (field= drizzle_fetch_field(result)) ; row++)
3183
3183
if (!strcmp(field->name,name))
3228
3228
char result= IGNORE_NONE;
3229
3229
char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3230
MYSQL_RES *res= NULL;
3230
DRIZZLE_RES *res= NULL;
3234
3234
/* Check memory for quote_for_like() */
3235
3235
assert(2*sizeof(table_name) < sizeof(show_name_buff));
3236
3236
snprintf(buff, sizeof(buff), "show table status like %s",
3237
3237
quote_for_like(table_name, show_name_buff));
3238
if (mysql_query_with_error_report(mysql, &res, buff))
3238
if (drizzle_query_with_error_report(drizzle, &res, buff))
3240
if (mysql_errno(mysql) != ER_PARSE_ERROR)
3241
{ /* If old MySQL version */
3240
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
3241
{ /* If old DRIZZLE version */
3242
3242
verbose_msg("-- Warning: Couldn't get status information for "
3243
"table %s (%s)\n", table_name, mysql_error(mysql));
3243
"table %s (%s)\n", table_name, drizzle_error(drizzle));
3244
3244
return(result); /* assume table is ok */
3247
if (!(row= mysql_fetch_row(res)))
3247
if (!(row= drizzle_fetch_row(res)))
3249
3249
fprintf(stderr,
3250
3250
"Error: Couldn't read status information for table %s (%s)\n",
3251
table_name, mysql_error(mysql));
3252
mysql_free_result(res);
3251
table_name, drizzle_error(drizzle));
3252
drizzle_free_result(res);
3253
3253
return(result); /* assume table is ok */
3318
3318
snprintf(show_keys_buff, sizeof(show_keys_buff),
3319
3319
"SHOW KEYS FROM %s", table_name);
3320
if (mysql_query(mysql, show_keys_buff) ||
3321
!(res= mysql_store_result(mysql)))
3320
if (drizzle_query(drizzle, show_keys_buff) ||
3321
!(res= drizzle_store_result(drizzle)))
3323
3323
fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3324
3324
" records are NOT sorted (%s)\n",
3325
table_name, mysql_error(mysql));
3325
table_name, drizzle_error(drizzle));
3326
3326
/* Don't exit, because it's better to print out unsorted records */
3333
3333
* row, and UNIQUE keys come before others. So we only need to check
3334
3334
* the first key, not all keys.
3336
if ((row= mysql_fetch_row(res)) && atoi(row[1]) == 0)
3336
if ((row= drizzle_fetch_row(res)) && atoi(row[1]) == 0)
3338
3338
/* Key is unique */
3341
3341
quoted_field= quote_name(row[4], buff, 0);
3342
3342
result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3343
} while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1);
3343
} while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1);
3346
3346
/* Build the ORDER BY clause result */
3354
3354
fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
3357
mysql_data_seek(res, 0);
3358
row= mysql_fetch_row(res);
3357
drizzle_data_seek(res, 0);
3358
row= drizzle_fetch_row(res);
3359
3359
quoted_field= quote_name(row[4], buff, 0);
3360
3360
end= strmov(result, quoted_field);
3361
while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1)
3361
while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
3363
3363
quoted_field= quote_name(row[4], buff, 0);
3364
3364
end= strxmov(end, ",", quoted_field, NullS);
3383
3383
uint init_alloc, uint alloc_increment)
3385
3385
if (init_dynamic_string(str, init_str, init_alloc, alloc_increment))
3386
die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3386
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3389
3389
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src)
3391
3391
if (dynstr_append(dest, src))
3392
die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3392
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3395
3395
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str)
3397
3397
if (dynstr_set(str, init_str))
3398
die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3398
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3401
3401
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
3404
3404
if (dynstr_append_mem(str, append, length))
3405
die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3405
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3408
3408
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size)
3410
3410
if (dynstr_realloc(str, additional_size))
3411
die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3411
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3434
3434
if(!(stderror_file= freopen(log_error_file, "a+", stderr)))
3436
3436
free_resources();
3437
exit(EX_DRIZZLEERR);
3441
3441
if (connect_to_db(current_host, current_user, opt_password))
3443
3443
free_resources();
3444
exit(EX_DRIZZLEERR);
3447
3447
write_header(md_result_file, *argv);
3449
if (opt_slave_data && do_stop_slave_sql(mysql))
3449
if (opt_slave_data && do_stop_slave_sql(drizzle))
3452
3452
if ((opt_lock_all_tables || opt_master_data) &&
3453
do_flush_tables_read_lock(mysql))
3453
do_flush_tables_read_lock(drizzle))
3455
if (opt_single_transaction && start_transaction(mysql))
3455
if (opt_single_transaction && start_transaction(drizzle))
3457
3457
if (opt_delete_master_logs)
3459
if (mysql_refresh(mysql, REFRESH_LOG) ||
3460
get_bin_log_name(mysql, bin_log_name, sizeof(bin_log_name)))
3459
if (drizzle_refresh(drizzle, REFRESH_LOG) ||
3460
get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
3464
3464
if (opt_lock_all_tables || opt_master_data)
3466
if (flush_logs && mysql_refresh(mysql, REFRESH_LOG))
3466
if (flush_logs && drizzle_refresh(drizzle, REFRESH_LOG))
3468
3468
flush_logs= 0; /* not anymore; that would not be sensible */
3470
3470
/* Add 'STOP SLAVE to beginning of dump */
3471
3471
if (opt_slave_apply && add_stop_slave())
3473
if (opt_master_data && do_show_master_status(mysql))
3475
if (opt_slave_data && do_show_slave_status(mysql))
3477
if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */
3473
if (opt_master_data && do_show_master_status(drizzle))
3475
if (opt_slave_data && do_show_slave_status(drizzle))
3477
if (opt_single_transaction && do_unlock_tables(drizzle)) /* unlock but no commit! */
3480
3480
if (opt_alldbs)
3503
3503
if (md_result_file && fflush(md_result_file))
3505
3505
if (!first_error)
3506
first_error= EX_MYSQLERR;
3506
first_error= EX_DRIZZLEERR;
3509
3509
/* everything successful, purge the old logs files */
3510
if (opt_delete_master_logs && purge_bin_logs_to(mysql, bin_log_name))
3510
if (opt_delete_master_logs && purge_bin_logs_to(drizzle, bin_log_name))