~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqldump.c

MergingĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 Drizzle Open Source Development Project
 
1
/* Copyright (C) 2000 MySQL AB
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
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
/* drizzledump.cc  - Dump a tables contents and format to an ASCII file
 
16
/* mysqldump.c  - Dump a tables contents and format to an ASCII file
17
17
**
18
18
** The author's original notes follow :-
19
19
**
22
22
** WARRANTY: None, expressed, impressed, implied
23
23
**          or other
24
24
** STATUS: Public domain
 
25
** Adapted and optimized for MySQL by
 
26
** Michael Widenius, Sinisa Milivojevic, Jani Tolonen
 
27
** -w --where added 9/10/98 by Jim Faucette
 
28
** slave code by David Saez Padros <david@ols.es>
 
29
** master/autocommit code by Brian Aker <brian@tangent.org>
 
30
** SSL by
 
31
** Andrei Errapart <andreie@no.spam.ee>
 
32
** Tõnu Samuel  <tonu@please.do.not.remove.this.spam.ee>
 
33
** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up
 
34
** and adapted to mysqldump 05/11/01 by Jani Tolonen
 
35
** Added --single-transaction option 06/06/2002 by Peter Zaitsev
 
36
** 10 Jun 2003: SET NAMES and --no-set-names by Alexander Barkov
25
37
*/
26
38
 
27
39
#define DUMP_VERSION "10.13"
28
40
 
29
 
#include "config.h"
30
 
#include <string>
 
41
#include <my_global.h>
 
42
#include <my_sys.h>
 
43
#include <m_string.h>
 
44
#include <m_ctype.h>
 
45
#include <hash.h>
 
46
#include <stdarg.h>
 
47
 
31
48
#include "client_priv.h"
32
 
 
33
 
#include <mysys/my_sys.h>
34
 
#include <mystrings/m_string.h>
35
 
#include <mystrings/m_ctype.h>
36
 
#include <mysys/hash.h>
37
 
#include <stdarg.h>
38
 
 
39
 
#include <drizzled/error.h>
40
 
 
41
 
using namespace std;
 
49
#include "drizzle_version.h"
 
50
#include "mysqld_error.h"
 
51
 
42
52
/* Exit codes */
43
53
 
44
54
#define EX_USAGE 1
45
 
#define EX_DRIZZLEERR 2
 
55
#define EX_MYSQLERR 2
46
56
#define EX_CONSCHECK 3
47
57
#define EX_EOM 4
48
58
#define EX_EOF 5 /* ferror for output file was got */
64
74
#define IGNORE_DATA 0x01 /* don't dump data for this table */
65
75
#define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
66
76
 
67
 
static void add_load_option(string &str, const char *option,
68
 
                            const char *option_value);
69
 
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
 
77
static void add_load_option(DYNAMIC_STRING *str, const char *option,
 
78
                             const char *option_value);
 
79
static ulong find_set(TYPELIB *lib, const char *x, uint length,
70
80
                      char **err_pos, uint *err_len);
71
81
 
72
 
static void field_escape(string &in, const char *from);
73
 
static bool  verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
 
82
static void field_escape(DYNAMIC_STRING* in, const char *from);
 
83
static my_bool  verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
74
84
                quick= 1, extended_insert= 1,
75
85
                lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
76
86
                opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
88
98
                opt_include_master_host_port= 0,
89
99
                opt_events= 0,
90
100
                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;
94
 
static string insert_pat;
 
101
static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
 
102
static ulong opt_max_allowed_packet, opt_net_buffer_length;
 
103
static MYSQL mysql_connection,*mysql=0;
 
104
static DYNAMIC_STRING insert_pat;
95
105
static char  *opt_password=0,*current_user=0,
96
106
             *current_host=0,*path=0,*fields_terminated=0,
97
107
             *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
102
112
static char **defaults_argv= 0;
103
113
static char compatible_mode_normal_str[255];
104
114
/* Server supports character_set_results session variable? */
105
 
static bool server_supports_switching_charsets= true;
106
 
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;
 
115
static my_bool server_supports_switching_charsets= TRUE;
 
116
static ulong opt_compatible_mode= 0;
 
117
#define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1
 
118
#define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2
 
119
#define MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
 
120
#define MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL 2
 
121
static uint opt_mysql_port= 0, opt_master_data;
112
122
static uint opt_slave_data;
113
123
static uint my_end_arg;
114
124
static int   first_error=0;
115
 
static string extended_row;
 
125
static DYNAMIC_STRING extended_row;
116
126
FILE *md_result_file= 0;
117
127
FILE *stderror_file=0;
118
128
 
 
129
#ifdef HAVE_SMEM
 
130
static char *shared_memory_base_name=0;
 
131
#endif
 
132
static uint opt_protocol= MYSQL_PROTOCOL_TCP;
 
133
 
 
134
/*
 
135
Dynamic_string wrapper functions. In this file use these
 
136
wrappers, they will terminate the process if there is
 
137
an allocation failure.
 
138
*/
 
139
static void init_dynamic_string_checked(DYNAMIC_STRING *str, const char *init_str,
 
140
                            uint init_alloc, uint alloc_increment);
 
141
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src);
 
142
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str);
 
143
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
 
144
                          uint length);
 
145
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size);
119
146
/*
120
147
  Constant for detection of default value of default_charset.
121
 
  If default_charset is equal to drizzle_universal_client_charset, then
 
148
  If default_charset is equal to mysql_universal_client_charset, then
122
149
  it is the default value which assigned at the very beginning of main().
123
150
*/
124
 
static const char *drizzle_universal_client_charset=
125
 
  DRIZZLE_UNIVERSAL_CLIENT_CHARSET;
 
151
static const char *mysql_universal_client_charset=
 
152
  MYSQL_UNIVERSAL_CLIENT_CHARSET;
126
153
static char *default_charset;
127
 
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
128
 
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
 
154
static CHARSET_INFO *charset_info= &my_charset_latin1;
 
155
const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
129
156
/* have we seen any VIEWs during table scanning? */
130
 
bool seen_views= 0;
 
