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
39
39
#define DUMP_VERSION "10.13"
41
#include <my_global.h>
41
#include "client_priv.h"
43
#include <mysys/my_sys.h>
44
#include <mystrings/m_string.h>
45
#include <mystrings/m_ctype.h>
46
#include <mysys/hash.h>
46
47
#include <stdarg.h>
48
#include "client_priv.h"
49
#include "drizzle_version.h"
50
#include "mysqld_error.h"
49
#include <drizzled/error.h>
54
#define EX_DRIZZLEERR 2
56
55
#define EX_CONSCHECK 3
58
57
#define EX_EOF 5 /* ferror for output file was got */
100
99
opt_alltspcs=0, opt_notspcs= 0;
101
100
static bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
102
101
static ulong opt_max_allowed_packet, opt_net_buffer_length;
103
static MYSQL mysql_connection,*mysql=0;
102
static DRIZZLE drizzle_connection,*drizzle=0;
104
103
static DYNAMIC_STRING insert_pat;
105
104
static char *opt_password=0,*current_user=0,
106
105
*current_host=0,*path=0,*fields_terminated=0,
114
113
/* Server supports character_set_results session variable? */
115
114
static bool server_supports_switching_charsets= true;
116
115
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;
116
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
117
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
118
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
119
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
120
static uint opt_drizzle_port= 0, opt_master_data;
122
121
static uint opt_slave_data;
123
122
static uint my_end_arg;
124
123
static int first_error=0;
142
141
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size);
144
143
Constant for detection of default value of default_charset.
145
If default_charset is equal to mysql_universal_client_charset, then
144
If default_charset is equal to drizzle_universal_client_charset, then
146
145
it is the default value which assigned at the very beginning of main().
148
static const char *mysql_universal_client_charset=
147
static const char *drizzle_universal_client_charset=
149
148
MYSQL_UNIVERSAL_CLIENT_CHARSET;
150
149
static char *default_charset;
151
150
static CHARSET_INFO *charset_info= &my_charset_latin1;
152
const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
151
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
153
152
/* have we seen any VIEWs during table scanning? */
154
153
bool seen_views= 0;
155
154
const char *compatible_mode_names[]=
202
201
{"allow-keywords", OPT_KEYWORDS,
203
202
"Allow creation of column names that are keywords.", (char**) &opt_keywords,
204
203
(char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
205
{"apply-slave-statements", OPT_MYSQLDUMP_SLAVE_APPLY,
204
{"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
206
205
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
207
206
(char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
208
207
0, 0, 0, 0, 0, 0},
213
212
(char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
214
213
1, 0, 0, 0, 0, 0},
215
214
{"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.",
215
"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
216
(char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
218
217
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
219
218
{"compact", OPT_COMPACT,
227
226
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
229
228
{"create-options", OPT_CREATE_OPTIONS,
230
"Include all MySQL specific create options.",
229
"Include all DRIZZLE specific create options.",
231
230
(char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
233
232
{"databases", 'B',
253
252
{"disable-keys", 'K',
254
253
"'/*!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
254
(char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
256
{"dump-slave", OPT_MYSQLDUMP_SLAVE_DATA,
255
{"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
257
256
"This causes the binary log position and filename of the master to be "
258
257
"appended to the dumped data output. Setting the value to 1, will print"
259
258
"it as a CHANGE MASTER command in the dumped data output; if equal"
265
264
"any action on logs will happen at the exact moment of the dump."
266
265
"Option automatically turns --lock-tables off.",
267
266
(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},
267
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
269
268
{"events", 'E', "Dump events.",
270
269
(char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
271
270
NO_ARG, 0, 0, 0, 0, 0, 0},
299
298
(char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
301
300
{"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. ",
301
"after dumping the DRIZZLE database. This option should be used any "
302
"time the dump contains the DRIZZLE database and any other database "
303
"that depends on the data in the DRIZZLE database for proper restore. ",
305
304
(char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
307
306
{"force", 'f', "Continue even if we get an sql-error.",
319
318
"use the directive multiple times, once for each table. Each table must "
320
319
"be specified with both database and table names, e.g. --ignore-table=database.table",
321
320
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
322
{"include-master-host-port", OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT,
321
{"include-master-host-port", OPT_DRIZZLEDUMP_INCLUDE_MASTER_HOST_PORT,
323
322
"Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
324
323
(char**) &opt_include_master_host_port,
325
324
(char**) &opt_include_master_host_port,
352
351
"any action on logs will happen at the exact moment of the dump."
353
352
"Option automatically turns --lock-tables off.",
354
353
(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},
354
GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
356
355
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
357
356
(char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
358
357
GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
386
385
{"password", 'p',
387
386
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
388
387
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,
388
{"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
389
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
392
391
{"quick", 'q', "Don't buffer query, dump directly to stdout.",
393
392
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
394
393
{"quote-names",'Q', "Quote table and column names with backticks (`).",
395
394
(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.",
396
{"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
398
397
(char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
400
399
{"result-file", 'r',
457
456
{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 };
459
static const char *load_default_groups[]= { "drizzledump","client",0 };
462
461
static void maybe_exit(int error);
463
462
static void die(int error, const char* reason, ...);
464
463
static void maybe_die(int error, const char* reason, ...);
465
464
static void write_header(FILE *sql_file, char *db_name);
466
static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
465
static void print_value(FILE *file, DRIZZLE_RES *result, DRIZZLE_ROW row,
467
466
const char *prefix,const char *name,
468
467
int string_value);
469
468
static int dump_selected_tables(char *db, char **table_names, int tables);
538
534
puts("By Igor Romanenko, Monty, Jani & Sinisa");
539
535
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");
540
puts("Dumping definition and data mysql database or table");
536
puts("Dumping definition and data DRIZZLE database or table");
541
537
short_usage_sub();
542
538
print_defaults("my",load_default_groups);
543
539
my_print_help(my_long_options);
563
556
Schema reference. Allows use of xsi:nil for NULL values and
564
557
xsi:type to define an element's data type.
566
fputs("<mysqldump ", sql_file);
559
fputs("<drizzledump ", sql_file);
567
560
fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
569
562
fputs(">\n", sql_file);
574
567
if (opt_comments)
576
569
fprintf(sql_file,
577
"-- MySQL dump %s Distrib %s, for %s (%s)\n--\n",
570
"-- DRIZZLE dump %s Distrib %s, for %s (%s)\n--\n",
578
571
DUMP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
579
572
fprintf(sql_file, "-- Host: %s Database: %s\n",
580
573
current_host ? current_host : "localhost", db_name ? db_name :
721
714
case (int) OPT_MASTER_DATA:
722
715
if (!argument) /* work like in old versions */
723
opt_master_data= MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL;
716
opt_master_data= DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL;
725
case (int) OPT_MYSQLDUMP_SLAVE_DATA:
718
case (int) OPT_DRIZZLEDUMP_SLAVE_DATA:
726
719
if (!argument) /* work like in old versions */
727
opt_slave_data= MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL;
720
opt_slave_data= DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL;
729
722
case (int) OPT_OPTIMIZE:
730
723
extended_insert= opt_drop= opt_lock= quick= create_options=
800
793
static int get_options(int *argc, char ***argv)
803
MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
796
DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
805
opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
806
opt_net_buffer_length= *mysql_params->p_net_buffer_length;
798
opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
799
opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
808
801
md_result_file= stdout;
809
802
load_defaults("my",load_default_groups,argc,argv);
831
824
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
832
825
return(ho_error);
834
*mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
835
*mysql_params->p_net_buffer_length= opt_net_buffer_length;
827
*drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
828
*drizzle_params->p_net_buffer_length= opt_net_buffer_length;
836
829
if (debug_info_flag)
837
830
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
838
831
if (debug_check_flag)
859
852
/* Ensure consistency of the set of binlog & locking options */
860
853
if (opt_delete_master_logs && !opt_master_data)
861
opt_master_data= MYSQL_OPT_MASTER_DATA_COMMENTED_SQL;
854
opt_master_data= DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL;
862
855
if (opt_single_transaction && opt_lock_all_tables)
864
857
fprintf(stderr, "%s: You can't use --single-transaction and "
903
** DB_error -- prints mysql error message and exits the program.
896
** DB_error -- prints DRIZZLE error message and exits the program.
905
static void DB_error(MYSQL *mysql_arg, const char *when)
898
static void DB_error(DRIZZLE *drizzle_arg, const char *when)
908
maybe_die(EX_MYSQLERR, "Got error: %d: %s %s",
909
mysql_errno(mysql_arg), mysql_error(mysql_arg), when);
901
maybe_die(EX_DRIZZLEERR, "Got error: %d: %s %s",
902
drizzle_errno(drizzle_arg), drizzle_error(drizzle_arg), when);
994
static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res,
987
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
995
988
const char *query)
997
if (mysql_query(mysql_con, query) ||
998
(res && !((*res)= mysql_store_result(mysql_con))))
990
if (drizzle_query(drizzle_con, query) ||
991
(res && !((*res)= drizzle_store_result(drizzle_con))))
1000
maybe_die(EX_MYSQLERR, "Couldn't execute '%s': %s (%d)",
1001
query, mysql_error(mysql_con), mysql_errno(mysql_con));
993
maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
994
query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
1098
1091
verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1099
mysql_init(&mysql_connection);
1092
drizzle_create(&drizzle_connection);
1100
1093
if (opt_compress)
1101
mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS);
1094
drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NullS);
1102
1095
if (opt_protocol)
1103
mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
1104
mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
1105
if (!(mysql= mysql_real_connect(&mysql_connection,host,user,passwd,
1106
NULL,opt_mysql_port, NULL,
1096
drizzle_options(&drizzle_connection,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
1097
drizzle_options(&drizzle_connection, DRIZZLE_SET_CHARSET_NAME, default_charset);
1098
if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
1099
NULL,opt_drizzle_port, NULL,
1109
DB_error(&mysql_connection, "when trying to connect");
1102
DB_error(&drizzle_connection, "when trying to connect");
1112
if (mysql_get_server_version(&mysql_connection) < 40100)
1105
if (drizzle_get_server_version(&drizzle_connection) < 40100)
1114
1107
/* Don't dump SET NAMES with a pre-4.1 server (bug#7997). */
1115
1108
opt_set_charset= 0;
1148
1141
if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1149
die(EX_MYSQLERR, "Couldn't allocate memory");
1142
die(EX_DRIZZLEERR, "Couldn't allocate memory");
1151
mysql_real_escape_string(&mysql_connection, tmp, pos, length);
1144
drizzle_real_escape_string(&drizzle_connection, tmp, pos, length);
1152
1145
fputc('\'', file);
1153
1146
fputs(tmp, file);
1154
1147
fputc('\'', file);
1216
1209
Quote \, _, ' and % characters
1218
Note: Because MySQL uses the C escape syntax in strings
1211
Note: Because DRIZZLE uses the C escape syntax in strings
1219
1212
(for example, '\n' to represent newline), you must double
1220
1213
any '\' that you use in your LIKE strings. For example, to
1221
1214
search for '\n', specify it as '\\n'. To search for '\', specify
1407
1400
static void print_xml_row(FILE *xml_file, const char *row_name,
1408
MYSQL_RES *tableRes, MYSQL_ROW *row)
1401
DRIZZLE_RES *tableRes, DRIZZLE_ROW *row)
1412
uint32_t *lengths= mysql_fetch_lengths(tableRes);
1404
DRIZZLE_FIELD *field;
1405
uint32_t *lengths= drizzle_fetch_lengths(tableRes);
1414
1407
fprintf(xml_file, "\t\t<%s", row_name);
1415
1408
check_io(xml_file);
1416
mysql_field_seek(tableRes, 0);
1417
for (i= 0; (field= mysql_fetch_field(tableRes)); i++)
1409
drizzle_field_seek(tableRes, 0);
1410
for (i= 0; (field= drizzle_fetch_field(tableRes)); i++)
1523
1516
order_by= primary_key_fields(result_table);
1526
if (!opt_xml && !mysql_query_with_error_report(mysql, 0, query_buff))
1519
if (!opt_xml && !drizzle_query_with_error_report(drizzle, 0, query_buff))
1528
1521
/* using SHOW CREATE statement */
1529
1522
if (!opt_no_create_info)
1531
1524
/* Make an sql-file, if path was given iow. option -T was given */
1532
1525
char buff[20+FN_REFLEN];
1526
DRIZZLE_FIELD *field;
1535
1528
snprintf(buff, sizeof(buff), "show create table %s", result_table);
1537
if (switch_character_set_results(mysql, "binary") ||
1538
mysql_query_with_error_report(mysql, &result, buff) ||
1539
switch_character_set_results(mysql, default_charset))
1530
if (switch_character_set_results(drizzle, "binary") ||
1531
drizzle_query_with_error_report(drizzle, &result, buff) ||
1532
switch_character_set_results(drizzle, default_charset))
1575
1568
verbose_msg("-- It's a view, create dummy table for view\n");
1577
1570
/* save "show create" statement for later */
1578
if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
1571
if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1579
1572
scv_buff= my_strdup(scv_buff, MYF(0));
1581
mysql_free_result(result);
1574
drizzle_free_result(result);
1584
1577
Create a table with the same name as the view and with columns of
1594
1587
snprintf(query_buff, sizeof(query_buff),
1595
1588
"SHOW FIELDS FROM %s", result_table);
1596
if (switch_character_set_results(mysql, "binary") ||
1597
mysql_query_with_error_report(mysql, &result, query_buff) ||
1598
switch_character_set_results(mysql, default_charset))
1589
if (switch_character_set_results(drizzle, "binary") ||
1590
drizzle_query_with_error_report(drizzle, &result, query_buff) ||
1591
switch_character_set_results(drizzle, default_charset))
1601
1594
View references invalid or privileged table/col/fun (err 1356),
1603
1596
a comment with the view's 'show create' statement. (Bug #17371)
1606
if (mysql_errno(mysql) == ER_VIEW_INVALID)
1599
if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1607
1600
fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1609
1602
my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1639
1632
there should be a _trailing_ comma.
1642
row= mysql_fetch_row(result);
1635
row= drizzle_fetch_row(result);
1644
1637
fprintf(sql_file, " %s %s", quote_name(row[0], name_buff, 0),
1647
while((row= mysql_fetch_row(result)))
1640
while((row= drizzle_fetch_row(result)))
1649
1642
/* col name, col type */
1650
1643
fprintf(sql_file, ",\n %s %s",
1678
1671
check_io(sql_file);
1679
mysql_free_result(result);
1672
drizzle_free_result(result);
1681
1674
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1683
if (mysql_query_with_error_report(mysql, &result, query_buff))
1676
if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1686
1679
my_fclose(sql_file, MYF(MY_WME));
1727
1720
quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1730
num_fields= mysql_num_rows(result);
1731
mysql_free_result(result);
1723
num_fields= drizzle_num_rows(result);
1724
drizzle_free_result(result);
1735
1728
verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
1736
my_progname, mysql_error(mysql));
1729
my_progname, drizzle_error(drizzle));
1738
1731
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1740
if (mysql_query_with_error_report(mysql, &result, query_buff))
1733
if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1743
1736
/* Make an sql-file, if path was given iow. option -T was given */
1826
1819
check_io(sql_file);
1829
num_fields= mysql_num_rows(result);
1830
mysql_free_result(result);
1822
num_fields= drizzle_num_rows(result);
1823
drizzle_free_result(result);
1831
1824
if (!opt_no_create_info)
1833
1826
/* Make an sql-file, if path was given iow. option -T was given */
1834
1827
char buff[20+FN_REFLEN];
1835
1828
uint keynr,primary_key;
1836
1829
snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1837
if (mysql_query_with_error_report(mysql, &result, buff))
1830
if (drizzle_query_with_error_report(drizzle, &result, buff))
1839
if (mysql_errno(mysql) == ER_WRONG_OBJECT)
1832
if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
1841
1834
/* it is VIEW */
1842
1835
fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1843
1836
goto continue_xml;
1845
1838
fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1846
my_progname, result_table, mysql_error(mysql));
1839
my_progname, result_table, drizzle_error(drizzle));
1848
1841
my_fclose(sql_file, MYF(MY_WME));
1916
1909
snprintf(buff, sizeof(buff), "show table status like %s",
1917
1910
quote_for_like(table, show_name_buff));
1919
if (mysql_query_with_error_report(mysql, &result, buff))
1912
if (drizzle_query_with_error_report(drizzle, &result, buff))
1921
if (mysql_errno(mysql) != ER_PARSE_ERROR)
1922
{ /* If old MySQL version */
1914
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
1915
{ /* If old DRIZZLE version */
1923
1916
verbose_msg("-- Warning: Couldn't get status information for " \
1924
"table %s (%s)\n", result_table,mysql_error(mysql));
1917
"table %s (%s)\n", result_table,drizzle_error(drizzle));
1927
else if (!(row= mysql_fetch_row(result)))
1920
else if (!(row= drizzle_fetch_row(result)))
1929
1922
fprintf(stderr,
1930
1923
"Error: Couldn't read status information for table %s (%s)\n",
1931
result_table,mysql_error(mysql));
1924
result_table,drizzle_error(drizzle));
2168
2161
dynstr_append_checked(&query_string, order_by);
2171
if (mysql_real_query(mysql, query_string.str, query_string.length))
2164
if (drizzle_real_query(drizzle, query_string.str, query_string.length))
2173
DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
2166
DB_error(drizzle, "when executing 'SELECT INTO OUTFILE'");
2174
2167
dynstr_free(&query_string);
2214
2207
fputs("\n", md_result_file);
2215
2208
check_io(md_result_file);
2217
if (mysql_query_with_error_report(mysql, 0, query_string.str))
2210
if (drizzle_query_with_error_report(drizzle, 0, query_string.str))
2219
DB_error(mysql, "when retrieving data from server");
2212
DB_error(drizzle, "when retrieving data from server");
2223
res=mysql_use_result(mysql);
2216
res=drizzle_use_result(drizzle);
2225
res=mysql_store_result(mysql);
2218
res=drizzle_store_result(drizzle);
2228
DB_error(mysql, "when retrieving data from server");
2221
DB_error(drizzle, "when retrieving data from server");
2232
2225
verbose_msg("-- Retrieving rows...\n");
2233
if (mysql_num_fields(res) != num_fields)
2226
if (drizzle_num_fields(res) != num_fields)
2235
2228
fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n",
2236
2229
my_progname, result_table);
2264
2257
check_io(md_result_file);
2267
while ((row= mysql_fetch_row(res)))
2260
while ((row= drizzle_fetch_row(res)))
2270
uint32_t *lengths= mysql_fetch_lengths(res);
2263
uint32_t *lengths= drizzle_fetch_lengths(res);
2272
2265
if (!extended_insert && !opt_xml)
2274
2267
fputs(insert_pat.str,md_result_file);
2275
2268
check_io(md_result_file);
2277
mysql_field_seek(res,0);
2270
drizzle_field_seek(res,0);
2282
2275
check_io(md_result_file);
2285
for (i= 0; i < mysql_num_fields(res); i++)
2278
for (i= 0; i < drizzle_num_fields(res); i++)
2288
2281
ulong length= lengths[i];
2290
if (!(field= mysql_fetch_field(res)))
2283
if (!(field= drizzle_fetch_field(res)))
2291
2284
die(EX_CONSCHECK,
2292
2285
"Not enough fields from table %s! Aborting.\n",
2298
2291
we'll dump in hex only BLOB columns.
2300
2293
is_blob= (opt_hex_blob && field->charsetnr == 63 &&
2301
(field->type == MYSQL_TYPE_STRING ||
2302
field->type == MYSQL_TYPE_VARCHAR ||
2303
field->type == MYSQL_TYPE_BLOB)) ? 1 : 0;
2294
(field->type == DRIZZLE_TYPE_STRING ||
2295
field->type == DRIZZLE_TYPE_VARCHAR ||
2296
field->type == DRIZZLE_TYPE_BLOB)) ? 1 : 0;
2304
2297
if (extended_insert && !opt_xml)
2326
2319
if (opt_hex_blob && is_blob)
2328
2321
dynstr_append_checked(&extended_row, "0x");
2329
extended_row.length+= mysql_hex_string(extended_row.str +
2322
extended_row.length+= drizzle_hex_string(extended_row.str +
2330
2323
extended_row.length,
2331
2324
row[i], length);
2332
2325
assert(extended_row.length+1 <= extended_row.max_length);
2333
/* mysql_hex_string() already terminated string by '\0' */
2326
/* drizzle_hex_string() already terminated string by '\0' */
2334
2327
assert(extended_row.str[extended_row.length] == '\0');
2338
2331
dynstr_append_checked(&extended_row,"'");
2339
2332
extended_row.length +=
2340
mysql_real_escape_string(&mysql_connection,
2333
drizzle_real_escape_string(&drizzle_connection,
2341
2334
&extended_row.str[extended_row.length],
2342
2335
row[i],length);
2343
2336
extended_row.str[extended_row.length]='\0';
2474
2467
fputs(";\n", md_result_file); /* If not empty table */
2475
2468
fflush(md_result_file);
2476
2469
check_io(md_result_file);
2477
if (mysql_errno(mysql))
2470
if (drizzle_errno(drizzle))
2479
2472
snprintf(buf, sizeof(buf),
2480
2473
"%s: Error %d: %s when dumping table %s at row: %ld\n",
2475
drizzle_errno(drizzle),
2476
drizzle_error(drizzle),
2486
2479
fputs(buf,stderr);
2520
2513
static char *getTableName(int reset)
2522
static MYSQL_RES *res= NULL;
2515
static DRIZZLE_RES *res= NULL;
2527
if (!(res= mysql_list_tables(mysql,NullS)))
2520
if (!(res= drizzle_list_tables(drizzle,NullS)))
2530
if ((row= mysql_fetch_row(res)))
2523
if ((row= drizzle_fetch_row(res)))
2531
2524
return((char*) row[0]);
2534
mysql_data_seek(res,0); /* We want to read again */
2527
drizzle_data_seek(res,0); /* We want to read again */
2537
mysql_free_result(res);
2530
drizzle_free_result(res);
2544
2537
static int dump_all_databases()
2547
MYSQL_RES *tableres;
2540
DRIZZLE_RES *tableres;
2550
if (mysql_query_with_error_report(mysql, &tableres, "SHOW DATABASES"))
2543
if (drizzle_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
2552
while ((row= mysql_fetch_row(tableres)))
2545
while ((row= drizzle_fetch_row(tableres)))
2554
2547
if (dump_all_tables_in_db(row[0]))
2593
2586
if (!opt_create_db)
2595
2588
char qbuf[256];
2590
DRIZZLE_RES *dbinfo;
2599
2592
snprintf(qbuf, sizeof(qbuf),
2600
2593
"SHOW CREATE DATABASE IF NOT EXISTS %s",
2603
if (mysql_query(mysql, qbuf) || !(dbinfo = mysql_store_result(mysql)))
2596
if (drizzle_query(drizzle, qbuf) || !(dbinfo = drizzle_store_result(drizzle)))
2605
2598
/* Old server version, dump generic CREATE DATABASE */
2606
2599
if (opt_drop_database)
2617
2610
fprintf(md_result_file,
2618
2611
"\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2620
row = mysql_fetch_row(dbinfo);
2613
row = drizzle_fetch_row(dbinfo);
2623
2616
fprintf(md_result_file,"\n%s;\n",row[1]);
2625
mysql_free_result(dbinfo);
2618
drizzle_free_result(dbinfo);
2632
2625
static int init_dumping(char *database, int init_func(char*))
2634
if (mysql_get_server_version(mysql) >= 50003 &&
2627
if (drizzle_get_server_version(drizzle) >= 50003 &&
2635
2628
!my_strcasecmp(&my_charset_latin1, database, "information_schema"))
2638
if (mysql_select_db(mysql, database))
2631
if (drizzle_select_db(drizzle, database))
2640
DB_error(mysql, "when selecting the database");
2633
DB_error(drizzle, "when selecting the database");
2641
2634
return 1; /* If --force */
2643
2636
if (!path && !opt_xml)
2707
2700
dynstr_append_checked(&query, " READ /*!32311 LOCAL */,");
2710
if (numrows && mysql_real_query(mysql, query.str, query.length-1))
2711
DB_error(mysql, "when using LOCK TABLES");
2703
if (numrows && drizzle_real_query(drizzle, query.str, query.length-1))
2704
DB_error(drizzle, "when using LOCK TABLES");
2712
2705
/* We shall continue here, if --force was given */
2713
2706
dynstr_free(&query);
2715
2708
if (flush_logs)
2717
if (mysql_refresh(mysql, REFRESH_LOG))
2718
DB_error(mysql, "when doing refresh");
2710
if (drizzle_refresh(drizzle, REFRESH_LOG))
2711
DB_error(drizzle, "when doing refresh");
2719
2712
/* We shall continue here, if --force was given */
2721
2714
while ((table= getTableName(0)))
2734
2727
check_io(md_result_file);
2736
2729
if (lock_tables)
2737
VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
2730
VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2738
2731
if (flush_privileges && using_mysql_db == 0)
2740
2733
fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2769
2762
snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2770
2763
quote_for_like(old_table_name, show_name_buff));
2772
if (mysql_query_with_error_report(mysql, 0, query))
2765
if (drizzle_query_with_error_report(drizzle, 0, query))
2775
if ((table_res= mysql_store_result(mysql)))
2768
if ((table_res= drizzle_store_result(drizzle)))
2777
uint64_t num_rows= mysql_num_rows(table_res);
2770
uint64_t num_rows= drizzle_num_rows(table_res);
2778
2771
if (num_rows > 0)
2780
2773
uint32_t *lengths;
2782
2775
Return first row
2783
2776
TODO: Return all matching rows
2785
row= mysql_fetch_row(table_res);
2786
lengths= mysql_fetch_lengths(table_res);
2778
row= drizzle_fetch_row(table_res);
2779
lengths= drizzle_fetch_lengths(table_res);
2787
2780
name= strmake_root(root, row[0], lengths[0]);
2789
mysql_free_result(table_res);
2782
drizzle_free_result(table_res);
2844
2837
dynstr_free(&lock_tables_query);
2845
2838
free_root(&root, MYF(0));
2847
DB_error(mysql, "when doing LOCK TABLES");
2840
DB_error(drizzle, "when doing LOCK TABLES");
2848
2841
/* We shall countinue here, if --force was given */
2851
2844
dynstr_free(&lock_tables_query);
2852
2845
if (flush_logs)
2854
if (mysql_refresh(mysql, REFRESH_LOG))
2847
if (drizzle_refresh(drizzle, REFRESH_LOG))
2856
2849
if (!ignore_errors)
2857
2850
free_root(&root, MYF(0));
2858
DB_error(mysql, "when doing refresh");
2851
DB_error(drizzle, "when doing refresh");
2860
2853
/* We shall countinue here, if --force was given */
2875
2868
check_io(md_result_file);
2877
2870
if (lock_tables)
2878
VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
2871
VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2880
2873
} /* dump_selected_tables */
2883
static int do_show_master_status(MYSQL *mysql_con)
2876
static int do_show_master_status(DRIZZLE *drizzle_con)
2879
DRIZZLE_RES *master;
2887
2880
const char *comment_prefix=
2888
(opt_master_data == MYSQL_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2889
if (mysql_query_with_error_report(mysql_con, &master, "SHOW MASTER STATUS"))
2881
(opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2882
if (drizzle_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2895
row= mysql_fetch_row(master);
2888
row= drizzle_fetch_row(master);
2896
2889
if (row && row[0] && row[1])
2898
2891
/* SHOW MASTER STATUS reports file and position */
2910
2903
/* SHOW MASTER STATUS reports nothing and --force is not enabled */
2911
2904
my_printf_error(0, "Error: Binlogging on server not active",
2913
mysql_free_result(master);
2914
maybe_exit(EX_MYSQLERR);
2906
drizzle_free_result(master);
2907
maybe_exit(EX_DRIZZLEERR);
2917
mysql_free_result(master);
2910
drizzle_free_result(master);
2922
static int do_stop_slave_sql(MYSQL *mysql_con)
2915
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
2925
2918
/* We need to check if the slave sql is running in the first place */
2926
if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
2919
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2930
MYSQL_ROW row= mysql_fetch_row(slave);
2923
DRIZZLE_ROW row= drizzle_fetch_row(slave);
2931
2924
if (row && row[11])
2933
2926
/* if SLAVE SQL is not running, we don't stop it */
2934
2927
if (!strcmp(row[11],"No"))
2936
mysql_free_result(slave);
2929
drizzle_free_result(slave);
2937
2930
/* Silently assume that they don't have the slave running */
2942
mysql_free_result(slave);
2935
drizzle_free_result(slave);
2944
2937
/* now, stop slave if running */
2945
if (mysql_query_with_error_report(mysql_con, 0, "STOP SLAVE SQL_THREAD"))
2938
if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2969
static int do_show_slave_status(MYSQL *mysql_con)
2962
static int do_show_slave_status(DRIZZLE *drizzle_con)
2972
2965
const char *comment_prefix=
2973
(opt_slave_data == MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2974
if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
2966
(opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2967
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2976
2969
if (!ignore_errors)
3006
2999
check_io(md_result_file);
3008
mysql_free_result(slave);
3001
drizzle_free_result(slave);
3013
static int do_start_slave_sql(MYSQL *mysql_con)
3006
static int do_start_slave_sql(DRIZZLE *drizzle_con)
3016
3009
/* We need to check if the slave sql is stopped in the first place */
3017
if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
3010
if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
3021
MYSQL_ROW row= mysql_fetch_row(slave);
3014
DRIZZLE_ROW row= drizzle_fetch_row(slave);
3022
3015
if (row && row[11])
3024
3017
/* if SLAVE SQL is not running, we don't start it */
3025
3018
if (!strcmp(row[11],"Yes"))
3027
mysql_free_result(slave);
3020
drizzle_free_result(slave);
3028
3021
/* Silently assume that they don't have the slave running */
3033
mysql_free_result(slave);
3026
drizzle_free_result(slave);
3035
3028
/* now, start slave if stopped */
3036
if (mysql_query_with_error_report(mysql_con, 0, "START SLAVE"))
3029
if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
3038
3031
my_printf_error(0, "Error: Unable to start slave", MYF(0));
3054
3047
update starts between the two FLUSHes, we have that bad stall.
3057
( mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES") ||
3058
mysql_query_with_error_report(mysql_con, 0,
3050
( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
3051
drizzle_query_with_error_report(drizzle_con, 0,
3059
3052
"FLUSH TABLES WITH READ LOCK") );
3063
static int do_unlock_tables(MYSQL *mysql_con)
3056
static int do_unlock_tables(DRIZZLE *drizzle_con)
3065
return mysql_query_with_error_report(mysql_con, 0, "UNLOCK TABLES");
3058
return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
3068
static int get_bin_log_name(MYSQL *mysql_con,
3061
static int get_bin_log_name(DRIZZLE *drizzle_con,
3069
3062
char* buff_log_name, uint buff_len)
3074
if (mysql_query(mysql_con, "SHOW MASTER STATUS") ||
3075
!(res= mysql_store_result(mysql)))
3067
if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
3068
!(res= drizzle_store_result(drizzle)))
3078
if (!(row= mysql_fetch_row(res)))
3071
if (!(row= drizzle_fetch_row(res)))
3080
mysql_free_result(res);
3073
drizzle_free_result(res);
3087
3080
strmake(buff_log_name, row[0], buff_len - 1);
3089
mysql_free_result(res);
3082
drizzle_free_result(res);
3093
static int purge_bin_logs_to(MYSQL *mysql_con, char* log_name)
3086
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
3095
3088
DYNAMIC_STRING str;
3097
3090
init_dynamic_string_checked(&str, "PURGE BINARY LOGS TO '", 1024, 1024);
3098
3091
dynstr_append_checked(&str, log_name);
3099
3092
dynstr_append_checked(&str, "'");
3100
err = mysql_query_with_error_report(mysql_con, 0, str.str);
3093
err = drizzle_query_with_error_report(drizzle_con, 0, str.str);
3101
3094
dynstr_free(&str);
3106
static int start_transaction(MYSQL *mysql_con)
3099
static int start_transaction(DRIZZLE *drizzle_con)
3109
3102
We use BEGIN for old servers. --single-transaction --master-data will fail
3114
3107
need the REPEATABLE READ level (not anything lower, for example READ
3115
3108
COMMITTED would give one new consistent read per dumped table).
3117
if ((mysql_get_server_version(mysql_con) < 40100) && opt_master_data)
3110
if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
3119
3112
fprintf(stderr, "-- %s: the combination of --single-transaction and "
3120
"--master-data requires a MySQL server version of at least 4.1 "
3113
"--master-data requires a DRIZZLE server version of at least 4.1 "
3121
3114
"(current server's version is %s). %s\n",
3122
3115
ignore_errors ? "Warning" : "Error",
3123
mysql_con->server_version ? mysql_con->server_version : "unknown",
3116
drizzle_con->server_version ? drizzle_con->server_version : "unknown",
3124
3117
ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3125
3118
if (!ignore_errors)
3119
exit(EX_DRIZZLEERR);
3129
return (mysql_query_with_error_report(mysql_con, 0,
3122
return (drizzle_query_with_error_report(drizzle_con, 0,
3130
3123
"SET SESSION TRANSACTION ISOLATION "
3131
3124
"LEVEL REPEATABLE READ") ||
3132
mysql_query_with_error_report(mysql_con, 0,
3125
drizzle_query_with_error_report(drizzle_con, 0,
3133
3126
"START TRANSACTION "
3134
3127
"/*!40100 WITH CONSISTENT SNAPSHOT */"));
3179
3172
/* Print a value with a prefix on file */
3180
static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
3173
static void print_value(FILE *file, DRIZZLE_RES *result, DRIZZLE_ROW row,
3181
3174
const char *prefix, const char *name,
3182
3175
int string_value)
3185
mysql_field_seek(result, 0);
3177
DRIZZLE_FIELD *field;
3178
drizzle_field_seek(result, 0);
3187
for ( ; (field= mysql_fetch_field(result)) ; row++)
3180
for ( ; (field= drizzle_fetch_field(result)) ; row++)
3189
3182
if (!strcmp(field->name,name))
3234
3227
char result= IGNORE_NONE;
3235
3228
char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3236
MYSQL_RES *res= NULL;
3229
DRIZZLE_RES *res= NULL;
3240
3233
/* Check memory for quote_for_like() */
3241
3234
assert(2*sizeof(table_name) < sizeof(show_name_buff));
3242
3235
snprintf(buff, sizeof(buff), "show table status like %s",
3243
3236
quote_for_like(table_name, show_name_buff));
3244
if (mysql_query_with_error_report(mysql, &res, buff))
3237
if (drizzle_query_with_error_report(drizzle, &res, buff))
3246
if (mysql_errno(mysql) != ER_PARSE_ERROR)
3247
{ /* If old MySQL version */
3239
if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
3240
{ /* If old DRIZZLE version */
3248
3241
verbose_msg("-- Warning: Couldn't get status information for "
3249
"table %s (%s)\n", table_name, mysql_error(mysql));
3242
"table %s (%s)\n", table_name, drizzle_error(drizzle));
3250
3243
return(result); /* assume table is ok */
3253
if (!(row= mysql_fetch_row(res)))
3246
if (!(row= drizzle_fetch_row(res)))
3255
3248
fprintf(stderr,
3256
3249
"Error: Couldn't read status information for table %s (%s)\n",
3257
table_name, mysql_error(mysql));
3258
mysql_free_result(res);
3250
table_name, drizzle_error(drizzle));
3251
drizzle_free_result(res);
3259
3252
return(result); /* assume table is ok */
3324
3317
snprintf(show_keys_buff, sizeof(show_keys_buff),
3325
3318
"SHOW KEYS FROM %s", table_name);
3326
if (mysql_query(mysql, show_keys_buff) ||
3327
!(res= mysql_store_result(mysql)))
3319
if (drizzle_query(drizzle, show_keys_buff) ||
3320
!(res= drizzle_store_result(drizzle)))
3329
3322
fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3330
3323
" records are NOT sorted (%s)\n",
3331
table_name, mysql_error(mysql));
3324
table_name, drizzle_error(drizzle));
3332
3325
/* Don't exit, because it's better to print out unsorted records */
3339
3332
* row, and UNIQUE keys come before others. So we only need to check
3340
3333
* the first key, not all keys.
3342
if ((row= mysql_fetch_row(res)) && atoi(row[1]) == 0)
3335
if ((row= drizzle_fetch_row(res)) && atoi(row[1]) == 0)
3344
3337
/* Key is unique */
3347
3340
quoted_field= quote_name(row[4], buff, 0);
3348
3341
result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3349
} while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1);
3342
} while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1);
3352
3345
/* Build the ORDER BY clause result */
3360
3353
fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
3363
mysql_data_seek(res, 0);
3364
row= mysql_fetch_row(res);
3356
drizzle_data_seek(res, 0);
3357
row= drizzle_fetch_row(res);
3365
3358
quoted_field= quote_name(row[4], buff, 0);
3366
3359
end= strmov(result, quoted_field);
3367
while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1)
3360
while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
3369
3362
quoted_field= quote_name(row[4], buff, 0);
3370
3363
end= strxmov(end, ",", quoted_field, NullS);
3389
3382
uint init_alloc, uint alloc_increment)
3391
3384
if (init_dynamic_string(str, init_str, init_alloc, alloc_increment))
3392
die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3385
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3395
3388
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src)
3397
3390
if (dynstr_append(dest, src))
3398
die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3391
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3401
3394
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str)
3403
3396
if (dynstr_set(str, init_str))
3404
die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3397
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3407
3400
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
3410
3403
if (dynstr_append_mem(str, append, length))
3411
die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3404
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3414
3407
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size)
3416
3409
if (dynstr_realloc(str, additional_size))
3417
die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3410
die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3425
3418
MY_INIT("mysqldump");
3427
3420
compatible_mode_normal_str[0]= 0;
3428
default_charset= (char *)mysql_universal_client_charset;
3429
bzero((char*) &ignore_table, sizeof(ignore_table));
3421
default_charset= (char *)drizzle_universal_client_charset;
3422
memset((char*) &ignore_table, 0, sizeof(ignore_table));
3431
3424
exit_code= get_options(&argc, &argv);
3440
3433
if(!(stderror_file= freopen(log_error_file, "a+", stderr)))
3442
3435
free_resources();
3436
exit(EX_DRIZZLEERR);
3447
3440
if (connect_to_db(current_host, current_user, opt_password))
3449
3442
free_resources();
3443
exit(EX_DRIZZLEERR);
3453
3446
write_header(md_result_file, *argv);
3455
if (opt_slave_data && do_stop_slave_sql(mysql))
3448
if (opt_slave_data && do_stop_slave_sql(drizzle))
3458
3451
if ((opt_lock_all_tables || opt_master_data) &&
3459
do_flush_tables_read_lock(mysql))
3452
do_flush_tables_read_lock(drizzle))
3461
if (opt_single_transaction && start_transaction(mysql))
3454
if (opt_single_transaction && start_transaction(drizzle))
3463
3456
if (opt_delete_master_logs)
3465
if (mysql_refresh(mysql, REFRESH_LOG) ||
3466
get_bin_log_name(mysql, bin_log_name, sizeof(bin_log_name)))
3458
if (drizzle_refresh(drizzle, REFRESH_LOG) ||
3459
get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
3470
3463
if (opt_lock_all_tables || opt_master_data)
3472
if (flush_logs && mysql_refresh(mysql, REFRESH_LOG))
3465
if (flush_logs && drizzle_refresh(drizzle, REFRESH_LOG))
3474
3467
flush_logs= 0; /* not anymore; that would not be sensible */
3476
3469
/* Add 'STOP SLAVE to beginning of dump */
3477
3470
if (opt_slave_apply && add_stop_slave())
3479
if (opt_master_data && do_show_master_status(mysql))
3481
if (opt_slave_data && do_show_slave_status(mysql))
3483
if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */
3472
if (opt_master_data && do_show_master_status(drizzle))
3474
if (opt_slave_data && do_show_slave_status(drizzle))
3476
if (opt_single_transaction && do_unlock_tables(drizzle)) /* unlock but no commit! */
3486
3479
if (opt_alldbs)
3509
3502
if (md_result_file && fflush(md_result_file))
3511
3504
if (!first_error)
3512
first_error= EX_MYSQLERR;
3505
first_error= EX_DRIZZLEERR;
3515
3508
/* everything successful, purge the old logs files */
3516
if (opt_delete_master_logs && purge_bin_logs_to(mysql, bin_log_name))
3509
if (opt_delete_master_logs && purge_bin_logs_to(drizzle, bin_log_name))