~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

Merged in latest plugin-slot-reorg.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 Drizzle Open Source Development Project
 
1
/* Copyright 2000-2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* drizzledump.cc  - Dump a tables contents and format to an ASCII file
 
17
 
 
18
 * Derived from mysqldump, which originally came from:
17
19
**
18
20
** The author's original notes follow :-
19
21
**
22
24
** WARRANTY: None, expressed, impressed, implied
23
25
**          or other
24
26
** STATUS: Public domain
 
27
 
 
28
* and more work by Monty, Jani & Sinisa
 
29
* and all the MySQL developers over the years.
25
30
*/
26
31
 
27
 
#define DUMP_VERSION "10.13"
28
 
 
29
 
#include "config.h"
 
32
#include "client_priv.h"
30
33
#include <string>
31
 
#include "client_priv.h"
32
34
 
33
35
#include <mysys/my_sys.h>
34
36
#include <mystrings/m_string.h>
35
37
#include <mystrings/m_ctype.h>
36
38
#include <mysys/hash.h>
37
39
#include <stdarg.h>
 
40
#include <algorithm>
 
41
 
 
42
#include <drizzled/gettext.h>
38
43
 
39
44
#include <drizzled/error.h>
40
45
 
41
46
using namespace std;
 
47
 
 
48
extern "C"
 
49
bool get_one_option(int optid, const struct my_option *, char *argument);
 
50
 
42
51
/* Exit codes */
43
52
 
44
53
#define EX_USAGE 1
47
56
#define EX_EOM 4
48
57
#define EX_EOF 5 /* ferror for output file was got */
49
58
#define EX_ILLEGAL_TABLE 6
 
59
#define EX_TABLE_STATUS 7
50
60
 
51
61
/* index into 'show fields from table' */
52
62
 
58
68
 
59
69
/* Size of buffer for dump's select query */
60
70
#define QUERY_LENGTH 1536
 
71
#define DRIZZLE_MAX_LINE_LENGTH 1024*1024L-1025
61
72
 
62
73
/* ignore table flags */
63
74
#define IGNORE_NONE 0x00 /* no ignore */
66
77
 
67
78
static void add_load_option(string &str, const char *option,
68
79
                            const char *option_value);
69
 
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
70
 
                      char **err_pos, uint *err_len);
 
80
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
 
81
                         char **err_pos, uint32_t *err_len);
71
82
 
72
83
static void field_escape(string &in, const char *from);
73
 
static bool  verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
74
 
                quick= 1, extended_insert= 1,
75
 
                lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
76
 
                opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
77
 
                opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0,
78
 
                opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0,
79
 
                opt_set_charset=0, opt_dump_date=1,
80
 
                opt_autocommit=0,opt_disable_keys=1,opt_xml=0,
81
 
                opt_delete_master_logs=0, tty_password=0,
82
 
                opt_single_transaction=0, opt_comments= 0, opt_compact= 0,
83
 
                opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0,
84
 
                opt_complete_insert= 0, opt_drop_database= 0,
85
 
                opt_replace_into= 0,
86
 
                opt_routines=0, opt_tz_utc=1,
87
 
                opt_slave_apply= 0, 
88
 
                opt_include_master_host_port= 0,
89
 
                opt_events= 0,
90
 
                opt_alltspcs=0, opt_notspcs= 0;
91
 
static bool debug_info_flag= 0, debug_check_flag= 0;
92
 
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
93
 
static DRIZZLE drizzle_connection,*drizzle=0;
 
84
static bool  verbose= false;
 
85
static bool opt_no_create_info= false;
 
86
static bool opt_no_data= false;
 
87
static bool quick= true;
 
88
static bool extended_insert= true;
 
89
static bool ignore_errors= false;
 
90
static bool flush_logs= false;
 
91
static bool opt_drop= true; 
 
92
static bool opt_keywords= false;
 
93
static bool opt_compress= false;
 
94
static bool opt_delayed= false; 
 
95
static bool create_options= true; 
 
96
static bool opt_quoted= false;
 
97
static bool opt_databases= false; 
 
98
static bool opt_alldbs= false; 
 
99
static bool opt_create_db= false;
 
100
static bool opt_lock_all_tables= false;
 
101
static bool opt_set_charset= false; 
 
102
static bool opt_dump_date= true;
 
103
static bool opt_autocommit= false; 
 
104
static bool opt_disable_keys= true;
 
105
static bool opt_xml= false;
 
106
static bool tty_password= false;
 
107
static bool opt_single_transaction= false; 
 
108
static bool opt_comments= false;
 
109
static bool opt_compact= false;
 
110
static bool opt_hex_blob= false;
 
111
static bool opt_order_by_primary=false; 
 
112
static bool opt_ignore= false;
 
113
static bool opt_complete_insert= false;
 
114
static bool opt_drop_database= false;
 
115
static bool opt_replace_into= false;
 
116
static bool opt_routines= false;
 
117
static bool opt_alltspcs= false;
 
118
static bool debug_info_flag= false;
 
119
static bool debug_check_flag= false;
 
120
static uint32_t show_progress_size= 0;
 
121
static uint64_t total_rows= 0;
 
122
static drizzle_st drizzle;
 
123
static drizzle_con_st dcon;
94
124
static string insert_pat;
95
 
static char  *opt_password=0,*current_user=0,
96
 
             *current_host=0,*path=0,*fields_terminated=0,
97
 
             *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
98
 
             *where=0, *order_by=0,
99
 
             *opt_compatible_mode_str= 0,
100
 
             *err_ptr= 0,
101
 
             *log_error_file= NULL;
102
 
static char **defaults_argv= 0;
 
125
static char  *opt_password= NULL;
 
126
static char *current_user= NULL;
 
127
static char  *current_host= NULL;
 
128
static char *path= NULL;
 
129
static char *fields_terminated= NULL;
 
130
static char *lines_terminated= NULL; 
 
131
static char *enclosed= NULL;
 
132
static char *opt_enclosed= NULL;
 
133
static char *escaped= NULL;
 
134
static char *where= NULL; 
 
135
static char *order_by= NULL;
 
136
static char *opt_compatible_mode_str= NULL;
 
137
static char *err_ptr= NULL;
 
138
static char **defaults_argv= NULL;
103
139
static char compatible_mode_normal_str[255];
104
 
/* Server supports character_set_results session variable? */
105
 
static bool server_supports_switching_charsets= true;
106
140
static uint32_t opt_compatible_mode= 0;
107
 
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
108
 
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
109
 
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
110
 
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
111
 
static uint opt_drizzle_port= 0, opt_master_data;
112
 
static uint opt_slave_data;
113
 
static uint my_end_arg;
114
 
static int   first_error=0;
 
141
static uint32_t opt_drizzle_port= 0;
 
142
static uint32_t my_end_arg;
 
143
static int first_error= 0;
115
144
static string extended_row;
116
145
FILE *md_result_file= 0;
117
 
FILE *stderror_file=0;
 
146
FILE *stderror_file= 0;
118
147
 
119
 
/*
120
 
  Constant for detection of default value of default_charset.
121
 
  If default_charset is equal to drizzle_universal_client_charset, then
122
 
  it is the default value which assigned at the very beginning of main().
123
 
*/
124
 
static const char *drizzle_universal_client_charset=
125
 
  DRIZZLE_UNIVERSAL_CLIENT_CHARSET;
126
 
static char *default_charset;
127
148
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
128
 
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
129
 
/* have we seen any VIEWs during table scanning? */
130
 
bool seen_views= 0;
 
149
 