157
my_bool seen_views= 0;
131
158
const char *compatible_mode_names[]=
132
159
{
133
160
  "MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
134
161
  "MAXDB", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS",
135
162
  "ANSI",
136
 
  NULL
 
163
  NullS
137
164
};
138
165
#define MASK_ANSI_QUOTES \
139
166
(\
152
179
static struct my_option my_long_options[] =
153
180
{
154
181
  {"all", 'a', "Deprecated. Use --create-options instead.",
155
 
   (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
 
182
   (uchar**) &create_options, (uchar**) &create_options, 0, GET_BOOL, NO_ARG, 1,
156
183
   0, 0, 0, 0, 0},
157
184
  {"all-databases", 'A',
158
185
   "Dump all the databases. This will be same as --databases with all databases selected.",
159
 
   (char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
186
   (uchar**) &opt_alldbs, (uchar**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
160
187
   0, 0},
161
188
  {"all-tablespaces", 'Y',
162
189
   "Dump all the tablespaces.",
163
 
   (char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
190
   (uchar**) &opt_alltspcs, (uchar**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
164
191
   0, 0},
165
192
  {"no-tablespaces", 'y',
166
193
   "Do not dump any tablespace information.",
167
 
   (char**) &opt_notspcs, (char**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
194
   (uchar**) &opt_notspcs, (uchar**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
168
195
   0, 0},
169
196
  {"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
170
 
   (char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
197
   (uchar**) &opt_drop_database, (uchar**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
171
198
   0},
172
199
  {"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
173
 
   (char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
 
200
   (uchar**) &opt_drop, (uchar**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
174
201
   0},
175
202
  {"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,
 
203
   (uchar**) &opt_lock, (uchar**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
177
204
   0},
178
205
  {"allow-keywords", OPT_KEYWORDS,
179
 
   "Allow creation of column names that are keywords.", (char**) &opt_keywords,
180
 
   (char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
181
 
  {"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
 
206
   "Allow creation of column names that are keywords.", (uchar**) &opt_keywords,
 
207
   (uchar**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
208
  {"apply-slave-statements", OPT_MYSQLDUMP_SLAVE_APPLY,
182
209
   "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,
 
210
   (uchar**) &opt_slave_apply, (uchar**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
184
211
   0, 0, 0, 0, 0, 0},
185
212
  {"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},
 
213
   "Directory where character sets are.", (uchar**) &charsets_dir,
 
214
   (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
188
215
  {"comments", 'i', "Write additional information.",
189
 
   (char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
 
216
   (uchar**) &opt_comments, (uchar**) &opt_comments, 0, GET_BOOL, NO_ARG,
190
217
   1, 0, 0, 0, 0, 0},
191
218
  {"compatible", OPT_COMPATIBLE,
192
 
   "Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires DRIZZLE server version 4.1.0 or higher. This option is ignored with earlier server versions.",
193
 
   (char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
 
219
   "Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires MySQL server version 4.1.0 or higher. This option is ignored with earlier server versions.",
 
220
   (uchar**) &opt_compatible_mode_str, (uchar**) &opt_compatible_mode_str, 0,
194
221
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
195
222
  {"compact", OPT_COMPACT,
196
223
   "Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs.  Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks",
197
 
   (char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
224
   (uchar**) &opt_compact, (uchar**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
198
225
   0, 0},
199
226
  {"complete-insert", 'c', "Use complete insert statements.",
200
 
   (char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
 
227
   (uchar**) &opt_complete_insert, (uchar**) &opt_complete_insert, 0, GET_BOOL,
201
228
   NO_ARG, 0, 0, 0, 0, 0, 0},
202
229
  {"compress", 'C', "Use compression in server/client protocol.",
203
 
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
230
   (uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
204
231
   0, 0, 0},
205
232
  {"create-options", OPT_CREATE_OPTIONS,
206
 
   "Include all DRIZZLE specific create options.",
207
 
   (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
 
233
   "Include all MySQL specific create options.",
 
234
   (uchar**) &create_options, (uchar**) &create_options, 0, GET_BOOL, NO_ARG, 1,
208
235
   0, 0, 0, 0, 0},
209
236
  {"databases", 'B',
210
237
   "To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output.",
211
 
   (char**) &opt_databases, (char**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
 
238
   (uchar**) &opt_databases, (uchar**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
212
239
   0, 0, 0, 0},
 
240
#ifdef DBUG_OFF
 
241
  {"debug", '#', "This is a non-debug version. Catch this and exit",
 
242
   0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
243
#else
 
244
  {"debug", '#', "Output debug log", (uchar**) &default_dbug_option,
 
245
   (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
246
#endif
213
247
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
214
 
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
248
   (uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
215
249
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
216
250
  {"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
217
 
   (char**) &debug_info_flag, (char**) &debug_info_flag,
 
251
   (uchar**) &debug_info_flag, (uchar**) &debug_info_flag,
218
252
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
219
253
  {"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},
 
254
   "Set the default character set.", (uchar**) &default_charset,
 
255
   (uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
222
256
  {"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
223
 
   (char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
257
   (uchar**) &opt_delayed, (uchar**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
224
258
   0, 0},
225
259
  {"delete-master-logs", OPT_DELETE_MASTER_LOGS,
226
260
   "Delete logs on master after backup. This automatically enables --master-data.",
227
 
   (char**) &opt_delete_master_logs, (char**) &opt_delete_master_logs, 0,
 
261
   (uchar**) &opt_delete_master_logs, (uchar**) &opt_delete_master_logs, 0,
228
262
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
229
263
  {"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,
231
 
   (char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
232
 
  {"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
 
264
   "'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (uchar**) &opt_disable_keys,
 
265
   (uchar**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
266
  {"dump-slave", OPT_MYSQLDUMP_SLAVE_DATA,
233
267
   "This causes the binary log position and filename of the master to be "
234
268
   "appended to the dumped data output. Setting the value to 1, will print"
235
269
   "it as a CHANGE MASTER command in the dumped data output; if equal"
240
274
   "- don't forget to read about --single-transaction below). In all cases "
241
275
   "any action on logs will happen at the exact moment of the dump."
242
276
   "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},
 
277
   (uchar**) &opt_slave_data, (uchar**) &opt_slave_data, 0,
 
278
   GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
245
279
  {"events", 'E', "Dump events.",
246
 
     (char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
 
280
     (uchar**) &opt_events, (uchar**) &opt_events, 0, GET_BOOL,
247
281
     NO_ARG, 0, 0, 0, 0, 0, 0},
248
282
  {"extended-insert", 'e',
249
283
   "Allows utilization of the new, much faster INSERT syntax.",
250
 
   (char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
 
284
   (uchar**) &extended_insert, (uchar**) &extended_insert, 0, GET_BOOL, NO_ARG,
251
285
   1, 0, 0, 0, 0, 0},
252
286
  {"fields-terminated-by", OPT_FTB,
253
 
   "Fields in the textfile are terminated by ...", (char**) &fields_terminated,
254
 
   (char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
287
   "Fields in the textfile are terminated by ...", (uchar**) &fields_terminated,
 
288
   (uchar**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
255
289
  {"fields-enclosed-by", OPT_ENC,
256
 
   "Fields in the importfile are enclosed by ...", (char**) &enclosed,
257
 
   (char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
 
290
   "Fields in the importfile are enclosed by ...", (uchar**) &enclosed,
 
291
   (uchar**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
258
292
  {"fields-optionally-enclosed-by", OPT_O_ENC,
259
 
   "Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
260
 
   (char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
 
293
   "Fields in the i.file are opt. enclosed by ...", (uchar**) &opt_enclosed,
 
294
   (uchar**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
261
295
  {"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
262
 
   (char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
296
   (uchar**) &escaped, (uchar**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
263
297
  {"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,
 
298
   (uchar**) &opt_lock_all_tables, (uchar**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
265
299
   0, 0, 0, 0, 0, 0},
266
300
  {"flush-logs", 'F', "Flush logs file in server before starting dump. "
267
301
   "Note that if you dump many databases at once (using the option "
272
306
   "to the moment all tables are locked. So if you want your dump and "
273
307
   "the log flush to happen at the same exact moment you should use "
274
308
   "--lock-all-tables or --master-data with --flush-logs",
275
 
   (char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
309
   (uchar**) &flush_logs, (uchar**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
276
310
   0, 0},
277
311
  {"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,
 
312
   "after dumping the mysql database.  This option should be used any "
 
313
   "time the dump contains the mysql database and any other database "
 
314
   "that depends on the data in the mysql database for proper restore. ",
 
315
   (uchar**) &flush_privileges, (uchar**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
282
316
   0, 0},
283
317
  {"force", 'f', "Continue even if we get an sql-error.",
284
 
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
 
318
   (uchar**) &ignore_errors, (uchar**) &ignore_errors, 0, GET_BOOL, NO_ARG,
285
319
   0, 0, 0, 0, 0, 0},
286
320
  {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
287
321
   NO_ARG, 0, 0, 0, 0, 0, 0},
288
322
  {"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, "
289
323
    "VARBINARY, BLOB) in hexadecimal format.",
290
 
   (char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
291
 
  {"host", 'h', "Connect to host.", (char**) &current_host,
292
 
   (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
324
   (uchar**) &opt_hex_blob, (uchar**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
325
  {"host", 'h', "Connect to host.", (uchar**) &current_host,
 
326
   (uchar**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
293
327
  {"ignore-table", OPT_IGNORE_TABLE,
294
328
   "Do not dump the specified table. To specify more than one table to ignore, "
295
329
   "use the directive multiple times, once for each table.  Each table must "
296
330
   "be specified with both database and table names, e.g. --ignore-table=database.table",
297
331
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
298
 
  {"include-master-host-port", OPT_DRIZZLEDUMP_INCLUDE_MASTER_HOST_PORT,
 
332
  {"include-master-host-port", OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT,
299
333
   "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, 
 
334
   (uchar**) &opt_include_master_host_port, 
 
335
   (uchar**) &opt_include_master_host_port, 
302
336
   0, GET_BOOL, NO_ARG,
303
337
   0, 0, 0, 0, 0, 0},
304
338
  {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
305
 
   (char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
339
   (uchar**) &opt_ignore, (uchar**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
306
340
   0, 0},
307
341
  {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
308
 
   (char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
 
342
   (uchar**) &lines_terminated, (uchar**) &lines_terminated, 0, GET_STR,
309
343
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
310
344
  {"lock-all-tables", 'x', "Locks all tables across all databases. This "
311
345
   "is achieved by taking a global read lock for the duration of the whole "
312
346
   "dump. Automatically turns --single-transaction and --lock-tables off.",
313
 
   (char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
 
347
   (uchar**) &opt_lock_all_tables, (uchar**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
314
348
   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},
 
349
  {"lock-tables", 'l', "Lock all tables for read.", (uchar**) &lock_tables,
 
350
   (uchar**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
317
351
  {"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,
 
352
   (uchar**) &log_error_file, (uchar**) &log_error_file, 0, GET_STR,
319
353
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
320
354
  {"master-data", OPT_MASTER_DATA,
321
355
   "This causes the binary log position and filename to be appended to the "
327
361
   "- don't forget to read about --single-transaction below). In all cases "
328
362
   "any action on logs will happen at the exact moment of the dump."
329
363
   "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},
 
364
   (uchar**) &opt_master_data, (uchar**) &opt_master_data, 0,
 
365
   GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
332
366
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
333
 
    (char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
 
367
    (uchar**) &opt_max_allowed_packet, (uchar**) &opt_max_allowed_packet, 0,
334
368
    GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
335
 
   (int64_t) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
 
369
   (longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
336
370
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
337
 
    (char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
 
371
    (uchar**) &opt_net_buffer_length, (uchar**) &opt_net_buffer_length, 0,
338
372
    GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
339
373
   MALLOC_OVERHEAD-1024, 1024, 0},
340
374
  {"no-autocommit", OPT_AUTOCOMMIT,
341
375
   "Wrap tables with autocommit/commit statements.",
342
 
   (char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
 
376
   (uchar**) &opt_autocommit, (uchar**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
343
377
   0, 0, 0, 0, 0, 0},
344
378
  {"no-create-db", 'n',
345
379
   "'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.}.",
346
 
   (char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
 
380
   (uchar**) &opt_create_db, (uchar**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
347
381
   0, 0, 0, 0},
348
382
  {"no-create-info", 't', "Don't write table creation info.",
349
 
   (char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
 
383
   (uchar**) &opt_no_create_info, (uchar**) &opt_no_create_info, 0, GET_BOOL,
350
384
   NO_ARG, 0, 0, 0, 0, 0, 0},
351
 
  {"no-data", 'd', "No row information.", (char**) &opt_no_data,
352
 
   (char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
385
  {"no-data", 'd', "No row information.", (uchar**) &opt_no_data,
 
386
   (uchar**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
353
387
  {"no-set-names", 'N',
354
388
   "Deprecated. Use --skip-set-charset instead.",
355
389
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
358
392
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
359
393
  {"order-by-primary", OPT_ORDER_BY_PRIMARY,
360
394
   "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
 
   (char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
395
   (uchar**) &opt_order_by_primary, (uchar**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
362
396
  {"password", 'p',
363
397
   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
364
398
   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,
 
399
  {"port", 'P', "Port number to use for connection.", (uchar**) &opt_mysql_port,
 
400
   (uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
367
401
   0},
368
402
  {"quick", 'q', "Don't buffer query, dump directly to stdout.",
369
 
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
403
   (uchar**) &quick, (uchar**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
370
404
  {"quote-names",'Q', "Quote table and column names with backticks (`).",
371
 
   (char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
 
405
   (uchar**) &opt_quoted, (uchar**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
372
406
   0, 0},
373
 
  {"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
374
 
   (char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
407
  {"replace", OPT_MYSQL_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
 
408
   (uchar**) &opt_replace_into, (uchar**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
375
409
   0, 0},
376
410
  {"result-file", 'r',
377
411
   "Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed).",
378
412
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
379
413
  {"routines", 'R', "Dump stored routines (functions and procedures).",
380
 
     (char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
 
414
     (uchar**) &opt_routines, (uchar**) &opt_routines, 0, GET_BOOL,
381
415
     NO_ARG, 0, 0, 0, 0, 0, 0},
382
416
  {"set-charset", OPT_SET_CHARSET,
383
417
   "Add 'SET NAMES default_character_set' to the output.",
384
 
   (char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
 
418
   (uchar**) &opt_set_charset, (uchar**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
385
419
   0, 0, 0, 0, 0},
386
420
  {"set-variable", 'O',
387
421
   "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
388
422
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
423
#ifdef HAVE_SMEM
 
424
  {"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
 
425
   "Base name of shared memory.", (uchar**) &shared_memory_base_name, (uchar**) &shared_memory_base_name,
 
426
   0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
427
#endif
389
428
  /*
390
429
    Note that the combination --single-transaction --master-data
391
430
    will give bullet-proof binlog position only if server >=4.1.3. That's the
401
440
   "connection should use the following statements: ALTER TABLE, DROP "
402
441
   "TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
403
442
   "isolated from them. Option automatically turns off --lock-tables.",
404
 
   (char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
 
443
   (uchar**) &opt_single_transaction, (uchar**) &opt_single_transaction, 0,
405
444
   GET_BOOL, NO_ARG,  0, 0, 0, 0, 0, 0},
406
445
  {"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.",
407
 
   (char**) &opt_dump_date, (char**) &opt_dump_date, 0,
 
446
   (uchar**) &opt_dump_date, (uchar**) &opt_dump_date, 0,
408
447
   GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
409
448
  {"skip-opt", OPT_SKIP_OPTIMIZATION,
410
449
   "Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
411
450
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
412
451
  {"tab",'T',
413
452
   "Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if mysqldump is run on the same machine as the mysqld daemon.",
414
 
   (char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
453
   (uchar**) &path, (uchar**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
415
454
  {"tables", OPT_TABLES, "Overrides option --databases (-B).",
416
455
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
417
456
  {"tz-utc", OPT_TZ_UTC,
418
457
    "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},
 
458
    (uchar**) &opt_tz_utc, (uchar**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
420
459
#ifndef DONT_ALLOW_USER_CHANGE
421
460
  {"user", 'u', "User for login if not current user.",
422
 
   (char**) &current_user, (char**) &current_user, 0, GET_STR, REQUIRED_ARG,
 
461
   (uchar**) &current_user, (uchar**) &current_user, 0, GET_STR, REQUIRED_ARG,
423
462
   0, 0, 0, 0, 0, 0},
424
463
#endif
425
464
  {"verbose", 'v', "Print info about the various stages.",
426
 
   (char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
465
   (uchar**) &verbose, (uchar**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
427
466
  {"version",'V', "Output version information and exit.", 0, 0, 0,
428
467
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
429
468
  {"where", 'w', "Dump only selected records; QUOTES mandatory!",
430
 
   (char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
469
   (uchar**) &where, (uchar**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
431
470
  {"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
432
471
   NO_ARG, 0, 0, 0, 0, 0, 0},
433
472
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
434
473
};
435
474
 
436
 
static const char *load_default_groups[]= { "drizzledump","client",0 };
 
475
static const char *load_default_groups[]= { "mysqldump","client",0 };
437
476
 
438
477
static void maybe_exit(int error);
439
478
static void die(int error, const char* reason, ...);
440
479
static void maybe_die(int error, const char* reason, ...);
441
480
static void write_header(FILE *sql_file, char *db_name);
442
 
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
 
481
static void print_value(FILE *file, MYSQL_RES  *result, MYSQL_ROW row,
443
482
                        const char *prefix,const char *name,
444
483
                        int string_value);
445
484
static int dump_selected_tables(char *db, char **table_names, int tables);
448
487
static int init_dumping(char *, int init_func(char*));
449
488
static int dump_databases(char **);
450
489
static int dump_all_databases(void);
451
 
static char *quote_name(const char *name, char *buff, bool force);
 
490
static char *quote_name(const char *name, char *buff, my_bool force);
452
491
char check_if_ignore_table(const char *table_name, char *table_type);
453
492
static char *primary_key_fields(const char *table_name);
454
493
 
 
494
#include <help_start.h>
 
495
 
455
496
/*
456
497
  Print the supplied message if in verbose mode
457
498
 
460
501
    fmt   format specifier
461
502
    ...   variable number of parameters
462
503
*/
 
504
 
463
505
static void verbose_msg(const char *fmt, ...)
464
506
{
465
507
  va_list args;
466
 
 
 
508
  DBUG_ENTER("verbose_msg");
467
509
 
468
510
  if (!verbose)
469
 
    return;
 
511
    DBUG_VOID_RETURN;
470
512
 
471
513
  va_start(args, fmt);
472
514
  vfprintf(stderr, fmt, args);
473
515
  va_end(args);
474
516
 
475
 
  return;
 
517
  DBUG_VOID_RETURN;
476
518
}
477
519
 
478
520
/*
492
534
static void print_version(void)
493
535
{
494
536
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
495
 
         drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
537
         MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
496
538
} /* print_version */
497
539
 
498
540
 
510
552
  print_version();
511
553
  puts("By Igor Romanenko, Monty, Jani & Sinisa");
512
554
  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");
 
555
  puts("Dumping definition and data mysql database or table");
514
556
  short_usage_sub();
515
557
  print_defaults("my",load_default_groups);
516
558
  my_print_help(my_long_options);
524
566
  printf("For more options, use %s --help\n", my_progname);
525
567
}
526
568
 
 
569
#include <help_end.h>
 
570
 
 
571
 
527
572
static void write_header(FILE *sql_file, char *db_name)
528
573
{
529
574
  if (opt_xml)
533
578
      Schema reference.  Allows use of xsi:nil for NULL values and 
534
579
      xsi:type to define an element's data type.
535
580
    */
536
 
    fputs("<drizzledump ", sql_file);
 
581
    fputs("<mysqldump ", sql_file);
537
582
    fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
538
583
          sql_file);
539
584
    fputs(">\n", sql_file);
544
589
    if (opt_comments)
545
590
    {
546
591
      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);
 
592
              "-- MySQL dump %s  Distrib %s, for %s (%s)\n--\n",
 
593
              DUMP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
550
594
      fprintf(sql_file, "-- Host: %s    Database: %s\n",
551
595
              current_host ? current_host : "localhost", db_name ? db_name :
552
596
              "");
553
597
      fputs("-- ------------------------------------------------------\n",
554
598
            sql_file);
555
599
      fprintf(sql_file, "-- Server version\t%s\n",
556
 
              drizzle_get_server_info(&drizzle_connection));
 
600
              mysql_get_server_info(&mysql_connection));
557
601
    }
558
602
    if (opt_set_charset)
559
603
      fprintf(sql_file,
 
604
"\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;"
 
605
"\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;"
560
606
"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
561
607
"\n/*!40101 SET NAMES %s */;\n",default_charset);
562
608
 
582
628
{
583
629
  if (opt_xml)
584
630
  {
585
 
    fputs("</drizzledump>\n", sql_file);
 
631
    fputs("</mysqldump>\n", sql_file);
586
632
    check_io(sql_file);
587
633
  }
588
634
  else if (!opt_compact)
598
644
    }
599
645
    if (opt_set_charset)
600
646
      fprintf(sql_file,
 
647
"/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n"
 
648
"/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n"
601
649
"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
602
650
    fprintf(sql_file,
603
651
            "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
621
669
 
622
670
static void free_table_ent(char *key)
623
671
{
624
 
  free(key);
 
672
  my_free(key, MYF(0));
625
673
}
626
674
 
627
675
 
628
 
static unsigned char* get_table_key(const char *entry, size_t *length,
629
 
                            bool not_used __attribute__((unused)))
 
676
static uchar* get_table_key(const char *entry, size_t *length,
 
677
                            my_bool not_used __attribute__((unused)))
630
678
{
631
679
  *length= strlen(entry);
632
 
  return (unsigned char*) entry;
 
680
  return (uchar*) entry;
633
681
}
634
682
 
635
683
 
636
 
static bool
 
684
static my_bool
637
685
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
638
686
               char *argument)
639
687
{
642
690
    if (argument)
643
691
    {
644
692
      char *start=argument;
645
 
      free(opt_password);
 
693
      my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
646
694
      opt_password=my_strdup(argument,MYF(MY_FAE));
647
695
      while (*argument) *argument++= 'x';               /* Destroy argument */
648
696
      if (*start)
653
701
      tty_password=1;
654
702
    break;
655
703
  case 'r':
656
 
    if (!(md_result_file= my_fopen(argument, O_WRONLY,
 
704
    if (!(md_result_file= my_fopen(argument, O_WRONLY | FILE_BINARY,
657
705
                                    MYF(MY_WME))))
658
706
      exit(1);
659
707
    break;
675
723
    }
676
724
 
677
725
    break;
 
726
  case '#':
 
727
    DBUG_PUSH(argument ? argument : default_dbug_option);
 
728
    debug_check_flag= 1;
 
729
    break;
678
730
  case 'V': print_version(); exit(0);
679
731
  case 'X':
680
732
    opt_xml= 1;
687
739
    exit(0);
688
740
  case (int) OPT_MASTER_DATA:
689
741
    if (!argument) /* work like in old versions */
690
 
      opt_master_data= DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL;
 
742
      opt_master_data= MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL;
691
743
    break;
692
 
  case (int) OPT_DRIZZLEDUMP_SLAVE_DATA:
 
744
  case (int) OPT_MYSQLDUMP_SLAVE_DATA:
693
745
    if (!argument) /* work like in old versions */
694
 
      opt_slave_data= DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL;
 
746
      opt_slave_data= MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL;
695
747
    break;
696
748
  case (int) OPT_OPTIMIZE:
697
749
    extended_insert= opt_drop= opt_lock= quick= create_options=
717
769
      fprintf(stderr, "Illegal use of option --ignore-table=<database>.<table>\n");
718
770
      exit(1);
719
771
    }
720
 
    if (my_hash_insert(&ignore_table, (unsigned char*)my_strdup(argument, MYF(0))))
 
772
    if (my_hash_insert(&ignore_table, (uchar*)my_strdup(argument, MYF(0))))
721
773
      exit(EX_EOM);
722
774
    break;
723
775
  }
725
777
    {
726
778
      char buff[255];
727
779
      char *end= compatible_mode_normal_str;
728
 
      uint32_t i;
729
 
      uint32_t mode;
730
 
      uint32_t error_len;
 
780
      int i;
 
781
      ulong mode;
 
782
      uint err_len;
731
783
 
732
784
      opt_quoted= 1;
733
785
      opt_set_charset= 0;
734
786
      opt_compatible_mode_str= argument;
735
787
      opt_compatible_mode= find_set(&compatible_mode_typelib,
736
788
                                    argument, strlen(argument),
737
 
                                    &err_ptr, &error_len);
738
 
      if (error_len)
 
789
                                    &err_ptr, &err_len);
 
790
      if (err_len)
739
791
      {
740
 
        strmake(buff, err_ptr, min((uint32_t)sizeof(buff), error_len));
 
792
        strmake(buff, err_ptr, min(sizeof(buff), err_len));
741
793
        fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
742
794
        exit(1);
743
795
      }
 
796
#if !defined(DBUG_OFF)
 
797
      {
 
798
        uint size_for_sql_mode= 0;
 
799
        const char **ptr;
 
800
        for (ptr= compatible_mode_names; *ptr; ptr++)
 
801
          size_for_sql_mode+= strlen(*ptr);
 
802
        size_for_sql_mode+= sizeof(compatible_mode_names)-1;
 
803
        DBUG_ASSERT(sizeof(compatible_mode_normal_str)>=size_for_sql_mode);
 
804
      }
 
805
#endif
744
806
      mode= opt_compatible_mode;
745
807
      for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++)
746
808
      {
747
809
        if (mode & 1)
748
810
        {
749
 
          end= my_stpcpy(end, compatible_mode_names[i]);
750
 
          end= my_stpcpy(end, ",");
 
811
          end= strmov(end, compatible_mode_names[i]);
 
812
          end= strmov(end, ",");
751
813
        }
752
814
      }
753
815
      if (end!=compatible_mode_normal_str)
756
818
        Set charset to the default compiled value if it hasn't
757
819
        been reset yet by --default-character-set=xxx.
758
820
      */
759
 
      if (default_charset == drizzle_universal_client_charset)
760
 
        default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
 
821
      if (default_charset == mysql_universal_client_charset)
 
822
        default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
761
823
      break;
762
824
    }
763
825
  }
767
829
static int get_options(int *argc, char ***argv)
768
830
{
769
831
  int ho_error;
770
 
  const DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
 
832
  MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
771
833
 
772
 
  opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
773
 
  opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
 
834
  opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
 
835
  opt_net_buffer_length= *mysql_params->p_net_buffer_length;
774
836
 
775
837
  md_result_file= stdout;
776
838
  load_defaults("my",load_default_groups,argc,argv);
782
844
    return(EX_EOM);
783
845
  /* Don't copy internal log tables */
784
846
  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))))
 
847
                     (uchar*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
 
848
      my_hash_insert(&ignore_table,
 
849
                     (uchar*) my_strdup("mysql.schema", MYF(MY_WME))) ||
 
850
      my_hash_insert(&ignore_table,
 
851
                     (uchar*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
 
852
      my_hash_insert(&ignore_table,
 
853
                     (uchar*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
 
854
      my_hash_insert(&ignore_table,
 
855
                     (uchar*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
 
856
      my_hash_insert(&ignore_table,
 
857
                     (uchar*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
796
858
    return(EX_EOM);
797
859
 
798
860
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
799
861
    return(ho_error);
800
862
 
801
 
  *drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
802
 
  *drizzle_params->p_net_buffer_length= opt_net_buffer_length;
 
863
  *mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
 
864
  *mysql_params->p_net_buffer_length= opt_net_buffer_length;
803
865
  if (debug_info_flag)
804
866
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
805
867
  if (debug_check_flag)
825
887
 
826
888
  /* Ensure consistency of the set of binlog & locking options */
827
889
  if (opt_delete_master_logs && !opt_master_data)
828
 
    opt_master_data= DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL;
 
890
    opt_master_data= MYSQL_OPT_MASTER_DATA_COMMENTED_SQL;
829
891
  if (opt_single_transaction && opt_lock_all_tables)
830
892
  {
831
893
    fprintf(stderr, "%s: You can't use --single-transaction and "
861
923
    return EX_USAGE;
862
924
  }
863
925
  if (tty_password)
864
 
    opt_password=get_tty_password(NULL);
 
926
    opt_password=get_tty_password(NullS);
865
927
  return(0);
866
928
} /* get_options */
867
929
 
868
930
 
869
931
/*
870
 
** DB_error -- prints DRIZZLE error message and exits the program.
 
932
** DB_error -- prints mysql error message and exits the program.
871
933
*/
872
 
static void DB_error(DRIZZLE *drizzle_arg, const char *when)
 
934
static void DB_error(MYSQL *mysql_arg, const char *when)
873
935
{
874
 
 
875
 
  maybe_die(EX_DRIZZLEERR, "Got error: %d: %s %s",
876
 
          drizzle_errno(drizzle_arg), drizzle_error(drizzle_arg), when);
877
 
  return;
 
936
  DBUG_ENTER("DB_error");
 
937
  maybe_die(EX_MYSQLERR, "Got error: %d: %s %s",
 
938
          mysql_errno(mysql_arg), mysql_error(mysql_arg), when);
 
939
  DBUG_VOID_RETURN;
878
940
}
879
941
 
880
942
 
947
1009
  some.
948
1010
 
949
1011
  SYNOPSIS
950
 
    drizzle_query_with_error_report()
951
 
    drizzle_con       connection to use
 
1012
    mysql_query_with_error_report()
 
1013
    mysql_con       connection to use
952
1014
    res             if non zero, result will be put there with
953
 
                    drizzle_store_result()
 
1015
                    mysql_store_result()
954
1016
    query           query to send to server
955
1017
 
956
1018
  RETURN VALUES
958
1020
    1               error
959
1021
*/
960
1022
 
961
 
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
 
1023
static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res,
962
1024
                                         const char *query)
963
1025
{
964
 
  if (drizzle_query(drizzle_con, query) ||
965
 
      (res && !((*res)= drizzle_store_result(drizzle_con))))
 
1026
  if (mysql_query(mysql_con, query) ||
 
1027
      (res && !((*res)= mysql_store_result(mysql_con))))
966
1028
  {
967
 
    maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
968
 
            query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
 
1029
    maybe_die(EX_MYSQLERR, "Couldn't execute '%s': %s (%d)",
 
1030
            query, mysql_error(mysql_con), mysql_errno(mysql_con));
969
1031
    return 1;
970
1032
  }
971
1033
  return 0;
984
1046
 
985
1047
  @returns  whether there was an error or not
986
1048
*/
987
 
static int switch_character_set_results(DRIZZLE *drizzle, const char *cs_name)
 
1049
static int switch_character_set_results(MYSQL *mysql, const char *cs_name)
988
1050
{
989
1051
  char query_buffer[QUERY_LENGTH];
990
1052
  size_t query_length;
991
1053
 
992
1054
  /* Server lacks facility.  This is not an error, by arbitrary decision . */
993
1055
  if (!server_supports_switching_charsets)
994
 
    return false;
 
1056
    return FALSE;
995
1057
 
996
1058
  query_length= snprintf(query_buffer,
997
1059
                         sizeof (query_buffer),
998
1060
                         "SET SESSION character_set_results = '%s'",
999
1061
                         (const char *) cs_name);
1000
1062
 
1001
 
  return drizzle_real_query(drizzle, query_buffer, query_length);
 
1063
  return mysql_real_query(mysql, query_buffer, query_length);
1002
1064
}
1003
1065
 
1004
1066
/*
1016
1078
{
1017
1079
  FILE* res;
1018
1080
  char filename[FN_REFLEN], tmp_path[FN_REFLEN];
1019
 
  convert_dirname(tmp_path,path,NULL);
 
1081
  convert_dirname(tmp_path,path,NullS);
1020
1082
  res= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
1021
1083
                O_WRONLY, MYF(MY_WME));
1022
1084
  return res;
1027
1089
{
1028
1090
  if (md_result_file && md_result_file != stdout)
1029
1091
    my_fclose(md_result_file, MYF(0));
1030
 
  free(opt_password);
 
1092
  my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
1031
1093
  if (hash_inited(&ignore_table))
1032
1094
    hash_free(&ignore_table);
 
1095
  if (extended_insert)
 
1096
    dynstr_free(&extended_row);
 
1097
  if (insert_pat_inited)
 
1098
    dynstr_free(&insert_pat);
1033
1099
  if (defaults_argv)
1034
1100
    free_defaults(defaults_argv);
1035
1101
  my_end(my_end_arg);
1042
1108
    first_error= error;
1043
1109
  if (ignore_errors)
1044
1110
    return;
1045
 
  if (drizzle)
1046
 
    drizzle_close(drizzle);
 
1111
  if (mysql)
 
1112
    mysql_close(mysql);
1047
1113
  free_resources();
1048
1114
  exit(error);
1049
1115
}
1056
1122
static int connect_to_db(char *host, char *user,char *passwd)
1057
1123
{
1058
1124
  char buff[20+FN_REFLEN];
1059
 
 
 
1125
  DBUG_ENTER("connect_to_db");
1060
1126
 
1061
1127
  verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1062
 
  drizzle_create(&drizzle_connection);
 
1128
  mysql_init(&mysql_connection);
1063
1129
  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,
 
1130
    mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS);
 
1131
  if (opt_protocol)
 
1132
    mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
 
1133
#ifdef HAVE_SMEM
 
1134
  if (shared_memory_base_name)
 
1135
    mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
 
1136
#endif
 
1137
  mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
 
1138
  if (!(mysql= mysql_real_connect(&mysql_connection,host,user,passwd,
 
1139
                                  NULL,opt_mysql_port, NULL,
1067
1140
                                  0)))
1068
1141
  {
1069
 
    DB_error(&drizzle_connection, "when trying to connect");
1070
 
    return(1);
 
1142
    DB_error(&mysql_connection, "when trying to connect");
 
1143
    DBUG_RETURN(1);
1071
1144
  }
1072
 
  if (drizzle_get_server_version(&drizzle_connection) < 40100)
 
1145
  if (mysql_get_server_version(&mysql_connection) < 40100)
1073
1146
  {
1074
1147
    /* Don't dump SET NAMES with a pre-4.1 server (bug#7997).  */
1075
1148
    opt_set_charset= 0;
1076
1149
 
1077
1150
    /* Don't switch charsets for 4.1 and earlier.  (bug#34192). */
1078
 
    server_supports_switching_charsets= false;
 
1151
    server_supports_switching_charsets= FALSE;
1079
1152
  } 
1080
1153
  /*
1081
1154
    set time_zone to UTC to allow dumping date types between servers with
1084
1157
  if (opt_tz_utc)
1085
1158
  {
1086
1159
    snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1087
 
    if (drizzle_query_with_error_report(drizzle, 0, buff))
1088
 
      return(1);
 
1160
    if (mysql_query_with_error_report(mysql, 0, buff))
 
1161
      DBUG_RETURN(1);
1089
1162
  }
1090
 
  return(0);
 
1163
  DBUG_RETURN(0);
1091
1164
} /* connect_to_db */
1092
1165
 
1093
1166
 
1097
1170
static void dbDisconnect(char *host)
1098
1171
{
1099
1172
  verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost");
1100
 
  drizzle_close(drizzle);
 
1173
  mysql_close(mysql);
1101
1174
} /* dbDisconnect */
1102
1175
 
1103
1176
 
1104
1177
static void unescape(FILE *file,char *pos,uint length)
1105
1178
{
1106
1179
  char *tmp;
1107
 
 
 
1180
  DBUG_ENTER("unescape");
1108
1181
  if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1109
 
    die(EX_DRIZZLEERR, "Couldn't allocate memory");
 
1182
    die(EX_MYSQLERR, "Couldn't allocate memory");
1110
1183
 
1111
 
  drizzle_escape_string(tmp, pos, length);
 
1184
  mysql_real_escape_string(&mysql_connection, tmp, pos, length);
1112
1185
  fputc('\'', file);
1113
1186
  fputs(tmp, file);
1114
1187
  fputc('\'', file);
1115
1188
  check_io(file);
1116
 
  free(tmp);
1117
 
  return;
 
1189
  my_free(tmp, MYF(MY_WME));
 
1190
  DBUG_VOID_RETURN;
1118
1191
} /* unescape */
1119
1192
 
1120
1193
 
1121
 
static bool test_if_special_chars(const char *str)
 
1194
static my_bool test_if_special_chars(const char *str)
1122
1195
{
 
1196
#if MYSQL_VERSION_ID >= 32300
1123
1197
  for ( ; *str ; str++)
1124
1198
    if (!my_isvar(charset_info,*str) && *str != '$')
1125
1199
      return 1;
 
1200
#endif
1126
1201
  return 0;
1127
1202
} /* test_if_special_chars */
1128
1203
 
1144
1219
  buff                 quoted string
1145
1220
 
1146
1221
*/
1147
 
static char *quote_name(const char *name, char *buff, bool force)
 
1222
static char *quote_name(const char *name, char *buff, my_bool force)
1148
1223
{
1149
1224
  char *to= buff;
1150
1225
  char qtype= (opt_compatible_mode & MASK_ANSI_QUOTES) ? '\"' : '`';
1175
1250
  DESCRIPTION
1176
1251
    Quote \, _, ' and % characters
1177
1252
 
1178
 
    Note: Because DRIZZLE uses the C escape syntax in strings
 
1253
    Note: Because MySQL uses the C escape syntax in strings
1179
1254
    (for example, '\n' to represent newline), you must double
1180
1255
    any '\' that you use in your LIKE  strings. For example, to
1181
1256
    search for '\n', specify it as '\\n'. To search for '\', specify
1221
1296
    Quote '<' '>' '&' '\"' chars and print a string to the xml_file.
1222
1297
*/
1223
1298
 
1224
 
static void print_quoted_xml(FILE *xml_file, const char *str, uint32_t len)
 
1299
static void print_quoted_xml(FILE *xml_file, const char *str, ulong len)
1225
1300
{
1226
1301
  const char *end;
1227
1302
 
1254
1329
 
1255
1330
  SYNOPSIS
1256
1331
    print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name, 
1257
 
                    ..., attribute_name_n, attribute_value_n, NULL)
 
1332
                    ..., attribute_name_n, attribute_value_n, NullS)
1258
1333
    xml_file              - output file
1259
1334
    sbeg                  - line beginning
1260
1335
    line_end              - line ending
1291
1366
 
1292
1367
  va_start(arg_list, first_attribute_name);
1293
1368
  attribute_name= first_attribute_name;
1294
 
  while (attribute_name != NULL)
 
1369
  while (attribute_name != NullS)
1295
1370
  {
1296
1371
    attribute_value= va_arg(arg_list, char *);
1297
 
    assert(attribute_value != NULL);
 
1372
    DBUG_ASSERT(attribute_value != NullS);
1298
1373
 
1299
1374
    fputc(' ', xml_file);
1300
1375
    fputs(attribute_name, xml_file);    
1365
1440
*/
1366
1441
 
1367
1442
static void print_xml_row(FILE *xml_file, const char *row_name,
1368
 
                          DRIZZLE_RES *tableRes, DRIZZLE_ROW *row)
 
1443
                          MYSQL_RES *tableRes, MYSQL_ROW *row)
1369
1444
{
1370
1445
  uint i;
1371
 
  DRIZZLE_FIELD *field;
1372
 
  uint32_t *lengths= drizzle_fetch_lengths(tableRes);
 
1446
  MYSQL_FIELD *field;
 
1447
  ulong *lengths= mysql_fetch_lengths(tableRes);
1373
1448
 
1374
1449
  fprintf(xml_file, "\t\t<%s", row_name);
1375
1450
  check_io(xml_file);
1376
 
  drizzle_field_seek(tableRes, 0);
1377
 
  for (i= 0; (field= drizzle_fetch_field(tableRes)); i++)
 
1451
  mysql_field_seek(tableRes, 0);
 
1452
  for (i= 0; (field= mysql_fetch_field(tableRes)); i++)
1378
1453
  {
1379
1454
    if ((*row)[i])
1380
1455
    {
1404
1479
    Print hex value for blob data.
1405
1480
*/
1406
1481
 
1407
 
static void print_blob_as_hex(FILE *output_file, const char *str, uint32_t len)
 
1482
static void print_blob_as_hex(FILE *output_file, const char *str, ulong len)
1408
1483
{
1409
1484
    /* sakaik got the idea to to provide blob's in hex notation. */
1410
1485
    const char *ptr= str, *end= ptr + len;
1411
1486
    for (; ptr < end ; ptr++)
1412
 
      fprintf(output_file, "%02X", *((unsigned char *)ptr));
 
1487
      fprintf(output_file, "%02X", *((uchar *)ptr));
1413
1488
    check_io(output_file);
1414
1489
}
1415
1490
 
1431
1506
static uint get_table_structure(char *table, char *db, char *table_type,
1432
1507
                                char *ignore_flag)
1433
1508
{
1434
 
  bool    init=0, delayed, write_data, complete_insert;
1435
 
  uint64_t num_fields;
 
1509
  my_bool    init=0, delayed, write_data, complete_insert;
 
1510
  my_ulonglong num_fields;
1436
1511
  char       *result_table, *opt_quoted_table;
1437
1512
  const char *insert_option;
1438
1513
  char       name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3];
1439
1514
  char       table_buff2[NAME_LEN*2+3], query_buff[QUERY_LENGTH];
1440
1515
  FILE       *sql_file= md_result_file;
1441
1516
  int        len;
1442
 
  DRIZZLE_RES  *result;
1443
 
  DRIZZLE_ROW  row;
 
1517
  MYSQL_RES  *result;
 
1518
  MYSQL_ROW  row;
 
1519
  DBUG_ENTER("get_table_structure");
 
1520
  DBUG_PRINT("enter", ("db: %s  table: %s", db, table));
1444
1521
 
1445
1522
  *ignore_flag= check_if_ignore_table(table, table_type);
1446
1523
 
1456
1533
  if ((write_data= !(*ignore_flag & IGNORE_DATA)))
1457
1534
  {
1458
1535
    complete_insert= opt_complete_insert;
1459
 
    insert_pat= "";
 
1536
    if (!insert_pat_inited)
 
1537
    {
 
1538
      insert_pat_inited= 1;
 
1539
      init_dynamic_string_checked(&insert_pat, "", 1024, 1024);
 
1540
    }
 
1541
    else
 
1542
      dynstr_set_checked(&insert_pat, "");
1460
1543
  }
1461
1544
 
1462
1545
  insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " :
1473
1556
 
1474
1557
  if (opt_order_by_primary)
1475
1558
  {
1476
 
    free(order_by);
 
1559
    my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
1477
1560
    order_by= primary_key_fields(result_table);
1478
1561
  }
1479
1562
 
1480
 
  if (!opt_xml && !drizzle_query_with_error_report(drizzle, 0, query_buff))
 
1563
  if (!opt_xml && !mysql_query_with_error_report(mysql, 0, query_buff))
1481
1564
  {
1482
1565
    /* using SHOW CREATE statement */
1483
1566
    if (!opt_no_create_info)
1484
1567
    {
1485
1568
      /* Make an sql-file, if path was given iow. option -T was given */
1486
1569
      char buff[20+FN_REFLEN];
1487
 
      const DRIZZLE_FIELD *field;
 
1570
      MYSQL_FIELD *field;
1488
1571
 
1489
1572
      snprintf(buff, sizeof(buff), "show create table %s", result_table);
1490
1573
 
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);
 
1574
      if (switch_character_set_results(mysql, "binary") ||
 
1575
          mysql_query_with_error_report(mysql, &result, buff) ||
 
1576
          switch_character_set_results(mysql, default_charset))
 
1577
        DBUG_RETURN(0);
1495
1578
 
1496
1579
      if (path)
1497
1580
      {
1498
1581
        if (!(sql_file= open_sql_file_for_table(table)))
1499
 
          return(0);
 
1582
          DBUG_RETURN(0);
1500
1583
 
1501
1584
        write_header(sql_file, db);
1502
1585
      }
1521
1604
        check_io(sql_file);
1522
1605
      }
1523
1606
 
1524
 
      field= drizzle_fetch_field_direct(result, 0);
 
1607
      field= mysql_fetch_field_direct(result, 0);
1525
1608
      if (strcmp(field->name, "View") == 0)
1526
1609
      {
1527
1610
        char *scv_buff= NULL;
1529
1612
        verbose_msg("-- It's a view, create dummy table for view\n");
1530
1613
 
1531
1614
        /* save "show create" statement for later */
1532
 
        if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
 
1615
        if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
1533
1616
          scv_buff= my_strdup(scv_buff, MYF(0));
1534
1617
 
1535
 
        drizzle_free_result(result);
 
1618
        mysql_free_result(result);
1536
1619
 
1537
1620
        /*
1538
1621
          Create a table with the same name as the view and with columns of
1547
1630
        */
1548
1631
        snprintf(query_buff, sizeof(query_buff),
1549
1632
                 "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))
 
1633
        if (switch_character_set_results(mysql, "binary") ||
 
1634
            mysql_query_with_error_report(mysql, &result, query_buff) ||
 
1635
            switch_character_set_results(mysql, default_charset))
1553
1636
        {
1554
1637
          /*
1555
1638
            View references invalid or privileged table/col/fun (err 1356),
1557
1640
            a comment with the view's 'show create' statement. (Bug #17371)
1558
1641
          */
1559
1642
 
1560
 
          if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
 
1643
          if (mysql_errno(mysql) == ER_VIEW_INVALID)
1561
1644
            fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1562
1645
 
1563
 
          free(scv_buff);
 
1646
          my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1564
1647
 
1565
 
          return(0);
 
1648
          DBUG_RETURN(0);
1566
1649
        }
1567
1650
        else
1568
 
          free(scv_buff);
 
1651
          my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1569
1652
 
1570
 
        if (drizzle_num_rows(result))
 
1653
        if (mysql_num_rows(result))
1571
1654
        {
1572
1655
          if (opt_drop)
1573
1656
          {
1582
1665
          }
1583
1666
 
1584
1667
          fprintf(sql_file,
 
1668
                  "SET @saved_cs_client     = @@character_set_client;\n"
 
1669
                  "SET character_set_client = utf8;\n"
1585
1670
                  "/*!50001 CREATE TABLE %s (\n",
1586
1671
                  result_table);
1587
1672
 
1591
1676
            there should be a _trailing_ comma.
1592
1677
          */
1593
1678
 
1594
 
          row= drizzle_fetch_row(result);
 
1679
          row= mysql_fetch_row(result);
1595
1680
 
1596
1681
          fprintf(sql_file, "  %s %s", quote_name(row[0], name_buff, 0),
1597
1682
                  row[1]);
1598
1683
 
1599
 
          while((row= drizzle_fetch_row(result)))
 
1684
          while((row= mysql_fetch_row(result)))
1600
1685
          {
1601
1686
            /* col name, col type */
1602
1687
            fprintf(sql_file, ",\n  %s %s",
1603
1688
                    quote_name(row[0], name_buff, 0), row[1]);
1604
1689
          }
1605
 
          fprintf(sql_file, "\n) */;\n"); 
 
1690
          fprintf(sql_file,
 
1691
                  "\n) */;\n"
 
1692
                  "SET character_set_client = @saved_cs_client;\n");
 
1693
 
1606
1694
          check_io(sql_file);
1607
1695
        }
1608
1696
 
1609
 
        drizzle_free_result(result);
 
1697
        mysql_free_result(result);
1610
1698
 
1611
1699
        if (path)
1612
1700
          my_fclose(sql_file, MYF(MY_WME));
1613
1701
 
1614
1702
        seen_views= 1;
1615
 
        return(0);
 
1703
        DBUG_RETURN(0);
1616
1704
      }
1617
1705
 
1618
 
      row= drizzle_fetch_row(result);
 
1706
      row= mysql_fetch_row(result);
1619
1707
 
1620
 
      fprintf(sql_file, "%s;\n", row[1]);
 
1708
      fprintf(sql_file,
 
1709
              "SET @saved_cs_client     = @@character_set_client;\n"
 
1710
              "SET character_set_client = utf8;\n"
 
1711
              "%s;\n"
 
1712
              "SET character_set_client = @saved_cs_client;\n",
 
1713
              row[1]);
1621
1714
 
1622
1715
      check_io(sql_file);
1623
 
      drizzle_free_result(result);
 
1716
      mysql_free_result(result);
1624
1717
    }
1625
1718
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1626
1719
             result_table);
1627
 
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
 
1720
    if (mysql_query_with_error_report(mysql, &result, query_buff))
1628
1721
    {
1629
1722
      if (path)
1630
1723
        my_fclose(sql_file, MYF(MY_WME));
1631
 
      return(0);
 
1724
      DBUG_RETURN(0);
1632
1725
    }
1633
1726
 
1634
1727
    /*
1640
1733
    if (write_data)
1641
1734
    {
1642
1735
      if (opt_replace_into)
1643
 
        insert_pat.append("REPLACE ");
 
1736
        dynstr_append_checked(&insert_pat, "REPLACE ");
1644
1737
      else
1645
 
        insert_pat.append("INSERT ");
1646
 
      insert_pat.append(insert_option);
1647
 
      insert_pat.append("INTO ");
1648
 
      insert_pat.append(opt_quoted_table);
 
1738
        dynstr_append_checked(&insert_pat, "INSERT ");
 
1739
      dynstr_append_checked(&insert_pat, insert_option);
 
1740
      dynstr_append_checked(&insert_pat, "INTO ");
 
1741
      dynstr_append_checked(&insert_pat, opt_quoted_table);
1649
1742
      if (complete_insert)
1650
1743
      {
1651
 
        insert_pat.append(" (");
 
1744
        dynstr_append_checked(&insert_pat, " (");
1652
1745
      }
1653
1746
      else
1654
1747
      {
1655
 
        insert_pat.append(" VALUES ");
 
1748
        dynstr_append_checked(&insert_pat, " VALUES ");
1656
1749
        if (!extended_insert)
1657
 
          insert_pat.append("(");
 
1750
          dynstr_append_checked(&insert_pat, "(");
1658
1751
      }
1659
1752
    }
1660
1753
 
1661
 
    while ((row= drizzle_fetch_row(result)))
 
1754
    while ((row= mysql_fetch_row(result)))
1662
1755
    {
1663
1756
      if (complete_insert)
1664
1757
      {
1665
1758
        if (init)
1666
1759
        {
1667
 
          insert_pat.append(", ");
 
1760
          dynstr_append_checked(&insert_pat, ", ");
1668
1761
        }
1669
1762
        init=1;
1670
 
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
 
1763
        dynstr_append_checked(&insert_pat,
 
1764
                      quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1671
1765
      }
1672
1766
    }
1673
 
    num_fields= drizzle_num_rows(result);
1674
 
    drizzle_free_result(result);
 
1767
    num_fields= mysql_num_rows(result);
 
1768
    mysql_free_result(result);
1675
1769
  }
1676
1770
  else
1677
1771
  {
1678
1772
    verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
1679
 
                my_progname, drizzle_error(drizzle));
 
1773
                my_progname, mysql_error(mysql));
1680
1774
 
1681
1775
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1682
1776
             result_table);
1683
 
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1684
 
      return(0);
 
1777
    if (mysql_query_with_error_report(mysql, &result, query_buff))
 
1778
      DBUG_RETURN(0);
1685
1779
 
1686
1780
    /* Make an sql-file, if path was given iow. option -T was given */
1687
1781
    if (!opt_no_create_info)
1689
1783
      if (path)
1690
1784
      {
1691
1785
        if (!(sql_file= open_sql_file_for_table(table)))
1692
 
          return(0);
 
1786
          DBUG_RETURN(0);
1693
1787
        write_header(sql_file, db);
1694
1788
      }
1695
1789
      if (!opt_xml && opt_comments)
1701
1795
        fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
1702
1796
      else
1703
1797
        print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table, 
1704
 
                NULL);
 
1798
                NullS);
1705
1799
      check_io(sql_file);
1706
1800
    }
1707
1801
 
1708
1802
    if (write_data)
1709
1803
    {
1710
1804
      if (opt_replace_into)
1711
 
        insert_pat.append("REPLACE ");
 
1805
        dynstr_append_checked(&insert_pat, "REPLACE ");
1712
1806
      else
1713
 
        insert_pat.append("INSERT ");
1714
 
      insert_pat.append(insert_option);
1715
 
      insert_pat.append("INTO ");
1716
 
      insert_pat.append(result_table);
 
1807
        dynstr_append_checked(&insert_pat, "INSERT ");
 
1808
      dynstr_append_checked(&insert_pat, insert_option);
 
1809
      dynstr_append_checked(&insert_pat, "INTO ");
 
1810
      dynstr_append_checked(&insert_pat, result_table);
1717
1811
      if (complete_insert)
1718
 
        insert_pat.append(" (");
 
1812
        dynstr_append_checked(&insert_pat, " (");
1719
1813
      else
1720
1814
      {
1721
 
        insert_pat.append(" VALUES ");
 
1815
        dynstr_append_checked(&insert_pat, " VALUES ");
1722
1816
        if (!extended_insert)
1723
 
          insert_pat.append("(");
 
1817
          dynstr_append_checked(&insert_pat, "(");
1724
1818
      }
1725
1819
    }
1726
1820
 
1727
 
    while ((row= drizzle_fetch_row(result)))
 
1821
    while ((row= mysql_fetch_row(result)))
1728
1822
    {
1729
 
      uint32_t *lengths= drizzle_fetch_lengths(result);
 
1823
      ulong *lengths= mysql_fetch_lengths(result);
1730
1824
      if (init)
1731
1825
      {
1732
1826
        if (!opt_xml && !opt_no_create_info)
1735
1829
          check_io(sql_file);
1736
1830
        }
1737
1831
        if (complete_insert)
1738
 
          insert_pat.append(", ");
 
1832
          dynstr_append_checked(&insert_pat, ", ");
1739
1833
      }
1740
1834
      init=1;
1741
1835
      if (complete_insert)
1742
 
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
 
1836
        dynstr_append_checked(&insert_pat,
 
1837
                      quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1743
1838
      if (!opt_no_create_info)
1744
1839
      {
1745
1840
        if (opt_xml)
1768
1863
        check_io(sql_file);
1769
1864
      }
1770
1865
    }
1771
 
    num_fields= drizzle_num_rows(result);
1772
 
    drizzle_free_result(result);
 
1866
    num_fields= mysql_num_rows(result);
 
1867
    mysql_free_result(result);
1773
1868
    if (!opt_no_create_info)
1774
1869
    {
1775
1870
      /* Make an sql-file, if path was given iow. option -T was given */
1776
1871
      char buff[20+FN_REFLEN];
1777
1872
      uint keynr,primary_key;
1778
1873
      snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1779
 
      if (drizzle_query_with_error_report(drizzle, &result, buff))
 
1874
      if (mysql_query_with_error_report(mysql, &result, buff))
1780
1875
      {
1781
 
        if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
 
1876
        if (mysql_errno(mysql) == ER_WRONG_OBJECT)
1782
1877
        {
1783
1878
          /* it is VIEW */
1784
1879
          fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1785
1880
          goto continue_xml;
1786
1881
        }
1787
1882
        fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1788
 
                my_progname, result_table, drizzle_error(drizzle));
 
1883
                my_progname, result_table, mysql_error(mysql));
1789
1884
        if (path)
1790
1885
          my_fclose(sql_file, MYF(MY_WME));
1791
 
        return(0);
 
1886
        DBUG_RETURN(0);
1792
1887
      }
1793
1888
 
1794
1889
      /* Find first which key is primary key */
1795
1890
      keynr=0;
1796
1891
      primary_key=INT_MAX;
1797
 
      while ((row= drizzle_fetch_row(result)))
 
1892
      while ((row= mysql_fetch_row(result)))
1798
1893
      {
1799
1894
        if (atoi(row[3]) == 1)
1800
1895
        {
1810
1905
          }
1811
1906
        }
1812
1907
      }
1813
 
      drizzle_data_seek(result,0);
 
1908
      mysql_data_seek(result,0);
1814
1909
      keynr=0;
1815
 
      while ((row= drizzle_fetch_row(result)))
 
1910
      while ((row= mysql_fetch_row(result)))
1816
1911
      {
1817
1912
        if (opt_xml)
1818
1913
        {
1840
1935
          fprintf(sql_file, " (%s)",row[7]);      /* Sub key */
1841
1936
        check_io(sql_file);
1842
1937
      }
1843
 
      drizzle_free_result(result);
 
1938
      mysql_free_result(result);
1844
1939
      if (!opt_xml)
1845
1940
      {
1846
1941
        if (keynr)
1849
1944
        check_io(sql_file);
1850
1945
      }
1851
1946
 
1852
 
      /* Get DRIZZLE specific create options */
 
1947
      /* Get MySQL specific create options */
1853
1948
      if (create_options)
1854
1949
      {
1855
1950
        char show_name_buff[NAME_LEN*2+2+24];
1858
1953
        snprintf(buff, sizeof(buff), "show table status like %s",
1859
1954
                 quote_for_like(table, show_name_buff));
1860
1955
 
1861
 
        if (drizzle_query_with_error_report(drizzle, &result, buff))
 
1956
        if (mysql_query_with_error_report(mysql, &result, buff))
1862
1957
        {
1863
 
          if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
1864
 
          {                                     /* If old DRIZZLE version */
 
1958
          if (mysql_errno(mysql) != ER_PARSE_ERROR)
 
1959
          {                                     /* If old MySQL version */
1865
1960
            verbose_msg("-- Warning: Couldn't get status information for " \
1866
 
                        "table %s (%s)\n", result_table,drizzle_error(drizzle));
 
1961
                        "table %s (%s)\n", result_table,mysql_error(mysql));
1867
1962
          }
1868
1963
        }
1869
 
        else if (!(row= drizzle_fetch_row(result)))
 
1964
        else if (!(row= mysql_fetch_row(result)))
1870
1965
        {
1871
1966
          fprintf(stderr,
1872
1967
                  "Error: Couldn't read status information for table %s (%s)\n",
1873
 
                  result_table,drizzle_error(drizzle));
 
1968
                  result_table,mysql_error(mysql));
1874
1969
        }
1875
1970
        else
1876
1971
        {
1886
1981
            check_io(sql_file);
1887
1982
          }
1888
1983
        }
1889
 
        drizzle_free_result(result);              /* Is always safe to free */
 
1984
        mysql_free_result(result);              /* Is always safe to free */
1890
1985
      }
1891
1986
continue_xml:
1892
1987
      if (!opt_xml)
1898
1993
  }
1899
1994
  if (complete_insert)
1900
1995
  {
1901
 
    insert_pat.append(") VALUES ");
 
1996
    dynstr_append_checked(&insert_pat, ") VALUES ");
1902
1997
    if (!extended_insert)
1903
 
      insert_pat.append("(");
 
1998
      dynstr_append_checked(&insert_pat, "(");
1904
1999
  }
1905
2000
  if (sql_file != md_result_file)
1906
2001
  {
1908
2003
    write_footer(sql_file);
1909
2004
    my_fclose(sql_file, MYF(MY_WME));
1910
2005
  }
1911
 
  return((uint) num_fields);
 
2006
  DBUG_RETURN((uint) num_fields);
1912
2007
} /* get_table_structure */
1913
2008
 
1914
 
static void add_load_option(string &str, const char *option,
1915
 
                            const char *option_value)
 
2009
static void add_load_option(DYNAMIC_STRING *str, const char *option,
 
2010
                             const char *option_value)
1916
2011
{
1917
2012
  if (!option_value)
1918
2013
  {
1920
2015
    return;
1921
2016
  }
1922
2017
 
1923
 
  str.append(option);
 
2018
  dynstr_append_checked(str, option);
1924
2019
  
1925
2020
  if (strncmp(option_value, "0x", sizeof("0x")-1) == 0)
1926
2021
  {
1927
2022
    /* It's a hex constant, don't escape */
1928
 
    str.append(option_value);
 
2023
    dynstr_append_checked(str, option_value);
1929
2024
  }
1930
2025
  else
1931
2026
  {
1942
2037
  syntax errors from the SQL parser.
1943
2038
*/
1944
2039
 
1945
 
static void field_escape(string &in, const char *from)
 
2040
static void field_escape(DYNAMIC_STRING* in, const char *from)
1946
2041
{
1947
2042
  uint end_backslashes= 0; 
1948
2043
 
1949
 
  in.append("'");
 
2044
  dynstr_append_checked(in, "'");
1950
2045
 
1951
2046
  while (*from)
1952
2047
  {
1953
 
    in.append(from, 1);
 
2048
    dynstr_append_mem_checked(in, from, 1);
1954
2049
 
1955
2050
    if (*from == '\\')
1956
2051
      end_backslashes^=1;    /* find odd number of backslashes */
1958
2053
    {
1959
2054
      if (*from == '\'' && !end_backslashes)
1960
2055
      {
1961
 
        /* We want a duplicate of "'" for DRIZZLE */
1962
 
        in.append("\'");
 
2056
        /* We want a duplicate of "'" for MySQL */
 
2057
        dynstr_append_checked(in, "\'");
1963
2058
      }
1964
2059
      end_backslashes=0;
1965
2060
    }
1967
2062
  }
1968
2063
  /* Add missing backslashes if user has specified odd number of backs.*/
1969
2064
  if (end_backslashes)
1970
 
    in.append("\\");
1971
 
 
1972
 
  in.append("'");
 
2065
    dynstr_append_checked(in, "\\");
 
2066
  
 
2067
  dynstr_append_checked(in, "'");
1973
2068
}
1974
2069
 
1975
2070
 
1994
2089
{
1995
2090
  char ignore_flag;
1996
2091
  char buf[200], table_buff[NAME_LEN+3];
1997
 
  string query_string;
 
2092
  DYNAMIC_STRING query_string;
1998
2093
  char table_type[NAME_LEN];
1999
2094
  char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
2000
2095
  int error= 0;
2001
 
  uint32_t         rownr, row_break, total_length, init_length;
 
2096
  ulong         rownr, row_break, total_length, init_length;
2002
2097
  uint num_fields;
2003
 
  DRIZZLE_RES     *res;
2004
 
  DRIZZLE_FIELD   *field;
2005
 
  DRIZZLE_ROW     row;
2006
 
 
 
2098
  MYSQL_RES     *res;
 
2099
  MYSQL_FIELD   *field;
 
2100
  MYSQL_ROW     row;
 
2101
  DBUG_ENTER("dump_table");
2007
2102
 
2008
2103
  /*
2009
2104
    Make sure you get the create table info before the following check for
2015
2110
    The "table" could be a view.  If so, we don't do anything here.
2016
2111
  */
2017
2112
  if (strcmp(table_type, "VIEW") == 0)
2018
 
    return;
 
2113
    DBUG_VOID_RETURN;
2019
2114
 
2020
2115
  /* Check --no-data flag */
2021
2116
  if (opt_no_data)
2022
2117
  {
2023
2118
    verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
2024
2119
                table);
2025
 
    return;
 
2120
    DBUG_VOID_RETURN;
2026
2121
  }
2027
2122
 
 
2123
  DBUG_PRINT("info",
 
2124
             ("ignore_flag: %x  num_fields: %d", (int) ignore_flag,
 
2125
              num_fields));
2028
2126
  /*
2029
2127
    If the table type is a merge table or any type that has to be
2030
2128
     _completely_ ignored and no data dumped
2033
2131
  {
2034
2132
    verbose_msg("-- Warning: Skipping data for table '%s' because " \
2035
2133
                "it's of type %s\n", table, table_type);
2036
 
    return;
 
2134
    DBUG_VOID_RETURN;
2037
2135
  }
2038
2136
  /* Check that there are any fields in the table */
2039
2137
  if (num_fields == 0)
2040
2138
  {
2041
2139
    verbose_msg("-- Skipping dump data for table '%s', it has no fields\n",
2042
2140
                table);
2043
 
    return;
 
2141
    DBUG_VOID_RETURN;
2044
2142
  }
2045
2143
 
2046
2144
  /*
2048
2146
     discarding SHOW CREATE EVENT statements generation. The myslq.event
2049
2147
     table data should be skipped too.
2050
2148
  */
2051
 
  if (!opt_events && !my_strcasecmp(&my_charset_utf8_general_ci, db, "mysql") &&
2052
 
      !my_strcasecmp(&my_charset_utf8_general_ci, table, "event"))
 
2149
  if (!opt_events && !my_strcasecmp(&my_charset_latin1, db, "mysql") &&
 
2150
      !my_strcasecmp(&my_charset_latin1, table, "event"))
2053
2151
  {
2054
2152
    verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2055
 
    return;
 
2153
    DBUG_VOID_RETURN;
2056
2154
  }
2057
2155
 
2058
2156
  result_table= quote_name(table,table_buff, 1);
2060
2158
 
2061
2159
  verbose_msg("-- Sending SELECT query...\n");
2062
2160
 
2063
 
  query_string.clear();
2064
 
  query_string.reserve(1024);
 
2161
  init_dynamic_string_checked(&query_string, "", 1024, 1024);
2065
2162
 
2066
2163
  if (path)
2067
2164
  {
2071
2168
      Convert the path to native os format
2072
2169
      and resolve to the full filepath.
2073
2170
    */
2074
 
    convert_dirname(tmp_path,path,NULL);    
 
2171
    convert_dirname(tmp_path,path,NullS);    
2075
2172
    my_load_path(tmp_path, tmp_path, NULL);
2076
2173
    fn_format(filename, table, tmp_path, ".txt", MYF(MY_UNPACK_FILENAME));
2077
2174
 
2083
2180
 
2084
2181
    /* now build the query string */
2085
2182
 
2086
 
    query_string.append( "SELECT * INTO OUTFILE '");
2087
 
    query_string.append( filename);
2088
 
    query_string.append( "'");
 
2183
    dynstr_append_checked(&query_string, "SELECT * INTO OUTFILE '");
 
2184
    dynstr_append_checked(&query_string, filename);
 
2185
    dynstr_append_checked(&query_string, "'");
2089
2186
 
2090
2187
    if (fields_terminated || enclosed || opt_enclosed || escaped)
2091
 
      query_string.append( " FIELDS");
 
2188
      dynstr_append_checked(&query_string, " FIELDS");
2092
2189
    
2093
 
    add_load_option(query_string, " TERMINATED BY ", fields_terminated);
2094
 
    add_load_option(query_string, " ENCLOSED BY ", enclosed);
2095
 
    add_load_option(query_string, " OPTIONALLY ENCLOSED BY ", opt_enclosed);
2096
 
    add_load_option(query_string, " ESCAPED BY ", escaped);
2097
 
    add_load_option(query_string, " LINES TERMINATED BY ", lines_terminated);
 
2190
    add_load_option(&query_string, " TERMINATED BY ", fields_terminated);
 
2191
    add_load_option(&query_string, " ENCLOSED BY ", enclosed);
 
2192
    add_load_option(&query_string, " OPTIONALLY ENCLOSED BY ", opt_enclosed);
 
2193
    add_load_option(&query_string, " ESCAPED BY ", escaped);
 
2194
    add_load_option(&query_string, " LINES TERMINATED BY ", lines_terminated);
2098
2195
 
2099
 
    query_string.append( " FROM ");
2100
 
    query_string.append( result_table);
 
2196
    dynstr_append_checked(&query_string, " FROM ");
 
2197
    dynstr_append_checked(&query_string, result_table);
2101
2198
 
2102
2199
    if (where)
2103
2200
    {
2104
 
      query_string.append( " WHERE ");
2105
 
      query_string.append( where);
 
2201
      dynstr_append_checked(&query_string, " WHERE ");
 
2202
      dynstr_append_checked(&query_string, where);
2106
2203
    }
2107
2204
 
2108
2205
    if (order_by)
2109
2206
    {
2110
 
      query_string.append( " ORDER BY ");
2111
 
      query_string.append( order_by);
 
2207
      dynstr_append_checked(&query_string, " ORDER BY ");
 
2208
      dynstr_append_checked(&query_string, order_by);
2112
2209
    }
2113
2210
 
2114
 
    if (drizzle_real_query(drizzle, query_string.c_str(), query_string.length()))
 
2211
    if (mysql_real_query(mysql, query_string.str, query_string.length))
2115
2212
    {
2116
 
      DB_error(drizzle, "when executing 'SELECT INTO OUTFILE'");
2117
 
      return;
 
2213
      DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
 
2214
      dynstr_free(&query_string);
 
2215
      DBUG_VOID_RETURN;
2118
2216
    }
2119
2217
  }
2120
2218
  else
2126
2224
      check_io(md_result_file);
2127
2225
    }
2128
2226
    
2129
 
    query_string.append( "SELECT * FROM ");
2130
 
    query_string.append( result_table);
 
2227
    dynstr_append_checked(&query_string, "SELECT * FROM ");
 
2228
    dynstr_append_checked(&query_string, result_table);
2131
2229
 
2132
2230
    if (where)
2133
2231
    {
2137
2235
        check_io(md_result_file);
2138
2236
      }
2139
2237
      
2140
 
      query_string.append( " WHERE ");
2141
 
      query_string.append( where);
 
2238
      dynstr_append_checked(&query_string, " WHERE ");
 
2239
      dynstr_append_checked(&query_string, where);
2142
2240
    }
2143
2241
    if (order_by)
2144
2242
    {
2147
2245
        fprintf(md_result_file, "-- ORDER BY:  %s\n", order_by);
2148
2246
        check_io(md_result_file);
2149
2247
      }
2150
 
      query_string.append( " ORDER BY ");
2151
 
      query_string.append( order_by);
 
2248
      dynstr_append_checked(&query_string, " ORDER BY ");
 
2249
      dynstr_append_checked(&query_string, order_by);
2152
2250
    }
2153
2251
 
2154
2252
    if (!opt_xml && !opt_compact)
2156
2254
      fputs("\n", md_result_file);
2157
2255
      check_io(md_result_file);
2158
2256
    }
2159
 
    if (drizzle_query_with_error_report(drizzle, 0, query_string.c_str()))
 
2257
    if (mysql_query_with_error_report(mysql, 0, query_string.str))
2160
2258
    {
2161
 
      DB_error(drizzle, "when retrieving data from server");
 
2259
      DB_error(mysql, "when retrieving data from server");
2162
2260
      goto err;
2163
2261
    }
2164
2262
    if (quick)
2165
 
      res=drizzle_use_result(drizzle);
 
2263
      res=mysql_use_result(mysql);
2166
2264
    else
2167
 
      res=drizzle_store_result(drizzle);
 
2265
      res=mysql_store_result(mysql);
2168
2266
    if (!res)
2169
2267
    {
2170
 
      DB_error(drizzle, "when retrieving data from server");
 
2268
      DB_error(mysql, "when retrieving data from server");
2171
2269
      goto err;
2172
2270
    }
2173
2271
 
2174
2272
    verbose_msg("-- Retrieving rows...\n");
2175
 
    if (drizzle_num_fields(res) != num_fields)
 
2273
    if (mysql_num_fields(res) != num_fields)
2176
2274
    {
2177
2275
      fprintf(stderr,"%s: Error in field count for table: %s !  Aborting.\n",
2178
2276
              my_progname, result_table);
2196
2294
    total_length= opt_net_buffer_length;                /* Force row break */
2197
2295
    row_break=0;
2198
2296
    rownr=0;
2199
 
    init_length=(uint) insert_pat.length()+4;
 
2297
    init_length=(uint) insert_pat.length+4;
2200
2298
    if (opt_xml)
2201
2299
      print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
2202
 
              NULL);
 
2300
              NullS);
2203
2301
    if (opt_autocommit)
2204
2302
    {
2205
2303
      fprintf(md_result_file, "set autocommit=0;\n");
2206
2304
      check_io(md_result_file);
2207
2305
    }
2208
2306
 
2209
 
    while ((row= drizzle_fetch_row(res)))
 
2307
    while ((row= mysql_fetch_row(res)))
2210
2308
    {
2211
2309
      uint i;
2212
 
      uint32_t *lengths= drizzle_fetch_lengths(res);
 
2310
      ulong *lengths= mysql_fetch_lengths(res);
2213
2311
      rownr++;
2214
2312
      if (!extended_insert && !opt_xml)
2215
2313
      {
2216
 
        fputs(insert_pat.c_str(),md_result_file);
 
2314
        fputs(insert_pat.str,md_result_file);
2217
2315
        check_io(md_result_file);
2218
2316
      }
2219
 
      drizzle_field_seek(res,0);
 
2317
      mysql_field_seek(res,0);
2220
2318
 
2221
2319
      if (opt_xml)
2222
2320
      {
2224
2322
        check_io(md_result_file);
2225
2323
      }
2226
2324
 
2227
 
      for (i= 0; i < drizzle_num_fields(res); i++)
 
2325
      for (i= 0; i < mysql_num_fields(res); i++)
2228
2326
      {
2229
2327
        int is_blob;
2230
 
        uint32_t length= lengths[i];
 
2328
        ulong length= lengths[i];
2231
2329
 
2232
 
        if (!(field= drizzle_fetch_field(res)))
 
2330
        if (!(field= mysql_fetch_field(res)))
2233
2331
          die(EX_CONSCHECK,
2234
2332
                      "Not enough fields from table %s! Aborting.\n",
2235
2333
                      result_table);
2240
2338
           we'll dump in hex only BLOB columns.
2241
2339
        */
2242
2340
        is_blob= (opt_hex_blob && field->charsetnr == 63 &&
2243
 
                  (field->type == DRIZZLE_TYPE_VARCHAR ||
2244
 
                   field->type == DRIZZLE_TYPE_BLOB)) ? 1 : 0;
 
2341
                  (field->type == MYSQL_TYPE_STRING ||
 
2342
                   field->type == MYSQL_TYPE_VARCHAR ||
 
2343
                   field->type == MYSQL_TYPE_BLOB)) ? 1 : 0;
2245
2344
        if (extended_insert && !opt_xml)
2246
2345
        {
2247
2346
          if (i == 0)
2248
 
            extended_row= "(";
 
2347
            dynstr_set_checked(&extended_row,"(");
2249
2348
          else
2250
 
            extended_row.append(",");
 
2349
            dynstr_append_checked(&extended_row,",");
2251
2350
 
2252
2351
          if (row[i])
2253
2352
          {
2254
2353
            if (length)
2255
2354
            {
2256
 
              if (!(field->type & NUM_FLAG))
 
2355
              if (!IS_NUM_FIELD(field))
2257
2356
              {
2258
2357
                /*
2259
2358
                  "length * 2 + 2" is OK for both HEX and non-HEX modes:
2263
2362
                  plus 2 bytes for leading and trailing '\'' characters.
2264
2363
                  Also we need to reserve 1 byte for terminating '\0'.
2265
2364
                */
2266
 
                char * tmp_str= (char *)malloc(length * 2 + 2 + 1);
2267
 
                memset(tmp_str, '\0', length * 2 + 2 + 1);
 
2365
                dynstr_realloc_checked(&extended_row,length * 2 + 2 + 1);
2268
2366
                if (opt_hex_blob && is_blob)
2269
2367
                {
2270
 
                  extended_row.append("0x");
2271
 
                  drizzle_hex_string(tmp_str, row[i], length);
2272
 
                  extended_row.append(tmp_str);
 
2368
                  dynstr_append_checked(&extended_row, "0x");
 
2369
                  extended_row.length+= mysql_hex_string(extended_row.str +
 
2370
                                                         extended_row.length,
 
2371
                                                         row[i], length);
 
2372
                  DBUG_ASSERT(extended_row.length+1 <= extended_row.max_length);
 
2373
                  /* mysql_hex_string() already terminated string by '\0' */
 
2374
                  DBUG_ASSERT(extended_row.str[extended_row.length] == '\0');
2273
2375
                }
2274
2376
                else
2275
2377
                {
2276
 
                  extended_row.append("'");
2277
 
                  drizzle_escape_string(tmp_str,
2278
 
                                        row[i],length);
2279
 
                  extended_row.append(tmp_str);
2280
 
                  extended_row.append("'");
 
2378
                  dynstr_append_checked(&extended_row,"'");
 
2379
                  extended_row.length +=
 
2380
                  mysql_real_escape_string(&mysql_connection,
 
2381
                                           &extended_row.str[extended_row.length],
 
2382
                                           row[i],length);
 
2383
                  extended_row.str[extended_row.length]='\0';
 
2384
                  dynstr_append_checked(&extended_row,"'");
2281
2385
                }
2282
 
                free(tmp_str);
2283
2386
              }
2284
2387
              else
2285
2388
              {
2287
2390
                char *ptr= row[i];
2288
2391
                if (my_isalpha(charset_info, *ptr) || (*ptr == '-' &&
2289
2392
                    my_isalpha(charset_info, ptr[1])))
2290
 
                  extended_row.append( "NULL");
 
2393
                  dynstr_append_checked(&extended_row, "NULL");
2291
2394
                else
2292
2395
                {
2293
 
                  extended_row.append( ptr);
 
2396
                  dynstr_append_checked(&extended_row, ptr);
2294
2397
                }
2295
2398
              }
2296
2399
            }
2297
2400
            else
2298
 
              extended_row.append("''");
 
2401
              dynstr_append_checked(&extended_row,"''");
2299
2402
          }
2300
2403
          else
2301
 
            extended_row.append("NULL");
 
2404
            dynstr_append_checked(&extended_row,"NULL");
2302
2405
        }
2303
2406
        else
2304
2407
        {
2309
2412
          }
2310
2413
          if (row[i])
2311
2414
          {
2312
 
            if (!(field->type & NUM_FLAG))
 
2415
            if (!IS_NUM_FIELD(field))
2313
2416
            {
2314
2417
              if (opt_xml)
2315
2418
              {
2317
2420
                {
2318
2421
                  /* Define xsi:type="xs:hexBinary" for hex encoded data */
2319
2422
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2320
 
                                field->name, "xsi:type=", "xs:hexBinary", NULL);
 
2423
                                field->name, "xsi:type=", "xs:hexBinary", NullS);
2321
2424
                  print_blob_as_hex(md_result_file, row[i], length);
2322
2425
                }
2323
2426
                else
2324
2427
                {
2325
2428
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=", 
2326
 
                                field->name, NULL);
 
2429
                                field->name, NullS);
2327
2430
                  print_quoted_xml(md_result_file, row[i], length);
2328
2431
                }
2329
2432
                fputs("</field>\n", md_result_file);
2343
2446
              if (opt_xml)
2344
2447
              {
2345
2448
                print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2346
 
                        field->name, NULL);
 
2449
                        field->name, NullS);
2347
2450
                fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
2348
2451
                      md_result_file);
2349
2452
                fputs("</field>\n", md_result_file);
2376
2479
 
2377
2480
      if (extended_insert)
2378
2481
      {
2379
 
        uint32_t row_length;
2380
 
        extended_row.append(")");
2381
 
        row_length= 2 + extended_row.length();
 
2482
        ulong row_length;
 
2483
        dynstr_append_checked(&extended_row,")");
 
2484
        row_length= 2 + extended_row.length;
2382
2485
        if (total_length + row_length < opt_net_buffer_length)
2383
2486
        {
2384
2487
          total_length+= row_length;
2385
2488
          fputc(',',md_result_file);            /* Always row break */
2386
 
          fputs(extended_row.c_str(),md_result_file);
 
2489
          fputs(extended_row.str,md_result_file);
2387
2490
        }
2388
2491
        else
2389
2492
        {
2391
2494
            fputs(";\n", md_result_file);
2392
2495
          row_break=1;                          /* This is first row */
2393
2496
 
2394
 
          fputs(insert_pat.c_str(),md_result_file);
2395
 
          fputs(extended_row.c_str(),md_result_file);
 
2497
          fputs(insert_pat.str,md_result_file);
 
2498
          fputs(extended_row.str,md_result_file);
2396
2499
          total_length= row_length+init_length;
2397
2500
        }
2398
2501
        check_io(md_result_file);
2411
2514
      fputs(";\n", md_result_file);             /* If not empty table */
2412
2515
    fflush(md_result_file);
2413
2516
    check_io(md_result_file);
2414
 
    if (drizzle_errno(drizzle))
 
2517
    if (mysql_errno(mysql))
2415
2518
    {
2416
2519
      snprintf(buf, sizeof(buf),
2417
 
               "%s: Error %d: %s when dumping table %s at row: %d\n",
 
2520
               "%s: Error %d: %s when dumping table %s at row: %ld\n",
2418
2521
               my_progname,
2419
 
               drizzle_errno(drizzle),
2420
 
               drizzle_error(drizzle),
 
2522
               mysql_errno(mysql),
 
2523
               mysql_error(mysql),
2421
2524
               result_table,
2422
2525
               rownr);
2423
2526
      fputs(buf,stderr);
2442
2545
      fprintf(md_result_file, "commit;\n");
2443
2546
      check_io(md_result_file);
2444
2547
    }
2445
 
    drizzle_free_result(res);
 
2548
    mysql_free_result(res);
2446
2549
  }
2447
 
  return;
 
2550
  dynstr_free(&query_string);
 
2551
  DBUG_VOID_RETURN;
2448
2552
 
2449
2553
err:
 
2554
  dynstr_free(&query_string);
2450
2555
  maybe_exit(error);
2451
 
  return;
 
2556
  DBUG_VOID_RETURN;
2452
2557
} /* dump_table */
2453
2558
 
2454
2559
 
2455
2560
static char *getTableName(int reset)
2456
2561
{
2457
 
  static DRIZZLE_RES *res= NULL;
2458
 
  DRIZZLE_ROW    row;
 
2562
  static MYSQL_RES *res= NULL;
 
2563
  MYSQL_ROW    row;
2459
2564
 
2460
2565
  if (!res)
2461
2566
  {
2462
 
    if (!(res= drizzle_list_tables(drizzle,NULL)))
 
2567
    if (!(res= mysql_list_tables(mysql,NullS)))
2463
2568
      return(NULL);
2464
2569
  }
2465
 
  if ((row= drizzle_fetch_row(res)))
 
2570
  if ((row= mysql_fetch_row(res)))
2466
2571
    return((char*) row[0]);
2467
2572
 
2468
2573
  if (reset)
2469
 
    drizzle_data_seek(res,0);      /* We want to read again */
 
2574
    mysql_data_seek(res,0);      /* We want to read again */
2470
2575
  else
2471
2576
  {
2472
 
    drizzle_free_result(res);
 
2577
    mysql_free_result(res);
2473
2578
    res= NULL;
2474
2579
  }
2475
2580
  return(NULL);
2478
2583
 
2479
2584
static int dump_all_databases()
2480
2585
{
2481
 
  DRIZZLE_ROW row;
2482
 
  DRIZZLE_RES *tableres;
 
2586
  MYSQL_ROW row;
 
2587
  MYSQL_RES *tableres;
2483
2588
  int result=0;
2484
2589
 
2485
 
  if (drizzle_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
 
2590
  if (mysql_query_with_error_report(mysql, &tableres, "SHOW DATABASES"))
2486
2591
    return 1;
2487
 
  while ((row= drizzle_fetch_row(tableres)))
 
2592
  while ((row= mysql_fetch_row(tableres)))
2488
2593
  {
2489
2594
    if (dump_all_tables_in_db(row[0]))
2490
2595
      result=1;
2498
2603
{
2499
2604
  int result=0;
2500
2605
  char **db;
2501
 
 
 
2606
  DBUG_ENTER("dump_databases");
2502
2607
 
2503
2608
  for (db= db_names ; *db ; db++)
2504
2609
  {
2505
2610
    if (dump_all_tables_in_db(*db))
2506
2611
      result=1;
2507
2612
  }
2508
 
  return(result);
 
2613
  DBUG_RETURN(result);
2509
2614
} /* dump_databases */
2510
2615
 
2511
2616
 
2523
2628
 
2524
2629
int init_dumping_tables(char *qdatabase)
2525
2630
{
2526
 
 
 
2631
  DBUG_ENTER("init_dumping_tables");
2527
2632
 
2528
2633
  if (!opt_create_db)
2529
2634
  {
2530
2635
    char qbuf[256];
2531
 
    DRIZZLE_ROW row;
2532
 
    DRIZZLE_RES *dbinfo;
 
2636
    MYSQL_ROW row;
 
2637
    MYSQL_RES *dbinfo;
2533
2638
 
2534
2639
    snprintf(qbuf, sizeof(qbuf),
2535
2640
             "SHOW CREATE DATABASE IF NOT EXISTS %s",
2536
2641
             qdatabase);
2537
2642
 
2538
 
    if (drizzle_query(drizzle, qbuf) || !(dbinfo = drizzle_store_result(drizzle)))
 
2643
    if (mysql_query(mysql, qbuf) || !(dbinfo = mysql_store_result(mysql)))
2539
2644
    {
2540
2645
      /* Old server version, dump generic CREATE DATABASE */
2541
2646
      if (opt_drop_database)
2552
2657
        fprintf(md_result_file,
2553
2658
                "\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2554
2659
                qdatabase);
2555
 
      row = drizzle_fetch_row(dbinfo);
 
2660
      row = mysql_fetch_row(dbinfo);
2556
2661
      if (row[1])
2557
2662
      {
2558
2663
        fprintf(md_result_file,"\n%s;\n",row[1]);
2559
2664
      }
2560
 
      drizzle_free_result(dbinfo);
 
2665
      mysql_free_result(dbinfo);
2561
2666
    }
2562
2667
  }
2563
 
  return(0);
 
2668
  DBUG_RETURN(0);
2564
2669
} /* init_dumping_tables */
2565
2670
 
2566
2671
 
2567
2672
static int init_dumping(char *database, int init_func(char*))
2568
2673
{
2569
 
  if (drizzle_get_server_version(drizzle) >= 50003 &&
2570
 
      !my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
 
2674
  if (mysql_get_server_version(mysql) >= 50003 &&
 
2675
      !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
2571
2676
    return 1;
2572
2677
 
2573
 
  if (drizzle_select_db(drizzle, database))
 
2678
  if (mysql_select_db(mysql, database))
2574
2679
  {
2575
 
    DB_error(drizzle, "when selecting the database");
 
2680
    DB_error(mysql, "when selecting the database");
2576
2681
    return 1;                   /* If --force */
2577
2682
  }
2578
2683
  if (!path && !opt_xml)
2598
2703
    }
2599
2704
  }
2600
2705
  if (extended_insert)
2601
 
    extended_row.clear();
 
2706
    init_dynamic_string_checked(&extended_row, "", 1024, 1024);
2602
2707
  return 0;
2603
2708
} /* init_dumping */
2604
2709
 
2605
2710
 
2606
2711
/* Return 1 if we should copy the table */
2607
2712
 
2608
 
static bool include_table(const unsigned char *hash_key, size_t len)
 
2713
static my_bool include_table(const uchar *hash_key, size_t len)
2609
2714
{
2610
2715
  return !hash_search(&ignore_table, hash_key, len);
2611
2716
}
2618
2723
  char table_buff[NAME_LEN*2+3];
2619
2724
  char hash_key[2*NAME_LEN+2];  /* "db.tablename" */
2620
2725
  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);
 
2726
  int using_mysql_db= my_strcasecmp(&my_charset_latin1, database, "mysql");
 
2727
  DBUG_ENTER("dump_all_tables_in_db");
 
2728
 
 
2729
  afterdot= strmov(hash_key, database);
2625
2730
  *afterdot++= '.';
2626
2731
 
2627
2732
  if (init_dumping(database, init_dumping_tables))
2628
 
    return(1);
 
2733
    DBUG_RETURN(1);
2629
2734
  if (opt_xml)
2630
 
    print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NULL);
 
2735
    print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
2631
2736
  if (lock_tables)
2632
2737
  {
2633
 
    string query;
2634
 
    query= "LOCK TABLES ";
 
2738
    DYNAMIC_STRING query;
 
2739
    init_dynamic_string_checked(&query, "LOCK TABLES ", 256, 1024);
2635
2740
    for (numrows= 0 ; (table= getTableName(1)) ; )
2636
2741
    {
2637
 
      char *end= my_stpcpy(afterdot, table);
2638
 
      if (include_table((unsigned char*) hash_key,end - hash_key))
 
2742
      char *end= strmov(afterdot, table);
 
2743
      if (include_table((uchar*) hash_key,end - hash_key))
2639
2744
      {
2640
2745
        numrows++;
2641
 
        query.append( quote_name(table, table_buff, 1));
2642
 
        query.append( " READ /*!32311 LOCAL */,");
 
2746
        dynstr_append_checked(&query, quote_name(table, table_buff, 1));
 
2747
        dynstr_append_checked(&query, " READ /*!32311 LOCAL */,");
2643
2748
      }
2644
2749
    }
2645
 
    if (numrows && drizzle_real_query(drizzle, query.c_str(), query.length()-1))
2646
 
      DB_error(drizzle, "when using LOCK TABLES");
 
2750
    if (numrows && mysql_real_query(mysql, query.str, query.length-1))
 
2751
      DB_error(mysql, "when using LOCK TABLES");
2647
2752
            /* We shall continue here, if --force was given */
2648
 
    query.clear();
 
2753
    dynstr_free(&query);
2649
2754
  }
2650
2755
  if (flush_logs)
2651
2756
  {
2652
 
    if (drizzle_refresh(drizzle, REFRESH_LOG))
2653
 
      DB_error(drizzle, "when doing refresh");
 
2757
    if (mysql_refresh(mysql, REFRESH_LOG))
 
2758
      DB_error(mysql, "when doing refresh");
2654
2759
           /* We shall continue here, if --force was given */
2655
2760
  }
2656
2761
  while ((table= getTableName(0)))
2657
2762
  {
2658
 
    char *end= my_stpcpy(afterdot, table);
2659
 
    if (include_table((unsigned char*) hash_key, end - hash_key))
 
2763
    char *end= strmov(afterdot, table);
 
2764
    if (include_table((uchar*) hash_key, end - hash_key))
2660
2765
    {
2661
2766
      dump_table(table,database);
2662
 
      free(order_by);
 
2767
      my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2663
2768
      order_by= 0;
2664
2769
    }
2665
2770
  }
2669
2774
    check_io(md_result_file);
2670
2775
  }
2671
2776
  if (lock_tables)
2672
 
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
 
2777
    VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
2673
2778
  if (flush_privileges && using_mysql_db == 0)
2674
2779
  {
2675
2780
    fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2676
2781
    fprintf(md_result_file,"\n/*! FLUSH PRIVILEGES */;\n");
2677
2782
  }
2678
 
  return(0);
 
2783
  DBUG_RETURN(0);
2679
2784
} /* dump_all_tables_in_db */
2680
2785
 
2681
2786
 
2693
2798
static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
2694
2799
{
2695
2800
  char *name= 0;
2696
 
  DRIZZLE_RES  *table_res;
2697
 
  DRIZZLE_ROW  row;
 
2801
  MYSQL_RES  *table_res;
 
2802
  MYSQL_ROW  row;
2698
2803
  char query[50 + 2*NAME_LEN];
2699
2804
  char show_name_buff[FN_REFLEN];
2700
 
 
 
2805
  DBUG_ENTER("get_actual_table_name");
2701
2806
 
2702
2807
  /* Check memory for quote_for_like() */
2703
 
  assert(2*sizeof(old_table_name) < sizeof(show_name_buff));
 
2808
  DBUG_ASSERT(2*sizeof(old_table_name) < sizeof(show_name_buff));
2704
2809
  snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2705
2810
           quote_for_like(old_table_name, show_name_buff));
2706
2811
 
2707
 
  if (drizzle_query_with_error_report(drizzle, 0, query))
2708
 
    return NULL;
 
2812
  if (mysql_query_with_error_report(mysql, 0, query))
 
2813
    return NullS;
2709
2814
 
2710
 
  if ((table_res= drizzle_store_result(drizzle)))
 
2815
  if ((table_res= mysql_store_result(mysql)))
2711
2816
  {
2712
 
    uint64_t num_rows= drizzle_num_rows(table_res);
 
2817
    my_ulonglong num_rows= mysql_num_rows(table_res);
2713
2818
    if (num_rows > 0)
2714
2819
    {
2715
 
      uint32_t *lengths;
 
2820
      ulong *lengths;
2716
2821
      /*
2717
2822
        Return first row
2718
2823
        TODO: Return all matching rows
2719
2824
      */
2720
 
      row= drizzle_fetch_row(table_res);
2721
 
      lengths= drizzle_fetch_lengths(table_res);
 
2825
      row= mysql_fetch_row(table_res);
 
2826
      lengths= mysql_fetch_lengths(table_res);
2722
2827
      name= strmake_root(root, row[0], lengths[0]);
2723
2828
    }
2724
 
    drizzle_free_result(table_res);
 
2829
    mysql_free_result(table_res);
2725
2830
  }
2726
 
  return(name);
 
2831
  DBUG_PRINT("exit", ("new_table_name: %s", name));
 
2832
  DBUG_RETURN(name);
2727
2833
}
2728
2834
 
2729
2835
 
2730
2836
static int dump_selected_tables(char *db, char **table_names, int tables)
2731
2837
{
2732
2838
  char table_buff[NAME_LEN*2+3];
2733
 
  string lock_tables_query;
 
2839
  DYNAMIC_STRING lock_tables_query;
2734
2840
  MEM_ROOT root;
2735
2841
  char **dump_tables, **pos, **end;
2736
 
 
 
2842
  DBUG_ENTER("dump_selected_tables");
2737
2843
 
2738
2844
  if (init_dumping(db, init_dumping_tables))
2739
 
    return(1);
 
2845
    DBUG_RETURN(1);
2740
2846
 
2741
2847
  init_alloc_root(&root, 8192, 0);
2742
2848
  if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
2743
2849
     die(EX_EOM, "alloc_root failure.");
2744
2850
 
2745
 
  lock_tables_query= "LOCK TABLES ";
 
2851
  init_dynamic_string_checked(&lock_tables_query, "LOCK TABLES ", 256, 1024);
2746
2852
  for (; tables > 0 ; tables-- , table_names++)
2747
2853
  {
2748
2854
    /* the table name passed on commandline may be wrong case */
2751
2857
      /* Add found table name to lock_tables_query */
2752
2858
      if (lock_tables)
2753
2859
      {
2754
 
        lock_tables_query.append( quote_name(*pos, table_buff, 1));
2755
 
        lock_tables_query.append( " READ /*!32311 LOCAL */,");
 
2860
        dynstr_append_checked(&lock_tables_query, quote_name(*pos, table_buff, 1));
 
2861
        dynstr_append_checked(&lock_tables_query, " READ /*!32311 LOCAL */,");
2756
2862
      }
2757
2863
      pos++;
2758
2864
    }
2760
2866
    {
2761
2867
      if (!ignore_errors)
2762
2868
      {
 
2869
        dynstr_free(&lock_tables_query);
2763
2870
        free_root(&root, MYF(0));
2764
2871
      }
2765
2872
      maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names);
2770
2877
 
2771
2878
  if (lock_tables)
2772
2879
  {
2773
 
    if (drizzle_real_query(drizzle, lock_tables_query.c_str(),
2774
 
                         lock_tables_query.length()-1))
 
2880
    if (mysql_real_query(mysql, lock_tables_query.str,
 
2881
                         lock_tables_query.length-1))
2775
2882
    {
2776
2883
      if (!ignore_errors)
2777
2884
      {
 
2885
        dynstr_free(&lock_tables_query);
2778
2886
        free_root(&root, MYF(0));
2779
2887
      }
2780
 
      DB_error(drizzle, "when doing LOCK TABLES");
 
2888
      DB_error(mysql, "when doing LOCK TABLES");
2781
2889
       /* We shall countinue here, if --force was given */
2782
2890
    }
2783
2891
  }
 
2892
  dynstr_free(&lock_tables_query);
2784
2893
  if (flush_logs)
2785
2894
  {
2786
 
    if (drizzle_refresh(drizzle, REFRESH_LOG))
 
2895
    if (mysql_refresh(mysql, REFRESH_LOG))
2787
2896
    {
2788
2897
      if (!ignore_errors)
2789
2898
        free_root(&root, MYF(0));
2790
 
      DB_error(drizzle, "when doing refresh");
 
2899
      DB_error(mysql, "when doing refresh");
2791
2900
    }
2792
2901
     /* We shall countinue here, if --force was given */
2793
2902
  }
2794
2903
  if (opt_xml)
2795
 
    print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
 
2904
    print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
2796
2905
 
2797
2906
  /* Dump each selected table */
2798
2907
  for (pos= dump_tables; pos < end; pos++)
 
2908
  {
 
2909
    DBUG_PRINT("info",("Dumping table %s", *pos));
2799
2910
    dump_table(*pos, db);
 
2911
  }
2800
2912
 
2801
2913
  free_root(&root, MYF(0));
2802
 
  free(order_by);
 
2914
  my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2803
2915
  order_by= 0;
2804
2916
  if (opt_xml)
2805
2917
  {
2807
2919
    check_io(md_result_file);
2808
2920
  }
2809
2921
  if (lock_tables)
2810
 
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2811
 
  return(0);
 
2922
    VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
 
2923
  DBUG_RETURN(0);
2812
2924
} /* dump_selected_tables */
2813
2925
 
2814
2926
 
2815
 
static int do_show_master_status(DRIZZLE *drizzle_con)
 
2927
static int do_show_master_status(MYSQL *mysql_con)
2816
2928
{
2817
 
  DRIZZLE_ROW row;
2818
 
  DRIZZLE_RES *master;
 
2929
  MYSQL_ROW row;
 
2930
  MYSQL_RES *master;
2819
2931
  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"))
 
2932
    (opt_master_data == MYSQL_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
 
2933
  if (mysql_query_with_error_report(mysql_con, &master, "SHOW MASTER STATUS"))
2822
2934
  {
2823
2935
    return 1;
2824
2936
  }
2825
2937
  else
2826
2938
  {
2827
 
    row= drizzle_fetch_row(master);
 
2939
    row= mysql_fetch_row(master);
2828
2940
    if (row && row[0] && row[1])
2829
2941
    {
2830
2942
      /* SHOW MASTER STATUS reports file and position */
2842
2954
      /* SHOW MASTER STATUS reports nothing and --force is not enabled */
2843
2955
      my_printf_error(0, "Error: Binlogging on server not active",
2844
2956
                      MYF(0));
2845
 
      drizzle_free_result(master);
2846
 
      maybe_exit(EX_DRIZZLEERR);
 
2957
      mysql_free_result(master);
 
2958
      maybe_exit(EX_MYSQLERR);
2847
2959
      return 1;
2848
2960
    }
2849
 
    drizzle_free_result(master);
 
2961
    mysql_free_result(master);
2850
2962
  }
2851
2963
  return 0;
2852
2964
}
2853
2965
 
2854
 
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
 
2966
static int do_stop_slave_sql(MYSQL *mysql_con)
2855
2967
{
2856
 
  DRIZZLE_RES *slave;
 
2968
  MYSQL_RES *slave;
2857
2969
  /* 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"))
 
2970
  if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
2859
2971
    return(1);
2860
2972
  else
2861
2973
  {
2862
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
 
2974
    MYSQL_ROW row= mysql_fetch_row(slave);
2863
2975
    if (row && row[11])
2864
2976
    {
2865
2977
      /* if SLAVE SQL is not running, we don't stop it */
2866
2978
      if (!strcmp(row[11],"No"))
2867
2979
      {
2868
 
        drizzle_free_result(slave);
 
2980
        mysql_free_result(slave);
2869
2981
        /* Silently assume that they don't have the slave running */
2870
2982
        return(0);
2871
2983
      }
2872
2984
    }
2873
2985
  }
2874
 
  drizzle_free_result(slave);
 
2986
  mysql_free_result(slave);
2875
2987
 
2876
2988
  /* now, stop slave if running */
2877
 
  if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
 
2989
  if (mysql_query_with_error_report(mysql_con, 0, "STOP SLAVE SQL_THREAD"))
2878
2990
    return(1);
2879
2991
 
2880
2992
  return(0);
2898
3010
  return(0);
2899
3011
}
2900
3012
 
2901
 
static int do_show_slave_status(DRIZZLE *drizzle_con)
 
3013
static int do_show_slave_status(MYSQL *mysql_con)
2902
3014
{
2903
 
  DRIZZLE_RES *slave;
 
3015
  MYSQL_RES *slave;
2904
3016
  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"))
 
3017
    (opt_slave_data == MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
 
3018
  if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
2907
3019
  {
2908
3020
    if (!ignore_errors)
2909
3021
    {
2914
3026
  }
2915
3027
  else
2916
3028
  {
2917
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
 
3029
    MYSQL_ROW row= mysql_fetch_row(slave);
2918
3030
    if (row && row[9] && row[21])
2919
3031
    {
2920
3032
      /* SHOW MASTER STATUS reports file and position */
2937
3049
 
2938
3050
      check_io(md_result_file);
2939
3051
    }
2940
 
    drizzle_free_result(slave);
 
3052
    mysql_free_result(slave);
2941
3053
  }
2942
3054
  return 0;
2943
3055
}
2944
3056
 
2945
 
static int do_start_slave_sql(DRIZZLE *drizzle_con)
 
3057
static int do_start_slave_sql(MYSQL *mysql_con)
2946
3058
{
2947
 
  DRIZZLE_RES *slave;
 
3059
  MYSQL_RES *slave;
2948
3060
  /* 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"))
 
3061
  if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
2950
3062
    return(1);
2951
3063
  else
2952
3064
  {
2953
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
 
3065
    MYSQL_ROW row= mysql_fetch_row(slave);
2954
3066
    if (row && row[11])
2955
3067
    {
2956
3068
      /* if SLAVE SQL is not running, we don't start it */
2957
3069
      if (!strcmp(row[11],"Yes"))
2958
3070
      {
2959
 
        drizzle_free_result(slave);
 
3071
        mysql_free_result(slave);
2960
3072
        /* Silently assume that they don't have the slave running */
2961
3073
        return(0);
2962
3074
      }
2963
3075
    }
2964
3076
  }
2965
 
  drizzle_free_result(slave);
 
3077
  mysql_free_result(slave);
2966
3078
 
2967
3079
  /* now, start slave if stopped */
2968
 
  if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
 
3080
  if (mysql_query_with_error_report(mysql_con, 0, "START SLAVE"))
2969
3081
  {
2970
3082
    my_printf_error(0, "Error: Unable to start slave", MYF(0));
2971
3083
    return 1;
2975
3087
 
2976
3088
 
2977
3089
 
2978
 
static int do_flush_tables_read_lock(DRIZZLE *drizzle_con)
 
3090
static int do_flush_tables_read_lock(MYSQL *mysql_con)
2979
3091
{
2980
3092
  /*
2981
3093
    We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
2986
3098
    update starts between the two FLUSHes, we have that bad stall.
2987
3099
  */
2988
3100
  return
2989
 
    ( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
2990
 
      drizzle_query_with_error_report(drizzle_con, 0,
 
3101
    ( mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES") ||
 
3102
      mysql_query_with_error_report(mysql_con, 0,
2991
3103
                                    "FLUSH TABLES WITH READ LOCK") );
2992
3104
}
2993
3105
 
2994
3106
 
2995
 
static int do_unlock_tables(DRIZZLE *drizzle_con)
 
3107
static int do_unlock_tables(MYSQL *mysql_con)
2996
3108
{
2997
 
  return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
 
3109
  return mysql_query_with_error_report(mysql_con, 0, "UNLOCK TABLES");
2998
3110
}
2999
3111
 
3000
 
static int get_bin_log_name(DRIZZLE *drizzle_con,
 
3112
static int get_bin_log_name(MYSQL *mysql_con,
3001
3113
                            char* buff_log_name, uint buff_len)
3002
3114
{
3003
 
  DRIZZLE_RES *res;
3004
 
  DRIZZLE_ROW row;
 
3115
  MYSQL_RES *res;
 
3116
  MYSQL_ROW row;
3005
3117
 
3006
 
  if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
3007
 
      !(res= drizzle_store_result(drizzle)))
 
3118
  if (mysql_query(mysql_con, "SHOW MASTER STATUS") ||
 
3119
      !(res= mysql_store_result(mysql)))
3008
3120
    return 1;
3009
3121
 
3010
 
  if (!(row= drizzle_fetch_row(res)))
 
3122
  if (!(row= mysql_fetch_row(res)))
3011
3123
  {
3012
 
    drizzle_free_result(res);
 
3124
    mysql_free_result(res);
3013
3125
    return 1;
3014
3126
  }
3015
3127
  /*
3018
3130
  */
3019
3131
  strmake(buff_log_name, row[0], buff_len - 1);
3020
3132
 
3021
 
  drizzle_free_result(res);
 
3133
  mysql_free_result(res);
3022
3134
  return 0;
3023
3135
}
3024
3136
 
3025
 
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
 
3137
static int purge_bin_logs_to(MYSQL *mysql_con, char* log_name)
3026
3138
{
 
3139
  DYNAMIC_STRING str;
3027
3140
  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());
 
3141
  init_dynamic_string_checked(&str, "PURGE BINARY LOGS TO '", 1024, 1024);
 
3142
  dynstr_append_checked(&str, log_name);
 
3143
  dynstr_append_checked(&str, "'");
 
3144
  err = mysql_query_with_error_report(mysql_con, 0, str.str);
 
3145
  dynstr_free(&str);
3032
3146
  return err;
3033
3147
}
3034
3148
 
3035
3149
 
3036
 
static int start_transaction(DRIZZLE *drizzle_con)
 
3150
static int start_transaction(MYSQL *mysql_con)
3037
3151
{
3038
3152
  /*
3039
3153
    We use BEGIN for old servers. --single-transaction --master-data will fail
3044
3158
    need the REPEATABLE READ level (not anything lower, for example READ
3045
3159
    COMMITTED would give one new consistent read per dumped table).
3046
3160
  */
3047
 
  if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
 
3161
  if ((mysql_get_server_version(mysql_con) < 40100) && opt_master_data)
3048
3162
  {
3049
3163
    fprintf(stderr, "-- %s: the combination of --single-transaction and "
3050
 
            "--master-data requires a DRIZZLE server version of at least 4.1 "
 
3164
            "--master-data requires a MySQL server version of at least 4.1 "
3051
3165
            "(current server's version is %s). %s\n",
3052
3166
            ignore_errors ? "Warning" : "Error",
3053
 
            drizzle_con->server_version ? drizzle_con->server_version : "unknown",
 
3167
            mysql_con->server_version ? mysql_con->server_version : "unknown",
3054
3168
            ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3055
3169
    if (!ignore_errors)
3056
 
      exit(EX_DRIZZLEERR);
 
3170
      exit(EX_MYSQLERR);
3057
3171
  }
3058
3172
 
3059
 
  return (drizzle_query_with_error_report(drizzle_con, 0,
 
3173
  return (mysql_query_with_error_report(mysql_con, 0,
3060
3174
                                        "SET SESSION TRANSACTION ISOLATION "
3061
3175
                                        "LEVEL REPEATABLE READ") ||
3062
 
          drizzle_query_with_error_report(drizzle_con, 0,
 
3176
          mysql_query_with_error_report(mysql_con, 0,
3063
3177
                                        "START TRANSACTION "
3064
3178
                                        "/*!40100 WITH CONSISTENT SNAPSHOT */"));
3065
3179
}
3066
3180
 
3067
3181
 
3068
 
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
 
3182
static ulong find_set(TYPELIB *lib, const char *x, uint length,
3069
3183
                      char **err_pos, uint *err_len)
3070
3184
{
3071
3185
  const char *end= x + length;
3072
 
  uint32_t found= 0;
 
3186
  ulong found= 0;
3073
3187
  uint find;
3074
3188
  char buff[255];
3075
3189
 
3084
3198
    for (;;)
3085
3199
    {
3086
3200
      const char *pos= start;
3087
 
      uint32_t var_len;
 
3201
      uint var_len;
3088
3202
 
3089
3203
      for (; pos != end && *pos != ','; pos++) ;
3090
 
      var_len= (uint32_t) (pos - start);
3091
 
      strmake(buff, start, min((uint32_t)sizeof(buff), var_len));
 
3204
      var_len= (uint) (pos - start);
 
3205
      strmake(buff, start, min(sizeof(buff), var_len));
3092
3206
      find= find_type(buff, lib, var_len);
3093
3207
      if (!find)
3094
3208
      {
3096
3210
        *err_len= var_len;
3097
3211
      }
3098
3212
      else
3099
 
        found|= ((int64_t) 1 << (find - 1));
 
3213
        found|= ((longlong) 1 << (find - 1));
3100
3214
      if (pos == end)
3101
3215
        break;
3102
3216
      start= pos + 1;
3107
3221
 
3108
3222
 
3109
3223
/* Print a value with a prefix on file */
3110
 
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
 
3224
static void print_value(FILE *file, MYSQL_RES  *result, MYSQL_ROW row,
3111
3225
                        const char *prefix, const char *name,
3112
3226
                        int string_value)
3113
3227
{
3114
 
  DRIZZLE_FIELD   *field;
3115
 
  drizzle_field_seek(result, 0);
 
3228
  MYSQL_FIELD   *field;
 
3229
  mysql_field_seek(result, 0);
3116
3230
 
3117
 
  for ( ; (field= drizzle_fetch_field(result)) ; row++)
 
3231
  for ( ; (field= mysql_fetch_field(result)) ; row++)
3118
3232
  {
3119
3233
    if (!strcmp(field->name,name))
3120
3234
    {
3140
3254
 
3141
3255
  Check if we the table is one of the table types that should be ignored:
3142
3256
  MRG_ISAM, MRG_MYISAM, if opt_delayed, if that table supports delayed inserts.
3143
 
  If the table should be altogether ignored, it returns a true, false if it
 
3257
  If the table should be altogether ignored, it returns a TRUE, FALSE if it
3144
3258
  should not be ignored. If the user has selected to use INSERT DELAYED, it
3145
3259
  sets the value of the bool pointer supports_delayed_inserts to 0 if not
3146
3260
  supported, 1 if it is supported.
3152
3266
    table_type                  Type of table
3153
3267
 
3154
3268
  GLOBAL VARIABLES
3155
 
    drizzle                       Drizzle connection
 
3269
    mysql                       MySQL connection
3156
3270
    verbose                     Write warning messages
3157
3271
 
3158
3272
  RETURN
3163
3277
{
3164
3278
  char result= IGNORE_NONE;
3165
3279
  char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3166
 
  DRIZZLE_RES *res= NULL;
3167
 
  DRIZZLE_ROW row;
3168
 
 
 
3280
  MYSQL_RES *res= NULL;
 
3281
  MYSQL_ROW row;
 
3282
  DBUG_ENTER("check_if_ignore_table");
3169
3283
 
3170
3284
  /* Check memory for quote_for_like() */
3171
 
  assert(2*sizeof(table_name) < sizeof(show_name_buff));
 
3285
  DBUG_ASSERT(2*sizeof(table_name) < sizeof(show_name_buff));
3172
3286
  snprintf(buff, sizeof(buff), "show table status like %s",
3173
3287
           quote_for_like(table_name, show_name_buff));
3174
 
  if (drizzle_query_with_error_report(drizzle, &res, buff))
 
3288
  if (mysql_query_with_error_report(mysql, &res, buff))
3175
3289
  {
3176
 
    if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
3177
 
    {                                   /* If old DRIZZLE version */
 
3290
    if (mysql_errno(mysql) != ER_PARSE_ERROR)
 
3291
    {                                   /* If old MySQL version */
3178
3292
      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 */
 
3293
                  "table %s (%s)\n", table_name, mysql_error(mysql));
 
3294
      DBUG_RETURN(result);                       /* assume table is ok */
3181
3295
    }
3182
3296
  }
3183
 
  if (!(row= drizzle_fetch_row(res)))
 
3297
  if (!(row= mysql_fetch_row(res)))
3184
3298
  {
3185
3299
    fprintf(stderr,
3186
3300
            "Error: Couldn't read status information for table %s (%s)\n",
3187
 
            table_name, drizzle_error(drizzle));
3188
 
    drizzle_free_result(res);
3189
 
    return(result);                         /* assume table is ok */
 
3301
            table_name, mysql_error(mysql));
 
3302
    mysql_free_result(res);
 
3303
    DBUG_RETURN(result);                         /* assume table is ok */
3190
3304
  }
3191
3305
  if (!(row[1]))
3192
3306
    strmake(table_type, "VIEW", NAME_LEN-1);
3213
3327
      If these two types, we do want to skip dumping the table
3214
3328
    */
3215
3329
    if (!opt_no_data &&
3216
 
        (!my_strcasecmp(&my_charset_utf8_general_ci, table_type, "MRG_MyISAM") ||
 
3330
        (!my_strcasecmp(&my_charset_latin1, table_type, "MRG_MyISAM") ||
3217
3331
         !strcmp(table_type,"MRG_ISAM")))
3218
3332
      result= IGNORE_DATA;
3219
3333
  }
3220
 
  drizzle_free_result(res);
3221
 
  return(result);
 
3334
  mysql_free_result(res);
 
3335
  DBUG_RETURN(result);
3222
3336
}
3223
3337
 
3224
3338
 
3242
3356
 
3243
3357
static char *primary_key_fields(const char *table_name)
3244
3358
{
3245
 
  DRIZZLE_RES  *res= NULL;
3246
 
  DRIZZLE_ROW  row;
 
3359
  MYSQL_RES  *res= NULL;
 
3360
  MYSQL_ROW  row;
3247
3361
  /* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3248
3362
  char show_keys_buff[15 + NAME_LEN * 2 + 3];
3249
3363
  uint result_length= 0;
3253
3367
 
3254
3368
  snprintf(show_keys_buff, sizeof(show_keys_buff),
3255
3369
           "SHOW KEYS FROM %s", table_name);
3256
 
  if (drizzle_query(drizzle, show_keys_buff) ||
3257
 
      !(res= drizzle_store_result(drizzle)))
 
3370
  if (mysql_query(mysql, show_keys_buff) ||
 
3371
      !(res= mysql_store_result(mysql)))
3258
3372
  {
3259
3373
    fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3260
3374
            " records are NOT sorted (%s)\n",
3261
 
            table_name, drizzle_error(drizzle));
 
3375
            table_name, mysql_error(mysql));
3262
3376
    /* Don't exit, because it's better to print out unsorted records */
3263
3377
    goto cleanup;
3264
3378
  }
3269
3383
   * row, and UNIQUE keys come before others.  So we only need to check
3270
3384
   * the first key, not all keys.
3271
3385
   */
3272
 
  if ((row= drizzle_fetch_row(res)) && atoi(row[1]) == 0)
 
3386
  if ((row= mysql_fetch_row(res)) && atoi(row[1]) == 0)
3273
3387
  {
3274
3388
    /* Key is unique */
3275
3389
    do
3276
3390
    {
3277
3391
      quoted_field= quote_name(row[4], buff, 0);
3278
3392
      result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3279
 
    } while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1);
 
3393
    } while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1);
3280
3394
  }
3281
3395
 
3282
3396
  /* Build the ORDER BY clause result */
3284
3398
  {
3285
3399
    char *end;
3286
3400
    /* result (terminating \0 is already in result_length) */
3287
 
    result= (char *)my_malloc(result_length + 10, MYF(MY_WME));
 
3401
    result= my_malloc(result_length + 10, MYF(MY_WME));
3288
3402
    if (!result)
3289
3403
    {
3290
3404
      fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
3291
3405
      goto cleanup;
3292
3406
    }
3293
 
    drizzle_data_seek(res, 0);
3294
 
    row= drizzle_fetch_row(res);
 
3407
    mysql_data_seek(res, 0);
 
3408
    row= mysql_fetch_row(res);
3295
3409
    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)
 
3410
    end= strmov(result, quoted_field);
 
3411
    while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1)
3298
3412
    {
3299
3413
      quoted_field= quote_name(row[4], buff, 0);
3300
 
      end= strxmov(end, ",", quoted_field, NULL);
 
3414
      end= strxmov(end, ",", quoted_field, NullS);
3301
3415
    }
3302
3416
  }
3303
3417
 
3304
3418
cleanup:
3305
3419
  if (res)
3306
 
    drizzle_free_result(res);
 
3420
    mysql_free_result(res);
3307
3421
 
3308
3422
  return result;
3309
3423
}
3310
3424
 
 
3425
/*
 
3426
  The following functions are wrappers for the dynamic string functions
 
3427
  and if they fail, the wrappers will terminate the current process.
 
3428
*/
 
3429
 
 
3430
#define DYNAMIC_STR_ERROR_MSG "Couldn't perform DYNAMIC_STRING operation"
 
3431
 
 
3432
static void init_dynamic_string_checked(DYNAMIC_STRING *str, const char *init_str,
 
3433
                            uint init_alloc, uint alloc_increment)
 
3434
{
 
3435
  if (init_dynamic_string(str, init_str, init_alloc, alloc_increment))
 
3436
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
 
3437
}
 
3438
 
 
3439
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src)
 
3440
{
 
3441
  if (dynstr_append(dest, src))
 
3442
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
 
3443
}
 
3444
 
 
3445
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str)
 
3446
{
 
3447
  if (dynstr_set(str, init_str))
 
3448
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
 
3449
}
 
3450
 
 
3451
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
 
3452
                          uint length)
 
3453
{
 
3454
  if (dynstr_append_mem(str, append, length))
 
3455
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
 
3456
}
 
3457
 
 
3458
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size)
 
3459
{
 
3460
  if (dynstr_realloc(str, additional_size))
 
3461
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
 
3462
}
 
3463
 
3311
3464
 
3312
3465
int main(int argc, char **argv)
3313
3466
{
3316
3469
  MY_INIT("mysqldump");
3317
3470
 
3318
3471
  compatible_mode_normal_str[0]= 0;
3319
 
  default_charset= (char *)drizzle_universal_client_charset;
3320
 
  memset(&ignore_table, 0, sizeof(ignore_table));
 
3472
  default_charset= (char *)mysql_universal_client_charset;
 
3473
  bzero((char*) &ignore_table, sizeof(ignore_table));
3321
3474
 
3322
3475
  exit_code= get_options(&argc, &argv);
3323
3476
  if (exit_code)
3331
3484
    if(!(stderror_file= freopen(log_error_file, "a+", stderr)))
3332
3485
    {
3333
3486
      free_resources();
3334
 
      exit(EX_DRIZZLEERR);
 
3487
      exit(EX_MYSQLERR);
3335
3488
    }
3336
3489
  }
3337
3490
 
3338
3491
  if (connect_to_db(current_host, current_user, opt_password))
3339
3492
  {
3340
3493
    free_resources();
3341
 
    exit(EX_DRIZZLEERR);
 
3494
    exit(EX_MYSQLERR);
3342
3495
  }
3343
3496
  if (!path)
3344
3497
    write_header(md_result_file, *argv);
3345
3498
 
3346
 
  if (opt_slave_data && do_stop_slave_sql(drizzle))
 
3499
  if (opt_slave_data && do_stop_slave_sql(mysql))
3347
3500
    goto err;
3348
3501
 
3349
3502
  if ((opt_lock_all_tables || opt_master_data) &&
3350
 
      do_flush_tables_read_lock(drizzle))
 
3503
      do_flush_tables_read_lock(mysql))
3351
3504
    goto err;
3352
 
  if (opt_single_transaction && start_transaction(drizzle))
 
3505
  if (opt_single_transaction && start_transaction(mysql))
3353
3506
      goto err;
3354
3507
  if (opt_delete_master_logs)
3355
3508
  {
3356
 
    if (drizzle_refresh(drizzle, REFRESH_LOG) ||
3357
 
        get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
 
3509
    if (mysql_refresh(mysql, REFRESH_LOG) ||
 
3510
        get_bin_log_name(mysql, bin_log_name, sizeof(bin_log_name)))
3358
3511
      goto err;
3359
3512
    flush_logs= 0;
3360
3513
  }
3361
3514
  if (opt_lock_all_tables || opt_master_data)
3362
3515
  {
3363
 
    if (flush_logs && drizzle_refresh(drizzle, REFRESH_LOG))
 
3516
    if (flush_logs && mysql_refresh(mysql, REFRESH_LOG))
3364
3517
      goto err;
3365
3518
    flush_logs= 0; /* not anymore; that would not be sensible */
3366
3519
  }
3367
3520
  /* Add 'STOP SLAVE to beginning of dump */
3368
3521
  if (opt_slave_apply && add_stop_slave())
3369
3522
    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! */
 
3523
  if (opt_master_data && do_show_master_status(mysql))
 
3524
    goto err;
 
3525
  if (opt_slave_data && do_show_slave_status(mysql))
 
3526
    goto err;
 
3527
  if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */
3375
3528
    goto err;
3376
3529
 
3377
3530
  if (opt_alldbs)
3389
3542
  }
3390
3543
 
3391
3544
  /* if --dump-slave , start the slave sql thread */
3392
 
  if (opt_slave_data && do_start_slave_sql(drizzle))
 
3545
  if (opt_slave_data && do_start_slave_sql(mysql))
3393
3546
    goto err;
3394
3547
 
3395
3548
  /* add 'START SLAVE' to end of dump */
3400
3553
  if (md_result_file && fflush(md_result_file))
3401
3554
  {
3402
3555
    if (!first_error)
3403
 
      first_error= EX_DRIZZLEERR;
 
3556
      first_error= EX_MYSQLERR;
3404
3557
    goto err;
3405
3558
  }
3406
3559
  /* everything successful, purge the old logs files */
3407
 
  if (opt_delete_master_logs && purge_bin_logs_to(drizzle, bin_log_name))
 
3560
  if (opt_delete_master_logs && purge_bin_logs_to(mysql, bin_log_name))
3408
3561
    goto err;
3409
3562
 
 
3563
#ifdef HAVE_SMEM
 
3564
  my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
 
3565
#endif
3410
3566
  /*
3411
3567
    No reason to explicitely COMMIT the transaction, neither to explicitely
3412
3568
    UNLOCK TABLES: these will be automatically be done by the server when we