~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqldump.c

  • Committer: Brian Aker
  • Date: 2008-07-03 00:14:39 UTC
  • Revision ID: brian@tangent.org-20080703001439-pit0mcl0wk8elxlq
Cleanup of sql-common and mysqldump

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