131
150
const char *compatible_mode_names[]=
132
151
{
133
152
  "MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
162
181
   "Dump all the tablespaces.",
163
182
   (char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
164
183
   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,
168
 
   0, 0},
169
184
  {"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
170
185
   (char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
171
186
   0},
172
187
  {"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
173
188
   (char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
174
189
   0},
175
 
  {"add-locks", OPT_LOCKS, "Add locks around insert statements.",
176
 
   (char**) &opt_lock, (char**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
177
 
   0},
178
190
  {"allow-keywords", OPT_KEYWORDS,
179
191
   "Allow creation of column names that are keywords.", (char**) &opt_keywords,
180
192
   (char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
181
 
  {"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
182
 
   "Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
183
 
   (char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
184
 
   0, 0, 0, 0, 0, 0},
185
 
  {"character-sets-dir", OPT_CHARSETS_DIR,
186
 
   "Directory where character sets are.", (char**) &charsets_dir,
187
 
   (char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
188
193
  {"comments", 'i', "Write additional information.",
189
194
   (char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
190
195
   1, 0, 0, 0, 0, 0},
216
221
  {"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
217
222
   (char**) &debug_info_flag, (char**) &debug_info_flag,
218
223
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
219
 
  {"default-character-set", OPT_DEFAULT_CHARSET,
220
 
   "Set the default character set.", (char**) &default_charset,
221
 
   (char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
222
224
  {"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
223
225
   (char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
224
226
   0, 0},
225
 
  {"delete-master-logs", OPT_DELETE_MASTER_LOGS,
226
 
   "Delete logs on master after backup. This automatically enables --master-data.",
227
 
   (char**) &opt_delete_master_logs, (char**) &opt_delete_master_logs, 0,
228
 
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
229
227
  {"disable-keys", 'K',
230
 
   "'/*!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,
 
228
   "'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.", (char**) &opt_disable_keys,
231
229
   (char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
232
 
  {"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
233
 
   "This causes the binary log position and filename of the master to be "
234
 
   "appended to the dumped data output. Setting the value to 1, will print"
235
 
   "it as a CHANGE MASTER command in the dumped data output; if equal"
236
 
   " to 2, that command will be prefixed with a comment symbol. "
237
 
   "This option will turn --lock-all-tables on, unless "
238
 
   "--single-transaction is specified too (in which case a "
239
 
   "global read lock is only taken a short time at the beginning of the dump "
240
 
   "- don't forget to read about --single-transaction below). In all cases "
241
 
   "any action on logs will happen at the exact moment of the dump."
242
 
   "Option automatically turns --lock-tables off.",
243
 
   (char**) &opt_slave_data, (char**) &opt_slave_data, 0,
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},
248
230
  {"extended-insert", 'e',
249
231
   "Allows utilization of the new, much faster INSERT syntax.",
250
232
   (char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
260
242
   (char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
261
243
  {"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
262
244
   (char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
263
 
  {"first-slave", 'x', "Deprecated, renamed to --lock-all-tables.",
264
 
   (char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
265
 
   0, 0, 0, 0, 0, 0},
266
245
  {"flush-logs", 'F', "Flush logs file in server before starting dump. "
267
246
   "Note that if you dump many databases at once (using the option "
268
247
   "--databases= or --all-databases), the logs will be flushed for "
269
248
   "each database dumped. The exception is when using --lock-all-tables "
270
 
   "or --master-data: "
271
249
   "in this case the logs will be flushed only once, corresponding "
272
250
   "to the moment all tables are locked. So if you want your dump and "
273
251
   "the log flush to happen at the same exact moment you should use "
274
 
   "--lock-all-tables or --master-data with --flush-logs",
 
252
   "--lock-all-tables or --flush-logs",
275
253
   (char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
276
254
   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,
282
 
   0, 0},
283
255
  {"force", 'f', "Continue even if we get an sql-error.",
284
256
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
285
257
   0, 0, 0, 0, 0, 0},
295
267
   "use the directive multiple times, once for each table.  Each table must "
296
268
   "be specified with both database and table names, e.g. --ignore-table=database.table",
297
269
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
298
 
  {"include-master-host-port", OPT_DRIZZLEDUMP_INCLUDE_MASTER_HOST_PORT,
299
 
   "Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
300
 
   (char**) &opt_include_master_host_port, 
301
 
   (char**) &opt_include_master_host_port, 
302
 
   0, GET_BOOL, NO_ARG,
303
 
   0, 0, 0, 0, 0, 0},
304
270
  {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
305
271
   (char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
306
272
   0, 0},
312
278
   "dump. Automatically turns --single-transaction and --lock-tables off.",
313
279
   (char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
314
280
   0, 0, 0, 0, 0, 0},
315
 
  {"lock-tables", 'l', "Lock all tables for read.", (char**) &lock_tables,
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},
320
 
  {"master-data", OPT_MASTER_DATA,
321
 
   "This causes the binary log position and filename to be appended to the "
322
 
   "output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
323
 
   " to 2, that command will be prefixed with a comment symbol. "
324
 
   "This option will turn --lock-all-tables on, unless "
325
 
   "--single-transaction is specified too (in which case a "
326
 
   "global read lock is only taken a short time at the beginning of the dump "
327
 
   "- don't forget to read about --single-transaction below). In all cases "
328
 
   "any action on logs will happen at the exact moment of the dump."
329
 
   "Option automatically turns --lock-tables off.",
330
 
   (char**) &opt_master_data, (char**) &opt_master_data, 0,
331
 
   GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
332
 
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
333
 
    (char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
334
 
    GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
335
 
   (int64_t) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
336
 
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
337
 
    (char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
338
 
    GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
339
 
   MALLOC_OVERHEAD-1024, 1024, 0},
340
281
  {"no-autocommit", OPT_AUTOCOMMIT,
341
282
   "Wrap tables with autocommit/commit statements.",
342
283
   (char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
343
284
   0, 0, 0, 0, 0, 0},
344
285
  {"no-create-db", 'n',
345
 
   "'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
 
286
   "'CREATE DATABASE IF NOT EXISTS db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
346
287
   (char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
347
288
   0, 0, 0, 0},
348
289
  {"no-create-info", 't', "Don't write table creation info.",
359
300
  {"order-by-primary", OPT_ORDER_BY_PRIMARY,
360
301
   "Sorts each table's rows by primary key, or first unique key, if such a key exists.  Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer.",
361
302
   (char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
362
 
  {"password", 'p',
 
303
  {"password", 'P',
363
304
   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
364
305
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
365
 
  {"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
366
 
   (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
367
 
   0},
 
306
  {"port", 'p', "Port number to use for connection.", 
 
307
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
368
308
  {"quick", 'q', "Don't buffer query, dump directly to stdout.",
369
309
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
370
310
  {"quote-names",'Q', "Quote table and column names with backticks (`).",
379
319
  {"routines", 'R', "Dump stored routines (functions and procedures).",
380
320
     (char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
381
321
     NO_ARG, 0, 0, 0, 0, 0, 0},
382
 
  {"set-charset", OPT_SET_CHARSET,
383
 
   "Add 'SET NAMES default_character_set' to the output.",
384
 
   (char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
385
 
   0, 0, 0, 0, 0},
386
 
  {"set-variable", 'O',
387
 
   "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
388
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
389
 
  /*
390
 
    Note that the combination --single-transaction --master-data
391
 
    will give bullet-proof binlog position only if server >=4.1.3. That's the
392
 
    old "FLUSH TABLES WITH READ LOCK does not block commit" fixed bug.
393
 
  */
394
322
  {"single-transaction", OPT_TRANSACTION,
395
323
   "Creates a consistent snapshot by dumping all tables in a single "
396
324
   "transaction. Works ONLY for tables stored in storage engines which "
397
325
   "support multiversioning (currently only InnoDB does); the dump is NOT "
398
326
   "guaranteed to be consistent for other storage engines. "
399
327
   "While a --single-transaction dump is in process, to ensure a valid "
400
 
   "dump file (correct table contents and binary log position), no other "
 
328
   "dump file (correct table contents), no other "
401
329
   "connection should use the following statements: ALTER TABLE, DROP "
402
330
   "TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
403
331
   "isolated from them. Option automatically turns off --lock-tables.",
414
342
   (char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
415
343
  {"tables", OPT_TABLES, "Overrides option --databases (-B).",
416
344
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
417
 
  {"tz-utc", OPT_TZ_UTC,
418
 
    "SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones.",
419
 
    (char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
420
 
#ifndef DONT_ALLOW_USER_CHANGE
 
345
  {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of rows before each output progress report (requires --verbose)."),
 
346
   (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
 
347
   10000, 0, 0, 0, 0, 0},
421
348
  {"user", 'u', "User for login if not current user.",
422
349
   (char**) &current_user, (char**) &current_user, 0, GET_STR, REQUIRED_ARG,
423
350
   0, 0, 0, 0, 0, 0},
424
 
#endif
425
351
  {"verbose", 'v', "Print info about the various stages.",
426
352
   (char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
427
353
  {"version",'V', "Output version information and exit.", 0, 0, 0,
439
365
static void die(int error, const char* reason, ...);
440
366
static void maybe_die(int error, const char* reason, ...);
441
367
static void write_header(FILE *sql_file, char *db_name);
442
 
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
443
 
                        const char *prefix,const char *name,
 
368
static void print_value(FILE *file, drizzle_result_st *result,
 
369
                        drizzle_row_t row, const char *prefix, const char *name,
444
370
                        int string_value);
 
371
static const char* fetch_named_row(drizzle_result_st *result, drizzle_row_t row,
 
372
                                   const char* name);
445
373
static int dump_selected_tables(char *db, char **table_names, int tables);
446
374
static int dump_all_tables_in_db(char *db);
447
375
static int init_dumping_tables(char *);
471
399
  va_start(args, fmt);
472
400
  vfprintf(stderr, fmt, args);
473
401
  va_end(args);
474
 
 
475
 
  return;
476
402
}
477
403
 
478
404
/*
486
412
static void check_io(FILE *file)
487
413
{
488
414
  if (ferror(file))
489
 
    die(EX_EOF, "Got errno %d on write", errno);
 
415
    die(EX_EOF, _("Got errno %d on write"), errno);
490
416
}
491
417
 
492
418
static void print_version(void)
493
419
{
494
 
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
495
 
         drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
420
  printf(_("%s  Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), my_progname,
 
421
         VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
496
422
} /* print_version */
497
423
 
498
424
 
499
425
static void short_usage_sub(void)
500
426
{
501
 
  printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
502
 
  printf("OR     %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n",
 
427
  printf(_("Usage: %s [OPTIONS] database [tables]\n"), my_progname);
 
428
  printf(_("OR     %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
503
429
         my_progname);
504
 
  printf("OR     %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname);
 
430
  printf(_("OR     %s [OPTIONS] --all-databases [OPTIONS]\n"), my_progname);
505
431
}
506
432
 
507
433
 
508
434
static void usage(void)
509
435
{
510
436
  print_version();
511
 
  puts("By Igor Romanenko, Monty, Jani & Sinisa");
512
 
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
513
 
  puts("Dumping definition and data DRIZZLE database or table");
 
437
  puts("");
 
438
  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"));
 
439
  puts(_("Dumps definitions and data from a Drizzle database server"));
514
440
  short_usage_sub();
515
 
  print_defaults("my",load_default_groups);
 
441
  print_defaults("drizzle",load_default_groups);
516
442
  my_print_help(my_long_options);
517
443
  my_print_variables(my_long_options);
518
444
} /* usage */
521
447
static void short_usage(void)
522
448
{
523
449
  short_usage_sub();
524
 
  printf("For more options, use %s --help\n", my_progname);
 
450
  printf(_("For more options, use %s --help\n"), my_progname);
525
451
}
526
452
 
527
453
static void write_header(FILE *sql_file, char *db_name)
530
456
  {
531
457
    fputs("<?xml version=\"1.0\"?>\n", sql_file);
532
458
    /*
533
 
      Schema reference.  Allows use of xsi:nil for NULL values and 
 
459
      Schema reference.  Allows use of xsi:nil for NULL values and
534
460
      xsi:type to define an element's data type.
535
461
    */
536
462
    fputs("<drizzledump ", sql_file);
544
470
    if (opt_comments)
545
471
    {
546
472
      fprintf(sql_file,
547
 
              "-- DRIZZLE dump %s  Distrib %s, for %s (%s)\n--\n",
548
 
              DUMP_VERSION, drizzle_get_client_info(),
549
 
              SYSTEM_TYPE, MACHINE_TYPE);
 
473
              "-- drizzledump %s libdrizzle %s, for %s-%s (%s)\n--\n",
 
474
              VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
550
475
      fprintf(sql_file, "-- Host: %s    Database: %s\n",
551
476
              current_host ? current_host : "localhost", db_name ? db_name :
552
477
              "");
553
478
      fputs("-- ------------------------------------------------------\n",
554
479
            sql_file);
555
480
      fprintf(sql_file, "-- Server version\t%s\n",
556
 
              drizzle_get_server_info(&drizzle_connection));
 
481
              drizzle_con_server_version(&dcon));
557
482
    }
558
483
    if (opt_set_charset)
559
484
      fprintf(sql_file,
560
 
"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
561
 
"\n/*!40101 SET NAMES %s */;\n",default_charset);
562
 
 
563
 
    if (opt_tz_utc)
564
 
    {
565
 
      fprintf(sql_file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
566
 
      fprintf(sql_file, "/*!40103 SET TIME_ZONE='+00:00' */;\n");
567
 
    }
568
 
 
569
 
    if (!path)
 
485
"\nSET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;\n");
 
486
 
 
487
    if (path == NULL)
570
488
    {
571
489
      fprintf(md_result_file,"\
572
 
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n\
573
 
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n\
 
490
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;\n\
 
491
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\n\
574
492
");
575
493
    }
576
494
    check_io(sql_file);
585
503
    fputs("</drizzledump>\n", sql_file);
586
504
    check_io(sql_file);
587
505
  }
588
 
  else if (!opt_compact)
 
506
  else if (opt_compact == false)
589
507
  {
590
 
    if (opt_tz_utc)
591
 
      fprintf(sql_file,"/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n");
592
 
 
593
 
    if (!path)
 
508
    if (path == NULL)
594
509
    {
595
510
      fprintf(md_result_file,"\
596
 
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n\
597
 
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n");
 
511
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;\n\
 
512
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;\n");
598
513
    }
599
514
    if (opt_set_charset)
600
 
      fprintf(sql_file,
601
 
"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
602
 
    fprintf(sql_file,
603
 
            "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
604
 
    fputs("\n", sql_file);
 
515
      fprintf(sql_file, "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;\n");
605
516
    if (opt_comments)
606
517
    {
607
518
      if (opt_dump_date)
625
536
}
626
537
 
627
538
 
628
 
static unsigned char* get_table_key(const char *entry, size_t *length,
629
 
                            bool not_used __attribute__((unused)))
 
539
static unsigned char* get_table_key(const char *entry, size_t *length, bool)
630
540
{
631
541
  *length= strlen(entry);
632
542
  return (unsigned char*) entry;
633
543
}
634
544
 
635
545
 
636
 
static bool
637
 
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
638
 
               char *argument)
 
546
bool get_one_option(int optid, const struct my_option *, char *argument)
639
547
{
 
548
  char *endchar= NULL;
 
549
  uint64_t temp_drizzle_port= 0;
 
550
 
640
551
  switch (optid) {
641
552
  case 'p':
 
553
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
 
554
    /* if there is an alpha character this is not a valid port */
 
555
    if (strlen(endchar) != 0)
 
556
    {
 
557
      fprintf(stderr, _("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead.\n"));
 
558
      exit(EX_USAGE);
 
559
    }
 
560
    /* If the port number is > 65535 it is not a valid port
 
561
 *        This also helps with potential data loss casting unsigned long to a
 
562
 *               uint32_t. */
 
563
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
 
564
    {
 
565
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
 
566
      exit(EX_USAGE);
 
567
    }
 
568
    else
 
569
    {
 
570
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
 
571
    }
 
572
    break;
 
573
  case 'P':
642
574
    if (argument)
643
575
    {
644
 
      char *start=argument;
645
 
      free(opt_password);
646
 
      opt_password=my_strdup(argument,MYF(MY_FAE));
647
 
      while (*argument) *argument++= 'x';               /* Destroy argument */
 
576
      char *start= argument;
 
577
      if (opt_password)
 
578
        free(opt_password);
 
579
      opt_password= strdup(argument);
 
580
      if (opt_password == NULL)
 
581
      {
 
582
        fprintf(stderr, _("Memory allocation error while copying password. "
 
583
                        "Aborting.\n"));
 
584
        exit(ENOMEM);
 
585
      }
 
586
      while (*argument)
 
587
      {
 
588
        /* Overwriting password with 'x' */
 
589
        *argument++= 'x';
 
590
      }
648
591
      if (*start)
649
 
        start[1]=0;                             /* Cut length of argument */
 
592
      {
 
593
        /* Cut length of argument */
 
594
        start[1]= 0;
 
595
      }
650
596
      tty_password= 0;
651
597
    }
652
598
    else
653
 
      tty_password=1;
 
599
    {
 
600
      tty_password= 1;
 
601
    }
654
602
    break;
655
603
  case 'r':
656
 
    if (!(md_result_file= my_fopen(argument, O_WRONLY | FILE_BINARY,
657
 
                                    MYF(MY_WME))))
 
604
    if (!(md_result_file= fopen(argument, "w")))
658
605
      exit(1);
659
606
    break;
660
607
  case 'N':
671
618
        a crash even if the input destination buffer is large enough
672
619
        to hold the output.
673
620
      */
674
 
      die(EX_USAGE, "Input filename too long: %s", argument);
 
621
      die(EX_USAGE, _("Input filename too long: %s"), argument);
675
622
    }
676
623
 
677
624
    break;
678
625
  case 'V': print_version(); exit(0);
679
626
  case 'X':
680
627
    opt_xml= 1;
681
 
    extended_insert= opt_drop= opt_lock=
 
628
    extended_insert= opt_drop=
682
629
      opt_disable_keys= opt_autocommit= opt_create_db= 0;
683
630
    break;
684
631
  case 'I':
685
632
  case '?':
686
633
    usage();
687
634
    exit(0);
688
 
  case (int) OPT_MASTER_DATA:
689
 
    if (!argument) /* work like in old versions */
690
 
      opt_master_data= DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL;
691
 
    break;
692
 
  case (int) OPT_DRIZZLEDUMP_SLAVE_DATA:
693
 
    if (!argument) /* work like in old versions */
694
 
      opt_slave_data= DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL;
695
 
    break;
696
635
  case (int) OPT_OPTIMIZE:
697
 
    extended_insert= opt_drop= opt_lock= quick= create_options=
698
 
      opt_disable_keys= lock_tables= opt_set_charset= 1;
 
636
    extended_insert= opt_drop= quick= create_options=
 
637
      opt_disable_keys= opt_set_charset= 1;
699
638
    break;
700
639
  case (int) OPT_SKIP_OPTIMIZATION:
701
 
    extended_insert= opt_drop= opt_lock= quick= create_options=
702
 
      opt_disable_keys= lock_tables= opt_set_charset= 0;
 
640
    extended_insert= opt_drop= quick= create_options=
 
641
      opt_disable_keys= opt_set_charset= 0;
703
642
    break;
704
643
  case (int) OPT_COMPACT:
705
644
  if (opt_compact)
706
645
  {
707
 
    opt_comments= opt_drop= opt_disable_keys= opt_lock= 0;
 
646
    opt_comments= opt_drop= opt_disable_keys= 0;
708
647
    opt_set_charset= 0;
709
648
  }
710
649
  case (int) OPT_TABLES:
714
653
  {
715
654
    if (!strchr(argument, '.'))
716
655
    {
717
 
      fprintf(stderr, "Illegal use of option --ignore-table=<database>.<table>\n");
 
656
      fprintf(stderr, _("Illegal use of option --ignore-table=<database>.<table>\n"));
718
657
      exit(1);
719
658
    }
720
 
    if (my_hash_insert(&ignore_table, (unsigned char*)my_strdup(argument, MYF(0))))
 
659
    char * tmpptr= strdup(argument);
 
660
    if (!(tmpptr) || my_hash_insert(&ignore_table, (unsigned char*)tmpptr))
721
661
      exit(EX_EOM);
722
662
    break;
723
663
  }
737
677
                                    &err_ptr, &error_len);
738
678
      if (error_len)
739
679
      {
740
 
        strmake(buff, err_ptr, min((uint32_t)sizeof(buff), error_len));
741
 
        fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
 
680
        strncpy(buff, err_ptr, min((uint32_t)sizeof(buff), error_len+1));
 
681
        fprintf(stderr, _("Invalid mode to --compatible: %s\n"), buff);
742
682
        exit(1);
743
683
      }
744
684
      mode= opt_compatible_mode;
746
686
      {
747
687
        if (mode & 1)
748
688
        {
749
 
          end= my_stpcpy(end, compatible_mode_names[i]);
750
 
          end= my_stpcpy(end, ",");
 
689
          uint32_t len = strlen(compatible_mode_names[i]);
 
690
          end= strcpy(end, compatible_mode_names[i]) + len;
 
691
          end= strcpy(end, ",")+1;
751
692
        }
752
693
      }
753
694
      if (end!=compatible_mode_normal_str)
754
695
        end[-1]= 0;
755
 
      /*
756
 
        Set charset to the default compiled value if it hasn't
757
 
        been reset yet by --default-character-set=xxx.
758
 
      */
759
 
      if (default_charset == drizzle_universal_client_charset)
760
 
        default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
761
 
      break;
762
696
    }
763
697
  }
764
698
  return 0;
767
701
static int get_options(int *argc, char ***argv)
768
702
{
769
703
  int ho_error;
770
 
  const DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
771
 
 
772
 
  opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
773
 
  opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
774
704
 
775
705
  md_result_file= stdout;
776
 
  load_defaults("my",load_default_groups,argc,argv);
 
706
  load_defaults("drizzle",load_default_groups,argc,argv);
777
707
  defaults_argv= *argv;
778
708
 
779
709
  if (hash_init(&ignore_table, charset_info, 16, 0, 0,
780
710
                (hash_get_key) get_table_key,
781
711
                (hash_free_key) free_table_ent, 0))
782
712
    return(EX_EOM);
783
 
  /* Don't copy internal log tables */
784
 
  if (my_hash_insert(&ignore_table,
785
 
                     (unsigned char*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
786
 
      my_hash_insert(&ignore_table,
787
 
                     (unsigned char*) my_strdup("mysql.schema", MYF(MY_WME))) ||
788
 
      my_hash_insert(&ignore_table,
789
 
                     (unsigned char*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
790
 
      my_hash_insert(&ignore_table,
791
 
                     (unsigned char*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
792
 
      my_hash_insert(&ignore_table,
793
 
                     (unsigned char*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
794
 
      my_hash_insert(&ignore_table,
795
 
                     (unsigned char*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
796
 
    return(EX_EOM);
797
713
 
798
714
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
799
715
    return(ho_error);
800
716
 
801
 
  *drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
802
 
  *drizzle_params->p_net_buffer_length= opt_net_buffer_length;
803
717
  if (debug_info_flag)
804
718
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
805
719
  if (debug_check_flag)
806
720
    my_end_arg= MY_CHECK_ERROR;
807
721
 
808
 
  if (opt_delayed)
809
 
    opt_lock=0;                         /* Can't have lock with delayed */
810
722
  if (!path && (enclosed || opt_enclosed || escaped || lines_terminated ||
811
723
                fields_terminated))
812
724
  {
813
725
    fprintf(stderr,
814
 
            "%s: You must use option --tab with --fields-...\n", my_progname);
 
726
            _("%s: You must use option --tab with --fields-...\n"), my_progname);
815
727
    return(EX_USAGE);
816
728
  }
817
729
 
818
 
  /* We don't delete master logs if slave data option */
819
 
  if (opt_slave_data)
820
 
  {
821
 
    opt_lock_all_tables= !opt_single_transaction;
822
 
    opt_master_data= 0;
823
 
    opt_delete_master_logs= 0;
824
 
  }
825
 
 
826
 
  /* Ensure consistency of the set of binlog & locking options */
827
 
  if (opt_delete_master_logs && !opt_master_data)
828
 
    opt_master_data= DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL;
829
730
  if (opt_single_transaction && opt_lock_all_tables)
830
731
  {
831
 
    fprintf(stderr, "%s: You can't use --single-transaction and "
832
 
            "--lock-all-tables at the same time.\n", my_progname);
 
732
    fprintf(stderr, _("%s: You can't use --single-transaction and "
 
733
            "--lock-all-tables at the same time.\n"), my_progname);
833
734
    return(EX_USAGE);
834
735
  }
835
 
  if (opt_master_data)
836
 
  {
837
 
    opt_lock_all_tables= !opt_single_transaction;
838
 
    opt_slave_data= 0;
839
 
  }
840
 
  if (opt_single_transaction || opt_lock_all_tables)
841
 
    lock_tables= 0;
842
736
  if (enclosed && opt_enclosed)
843
737
  {
844
 
    fprintf(stderr, "%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n", my_progname);
 
738
    fprintf(stderr, _("%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n"), my_progname);
845
739
    return(EX_USAGE);
846
740
  }
847
741
  if ((opt_databases || opt_alldbs) && path)
848
742
  {
849
743
    fprintf(stderr,
850
 
            "%s: --databases or --all-databases can't be used with --tab.\n",
 
744
            _("%s: --databases or --all-databases can't be used with --tab.\n"),
851
745
            my_progname);
852
746
    return(EX_USAGE);
853
747
  }
854
 
  if (strcmp(default_charset, charset_info->csname) &&
855
 
      !(charset_info= get_charset_by_csname(default_charset,
856
 
                                            MY_CS_PRIMARY, MYF(MY_WME))))
857
 
    exit(1);
858
748
  if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs))
859
749
  {
860
750
    short_usage();
861
751
    return EX_USAGE;
862
752
  }
863
753
  if (tty_password)
864
 
    opt_password=get_tty_password(NULL);
 
754
    opt_password=client_get_tty_password(NULL);
865
755
  return(0);
866
756
} /* get_options */
867
757
 
869
759
/*
870
760
** DB_error -- prints DRIZZLE error message and exits the program.
871
761
*/
872
 
static void DB_error(DRIZZLE *drizzle_arg, const char *when)
 
762
static void DB_error(drizzle_result_st *res, drizzle_return_t ret,
 
763
                     const char *when)
873
764
{
 
765
  if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
766
  {
 
767
    maybe_die(EX_DRIZZLEERR, _("Got error: %s (%d) %s"),
 
768
              drizzle_result_error(res),
 
769
              drizzle_result_error_code(res),
 
770
              when);
 
771
    drizzle_result_free(res);
 
772
  }
 
773
  else
 
774
    maybe_die(EX_DRIZZLEERR, _("Got error: %d %s"), ret, when);
874
775
 
875
 
  maybe_die(EX_DRIZZLEERR, "Got error: %d: %s %s",
876
 
          drizzle_errno(drizzle_arg), drizzle_error(drizzle_arg), when);
877
776
  return;
878
777
}
879
778
 
887
786
    error_num   - process return value
888
787
    fmt_reason  - a format string for use by vsnprintf.
889
788
    ...         - variable arguments for above fmt_reason string
890
 
  
 
789
 
891
790
  DESCRIPTION
892
791
    This call prints out the formatted error message to stderr and then
893
792
    terminates the process.
916
815
    error_num   - process return value
917
816
    fmt_reason  - a format string for use by vsnprintf.
918
817
    ...         - variable arguments for above fmt_reason string
919
 
  
 
818
 
920
819
  DESCRIPTION
921
820
    This call prints out the formatted error message to stderr and then
922
821
    terminates the process, unless the --force command line option is used.
923
 
    
 
822
 
924
823
    This call should be used for non-fatal errors (such as database
925
824
    errors) that the code may still be able to continue to the next unit
926
825
    of work.
927
 
    
 
826
 
928
827
*/
929
828
static void maybe_die(int error_num, const char* fmt_reason, ...)
930
829
{
947
846
  some.
948
847
 
949
848
  SYNOPSIS
950
 
    drizzle_query_with_error_report()
 
849
    drizzleclient_query_with_error_report()
951
850
    drizzle_con       connection to use
952
851
    res             if non zero, result will be put there with
953
 
                    drizzle_store_result()
 
852
                    drizzleclient_store_result()
954
853
    query           query to send to server
955
854
 
956
855
  RETURN VALUES
958
857
    1               error
959
858
*/
960
859
 
961
 
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
962
 
                                         const char *query)
 
860
static int drizzleclient_query_with_error_report(drizzle_con_st *con,
 
861
                                                 drizzle_result_st *result,
 
862
                                                 const char *query_str,
 
863
                                                 bool no_buffer)
963
864
{
964
 
  if (drizzle_query(drizzle_con, query) ||
965
 
      (res && !((*res)= drizzle_store_result(drizzle_con))))
966
 
  {
967
 
    maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
968
 
            query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
969
 
    return 1;
970
 
  }
 
865
  drizzle_return_t ret;
 
866
 
 
867
  if (drizzle_query_str(con, result, query_str, &ret) == NULL ||
 
868
      ret != DRIZZLE_RETURN_OK)
 
869
  {
 
870
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
871
    {
 
872
      maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
 
873
                query_str, drizzle_result_error(result),
 
874
                drizzle_result_error_code(result));
 
875
      drizzle_result_free(result);
 
876
    }
 
877
    else
 
878
    {
 
879
      maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
 
880
                query_str, drizzle_con_error(con), ret);
 
881
    }
 
882
    return 1;
 
883
  }
 
884
 
 
885
  if (no_buffer)
 
886
    ret= drizzle_column_buffer(result);
 
887
  else
 
888
    ret= drizzle_result_buffer(result);
 
889
  if (ret != DRIZZLE_RETURN_OK)
 
890
  {
 
891
    drizzle_result_free(result);
 
892
    maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
 
893
              query_str, drizzle_con_error(con), ret);
 
894
    return 1;
 
895
  }
 
896
 
971
897
  return 0;
972
898
}
973
899
 
974
 
 
975
 
/**
976
 
  Switch charset for results to some specified charset.  If the server does not
977
 
  support character_set_results variable, nothing can be done here.  As for
978
 
  whether something should be done here, future new callers of this function
979
 
  should be aware that the server lacking the facility of switching charsets is
980
 
  treated as success.
981
 
 
982
 
  @note  If the server lacks support, then nothing is changed and no error
983
 
         condition is returned.
984
 
 
985
 
  @returns  whether there was an error or not
986
 
*/
987
 
static int switch_character_set_results(DRIZZLE *drizzle, const char *cs_name)
988
 
{
989
 
  char query_buffer[QUERY_LENGTH];
990
 
  size_t query_length;
991
 
 
992
 
  /* Server lacks facility.  This is not an error, by arbitrary decision . */
993
 
  if (!server_supports_switching_charsets)
994
 
    return false;
995
 
 
996
 
  query_length= snprintf(query_buffer,
997
 
                         sizeof (query_buffer),
998
 
                         "SET SESSION character_set_results = '%s'",
999
 
                         (const char *) cs_name);
1000
 
 
1001
 
  return drizzle_real_query(drizzle, query_buffer, query_length);
1002
 
}
1003
 
 
1004
900
/*
1005
901
  Open a new .sql file to dump the table or view into
1006
902
 
1017
913
  FILE* res;
1018
914
  char filename[FN_REFLEN], tmp_path[FN_REFLEN];
1019
915
  convert_dirname(tmp_path,path,NULL);
1020
 
  res= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
1021
 
                O_WRONLY, MYF(MY_WME));
 
916
  res= fopen(fn_format(filename, table, tmp_path, ".sql", 4), "w");
 
917
 
1022
918
  return res;
1023
919
}
1024
920
 
1026
922
static void free_resources(void)
1027
923
{
1028
924
  if (md_result_file && md_result_file != stdout)
1029
 
    my_fclose(md_result_file, MYF(0));
 
925
    fclose(md_result_file);
1030
926
  free(opt_password);
1031
927
  if (hash_inited(&ignore_table))
1032
928
    hash_free(&ignore_table);
1042
938
    first_error= error;
1043
939
  if (ignore_errors)
1044
940
    return;
1045
 
  if (drizzle)
1046
 
    drizzle_close(drizzle);
 
941
  drizzle_con_free(&dcon);
 
942
  drizzle_free(&drizzle);
1047
943
  free_resources();
1048
944
  exit(error);
1049
945
}
1055
951
 
1056
952
static int connect_to_db(char *host, char *user,char *passwd)
1057
953
{
1058
 
  char buff[20+FN_REFLEN];
1059
 
 
1060
 
 
1061
 
  verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1062
 
  drizzle_create(&drizzle_connection);
1063
 
  if (opt_compress)
1064
 
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NULL);
1065
 
  if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
1066
 
                                  NULL,opt_drizzle_port, NULL,
1067
 
                                  0)))
 
954
  drizzle_return_t ret;
 
955
 
 
956
  verbose_msg(_("-- Connecting to %s...\n"), host ? host : "localhost");
 
957
  drizzle_create(&drizzle);
 
958
  drizzle_con_create(&drizzle, &dcon);
 
959
  drizzle_con_set_tcp(&dcon, host, opt_drizzle_port);
 
960
  drizzle_con_set_auth(&dcon, user, passwd);
 
961
  ret= drizzle_con_connect(&dcon);
 
962
  if (ret != DRIZZLE_RETURN_OK)
1068
963
  {
1069
 
    DB_error(&drizzle_connection, "when trying to connect");
 
964
    DB_error(NULL, ret, "when trying to connect");
1070
965
    return(1);
1071
966
  }
1072
 
  if (drizzle_get_server_version(&drizzle_connection) < 40100)
1073
 
  {
1074
 
    /* Don't dump SET NAMES with a pre-4.1 server (bug#7997).  */
1075
 
    opt_set_charset= 0;
1076
967
 
1077
 
    /* Don't switch charsets for 4.1 and earlier.  (bug#34192). */
1078
 
    server_supports_switching_charsets= false;
1079
 
  } 
1080
 
  /*
1081
 
    set time_zone to UTC to allow dumping date types between servers with
1082
 
    different time zone settings
1083
 
  */
1084
 
  if (opt_tz_utc)
1085
 
  {
1086
 
    snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1087
 
    if (drizzle_query_with_error_report(drizzle, 0, buff))
1088
 
      return(1);
1089
 
  }
1090
968
  return(0);
1091
969
} /* connect_to_db */
1092
970
 
1096
974
*/
1097
975
static void dbDisconnect(char *host)
1098
976
{
1099
 
  verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost");
1100
 
  drizzle_close(drizzle);
 
977
  verbose_msg(_("-- Disconnecting from %s...\n"), host ? host : "localhost");
 
978
  drizzle_con_free(&dcon);
 
979
  drizzle_free(&drizzle);
1101
980
} /* dbDisconnect */
1102
981
 
1103
982
 
1104
 
static void unescape(FILE *file,char *pos,uint length)
 
983
static void unescape(FILE *file,char *pos,uint32_t length)
1105
984
{
1106
985
  char *tmp;
1107
986
 
1108
 
  if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1109
 
    die(EX_DRIZZLEERR, "Couldn't allocate memory");
 
987
  if (!(tmp=(char*) malloc(length*2+1)))
 
988
    die(EX_DRIZZLEERR, _("Couldn't allocate memory"));
1110
989
 
1111
990
  drizzle_escape_string(tmp, pos, length);
1112
991
  fputc('\'', file);
1147
1026
static char *quote_name(const char *name, char *buff, bool force)
1148
1027
{
1149
1028
  char *to= buff;
1150
 
  char qtype= (opt_compatible_mode & MASK_ANSI_QUOTES) ? '\"' : '`';
 
1029
  char qtype= '`';
1151
1030
 
1152
1031
  if (!force && !opt_quoted && !test_if_special_chars(name))
1153
1032
    return (char*) name;
1253
1132
  Print xml tag. Optionally add attribute(s).
1254
1133
 
1255
1134
  SYNOPSIS
1256
 
    print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name, 
 
1135
    print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name,
1257
1136
                    ..., attribute_name_n, attribute_value_n, NULL)
1258
1137
    xml_file              - output file
1259
1138
    sbeg                  - line beginning
1268
1147
    Print XML tag with any number of attribute="value" pairs to the xml_file.
1269
1148
 
1270
1149
    Format is:
1271
 
      sbeg<tag_name first_attribute_name="first_attribute_value" ... 
 
1150
      sbeg<tag_name first_attribute_name="first_attribute_value" ...
1272
1151
      attribute_name_n="attribute_value_n">send
1273
1152
  NOTE
1274
1153
    Additional arguments must be present in attribute/value pairs.
1278
1157
*/
1279
1158
 
1280
1159
static void print_xml_tag(FILE * xml_file, const char* sbeg,
1281
 
                          const char* line_end, 
1282
 
                          const char* tag_name, 
 
1160
                          const char* line_end,
 
1161
                          const char* tag_name,
1283
1162
                          const char* first_attribute_name, ...)
1284
1163
{
1285
1164
  va_list arg_list;
1287
1166
 
1288
1167
  fputs(sbeg, xml_file);
1289
1168
  fputc('<', xml_file);
1290
 
  fputs(tag_name, xml_file);  
 
1169
  fputs(tag_name, xml_file);
1291
1170
 
1292
1171
  va_start(arg_list, first_attribute_name);
1293
1172
  attribute_name= first_attribute_name;
1297
1176
    assert(attribute_value != NULL);
1298
1177
 
1299
1178
    fputc(' ', xml_file);
1300
 
    fputs(attribute_name, xml_file);    
 
1179
    fputs(attribute_name, xml_file);
1301
1180
    fputc('\"', xml_file);
1302
 
    
 
1181
 
1303
1182
    print_quoted_xml(xml_file, attribute_value, strlen(attribute_value));
1304
1183
    fputc('\"', xml_file);
1305
1184
 
1365
1244
*/
1366
1245
 
1367
1246
static void print_xml_row(FILE *xml_file, const char *row_name,
1368
 
                          DRIZZLE_RES *tableRes, DRIZZLE_ROW *row)
 
1247
                          drizzle_result_st *tableRes, drizzle_row_t *row)
1369
1248
{
1370
 
  uint i;
1371
 
  DRIZZLE_FIELD *field;
1372
 
  uint32_t *lengths= drizzle_fetch_lengths(tableRes);
 
1249
  uint32_t i;
 
1250
  drizzle_column_st *column;
 
1251
  size_t *lengths= drizzle_row_field_sizes(tableRes);
1373
1252
 
1374
1253
  fprintf(xml_file, "\t\t<%s", row_name);
1375
1254
  check_io(xml_file);
1376
 
  drizzle_field_seek(tableRes, 0);
1377
 
  for (i= 0; (field= drizzle_fetch_field(tableRes)); i++)
 
1255
  drizzle_column_seek(tableRes, 0);
 
1256
  for (i= 0; (column= drizzle_column_next(tableRes)); i++)
1378
1257
  {
1379
1258
    if ((*row)[i])
1380
1259
    {
1381
1260
      fputc(' ', xml_file);
1382
 
      print_quoted_xml(xml_file, field->name, field->name_length);
 
1261
      print_quoted_xml(xml_file, drizzle_column_name(column),
 
1262
                       strlen(drizzle_column_name(column)));
1383
1263
      fputs("=\"", xml_file);
1384
1264
      print_quoted_xml(xml_file, (*row)[i], lengths[i]);
1385
1265
      fputc('"', xml_file);
1423
1303
    db          - db name
1424
1304
    table_type  - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW"
1425
1305
    ignore_flag - what we must particularly ignore - see IGNORE_ defines above
 
1306
    num_fields  - number of fields in the table
1426
1307
 
1427
1308
  RETURN
1428
 
    number of fields in table, 0 if error
 
1309
    true if success, false if error
1429
1310
*/
1430
1311
 
1431
 
static uint get_table_structure(char *table, char *db, char *table_type,
1432
 
                                char *ignore_flag)
 
1312
static bool get_table_structure(char *table, char *db, char *table_type,
 
1313
                                char *ignore_flag, uint64_t *num_fields)
1433
1314
{
1434
1315
  bool    init=0, delayed, write_data, complete_insert;
1435
 
  uint64_t num_fields;
1436
1316
  char       *result_table, *opt_quoted_table;
1437
1317
  const char *insert_option;
1438
 
  char       name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3];
1439
 
  char       table_buff2[NAME_LEN*2+3], query_buff[QUERY_LENGTH];
 
1318
  char       name_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE+3];
 
1319
  char       table_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE*2+3];
 
1320
  char       table_buff2[DRIZZLE_MAX_TABLE_SIZE*2+3];
 
1321
  char       query_buff[QUERY_LENGTH];
1440
1322
  FILE       *sql_file= md_result_file;
1441
 
  int        len;
1442
 
  DRIZZLE_RES  *result;
1443
 
  DRIZZLE_ROW  row;
 
1323
  drizzle_result_st result;
 
1324
  drizzle_row_t  row;
1444
1325
 
1445
1326
  *ignore_flag= check_if_ignore_table(table, table_type);
1446
1327
 
1448
1329
  if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED))
1449
1330
  {
1450
1331
    delayed= 0;
1451
 
    verbose_msg("-- Warning: Unable to use delayed inserts for table '%s' "
1452
 
                "because it's of type %s\n", table, table_type);
 
1332
    verbose_msg(_("-- Warning: Unable to use delayed inserts for table '%s' "
 
1333
                "because it's of type %s\n"), table, table_type);
1453
1334
  }
1454
1335
 
1455
1336
  complete_insert= 0;
1456
1337
  if ((write_data= !(*ignore_flag & IGNORE_DATA)))
1457
1338
  {
1458
1339
    complete_insert= opt_complete_insert;
1459
 
    insert_pat= "";
 
1340
    insert_pat.clear();
1460
1341
  }
1461
1342
 
1462
1343
  insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " :
1463
1344
                  delayed ? " DELAYED " : opt_ignore ? " IGNORE " : "");
1464
1345
 
1465
 
  verbose_msg("-- Retrieving table structure for table %s...\n", table);
1466
 
 
1467
 
  len= snprintf(query_buff, sizeof(query_buff),
1468
 
                "SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
1469
 
                (opt_quoted || opt_keywords));
 
1346
  verbose_msg(_("-- Retrieving table structure for table %s...\n"), table);
1470
1347
 
1471
1348
  result_table=     quote_name(table, table_buff, 1);
1472
1349
  opt_quoted_table= quote_name(table, table_buff2, 0);
1477
1354
    order_by= primary_key_fields(result_table);
1478
1355
  }
1479
1356
 
1480
 
  if (!opt_xml && !drizzle_query_with_error_report(drizzle, 0, query_buff))
 
1357
  if (!opt_xml)
1481
1358
  {
1482
1359
    /* using SHOW CREATE statement */
1483
1360
    if (!opt_no_create_info)
1484
1361
    {
1485
1362
      /* Make an sql-file, if path was given iow. option -T was given */
1486
1363
      char buff[20+FN_REFLEN];
1487
 
      const DRIZZLE_FIELD *field;
 
1364
      const drizzle_column_st *column;
1488
1365
 
1489
1366
      snprintf(buff, sizeof(buff), "show create table %s", result_table);
1490
1367
 
1491
 
      if (switch_character_set_results(drizzle, "binary") ||
1492
 
          drizzle_query_with_error_report(drizzle, &result, buff) ||
1493
 
          switch_character_set_results(drizzle, default_charset))
1494
 
        return(0);
 
1368
      if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
 
1369
        return false;
1495
1370
 
1496
1371
      if (path)
1497
1372
      {
1498
1373
        if (!(sql_file= open_sql_file_for_table(table)))
1499
 
          return(0);
 
1374
        {
 
1375
          drizzle_result_free(&result);
 
1376
          return false;
 
1377
        }
1500
1378
 
1501
1379
        write_header(sql_file, db);
1502
1380
      }
1503
1381
      if (!opt_xml && opt_comments)
1504
1382
      {
1505
 
      if (strcmp (table_type, "VIEW") == 0)         /* view */
1506
 
        fprintf(sql_file, "\n--\n-- Temporary table structure for view %s\n--\n\n",
1507
 
                result_table);
1508
 
      else
1509
1383
        fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n",
1510
1384
                result_table);
1511
1385
        check_io(sql_file);
1513
1387
      if (opt_drop)
1514
1388
      {
1515
1389
      /*
1516
 
        Even if the "table" is a view, we do a DROP TABLE here.  The
1517
 
        view-specific code below fills in the DROP VIEW.
 
1390
        Even if the "table" is a view, we do a DROP TABLE here.
1518
1391
       */
1519
 
        fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
1520
 
                opt_quoted_table);
 
1392
        fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table);
1521
1393
        check_io(sql_file);
1522
1394
      }
1523
1395
 
1524
 
      field= drizzle_fetch_field_direct(result, 0);
1525
 
      if (strcmp(field->name, "View") == 0)
1526
 
      {
1527
 
        char *scv_buff= NULL;
1528
 
 
1529
 
        verbose_msg("-- It's a view, create dummy table for view\n");
1530
 
 
1531
 
        /* save "show create" statement for later */
1532
 
        if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1533
 
          scv_buff= my_strdup(scv_buff, MYF(0));
1534
 
 
1535
 
        drizzle_free_result(result);
1536
 
 
1537
 
        /*
1538
 
          Create a table with the same name as the view and with columns of
1539
 
          the same name in order to satisfy views that depend on this view.
1540
 
          The table will be removed when the actual view is created.
1541
 
 
1542
 
          The properties of each column, aside from the data type, are not
1543
 
          preserved in this temporary table, because they are not necessary.
1544
 
 
1545
 
          This will not be necessary once we can determine dependencies
1546
 
          between views and can simply dump them in the appropriate order.
1547
 
        */
1548
 
        snprintf(query_buff, sizeof(query_buff),
1549
 
                 "SHOW FIELDS FROM %s", result_table);
1550
 
        if (switch_character_set_results(drizzle, "binary") ||
1551
 
            drizzle_query_with_error_report(drizzle, &result, query_buff) ||
1552
 
            switch_character_set_results(drizzle, default_charset))
1553
 
        {
1554
 
          /*
1555
 
            View references invalid or privileged table/col/fun (err 1356),
1556
 
            so we cannot create a stand-in table.  Be defensive and dump
1557
 
            a comment with the view's 'show create' statement. (Bug #17371)
1558
 
          */
1559
 
 
1560
 
          if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1561
 
            fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1562
 
 
1563
 
          free(scv_buff);
1564
 
 
1565
 
          return(0);
1566
 
        }
1567
 
        else
1568
 
          free(scv_buff);
1569
 
 
1570
 
        if (drizzle_num_rows(result))
1571
 
        {
1572
 
          if (opt_drop)
1573
 
          {
1574
 
            /*
1575
 
              We have already dropped any table of the same name above, so
1576
 
              here we just drop the view.
1577
 
            */
1578
 
 
1579
 
            fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
1580
 
                    opt_quoted_table);
1581
 
            check_io(sql_file);
1582
 
          }
1583
 
 
1584
 
          fprintf(sql_file,
1585
 
                  "/*!50001 CREATE TABLE %s (\n",
1586
 
                  result_table);
1587
 
 
1588
 
          /*
1589
 
            Get first row, following loop will prepend comma - keeps from
1590
 
            having to know if the row being printed is last to determine if
1591
 
            there should be a _trailing_ comma.
1592
 
          */
1593
 
 
1594
 
          row= drizzle_fetch_row(result);
1595
 
 
1596
 
          fprintf(sql_file, "  %s %s", quote_name(row[0], name_buff, 0),
1597
 
                  row[1]);
1598
 
 
1599
 
          while((row= drizzle_fetch_row(result)))
1600
 
          {
1601
 
            /* col name, col type */
1602
 
            fprintf(sql_file, ",\n  %s %s",
1603
 
                    quote_name(row[0], name_buff, 0), row[1]);
1604
 
          }
1605
 
          fprintf(sql_file, "\n) */;\n"); 
1606
 
          check_io(sql_file);
1607
 
        }
1608
 
 
1609
 
        drizzle_free_result(result);
1610
 
 
1611
 
        if (path)
1612
 
          my_fclose(sql_file, MYF(MY_WME));
1613
 
 
1614
 
        seen_views= 1;
1615
 
        return(0);
1616
 
      }
1617
 
 
1618
 
      row= drizzle_fetch_row(result);
 
1396
      column= drizzle_column_index(&result, 0);
 
1397
 
 
1398
      row= drizzle_row_next(&result);
1619
1399
 
1620
1400
      fprintf(sql_file, "%s;\n", row[1]);
1621
1401
 
1622
1402
      check_io(sql_file);
1623
 
      drizzle_free_result(result);
 
1403
      drizzle_result_free(&result);
1624
1404
    }
 
1405
 
1625
1406
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1626
1407
             result_table);
1627
 
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
 
1408
 
 
1409
    if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
1628
1410
    {
1629
1411
      if (path)
1630
 
        my_fclose(sql_file, MYF(MY_WME));
1631
 
      return(0);
 
1412
        fclose(sql_file);
 
1413
      return false;
1632
1414
    }
1633
1415
 
1634
1416
    /*
1658
1440
      }
1659
1441
    }
1660
1442
 
1661
 
    while ((row= drizzle_fetch_row(result)))
 
1443
    while ((row= drizzle_row_next(&result)))
1662
1444
    {
1663
1445
      if (complete_insert)
1664
1446
      {
1670
1452
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1671
1453
      }
1672
1454
    }
1673
 
    num_fields= drizzle_num_rows(result);
1674
 
    drizzle_free_result(result);
 
1455
    *num_fields= drizzle_result_row_count(&result);
 
1456
    drizzle_result_free(&result);
1675
1457
  }
1676
1458
  else
1677
1459
  {
1678
 
    verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
1679
 
                my_progname, drizzle_error(drizzle));
 
1460
    verbose_msg(_("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n"),
 
1461
                my_progname, drizzle_con_error(&dcon));
1680
1462
 
1681
1463
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1682
1464
             result_table);
1683
 
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1684
 
      return(0);
 
1465
    if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
 
1466
      return false;
1685
1467
 
1686
1468
    /* Make an sql-file, if path was given iow. option -T was given */
1687
1469
    if (!opt_no_create_info)
1689
1471
      if (path)
1690
1472
      {
1691
1473
        if (!(sql_file= open_sql_file_for_table(table)))
1692
 
          return(0);
 
1474
        {
 
1475
          drizzle_result_free(&result);
 
1476
          return false;
 
1477
        }
1693
1478
        write_header(sql_file, db);
1694
1479
      }
1695
1480
      if (!opt_xml && opt_comments)
1700
1485
      if (!opt_xml)
1701
1486
        fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
1702
1487
      else
1703
 
        print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table, 
 
1488
        print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table,
1704
1489
                NULL);
1705
1490
      check_io(sql_file);
1706
1491
    }
1724
1509
      }
1725
1510
    }
1726
1511
 
1727
 
    while ((row= drizzle_fetch_row(result)))
 
1512
    while ((row= drizzle_row_next(&result)))
1728
1513
    {
1729
 
      uint32_t *lengths= drizzle_fetch_lengths(result);
 
1514
      size_t *lengths= drizzle_row_field_sizes(&result);
1730
1515
      if (init)
1731
1516
      {
1732
1517
        if (!opt_xml && !opt_no_create_info)
1744
1529
      {
1745
1530
        if (opt_xml)
1746
1531
        {
1747
 
          print_xml_row(sql_file, "field", result, &row);
 
1532
          print_xml_row(sql_file, "field", &result, &row);
1748
1533
          continue;
1749
1534
        }
1750
1535
 
1768
1553
        check_io(sql_file);
1769
1554
      }
1770
1555
    }
1771
 
    num_fields= drizzle_num_rows(result);
1772
 
    drizzle_free_result(result);
 
1556
    *num_fields= drizzle_result_row_count(&result);
 
1557
    drizzle_result_free(&result);
 
1558
 
1773
1559
    if (!opt_no_create_info)
1774
1560
    {
1775
1561
      /* Make an sql-file, if path was given iow. option -T was given */
1776
1562
      char buff[20+FN_REFLEN];
1777
 
      uint keynr,primary_key;
 
1563
      uint32_t keynr,primary_key;
1778
1564
      snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1779
 
      if (drizzle_query_with_error_report(drizzle, &result, buff))
 
1565
      if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1780
1566
      {
1781
 
        if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
1782
 
        {
1783
 
          /* it is VIEW */
1784
 
          fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1785
 
          goto continue_xml;
1786
 
        }
1787
 
        fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1788
 
                my_progname, result_table, drizzle_error(drizzle));
 
1567
        fprintf(stderr, _("%s: Can't get keys for table %s\n"),
 
1568
                my_progname, result_table);
1789
1569
        if (path)
1790
 
          my_fclose(sql_file, MYF(MY_WME));
1791
 
        return(0);
 
1570
          fclose(sql_file);
 
1571
        return false;
1792
1572
      }
1793
1573
 
1794
1574
      /* Find first which key is primary key */
1795
1575
      keynr=0;
1796
1576
      primary_key=INT_MAX;
1797
 
      while ((row= drizzle_fetch_row(result)))
 
1577
      while ((row= drizzle_row_next(&result)))
1798
1578
      {
1799
1579
        if (atoi(row[3]) == 1)
1800
1580
        {
1810
1590
          }
1811
1591
        }
1812
1592
      }
1813
 
      drizzle_data_seek(result,0);
 
1593
      drizzle_row_seek(&result,0);
1814
1594
      keynr=0;
1815
 
      while ((row= drizzle_fetch_row(result)))
 
1595
      while ((row= drizzle_row_next(&result)))
1816
1596
      {
1817
1597
        if (opt_xml)
1818
1598
        {
1819
 
          print_xml_row(sql_file, "key", result, &row);
 
1599
          print_xml_row(sql_file, "key", &result, &row);
1820
1600
          continue;
1821
1601
        }
1822
1602
 
1840
1620
          fprintf(sql_file, " (%s)",row[7]);      /* Sub key */
1841
1621
        check_io(sql_file);
1842
1622
      }
1843
 
      drizzle_free_result(result);
 
1623
      drizzle_result_free(&result);
1844
1624
      if (!opt_xml)
1845
1625
      {
1846
1626
        if (keynr)
1848
1628
        fputs("\n)",sql_file);
1849
1629
        check_io(sql_file);
1850
1630
      }
1851
 
 
1852
1631
      /* Get DRIZZLE specific create options */
1853
1632
      if (create_options)
1854
1633
      {
1855
 
        char show_name_buff[NAME_LEN*2+2+24];
 
1634
        char show_name_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE*2+2+24];
1856
1635
 
1857
1636
        /* Check memory for quote_for_like() */
1858
1637
        snprintf(buff, sizeof(buff), "show table status like %s",
1859
1638
                 quote_for_like(table, show_name_buff));
1860
1639
 
1861
 
        if (drizzle_query_with_error_report(drizzle, &result, buff))
 
1640
        if (!drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1862
1641
        {
1863
 
          if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
1864
 
          {                                     /* If old DRIZZLE version */
1865
 
            verbose_msg("-- Warning: Couldn't get status information for " \
1866
 
                        "table %s (%s)\n", result_table,drizzle_error(drizzle));
 
1642
          if (!(row= drizzle_row_next(&result)))
 
1643
          {
 
1644
            fprintf(stderr,
 
1645
                    _("Error: Couldn't read status information for table %s\n"),
 
1646
                    result_table);
1867
1647
          }
1868
 
        }
1869
 
        else if (!(row= drizzle_fetch_row(result)))
1870
 
        {
1871
 
          fprintf(stderr,
1872
 
                  "Error: Couldn't read status information for table %s (%s)\n",
1873
 
                  result_table,drizzle_error(drizzle));
1874
 
        }
1875
 
        else
1876
 
        {
1877
 
          if (opt_xml)
1878
 
            print_xml_row(sql_file, "options", result, &row);
1879
1648
          else
1880
1649
          {
1881
 
            fputs("/*!",sql_file);
1882
 
            print_value(sql_file,result,row,"engine=","Engine",0);
1883
 
            print_value(sql_file,result,row,"","Create_options",0);
1884
 
            print_value(sql_file,result,row,"comment=","Comment",1);
1885
 
            fputs(" */",sql_file);
1886
 
            check_io(sql_file);
 
1650
            if (opt_xml)
 
1651
              print_xml_row(sql_file, "options", &result, &row);
 
1652
            else
 
1653
            {
 
1654
              fputs("/*!",sql_file);
 
1655
              print_value(sql_file,&result,row,"engine=","Engine",0);
 
1656
              print_value(sql_file,&result,row,"","Create_options",0);
 
1657
              print_value(sql_file,&result,row,"comment=","Comment",1);
 
1658
 
 
1659
              fputs(" */",sql_file);
 
1660
              check_io(sql_file);
 
1661
            }
1887
1662
          }
 
1663
          drizzle_result_free(&result);
1888
1664
        }
1889
 
        drizzle_free_result(result);              /* Is always safe to free */
1890
1665
      }
1891
 
continue_xml:
1892
1666
      if (!opt_xml)
1893
1667
        fputs(";\n", sql_file);
1894
1668
      else
1896
1670
      check_io(sql_file);
1897
1671
    }
1898
1672
  }
1899
 
  if (complete_insert)
1900
 
  {
 
1673
  if (complete_insert) {
1901
1674
    insert_pat.append(") VALUES ");
1902
1675
    if (!extended_insert)
1903
1676
      insert_pat.append("(");
1906
1679
  {
1907
1680
    fputs("\n", sql_file);
1908
1681
    write_footer(sql_file);
1909
 
    my_fclose(sql_file, MYF(MY_WME));
 
1682
    fclose(sql_file);
1910
1683
  }
1911
 
  return((uint) num_fields);
 
1684
  return true;
1912
1685
} /* get_table_structure */
1913
1686
 
1914
1687
static void add_load_option(string &str, const char *option,
1921
1694
  }
1922
1695
 
1923
1696
  str.append(option);
1924
 
  
 
1697
 
1925
1698
  if (strncmp(option_value, "0x", sizeof("0x")-1) == 0)
1926
1699
  {
1927
1700
    /* It's a hex constant, don't escape */
1944
1717
 
1945
1718
static void field_escape(string &in, const char *from)
1946
1719
{
1947
 
  uint end_backslashes= 0; 
 
1720
  uint32_t end_backslashes= 0;
1948
1721
 
1949
1722
  in.append("'");
1950
1723
 
1993
1766
static void dump_table(char *table, char *db)
1994
1767
{
1995
1768
  char ignore_flag;
1996
 
  char buf[200], table_buff[NAME_LEN+3];
 
1769
  char table_buff[DRIZZLE_MAX_TABLE_SIZE+3];
1997
1770
  string query_string;
1998
 
  char table_type[NAME_LEN];
1999
 
  char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
 
1771
  char table_type[DRIZZLE_MAX_TABLE_SIZE];
 
1772
  char *result_table, table_buff2[DRIZZLE_MAX_TABLE_SIZE*2+3], *opt_quoted_table;
2000
1773
  int error= 0;
2001
 
  uint32_t         rownr, row_break, total_length, init_length;
2002
 
  uint num_fields;
2003
 
  DRIZZLE_RES     *res;
2004
 
  DRIZZLE_FIELD   *field;
2005
 
  DRIZZLE_ROW     row;
 
1774
  uint32_t rownr, row_break, total_length, init_length;
 
1775
  uint64_t num_fields= 0;
 
1776
  drizzle_return_t ret;
 
1777
  drizzle_result_st result;
 
1778
  drizzle_column_st *column;
 
1779
  drizzle_row_t row;
2006
1780
 
2007
1781
 
2008
1782
  /*
2009
1783
    Make sure you get the create table info before the following check for
2010
1784
    --no-data flag below. Otherwise, the create table info won't be printed.
2011
1785
  */
2012
 
  num_fields= get_table_structure(table, db, table_type, &ignore_flag);
2013
 
 
2014
 
  /*
2015
 
    The "table" could be a view.  If so, we don't do anything here.
2016
 
  */
2017
 
  if (strcmp(table_type, "VIEW") == 0)
 
1786
  if (!get_table_structure(table, db, table_type, &ignore_flag, &num_fields))
 
1787
  {
 
1788
    maybe_die(EX_TABLE_STATUS, _("Error retrieving table structure for table: \"%s\""), table);
2018
1789
    return;
 
1790
  }
2019
1791
 
2020
1792
  /* Check --no-data flag */
2021
1793
  if (opt_no_data)
2022
1794
  {
2023
 
    verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
 
1795
    verbose_msg(_("-- Skipping dump data for table '%s', --no-data was used\n"),
2024
1796
                table);
2025
1797
    return;
2026
1798
  }
2031
1803
  */
2032
1804
  if (ignore_flag & IGNORE_DATA)
2033
1805
  {
2034
 
    verbose_msg("-- Warning: Skipping data for table '%s' because " \
2035
 
                "it's of type %s\n", table, table_type);
 
1806
    verbose_msg(_("-- Warning: Skipping data for table '%s' because " \
 
1807
                "it's of type %s\n"), table, table_type);
2036
1808
    return;
2037
1809
  }
2038
1810
  /* Check that there are any fields in the table */
2039
1811
  if (num_fields == 0)
2040
1812
  {
2041
 
    verbose_msg("-- Skipping dump data for table '%s', it has no fields\n",
 
1813
    verbose_msg(_("-- Skipping dump data for table '%s', it has no fields\n"),
2042
1814
                table);
2043
1815
    return;
2044
1816
  }
2045
1817
 
2046
 
  /*
2047
 
     Check --skip-events flag: it is not enough to skip creation of events
2048
 
     discarding SHOW CREATE EVENT statements generation. The myslq.event
2049
 
     table data should be skipped too.
2050
 
  */
2051
 
  if (!opt_events && !my_strcasecmp(&my_charset_utf8_general_ci, db, "mysql") &&
2052
 
      !my_strcasecmp(&my_charset_utf8_general_ci, table, "event"))
2053
 
  {
2054
 
    verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2055
 
    return;
2056
 
  }
2057
 
 
2058
1818
  result_table= quote_name(table,table_buff, 1);
2059
1819
  opt_quoted_table= quote_name(table, table_buff2, 0);
2060
1820
 
2061
 
  verbose_msg("-- Sending SELECT query...\n");
 
1821
  verbose_msg(_("-- Sending SELECT query...\n"));
2062
1822
 
2063
1823
  query_string.clear();
2064
1824
  query_string.reserve(1024);
2071
1831
      Convert the path to native os format
2072
1832
      and resolve to the full filepath.
2073
1833
    */
2074
 
    convert_dirname(tmp_path,path,NULL);    
 
1834
    convert_dirname(tmp_path,path,NULL);
2075
1835
    my_load_path(tmp_path, tmp_path, NULL);
2076
1836
    fn_format(filename, table, tmp_path, ".txt", MYF(MY_UNPACK_FILENAME));
2077
1837
 
2078
1838
    /* Must delete the file that 'INTO OUTFILE' will write to */
2079
1839
    my_delete(filename, MYF(0));
2080
1840
 
2081
 
    /* convert to a unix path name to stick into the query */
2082
 
    to_unix_path(filename);
2083
 
 
2084
1841
    /* now build the query string */
2085
1842
 
2086
1843
    query_string.append( "SELECT * INTO OUTFILE '");
2089
1846
 
2090
1847
    if (fields_terminated || enclosed || opt_enclosed || escaped)
2091
1848
      query_string.append( " FIELDS");
2092
 
    
 
1849
 
2093
1850
    add_load_option(query_string, " TERMINATED BY ", fields_terminated);
2094
1851
    add_load_option(query_string, " ENCLOSED BY ", enclosed);
2095
1852
    add_load_option(query_string, " OPTIONALLY ENCLOSED BY ", opt_enclosed);
2111
1868
      query_string.append( order_by);
2112
1869
    }
2113
1870
 
2114
 
    if (drizzle_real_query(drizzle, query_string.c_str(), query_string.length()))
 
1871
    if (drizzle_query(&dcon, &result, query_string.c_str(),
 
1872
                      query_string.length(), &ret) == NULL ||
 
1873
        ret != DRIZZLE_RETURN_OK)
2115
1874
    {
2116
 
      DB_error(drizzle, "when executing 'SELECT INTO OUTFILE'");
 
1875
      DB_error(&result, ret, _("when executing 'SELECT INTO OUTFILE'"));
 
1876
 
2117
1877
      return;
2118
1878
    }
 
1879
    drizzle_result_free(&result);
2119
1880
  }
2120
1881
  else
2121
1882
  {
2122
1883
    if (!opt_xml && opt_comments)
2123
1884
    {
2124
 
      fprintf(md_result_file,"\n--\n-- Dumping data for table %s\n--\n",
 
1885
      fprintf(md_result_file,_("\n--\n-- Dumping data for table %s\n--\n"),
2125
1886
              result_table);
2126
1887
      check_io(md_result_file);
2127
1888
    }
2128
 
    
 
1889
 
2129
1890
    query_string.append( "SELECT * FROM ");
2130
1891
    query_string.append( result_table);
2131
1892
 
2136
1897
        fprintf(md_result_file, "-- WHERE:  %s\n", where);
2137
1898
        check_io(md_result_file);
2138
1899
      }
2139
 
      
 
1900
 
2140
1901
      query_string.append( " WHERE ");
2141
1902
      query_string.append( where);
2142
1903
    }
2156
1917
      fputs("\n", md_result_file);
2157
1918
      check_io(md_result_file);
2158
1919
    }
2159
 
    if (drizzle_query_with_error_report(drizzle, 0, query_string.c_str()))
2160
 
    {
2161
 
      DB_error(drizzle, "when retrieving data from server");
2162
 
      goto err;
2163
 
    }
2164
 
    if (quick)
2165
 
      res=drizzle_use_result(drizzle);
2166
 
    else
2167
 
      res=drizzle_store_result(drizzle);
2168
 
    if (!res)
2169
 
    {
2170
 
      DB_error(drizzle, "when retrieving data from server");
 
1920
    if (drizzleclient_query_with_error_report(&dcon, &result,
 
1921
                                              query_string.c_str(), quick))
 
1922
    {
2171
1923
      goto err;
2172
1924
    }
2173
1925
 
2174
 
    verbose_msg("-- Retrieving rows...\n");
2175
 
    if (drizzle_num_fields(res) != num_fields)
 
1926
    verbose_msg(_("-- Retrieving rows...\n"));
 
1927
    if (drizzle_result_column_count(&result) != num_fields)
2176
1928
    {
2177
 
      fprintf(stderr,"%s: Error in field count for table: %s !  Aborting.\n",
 
1929
      fprintf(stderr,_("%s: Error in field count for table: %s !  Aborting.\n"),
2178
1930
              my_progname, result_table);
2179
1931
      error= EX_CONSCHECK;
 
1932
      drizzle_result_free(&result);
2180
1933
      goto err;
2181
1934
    }
2182
1935
 
2183
 
    if (opt_lock)
2184
 
    {
2185
 
      fprintf(md_result_file,"LOCK TABLES %s WRITE;\n", opt_quoted_table);
2186
 
      check_io(md_result_file);
2187
 
    }
2188
1936
    /* Moved disable keys to after lock per bug 15977 */
2189
1937
    if (opt_disable_keys)
2190
1938
    {
2191
 
      fprintf(md_result_file, "/*!40000 ALTER TABLE %s DISABLE KEYS */;\n",
 
1939
      fprintf(md_result_file, "ALTER TABLE %s DISABLE KEYS;\n",
2192
1940
              opt_quoted_table);
2193
1941
      check_io(md_result_file);
2194
1942
    }
2195
1943
 
2196
 
    total_length= opt_net_buffer_length;                /* Force row break */
 
1944
    total_length= DRIZZLE_MAX_LINE_LENGTH;                /* Force row break */
2197
1945
    row_break=0;
2198
1946
    rownr=0;
2199
 
    init_length=(uint) insert_pat.length()+4;
 
1947
    init_length=(uint32_t) insert_pat.length()+4;
2200
1948
    if (opt_xml)
2201
1949
      print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
2202
1950
              NULL);
2206
1954
      check_io(md_result_file);
2207
1955
    }
2208
1956
 
2209
 
    while ((row= drizzle_fetch_row(res)))
 
1957
    row= NULL;
 
1958
 
 
1959
    while (1)
2210
1960
    {
2211
 
      uint i;
2212
 
      uint32_t *lengths= drizzle_fetch_lengths(res);
 
1961
      uint32_t i;
 
1962
      size_t *lengths;
 
1963
 
 
1964
      if (quick)
 
1965
      {
 
1966
        if (row)
 
1967
          drizzle_row_free(&result, row);
 
1968
 
 
1969
        row= drizzle_row_buffer(&result, &ret);
 
1970
        if (ret != DRIZZLE_RETURN_OK)
 
1971
        {
 
1972
          fprintf(stderr,
 
1973
                _("%s: Error reading rows for table: %s (%d:%s) ! Aborting.\n"),
 
1974
                  my_progname, result_table, ret, drizzle_con_error(&dcon));
 
1975
          drizzle_result_free(&result);
 
1976
          goto err;
 
1977
        }
 
1978
      }
 
1979
      else
 
1980
        row= drizzle_row_next(&result);
 
1981
 
 
1982
      if (row == NULL)
 
1983
        break;
 
1984
 
 
1985
      lengths= drizzle_row_field_sizes(&result);
 
1986
 
2213
1987
      rownr++;
 
1988
      if ((rownr % show_progress_size) == 0)
 
1989
      {
 
1990
        verbose_msg(_("-- %"PRIu32" of ~%"PRIu64" rows dumped for table %s\n"), rownr, total_rows, opt_quoted_table);
 
1991
      }
2214
1992
      if (!extended_insert && !opt_xml)
2215
1993
      {
2216
1994
        fputs(insert_pat.c_str(),md_result_file);
2217
1995
        check_io(md_result_file);
2218
1996
      }
2219
 
      drizzle_field_seek(res,0);
 
1997
      drizzle_column_seek(&result,0);
2220
1998
 
2221
1999
      if (opt_xml)
2222
2000
      {
2224
2002
        check_io(md_result_file);
2225
2003
      }
2226
2004
 
2227
 
      for (i= 0; i < drizzle_num_fields(res); i++)
 
2005
      for (i= 0; i < drizzle_result_column_count(&result); i++)
2228
2006
      {
2229
2007
        int is_blob;
2230
2008
        uint32_t length= lengths[i];
2231
2009
 
2232
 
        if (!(field= drizzle_fetch_field(res)))
 
2010
        if (!(column= drizzle_column_next(&result)))
2233
2011
          die(EX_CONSCHECK,
2234
 
                      "Not enough fields from table %s! Aborting.\n",
 
2012
                      _("Not enough fields from table %s! Aborting.\n"),
2235
2013
                      result_table);
2236
2014
 
2237
2015
        /*
2239
2017
           we have not a BLOB but a TEXT column.
2240
2018
           we'll dump in hex only BLOB columns.
2241
2019
        */
2242
 
        is_blob= (opt_hex_blob && field->charsetnr == 63 &&
2243
 
                  (field->type == DRIZZLE_TYPE_VARCHAR ||
2244
 
                   field->type == DRIZZLE_TYPE_BLOB)) ? 1 : 0;
 
2020
        is_blob= (opt_hex_blob && drizzle_column_charset(column) == 63 &&
 
2021
                  (drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_VARCHAR ||
 
2022
                   drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_BLOB)) ? 1 : 0;
2245
2023
        if (extended_insert && !opt_xml)
2246
2024
        {
2247
2025
          if (i == 0)
2248
 
            extended_row= "(";
 
2026
          {
 
2027
            extended_row.clear();
 
2028
            extended_row.append("(");
 
2029
          }
2249
2030
          else
2250
2031
            extended_row.append(",");
2251
2032
 
2253
2034
          {
2254
2035
            if (length)
2255
2036
            {
2256
 
              if (!(field->type & NUM_FLAG))
 
2037
              if (!(drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_NUM))
2257
2038
              {
2258
2039
                /*
2259
2040
                  "length * 2 + 2" is OK for both HEX and non-HEX modes:
2274
2055
                else
2275
2056
                {
2276
2057
                  extended_row.append("'");
2277
 
                  drizzle_escape_string(tmp_str,
2278
 
                                        row[i],length);
 
2058
                  drizzle_escape_string(tmp_str, row[i],length);
2279
2059
                  extended_row.append(tmp_str);
2280
2060
                  extended_row.append("'");
2281
2061
                }
2309
2089
          }
2310
2090
          if (row[i])
2311
2091
          {
2312
 
            if (!(field->type & NUM_FLAG))
 
2092
            if (!(drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_NUM))
2313
2093
            {
2314
2094
              if (opt_xml)
2315
2095
              {
2317
2097
                {
2318
2098
                  /* Define xsi:type="xs:hexBinary" for hex encoded data */
2319
2099
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2320
 
                                field->name, "xsi:type=", "xs:hexBinary", NULL);
 
2100
                                drizzle_column_name(column), "xsi:type=", "xs:hexBinary", NULL);
2321
2101
                  print_blob_as_hex(md_result_file, row[i], length);
2322
2102
                }
2323
2103
                else
2324
2104
                {
2325
 
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=", 
2326
 
                                field->name, NULL);
 
2105
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
 
2106
                                drizzle_column_name(column), NULL);
2327
2107
                  print_quoted_xml(md_result_file, row[i], length);
2328
2108
                }
2329
2109
                fputs("</field>\n", md_result_file);
2343
2123
              if (opt_xml)
2344
2124
              {
2345
2125
                print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2346
 
                        field->name, NULL);
 
2126
                        drizzle_column_name(column), NULL);
2347
2127
                fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
2348
2128
                      md_result_file);
2349
2129
                fputs("</field>\n", md_result_file);
2362
2142
              fputs("NULL", md_result_file);
2363
2143
            else
2364
2144
              print_xml_null_tag(md_result_file, "\t\t", "field name=",
2365
 
                                 field->name, "\n");
 
2145
                                 drizzle_column_name(column), "\n");
2366
2146
          }
2367
2147
          check_io(md_result_file);
2368
2148
        }
2379
2159
        uint32_t row_length;
2380
2160
        extended_row.append(")");
2381
2161
        row_length= 2 + extended_row.length();
2382
 
        if (total_length + row_length < opt_net_buffer_length)
 
2162
        if (total_length + row_length < DRIZZLE_MAX_LINE_LENGTH)
2383
2163
        {
2384
2164
          total_length+= row_length;
2385
2165
          fputc(',',md_result_file);            /* Always row break */
2411
2191
      fputs(";\n", md_result_file);             /* If not empty table */
2412
2192
    fflush(md_result_file);
2413
2193
    check_io(md_result_file);
2414
 
    if (drizzle_errno(drizzle))
2415
 
    {
2416
 
      snprintf(buf, sizeof(buf),
2417
 
               "%s: Error %d: %s when dumping table %s at row: %d\n",
2418
 
               my_progname,
2419
 
               drizzle_errno(drizzle),
2420
 
               drizzle_error(drizzle),
2421
 
               result_table,
2422
 
               rownr);
2423
 
      fputs(buf,stderr);
2424
 
      error= EX_CONSCHECK;
2425
 
      goto err;
2426
 
    }
2427
2194
 
2428
2195
    /* Moved enable keys to before unlock per bug 15977 */
2429
2196
    if (opt_disable_keys)
2430
2197
    {
2431
 
      fprintf(md_result_file,"/*!40000 ALTER TABLE %s ENABLE KEYS */;\n",
 
2198
      fprintf(md_result_file,"ALTER TABLE %s ENABLE KEYS;\n",
2432
2199
              opt_quoted_table);
2433
2200
      check_io(md_result_file);
2434
2201
    }
2435
 
    if (opt_lock)
2436
 
    {
2437
 
      fputs("UNLOCK TABLES;\n", md_result_file);
2438
 
      check_io(md_result_file);
2439
 
    }
2440
2202
    if (opt_autocommit)
2441
2203
    {
2442
2204
      fprintf(md_result_file, "commit;\n");
2443
2205
      check_io(md_result_file);
2444
2206
    }
2445
 
    drizzle_free_result(res);
 
2207
    drizzle_result_free(&result);
2446
2208
  }
2447
2209
  return;
2448
2210
 
2454
2216
 
2455
2217
static char *getTableName(int reset)
2456
2218
{
2457
 
  static DRIZZLE_RES *res= NULL;
2458
 
  DRIZZLE_ROW    row;
 
2219
  static drizzle_result_st result;
 
2220
  static bool have_result= false;
 
2221
  drizzle_row_t row;
2459
2222
 
2460
 
  if (!res)
 
2223
  if (!have_result)
2461
2224
  {
2462
 
    if (!(res= drizzle_list_tables(drizzle,NULL)))
2463
 
      return(NULL);
 
2225
    if (drizzleclient_query_with_error_report(&dcon, &result, "SHOW TABLES", false))
 
2226
      return NULL;
 
2227
    have_result= true;
2464
2228
  }
2465
 
  if ((row= drizzle_fetch_row(res)))
2466
 
    return((char*) row[0]);
 
2229
 
 
2230
  if ((row= drizzle_row_next(&result)))
 
2231
    return row[0];
2467
2232
 
2468
2233
  if (reset)
2469
 
    drizzle_data_seek(res,0);      /* We want to read again */
 
2234
    drizzle_row_seek(&result, 0);
2470
2235
  else
2471
2236
  {
2472
 
    drizzle_free_result(res);
2473
 
    res= NULL;
 
2237
    drizzle_result_free(&result);
 
2238
    have_result= false;
2474
2239
  }
2475
 
  return(NULL);
 
2240
  return NULL;
2476
2241
} /* getTableName */
2477
2242
 
2478
2243
 
2479
2244
static int dump_all_databases()
2480
2245
{
2481
 
  DRIZZLE_ROW row;
2482
 
  DRIZZLE_RES *tableres;
 
2246
  drizzle_row_t row;
 
2247
  drizzle_result_st tableres;
2483
2248
  int result=0;
2484
2249
 
2485
 
  if (drizzle_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
 
2250
  if (drizzleclient_query_with_error_report(&dcon, &tableres, "SHOW DATABASES", false))
2486
2251
    return 1;
2487
 
  while ((row= drizzle_fetch_row(tableres)))
 
2252
  while ((row= drizzle_row_next(&tableres)))
2488
2253
  {
2489
2254
    if (dump_all_tables_in_db(row[0]))
2490
2255
      result=1;
2491
2256
  }
 
2257
  drizzle_result_free(&tableres);
2492
2258
  return result;
2493
2259
}
2494
2260
/* dump_all_databases */
2523
2289
 
2524
2290
int init_dumping_tables(char *qdatabase)
2525
2291
{
2526
 
 
2527
 
 
2528
2292
  if (!opt_create_db)
2529
2293
  {
2530
2294
    char qbuf[256];
2531
 
    DRIZZLE_ROW row;
2532
 
    DRIZZLE_RES *dbinfo;
 
2295
    drizzle_row_t row;
 
2296
    drizzle_result_st result;
 
2297
    drizzle_return_t ret;
2533
2298
 
2534
2299
    snprintf(qbuf, sizeof(qbuf),
2535
2300
             "SHOW CREATE DATABASE IF NOT EXISTS %s",
2536
2301
             qdatabase);
2537
2302
 
2538
 
    if (drizzle_query(drizzle, qbuf) || !(dbinfo = drizzle_store_result(drizzle)))
 
2303
    if (drizzle_query_str(&dcon, &result, qbuf, &ret) == NULL ||
 
2304
        ret != DRIZZLE_RETURN_OK)
2539
2305
    {
 
2306
      if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
2307
        drizzle_result_free(&result);
 
2308
 
2540
2309
      /* Old server version, dump generic CREATE DATABASE */
2541
2310
      if (opt_drop_database)
2542
2311
        fprintf(md_result_file,
2543
 
                "\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
 
2312
                "\nDROP DATABASE IF EXISTS %s;\n",
2544
2313
                qdatabase);
2545
2314
      fprintf(md_result_file,
2546
 
              "\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n",
 
2315
              "\nCREATE DATABASE IF NOT EXISTS %s;\n",
2547
2316
              qdatabase);
2548
2317
    }
2549
2318
    else
2550
2319
    {
2551
 
      if (opt_drop_database)
2552
 
        fprintf(md_result_file,
2553
 
                "\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2554
 
                qdatabase);
2555
 
      row = drizzle_fetch_row(dbinfo);
2556
 
      if (row[1])
 
2320
      if (drizzle_result_buffer(&result) == DRIZZLE_RETURN_OK)
2557
2321
      {
2558
 
        fprintf(md_result_file,"\n%s;\n",row[1]);
 
2322
        if (opt_drop_database)
 
2323
          fprintf(md_result_file,
 
2324
                  "\nDROP DATABASE IF EXISTS %s;\n",
 
2325
                  qdatabase);
 
2326
        row = drizzle_row_next(&result);
 
2327
        if (row != NULL && row[1])
 
2328
        {
 
2329
          fprintf(md_result_file,"\n%s;\n",row[1]);
 
2330
        }
2559
2331
      }
2560
 
      drizzle_free_result(dbinfo);
 
2332
      drizzle_result_free(&result);
2561
2333
    }
2562
2334
  }
2563
2335
  return(0);
2566
2338
 
2567
2339
static int init_dumping(char *database, int init_func(char*))
2568
2340
{
2569
 
  if (drizzle_get_server_version(drizzle) >= 50003 &&
2570
 
      !my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
 
2341
  drizzle_result_st result;
 
2342
  drizzle_return_t ret;
 
2343
 
 
2344
  if (!my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
2571
2345
    return 1;
2572
2346
 
2573
 
  if (drizzle_select_db(drizzle, database))
 
2347
  if (drizzle_select_db(&dcon, &result, database, &ret) == NULL ||
 
2348
        ret != DRIZZLE_RETURN_OK)
2574
2349
  {
2575
 
    DB_error(drizzle, "when selecting the database");
 
2350
    DB_error(&result, ret, _("when executing 'SELECT INTO OUTFILE'"));
2576
2351
    return 1;                   /* If --force */
2577
2352
  }
 
2353
  drizzle_result_free(&result);
 
2354
 
2578
2355
  if (!path && !opt_xml)
2579
2356
  {
2580
2357
    if (opt_databases || opt_alldbs)
2582
2359
      /*
2583
2360
        length of table name * 2 (if name contains quotes), 2 quotes and 0
2584
2361
      */
2585
 
      char quoted_database_buf[NAME_LEN*2+3];
 
2362
      char quoted_database_buf[DRIZZLE_MAX_DB_SIZE*2+3];
2586
2363
      char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
2587
2364
      if (opt_comments)
2588
2365
      {
2614
2391
static int dump_all_tables_in_db(char *database)
2615
2392
{
2616
2393
  char *table;
2617
 
  uint numrows;
2618
 
  char table_buff[NAME_LEN*2+3];
2619
 
  char hash_key[2*NAME_LEN+2];  /* "db.tablename" */
 
2394
  char hash_key[DRIZZLE_MAX_DB_SIZE+DRIZZLE_MAX_TABLE_SIZE+2];  /* "db.tablename" */
2620
2395
  char *afterdot;
2621
 
  int using_mysql_db= my_strcasecmp(&my_charset_utf8_general_ci, database, "mysql");
2622
 
 
2623
 
 
2624
 
  afterdot= my_stpcpy(hash_key, database);
 
2396
  drizzle_result_st result;
 
2397
  drizzle_return_t ret;
 
2398
 
 
2399
  afterdot= strcpy(hash_key, database) + strlen(database);
2625
2400
  *afterdot++= '.';
2626
2401
 
2627
2402
  if (init_dumping(database, init_dumping_tables))
2628
2403
    return(1);
2629
2404
  if (opt_xml)
2630
2405
    print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NULL);
2631
 
  if (lock_tables)
 
2406
  if (flush_logs)
2632
2407
  {
2633
 
    string query;
2634
 
    query= "LOCK TABLES ";
2635
 
    for (numrows= 0 ; (table= getTableName(1)) ; )
 
2408
    if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
 
2409
        ret != DRIZZLE_RETURN_OK)
2636
2410
    {
2637
 
      char *end= my_stpcpy(afterdot, table);
2638
 
      if (include_table((unsigned char*) hash_key,end - hash_key))
2639
 
      {
2640
 
        numrows++;
2641
 
        query.append( quote_name(table, table_buff, 1));
2642
 
        query.append( " READ /*!32311 LOCAL */,");
2643
 
      }
 
2411
      DB_error(&result, ret, _("when doing refresh"));
 
2412
      /* We shall continue here, if --force was given */
2644
2413
    }
2645
 
    if (numrows && drizzle_real_query(drizzle, query.c_str(), query.length()-1))
2646
 
      DB_error(drizzle, "when using LOCK TABLES");
2647
 
            /* We shall continue here, if --force was given */
2648
 
    query.clear();
2649
 
  }
2650
 
  if (flush_logs)
2651
 
  {
2652
 
    if (drizzle_refresh(drizzle, REFRESH_LOG))
2653
 
      DB_error(drizzle, "when doing refresh");
2654
 
           /* We shall continue here, if --force was given */
 
2414
    else
 
2415
      drizzle_result_free(&result);
2655
2416
  }
2656
2417
  while ((table= getTableName(0)))
2657
2418
  {
2658
 
    char *end= my_stpcpy(afterdot, table);
 
2419
    char *end= strcpy(afterdot, table) + strlen(table);
2659
2420
    if (include_table((unsigned char*) hash_key, end - hash_key))
2660
2421
    {
2661
2422
      dump_table(table,database);
2668
2429
    fputs("</database>\n", md_result_file);
2669
2430
    check_io(md_result_file);
2670
2431
  }
2671
 
  if (lock_tables)
2672
 
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2673
 
  if (flush_privileges && using_mysql_db == 0)
2674
 
  {
2675
 
    fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2676
 
    fprintf(md_result_file,"\n/*! FLUSH PRIVILEGES */;\n");
2677
 
  }
2678
 
  return(0);
 
2432
 
 
2433
  return 0;
2679
2434
} /* dump_all_tables_in_db */
2680
2435
 
2681
2436
 
2693
2448
static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
2694
2449
{
2695
2450
  char *name= 0;
2696
 
  DRIZZLE_RES  *table_res;
2697
 
  DRIZZLE_ROW  row;
2698
 
  char query[50 + 2*NAME_LEN];
 
2451
  drizzle_result_st result;
 
2452
  drizzle_row_t  row;
 
2453
  char query[50 + 2*DRIZZLE_MAX_TABLE_SIZE];
2699
2454
  char show_name_buff[FN_REFLEN];
 
2455
  uint64_t num_rows;
2700
2456
 
2701
2457
 
2702
2458
  /* Check memory for quote_for_like() */
2704
2460
  snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2705
2461
           quote_for_like(old_table_name, show_name_buff));
2706
2462
 
2707
 
  if (drizzle_query_with_error_report(drizzle, 0, query))
 
2463
  if (drizzleclient_query_with_error_report(&dcon, &result, query, false))
2708
2464
    return NULL;
2709
2465
 
2710
 
  if ((table_res= drizzle_store_result(drizzle)))
 
2466
  num_rows= drizzle_result_row_count(&result);
 
2467
  if (num_rows > 0)
2711
2468
  {
2712
 
    uint64_t num_rows= drizzle_num_rows(table_res);
2713
 
    if (num_rows > 0)
2714
 
    {
2715
 
      uint32_t *lengths;
2716
 
      /*
2717
 
        Return first row
2718
 
        TODO: Return all matching rows
2719
 
      */
2720
 
      row= drizzle_fetch_row(table_res);
2721
 
      lengths= drizzle_fetch_lengths(table_res);
2722
 
      name= strmake_root(root, row[0], lengths[0]);
2723
 
    }
2724
 
    drizzle_free_result(table_res);
 
2469
    size_t *lengths;
 
2470
    /*
 
2471
      Return first row
 
2472
      TODO: Return all matching rows
 
2473
    */
 
2474
    row= drizzle_row_next(&result);
 
2475
    lengths= drizzle_row_field_sizes(&result);
 
2476
    name= strmake_root(root, row[0], lengths[0]);
2725
2477
  }
 
2478
  drizzle_result_free(&result);
 
2479
 
2726
2480
  return(name);
2727
2481
}
2728
2482
 
2729
2483
 
2730
2484
static int dump_selected_tables(char *db, char **table_names, int tables)
2731
2485
{
2732
 
  char table_buff[NAME_LEN*2+3];
2733
 
  string lock_tables_query;
2734
2486
  MEM_ROOT root;
2735
2487
  char **dump_tables, **pos, **end;
 
2488
  drizzle_result_st result;
 
2489
  drizzle_return_t ret;
2736
2490
 
2737
2491
 
2738
2492
  if (init_dumping(db, init_dumping_tables))
2740
2494
 
2741
2495
  init_alloc_root(&root, 8192, 0);
2742
2496
  if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
2743
 
     die(EX_EOM, "alloc_root failure.");
 
2497
     die(EX_EOM, _("alloc_root failure."));
2744
2498
 
2745
 
  lock_tables_query= "LOCK TABLES ";
2746
2499
  for (; tables > 0 ; tables-- , table_names++)
2747
2500
  {
2748
2501
    /* the table name passed on commandline may be wrong case */
2749
2502
    if ((*pos= get_actual_table_name(*table_names, &root)))
2750
2503
    {
2751
 
      /* Add found table name to lock_tables_query */
2752
 
      if (lock_tables)
2753
 
      {
2754
 
        lock_tables_query.append( quote_name(*pos, table_buff, 1));
2755
 
        lock_tables_query.append( " READ /*!32311 LOCAL */,");
2756
 
      }
2757
2504
      pos++;
2758
2505
    }
2759
2506
    else
2762
2509
      {
2763
2510
        free_root(&root, MYF(0));
2764
2511
      }
2765
 
      maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names);
 
2512
      maybe_die(EX_ILLEGAL_TABLE, _("Couldn't find table: \"%s\""), *table_names);
2766
2513
      /* We shall countinue here, if --force was given */
2767
2514
    }
2768
2515
  }
2769
2516
  end= pos;
2770
2517
 
2771
 
  if (lock_tables)
2772
 
  {
2773
 
    if (drizzle_real_query(drizzle, lock_tables_query.c_str(),
2774
 
                         lock_tables_query.length()-1))
2775
 
    {
2776
 
      if (!ignore_errors)
2777
 
      {
2778
 
        free_root(&root, MYF(0));
2779
 
      }
2780
 
      DB_error(drizzle, "when doing LOCK TABLES");
2781
 
       /* We shall countinue here, if --force was given */
2782
 
    }
2783
 
  }
2784
2518
  if (flush_logs)
2785
2519
  {
2786
 
    if (drizzle_refresh(drizzle, REFRESH_LOG))
 
2520
    if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
 
2521
        ret != DRIZZLE_RETURN_OK)
2787
2522
    {
2788
2523
      if (!ignore_errors)
2789
2524
        free_root(&root, MYF(0));
2790
 
      DB_error(drizzle, "when doing refresh");
 
2525
      DB_error(&result, ret, _("when doing refresh"));
 
2526
      /* We shall countinue here, if --force was given */
2791
2527
    }
2792
 
     /* We shall countinue here, if --force was given */
 
2528
    else
 
2529
      drizzle_result_free(&result);
2793
2530
  }
2794
2531
  if (opt_xml)
2795
2532
    print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
2806
2543
    fputs("</database>\n", md_result_file);
2807
2544
    check_io(md_result_file);
2808
2545
  }
2809
 
  if (lock_tables)
2810
 
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2811
 
  return(0);
 
2546
  return 0;
2812
2547
} /* dump_selected_tables */
2813
2548
 
2814
 
 
2815
 
static int do_show_master_status(DRIZZLE *drizzle_con)
2816
 
{
2817
 
  DRIZZLE_ROW row;
2818
 
  DRIZZLE_RES *master;
2819
 
  const char *comment_prefix=
2820
 
    (opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2821
 
  if (drizzle_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2822
 
  {
2823
 
    return 1;
2824
 
  }
2825
 
  else
2826
 
  {
2827
 
    row= drizzle_fetch_row(master);
2828
 
    if (row && row[0] && row[1])
2829
 
    {
2830
 
      /* SHOW MASTER STATUS reports file and position */
2831
 
      if (opt_comments)
2832
 
        fprintf(md_result_file,
2833
 
                "\n--\n-- Position to start replication or point-in-time "
2834
 
                "recovery from\n--\n\n");
2835
 
      fprintf(md_result_file,
2836
 
              "%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n",
2837
 
              comment_prefix, row[0], row[1]);
2838
 
      check_io(md_result_file);
2839
 
    }
2840
 
    else if (!ignore_errors)
2841
 
    {
2842
 
      /* SHOW MASTER STATUS reports nothing and --force is not enabled */
2843
 
      my_printf_error(0, "Error: Binlogging on server not active",
2844
 
                      MYF(0));
2845
 
      drizzle_free_result(master);
2846
 
      maybe_exit(EX_DRIZZLEERR);
2847
 
      return 1;
2848
 
    }
2849
 
    drizzle_free_result(master);
2850
 
  }
2851
 
  return 0;
2852
 
}
2853
 
 
2854
 
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
2855
 
{
2856
 
  DRIZZLE_RES *slave;
2857
 
  /* We need to check if the slave sql is running in the first place */
2858
 
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2859
 
    return(1);
2860
 
  else
2861
 
  {
2862
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
2863
 
    if (row && row[11])
2864
 
    {
2865
 
      /* if SLAVE SQL is not running, we don't stop it */
2866
 
      if (!strcmp(row[11],"No"))
2867
 
      {
2868
 
        drizzle_free_result(slave);
2869
 
        /* Silently assume that they don't have the slave running */
2870
 
        return(0);
2871
 
      }
2872
 
    }
2873
 
  }
2874
 
  drizzle_free_result(slave);
2875
 
 
2876
 
  /* now, stop slave if running */
2877
 
  if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2878
 
    return(1);
2879
 
 
2880
 
  return(0);
2881
 
}
2882
 
 
2883
 
static int add_stop_slave(void)
2884
 
{
2885
 
  if (opt_comments)
2886
 
    fprintf(md_result_file,
2887
 
            "\n--\n-- stop slave statement to make a recovery dump)\n--\n\n");
2888
 
  fprintf(md_result_file, "STOP SLAVE;\n");
2889
 
  return(0);
2890
 
}
2891
 
 
2892
 
static int add_slave_statements(void)
2893
 
{
2894
 
  if (opt_comments)
2895
 
    fprintf(md_result_file,
2896
 
            "\n--\n-- start slave statement to make a recovery dump)\n--\n\n");
2897
 
  fprintf(md_result_file, "START SLAVE;\n");
2898
 
  return(0);
2899
 
}
2900
 
 
2901
 
static int do_show_slave_status(DRIZZLE *drizzle_con)
2902
 
{
2903
 
  DRIZZLE_RES *slave;
2904
 
  const char *comment_prefix=
2905
 
    (opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2906
 
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2907
 
  {
2908
 
    if (!ignore_errors)
2909
 
    {
2910
 
      /* SHOW SLAVE STATUS reports nothing and --force is not enabled */
2911
 
      my_printf_error(0, "Error: Slave not set up", MYF(0));
2912
 
    }
2913
 
    return 1;
2914
 
  }
2915
 
  else
2916
 
  {
2917
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
2918
 
    if (row && row[9] && row[21])
2919
 
    {
2920
 
      /* SHOW MASTER STATUS reports file and position */
2921
 
      if (opt_comments)
2922
 
        fprintf(md_result_file,
2923
 
                "\n--\n-- Position to start replication or point-in-time "
2924
 
                "recovery from (the master of this slave)\n--\n\n");
2925
 
 
2926
 
      fprintf(md_result_file, "%sCHANGE MASTER TO ", comment_prefix);
2927
 
 
2928
 
      if (opt_include_master_host_port)
2929
 
      {
2930
 
        if (row[1])
2931
 
          fprintf(md_result_file, "MASTER_HOST='%s', ", row[1]);
2932
 
        if (row[3])
2933
 
          fprintf(md_result_file, "MASTER_PORT='%s', ", row[3]);
2934
 
      }
2935
 
      fprintf(md_result_file,
2936
 
              "MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", row[9], row[21]);
2937
 
 
2938
 
      check_io(md_result_file);
2939
 
    }
2940
 
    drizzle_free_result(slave);
2941
 
  }
2942
 
  return 0;
2943
 
}
2944
 
 
2945
 
static int do_start_slave_sql(DRIZZLE *drizzle_con)
2946
 
{
2947
 
  DRIZZLE_RES *slave;
2948
 
  /* We need to check if the slave sql is stopped in the first place */
2949
 
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2950
 
    return(1);
2951
 
  else
2952
 
  {
2953
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
2954
 
    if (row && row[11])
2955
 
    {
2956
 
      /* if SLAVE SQL is not running, we don't start it */
2957
 
      if (!strcmp(row[11],"Yes"))
2958
 
      {
2959
 
        drizzle_free_result(slave);
2960
 
        /* Silently assume that they don't have the slave running */
2961
 
        return(0);
2962
 
      }
2963
 
    }
2964
 
  }
2965
 
  drizzle_free_result(slave);
2966
 
 
2967
 
  /* now, start slave if stopped */
2968
 
  if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
2969
 
  {
2970
 
    my_printf_error(0, "Error: Unable to start slave", MYF(0));
2971
 
    return 1;
2972
 
  }
2973
 
  return(0);
2974
 
}
2975
 
 
2976
 
 
2977
 
 
2978
 
static int do_flush_tables_read_lock(DRIZZLE *drizzle_con)
 
2549
static int do_flush_tables_read_lock(drizzle_con_st *drizzle_con)
2979
2550
{
2980
2551
  /*
2981
2552
    We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
2986
2557
    update starts between the two FLUSHes, we have that bad stall.
2987
2558
  */
2988
2559
  return
2989
 
    ( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
2990
 
      drizzle_query_with_error_report(drizzle_con, 0,
2991
 
                                    "FLUSH TABLES WITH READ LOCK") );
2992
 
}
2993
 
 
2994
 
 
2995
 
static int do_unlock_tables(DRIZZLE *drizzle_con)
2996
 
{
2997
 
  return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
2998
 
}
2999
 
 
3000
 
static int get_bin_log_name(DRIZZLE *drizzle_con,
3001
 
                            char* buff_log_name, uint buff_len)
3002
 
{
3003
 
  DRIZZLE_RES *res;
3004
 
  DRIZZLE_ROW row;
3005
 
 
3006
 
  if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
3007
 
      !(res= drizzle_store_result(drizzle)))
3008
 
    return 1;
3009
 
 
3010
 
  if (!(row= drizzle_fetch_row(res)))
3011
 
  {
3012
 
    drizzle_free_result(res);
3013
 
    return 1;
3014
 
  }
3015
 
  /*
3016
 
    Only one row is returned, and the first column is the name of the
3017
 
    active log.
3018
 
  */
3019
 
  strmake(buff_log_name, row[0], buff_len - 1);
3020
 
 
3021
 
  drizzle_free_result(res);
3022
 
  return 0;
3023
 
}
3024
 
 
3025
 
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
3026
 
{
3027
 
  int err;
3028
 
  string str= "PURGE BINARY LOGS TO '";
3029
 
  str.append(log_name);
3030
 
  str.append("'");
3031
 
  err = drizzle_query_with_error_report(drizzle_con, 0, str.c_str());
3032
 
  return err;
3033
 
}
3034
 
 
3035
 
 
3036
 
static int start_transaction(DRIZZLE *drizzle_con)
3037
 
{
3038
 
  /*
3039
 
    We use BEGIN for old servers. --single-transaction --master-data will fail
3040
 
    on old servers, but that's ok as it was already silently broken (it didn't
3041
 
    do a consistent read, so better tell people frankly, with the error).
3042
 
 
3043
 
    We want the first consistent read to be used for all tables to dump so we
3044
 
    need the REPEATABLE READ level (not anything lower, for example READ
3045
 
    COMMITTED would give one new consistent read per dumped table).
3046
 
  */
3047
 
  if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
3048
 
  {
3049
 
    fprintf(stderr, "-- %s: the combination of --single-transaction and "
3050
 
            "--master-data requires a DRIZZLE server version of at least 4.1 "
3051
 
            "(current server's version is %s). %s\n",
3052
 
            ignore_errors ? "Warning" : "Error",
3053
 
            drizzle_con->server_version ? drizzle_con->server_version : "unknown",
3054
 
            ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3055
 
    if (!ignore_errors)
3056
 
      exit(EX_DRIZZLEERR);
3057
 
  }
3058
 
 
3059
 
  return (drizzle_query_with_error_report(drizzle_con, 0,
 
2560
    ( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES", false) ||
 
2561
      drizzleclient_query_with_error_report(drizzle_con, 0,
 
2562
                                    "FLUSH TABLES WITH READ LOCK", false) );
 
2563
}
 
2564
 
 
2565
static int do_unlock_tables(drizzle_con_st *drizzle_con)
 
2566
{
 
2567
  return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES", false);
 
2568
}
 
2569
 
 
2570
static int start_transaction(drizzle_con_st *drizzle_con)
 
2571
{
 
2572
  return (drizzleclient_query_with_error_report(drizzle_con, 0,
3060
2573
                                        "SET SESSION TRANSACTION ISOLATION "
3061
 
                                        "LEVEL REPEATABLE READ") ||
3062
 
          drizzle_query_with_error_report(drizzle_con, 0,
 
2574
                                        "LEVEL REPEATABLE READ", false) ||
 
2575
          drizzleclient_query_with_error_report(drizzle_con, 0,
3063
2576
                                        "START TRANSACTION "
3064
 
                                        "/*!40100 WITH CONSISTENT SNAPSHOT */"));
 
2577
                                        "WITH CONSISTENT SNAPSHOT", false));
3065
2578
}
3066
2579
 
3067
2580
 
3068
 
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
3069
 
                      char **err_pos, uint *err_len)
 
2581
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
 
2582
                      char **err_pos, uint32_t *err_len)
3070
2583
{
3071
2584
  const char *end= x + length;
3072
2585
  uint32_t found= 0;
3073
 
  uint find;
 
2586
  uint32_t find;
3074
2587
  char buff[255];
3075
2588
 
3076
2589
  *err_pos= 0;                  /* No error yet */
3088
2601
 
3089
2602
      for (; pos != end && *pos != ','; pos++) ;
3090
2603
      var_len= (uint32_t) (pos - start);
3091
 
      strmake(buff, start, min((uint32_t)sizeof(buff), var_len));
 
2604
      strncpy(buff, start, min((uint32_t)sizeof(buff), var_len+1));
3092
2605
      find= find_type(buff, lib, var_len);
3093
2606
      if (!find)
3094
2607
      {
3096
2609
        *err_len= var_len;
3097
2610
      }
3098
2611
      else
3099
 
        found|= ((int64_t) 1 << (find - 1));
 
2612
        found|= (uint32_t)((int64_t) 1 << (find - 1));
3100
2613
      if (pos == end)
3101
2614
        break;
3102
2615
      start= pos + 1;
3107
2620
 
3108
2621
 
3109
2622
/* Print a value with a prefix on file */
3110
 
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
 
2623
static void print_value(FILE *file, drizzle_result_st  *result, drizzle_row_t row,
3111
2624
                        const char *prefix, const char *name,
3112
2625
                        int string_value)
3113
2626
{
3114
 
  DRIZZLE_FIELD   *field;
3115
 
  drizzle_field_seek(result, 0);
 
2627
  drizzle_column_st *column;
 
2628
  drizzle_column_seek(result, 0);
3116
2629
 
3117
 
  for ( ; (field= drizzle_fetch_field(result)) ; row++)
 
2630
  for ( ; (column= drizzle_column_next(result)) ; row++)
3118
2631
  {
3119
 
    if (!strcmp(field->name,name))
 
2632
    if (!strcmp(drizzle_column_name(column),name))
3120
2633
    {
3121
2634
      if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
3122
2635
      {
3123
2636
        fputc(' ',file);
3124
2637
        fputs(prefix, file);
3125
2638
        if (string_value)
3126
 
          unescape(file,row[0],(uint) strlen(row[0]));
 
2639
          unescape(file,row[0],(uint32_t) strlen(row[0]));
3127
2640
        else
3128
2641
          fputs(row[0], file);
3129
2642
        check_io(file);
3134
2647
  return;                                       /* This shouldn't happen */
3135
2648
} /* print_value */
3136
2649
 
 
2650
/**
 
2651
 * Fetches a row from a result based on a field name
 
2652
 * Returns const char* of the data in that row or NULL if not found
 
2653
 */
 
2654
 
 
2655
static const char* fetch_named_row(drizzle_result_st *result, drizzle_row_t row, const char *name)
 
2656
{
 
2657
  drizzle_column_st *column;
 
2658
  drizzle_column_seek(result, 0);
 
2659
 
 
2660
  for ( ; (column= drizzle_column_next(result)) ; row++)
 
2661
  {
 
2662
    if (!strcmp(drizzle_column_name(column),name))
 
2663
    {
 
2664
      if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
 
2665
      {
 
2666
        drizzle_column_seek(result, 0);
 
2667
        return row[0];
 
2668
      }
 
2669
    }
 
2670
  }
 
2671
  drizzle_column_seek(result, 0);
 
2672
  return NULL;
 
2673
}
 
2674
 
3137
2675
 
3138
2676
/*
3139
2677
  SYNOPSIS
3163
2701
{
3164
2702
  char result= IGNORE_NONE;
3165
2703
  char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3166
 
  DRIZZLE_RES *res= NULL;
3167
 
  DRIZZLE_ROW row;
3168
 
 
 
2704
  const char *number_of_rows= NULL;
 
2705
  drizzle_result_st res;
 
2706
  drizzle_row_t row;
3169
2707
 
3170
2708
  /* Check memory for quote_for_like() */
3171
2709
  assert(2*sizeof(table_name) < sizeof(show_name_buff));
3172
2710
  snprintf(buff, sizeof(buff), "show table status like %s",
3173
2711
           quote_for_like(table_name, show_name_buff));
3174
 
  if (drizzle_query_with_error_report(drizzle, &res, buff))
 
2712
  if (drizzleclient_query_with_error_report(&dcon, &res, buff, false))
3175
2713
  {
3176
 
    if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
3177
 
    {                                   /* If old DRIZZLE version */
3178
 
      verbose_msg("-- Warning: Couldn't get status information for "
3179
 
                  "table %s (%s)\n", table_name, drizzle_error(drizzle));
3180
 
      return(result);                       /* assume table is ok */
3181
 
    }
 
2714
    return result;
3182
2715
  }
3183
 
  if (!(row= drizzle_fetch_row(res)))
 
2716
  if (!(row= drizzle_row_next(&res)))
3184
2717
  {
3185
2718
    fprintf(stderr,
3186
 
            "Error: Couldn't read status information for table %s (%s)\n",
3187
 
            table_name, drizzle_error(drizzle));
3188
 
    drizzle_free_result(res);
 
2719
            _("Error: Couldn't read status information for table %s\n"),
 
2720
            table_name);
 
2721
    drizzle_result_free(&res);
3189
2722
    return(result);                         /* assume table is ok */
3190
2723
  }
3191
 
  if (!(row[1]))
3192
 
    strmake(table_type, "VIEW", NAME_LEN-1);
3193
2724
  else
3194
2725
  {
3195
 
    /*
3196
 
      If the table type matches any of these, we do support delayed inserts.
3197
 
      Note: we do not want to skip dumping this table if if is not one of
3198
 
      these types, but we do want to use delayed inserts in the dump if
3199
 
      the table type is _NOT_ one of these types
 
2726
    if ((number_of_rows= fetch_named_row(&res, row, "Rows")) != NULL)
 
2727
    {
 
2728
      total_rows= strtoul(number_of_rows, NULL, 10);
 
2729
    }
 
2730
  }
 
2731
  /*
 
2732
    If the table type matches any of these, we do support delayed inserts.
 
2733
    Note: we do not want to skip dumping this table if if is not one of
 
2734
    these types, but we do want to use delayed inserts in the dump if
 
2735
    the table type is _NOT_ one of these types
3200
2736
    */
3201
 
    strmake(table_type, row[1], NAME_LEN-1);
 
2737
  {
 
2738
    strncpy(table_type, row[1], DRIZZLE_MAX_TABLE_SIZE-1);
3202
2739
    if (opt_delayed)
3203
2740
    {
3204
2741
      if (strcmp(table_type,"MyISAM") &&
3205
 
          strcmp(table_type,"ISAM") &&
3206
2742
          strcmp(table_type,"ARCHIVE") &&
3207
2743
          strcmp(table_type,"HEAP") &&
3208
2744
          strcmp(table_type,"MEMORY"))
3209
2745
        result= IGNORE_INSERT_DELAYED;
3210
2746
    }
3211
 
 
3212
 
    /*
3213
 
      If these two types, we do want to skip dumping the table
3214
 
    */
3215
 
    if (!opt_no_data &&
3216
 
        (!my_strcasecmp(&my_charset_utf8_general_ci, table_type, "MRG_MyISAM") ||
3217
 
         !strcmp(table_type,"MRG_ISAM")))
3218
 
      result= IGNORE_DATA;
3219
2747
  }
3220
 
  drizzle_free_result(res);
 
2748
  drizzle_result_free(&res);
3221
2749
  return(result);
3222
2750
}
3223
2751
 
3242
2770
 
3243
2771
static char *primary_key_fields(const char *table_name)
3244
2772
{
3245
 
  DRIZZLE_RES  *res= NULL;
3246
 
  DRIZZLE_ROW  row;
 
2773
  drizzle_result_st res;
 
2774
  drizzle_return_t ret;
 
2775
  drizzle_row_t  row;
3247
2776
  /* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3248
 
  char show_keys_buff[15 + NAME_LEN * 2 + 3];
3249
 
  uint result_length= 0;
 
2777
  char show_keys_buff[15 + DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
 
2778
  uint32_t result_length= 0;
3250
2779
  char *result= 0;
3251
 
  char buff[NAME_LEN * 2 + 3];
 
2780
  char buff[DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
3252
2781
  char *quoted_field;
3253
2782
 
3254
2783
  snprintf(show_keys_buff, sizeof(show_keys_buff),
3255
2784
           "SHOW KEYS FROM %s", table_name);
3256
 
  if (drizzle_query(drizzle, show_keys_buff) ||
3257
 
      !(res= drizzle_store_result(drizzle)))
3258
 
  {
3259
 
    fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3260
 
            " records are NOT sorted (%s)\n",
3261
 
            table_name, drizzle_error(drizzle));
3262
 
    /* Don't exit, because it's better to print out unsorted records */
3263
 
    goto cleanup;
 
2785
  if (drizzle_query_str(&dcon, &res, show_keys_buff, &ret) == NULL ||
 
2786
      ret != DRIZZLE_RETURN_OK)
 
2787
  {
 
2788
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
2789
    {
 
2790
      fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
 
2791
              " records are NOT sorted (%s)\n"),
 
2792
              table_name, drizzle_result_error(&res));
 
2793
      drizzle_result_free(&res);
 
2794
    }
 
2795
    else
 
2796
    {
 
2797
      fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
 
2798
              " records are NOT sorted (%s)\n"),
 
2799
              table_name, drizzle_con_error(&dcon));
 
2800
    }
 
2801
 
 
2802
    return result;
 
2803
  }
 
2804
 
 
2805
  if (drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
 
2806
  {
 
2807
    fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
 
2808
            " records are NOT sorted (%s)\n"),
 
2809
            table_name, drizzle_con_error(&dcon));
 
2810
    return result;
3264
2811
  }
3265
2812
 
3266
2813
  /*
3269
2816
   * row, and UNIQUE keys come before others.  So we only need to check
3270
2817
   * the first key, not all keys.
3271
2818
   */
3272
 
  if ((row= drizzle_fetch_row(res)) && atoi(row[1]) == 0)
 
2819
  if ((row= drizzle_row_next(&res)) && atoi(row[1]) == 0)
3273
2820
  {
3274
2821
    /* Key is unique */
3275
2822
    do
3276
2823
    {
3277
2824
      quoted_field= quote_name(row[4], buff, 0);
3278
2825
      result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3279
 
    } while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1);
 
2826
    } while ((row= drizzle_row_next(&res)) && atoi(row[3]) > 1);
3280
2827
  }
3281
2828
 
3282
2829
  /* Build the ORDER BY clause result */
3284
2831
  {
3285
2832
    char *end;
3286
2833
    /* result (terminating \0 is already in result_length) */
3287
 
    result= (char *)my_malloc(result_length + 10, MYF(MY_WME));
 
2834
    result= (char *)malloc(result_length + 10);
3288
2835
    if (!result)
3289
2836
    {
3290
 
      fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
3291
 
      goto cleanup;
 
2837
      fprintf(stderr, _("Error: Not enough memory to store ORDER BY clause\n"));
 
2838
      drizzle_result_free(&res);
 
2839
      return result;
3292
2840
    }
3293
 
    drizzle_data_seek(res, 0);
3294
 
    row= drizzle_fetch_row(res);
 
2841
    drizzle_row_seek(&res, 0);
 
2842
    row= drizzle_row_next(&res);
3295
2843
    quoted_field= quote_name(row[4], buff, 0);
3296
 
    end= my_stpcpy(result, quoted_field);
3297
 
    while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
 
2844
    end= strcpy(result, quoted_field) + strlen(quoted_field);
 
2845
    while ((row= drizzle_row_next(&res)) && atoi(row[3]) > 1)
3298
2846
    {
3299
2847
      quoted_field= quote_name(row[4], buff, 0);
3300
 
      end= strxmov(end, ",", quoted_field, NULL);
 
2848
      end+= sprintf(end,",%s",quoted_field);
3301
2849
    }
3302
2850
  }
3303
2851
 
3304
 
cleanup:
3305
 
  if (res)
3306
 
    drizzle_free_result(res);
3307
 
 
 
2852
  drizzle_result_free(&res);
3308
2853
  return result;
3309
2854
}
3310
2855
 
3311
2856
 
3312
2857
int main(int argc, char **argv)
3313
2858
{
3314
 
  char bin_log_name[FN_REFLEN];
3315
2859
  int exit_code;
3316
 
  MY_INIT("mysqldump");
 
2860
  MY_INIT("drizzledump");
 
2861
  drizzle_result_st result;
3317
2862
 
3318
2863
  compatible_mode_normal_str[0]= 0;
3319
 
  default_charset= (char *)drizzle_universal_client_charset;
3320
2864
  memset(&ignore_table, 0, sizeof(ignore_table));
3321
2865
 
3322
2866
  exit_code= get_options(&argc, &argv);
3326
2870
    exit(exit_code);
3327
2871
  }
3328
2872
 
3329
 
  if (log_error_file)
3330
 
  {
3331
 
    if(!(stderror_file= freopen(log_error_file, "a+", stderr)))
3332
 
    {
3333
 
      free_resources();
3334
 
      exit(EX_DRIZZLEERR);
3335
 
    }
3336
 
  }
3337
 
 
3338
2873
  if (connect_to_db(current_host, current_user, opt_password))
3339
2874
  {
3340
2875
    free_resources();
3343
2878
  if (!path)
3344
2879
    write_header(md_result_file, *argv);
3345
2880
 
3346
 
  if (opt_slave_data && do_stop_slave_sql(drizzle))
3347
 
    goto err;
3348
 
 
3349
 
  if ((opt_lock_all_tables || opt_master_data) &&
3350
 
      do_flush_tables_read_lock(drizzle))
3351
 
    goto err;
3352
 
  if (opt_single_transaction && start_transaction(drizzle))
3353
 
      goto err;
3354
 
  if (opt_delete_master_logs)
3355
 
  {
3356
 
    if (drizzle_refresh(drizzle, REFRESH_LOG) ||
3357
 
        get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
3358
 
      goto err;
3359
 
    flush_logs= 0;
3360
 
  }
3361
 
  if (opt_lock_all_tables || opt_master_data)
3362
 
  {
3363
 
    if (flush_logs && drizzle_refresh(drizzle, REFRESH_LOG))
3364
 
      goto err;
 
2881
  if ((opt_lock_all_tables) && do_flush_tables_read_lock(&dcon))
 
2882
    goto err;
 
2883
  if (opt_single_transaction && start_transaction(&dcon))
 
2884
      goto err;
 
2885
  if (opt_lock_all_tables)
 
2886
  {
 
2887
    if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))
 
2888
      goto err;
 
2889
    drizzle_result_free(&result);
3365
2890
    flush_logs= 0; /* not anymore; that would not be sensible */
3366
2891
  }
3367
 
  /* Add 'STOP SLAVE to beginning of dump */
3368
 
  if (opt_slave_apply && add_stop_slave())
3369
 
    goto err;
3370
 
  if (opt_master_data && do_show_master_status(drizzle))
3371
 
    goto err;
3372
 
  if (opt_slave_data && do_show_slave_status(drizzle))
3373
 
    goto err;
3374
 
  if (opt_single_transaction && do_unlock_tables(drizzle)) /* unlock but no commit! */
 
2892
  if (opt_single_transaction && do_unlock_tables(&dcon)) /* unlock but no commit! */
3375
2893
    goto err;
3376
2894
 
3377
2895
  if (opt_alldbs)
3388
2906
    dump_databases(argv);
3389
2907
  }
3390
2908
 
3391
 
  /* if --dump-slave , start the slave sql thread */
3392
 
  if (opt_slave_data && do_start_slave_sql(drizzle))
3393
 
    goto err;
3394
 
 
3395
 
  /* add 'START SLAVE' to end of dump */
3396
 
  if (opt_slave_apply && add_slave_statements())
3397
 
    goto err;
3398
 
 
3399
2909
  /* ensure dumped data flushed */
3400
2910
  if (md_result_file && fflush(md_result_file))
3401
2911
  {
3403
2913
      first_error= EX_DRIZZLEERR;
3404
2914
    goto err;
3405
2915
  }
3406
 
  /* everything successful, purge the old logs files */
3407
 
  if (opt_delete_master_logs && purge_bin_logs_to(drizzle, bin_log_name))
3408
 
    goto err;
3409
2916
 
3410
2917
  /*
3411
2918
    No reason to explicitely COMMIT the transaction, neither to explicitely