~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

Merge Siddharth, ran formatting across it.

Someone really should take these programs apart and clean them up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright 2000-2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
2
2
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
3
  This program is free software; you can redistribute it and/or modify
 
4
  it under the terms of the GNU General Public License as published by
 
5
  the Free Software Foundation; version 2 of the License.
 
6
 
 
7
  This program is distributed in the hope that it will be useful,
 
8
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
  GNU General Public License for more details.
 
11
 
 
12
  You should have received a copy of the GNU General Public License
 
13
  along with this program; if not, write to the Free Software
 
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* drizzledump.cc  - Dump a tables contents and format to an ASCII file
17
17
 
18
18
 * Derived from mysqldump, which originally came from:
19
 
**
20
 
** The author's original notes follow :-
21
 
**
22
 
** AUTHOR: Igor Romanenko (igor@frog.kiev.ua)
23
 
** DATE:   December 3, 1994
24
 
** WARRANTY: None, expressed, impressed, implied
25
 
**          or other
26
 
** STATUS: Public domain
 
19
 **
 
20
 ** The author's original notes follow :-
 
21
 **
 
22
 ** AUTHOR: Igor Romanenko (igor@frog.kiev.ua)
 
23
 ** DATE:   December 3, 1994
 
24
 ** WARRANTY: None, expressed, impressed, implied
 
25
 **          or other
 
26
 ** STATUS: Public domain
27
27
 
28
 
* and more work by Monty, Jani & Sinisa
29
 
* and all the MySQL developers over the years.
 
28
 * and more work by Monty, Jani & Sinisa
 
29
 * and all the MySQL developers over the years.
30
30
*/
31
31
 
32
32
#include "client_priv.h"
76
76
static void add_load_option(string &str, const char *option,
77
77
                            const char *option_value);
78
78
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
79
 
                         char **err_pos, uint32_t *err_len);
 
79
                         char **err_pos, uint32_t *err_len);
80
80
 
81
81
static void field_escape(string &in, const char *from);
82
82
static bool  verbose= false;
151
151
  NULL
152
152
};
153
153
static TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
154
 
                                  "", compatible_mode_names, NULL};
 
154
  "", compatible_mode_names, NULL};
155
155
 
156
156
drizzled::hash_set<string> ignore_table;
157
157
 
158
158
static struct my_option my_long_options[] =
159
159
{
160
160
  {"all", 'a', "Deprecated. Use --create-options instead.",
161
 
   (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
162
 
   0, 0, 0, 0, 0},
 
161
    (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
 
162
    0, 0, 0, 0, 0},
163
163
  {"all-databases", 'A',
164
 
   "Dump all the databases. This will be same as --databases with all databases selected.",
165
 
   (char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
166
 
   0, 0},
 
164
    "Dump all the databases. This will be same as --databases with all databases selected.",
 
165
    (char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
166
    0, 0},
167
167
  {"all-tablespaces", 'Y',
168
 
   "Dump all the tablespaces.",
169
 
   (char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
170
 
   0, 0},
 
168
    "Dump all the tablespaces.",
 
169
    (char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
170
    0, 0},
171
171
  {"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
172
 
   (char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
173
 
   0},
 
172
    (char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
173
    0},
174
174
  {"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
175
 
   (char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
176
 
   0},
 
175
    (char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
 
176
    0},
177
177
  {"allow-keywords", OPT_KEYWORDS,
178
 
   "Allow creation of column names that are keywords.", (char**) &opt_keywords,
179
 
   (char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
178
    "Allow creation of column names that are keywords.", (char**) &opt_keywords,
 
179
    (char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
180
180
  {"comments", 'i', "Write additional information.",
181
 
   (char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
182
 
   1, 0, 0, 0, 0, 0},
 
181
    (char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
 
182
    1, 0, 0, 0, 0, 0},
183
183
  {"compatible", OPT_COMPATIBLE,
184
 
   "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.",
185
 
   (char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
186
 
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
184
    "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.",
 
185
    (char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
 
186
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
187
187
  {"compact", OPT_COMPACT,
188
 
   "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",
189
 
   (char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
190
 
   0, 0},
 
188
    "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",
 
189
    (char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
190
    0, 0},
191
191
  {"complete-insert", 'c', "Use complete insert statements.",
192
 
   (char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
193
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
192
    (char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
 
193
    NO_ARG, 0, 0, 0, 0, 0, 0},
194
194
  {"compress", 'C', "Use compression in server/client protocol.",
195
 
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
196
 
   0, 0, 0},
 
195
    (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
196
    0, 0, 0},
197
197
  {"create-options", OPT_CREATE_OPTIONS,
198
 
   "Include all DRIZZLE specific create options.",
199
 
   (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
200
 
   0, 0, 0, 0, 0},
 
198
    "Include all DRIZZLE specific create options.",
 
199
    (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
 
200
    0, 0, 0, 0, 0},
201
201
  {"databases", 'B',
202
 
   "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.",
203
 
   (char**) &opt_databases, (char**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
204
 
   0, 0, 0, 0},
 
202
    "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.",
 
203
    (char**) &opt_databases, (char**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
 
204
    0, 0, 0, 0},
205
205
  {"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
206
 
   (char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
207
 
   0, 0},
 
206
    (char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
207
    0, 0},
208
208
  {"disable-keys", 'K',
209
 
   "'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.", (char**) &opt_disable_keys,
210
 
   (char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
209
    "'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.", (char**) &opt_disable_keys,
 
210
    (char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
211
211
  {"extended-insert", 'e',
212
 
   "Allows utilization of the new, much faster INSERT syntax.",
213
 
   (char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
214
 
   1, 0, 0, 0, 0, 0},
 
212
    "Allows utilization of the new, much faster INSERT syntax.",
 
213
    (char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
 
214
    1, 0, 0, 0, 0, 0},
215
215
  {"fields-terminated-by", OPT_FTB,
216
 
   "Fields in the textfile are terminated by ...", (char**) &fields_terminated,
217
 
   (char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
216
    "Fields in the textfile are terminated by ...", (char**) &fields_terminated,
 
217
    (char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
218
218
  {"fields-enclosed-by", OPT_ENC,
219
 
   "Fields in the importfile are enclosed by ...", (char**) &enclosed,
220
 
   (char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
 
219
    "Fields in the importfile are enclosed by ...", (char**) &enclosed,
 
220
    (char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
221
221
  {"fields-optionally-enclosed-by", OPT_O_ENC,
222
 
   "Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
223
 
   (char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
 
222
    "Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
 
223
    (char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
224
224
  {"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
225
 
   (char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
225
    (char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
226
226
  {"flush-logs", 'F', "Flush logs file in server before starting dump. "
227
 
   "Note that if you dump many databases at once (using the option "
228
 
   "--databases= or --all-databases), the logs will be flushed for "
229
 
   "each database dumped. The exception is when using --lock-all-tables "
230
 
   "in this case the logs will be flushed only once, corresponding "
231
 
   "to the moment all tables are locked. So if you want your dump and "
232
 
   "the log flush to happen at the same exact moment you should use "
233
 
   "--lock-all-tables or --flush-logs",
234
 
   (char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
235
 
   0, 0},
 
227
    "Note that if you dump many databases at once (using the option "
 
228
      "--databases= or --all-databases), the logs will be flushed for "
 
229
      "each database dumped. The exception is when using --lock-all-tables "
 
230
      "in this case the logs will be flushed only once, corresponding "
 
231
      "to the moment all tables are locked. So if you want your dump and "
 
232
      "the log flush to happen at the same exact moment you should use "
 
233
      "--lock-all-tables or --flush-logs",
 
234
    (char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
235
    0, 0},
236
236
  {"force", 'f', "Continue even if we get an sql-error.",
237
 
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
238
 
   0, 0, 0, 0, 0, 0},
 
237
    (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
 
238
    0, 0, 0, 0, 0, 0},
239
239
  {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
240
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
240
    NO_ARG, 0, 0, 0, 0, 0, 0},
241
241
  {"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, "
242
242
    "VARBINARY, BLOB) in hexadecimal format.",
243
 
   (char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
243
    (char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
244
244
  {"host", 'h', "Connect to host.", (char**) &current_host,
245
 
   (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
245
    (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
246
246
  {"ignore-table", OPT_IGNORE_TABLE,
247
 
   "Do not dump the specified table. To specify more than one table to ignore, "
248
 
   "use the directive multiple times, once for each table.  Each table must "
249
 
   "be specified with both database and table names, e.g. --ignore-table=database.table",
250
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
247
    "Do not dump the specified table. To specify more than one table to ignore, "
 
248
      "use the directive multiple times, once for each table.  Each table must "
 
249
      "be specified with both database and table names, e.g. --ignore-table=database.table",
 
250
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
251
251
  {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
252
 
   (char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
253
 
   0, 0},
 
252
    (char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
253
    0, 0},
254
254
  {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
255
 
   (char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
256
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
255
    (char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
 
256
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
257
257
  {"lock-all-tables", 'x', "Locks all tables across all databases. This "
258
 
   "is achieved by taking a global read lock for the duration of the whole "
259
 
   "dump. Automatically turns --single-transaction and --lock-tables off.",
260
 
   (char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
261
 
   0, 0, 0, 0, 0, 0},
 
258
    "is achieved by taking a global read lock for the duration of the whole "
 
259
      "dump. Automatically turns --single-transaction and --lock-tables off.",
 
260
    (char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
 
261
    0, 0, 0, 0, 0, 0},
262
262
  {"mysql", 'm', N_("Use MySQL Protocol."),
263
 
   (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
264
 
   0, 0, 0},
 
263
    (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
 
264
    0, 0, 0},
265
265
  {"no-autocommit", OPT_AUTOCOMMIT,
266
 
   "Wrap tables with autocommit/commit statements.",
267
 
   (char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
268
 
   0, 0, 0, 0, 0, 0},
 
266
    "Wrap tables with autocommit/commit statements.",
 
267
    (char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
 
268
    0, 0, 0, 0, 0, 0},
269
269
  {"no-create-db", 'n',
270
 
   "'CREATE DATABASE IF NOT EXISTS db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
271
 
   (char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
272
 
   0, 0, 0, 0},
 
270
    "'CREATE DATABASE IF NOT EXISTS db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
 
271
    (char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
 
272
    0, 0, 0, 0},
273
273
  {"no-create-info", 't', "Don't write table creation info.",
274
 
   (char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
275
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
274
    (char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
 
275
    NO_ARG, 0, 0, 0, 0, 0, 0},
276
276
  {"no-data", 'd', "No row information.", (char**) &opt_no_data,
277
 
   (char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
277
    (char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
278
278
  {"no-set-names", 'N',
279
 
   "Deprecated. Use --skip-set-charset instead.",
280
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
279
    "Deprecated. Use --skip-set-charset instead.",
 
280
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
281
281
  {"opt", OPT_OPTIMIZE,
282
 
   "Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt.",
283
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
282
    "Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt.",
 
283
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
284
284
  {"order-by-primary", OPT_ORDER_BY_PRIMARY,
285
 
   "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.",
286
 
   (char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
285
    "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.",
 
286
    (char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
287
287
  {"password", 'P',
288
 
   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
289
 
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
288
    "Password to use when connecting to server. If password is not given it's solicited on the tty.",
 
289
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
290
290
  {"port", 'p', "Port number to use for connection.", 
291
 
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
291
    0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
292
292
  {"quick", 'q', "Don't buffer query, dump directly to stdout.",
293
 
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
293
    (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
294
294
  {"quote-names",'Q', "Quote table and column names with backticks (`).",
295
 
   (char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
296
 
   0, 0},
 
295
    (char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
 
296
    0, 0},
297
297
  {"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
298
 
   (char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
299
 
   0, 0},
 
298
    (char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
299
    0, 0},
300
300
  {"result-file", 'r',
301
 
   "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).",
302
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
301
    "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).",
 
302
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
303
303
  {"routines", 'R', "Dump stored routines (functions and procedures).",
304
 
     (char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
305
 
     NO_ARG, 0, 0, 0, 0, 0, 0},
 
304
    (char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
 
305
    NO_ARG, 0, 0, 0, 0, 0, 0},
306
306
  {"single-transaction", OPT_TRANSACTION,
307
 
   "Creates a consistent snapshot by dumping all tables in a single "
308
 
   "transaction. Works ONLY for tables stored in storage engines which "
309
 
   "support multiversioning (currently only InnoDB does); the dump is NOT "
310
 
   "guaranteed to be consistent for other storage engines. "
311
 
   "While a --single-transaction dump is in process, to ensure a valid "
312
 
   "dump file (correct table contents), no other "
313
 
   "connection should use the following statements: ALTER TABLE, DROP "
314
 
   "TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
315
 
   "isolated from them. Option automatically turns off --lock-tables.",
316
 
   (char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
317
 
   GET_BOOL, NO_ARG,  0, 0, 0, 0, 0, 0},
 
307
    "Creates a consistent snapshot by dumping all tables in a single "
 
308
      "transaction. Works ONLY for tables stored in storage engines which "
 
309
      "support multiversioning (currently only InnoDB does); the dump is NOT "
 
310
      "guaranteed to be consistent for other storage engines. "
 
311
      "While a --single-transaction dump is in process, to ensure a valid "
 
312
      "dump file (correct table contents), no other "
 
313
      "connection should use the following statements: ALTER TABLE, DROP "
 
314
      "TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
 
315
      "isolated from them. Option automatically turns off --lock-tables.",
 
316
    (char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
 
317
    GET_BOOL, NO_ARG,  0, 0, 0, 0, 0, 0},
318
318
  {"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.",
319
 
   (char**) &opt_dump_date, (char**) &opt_dump_date, 0,
320
 
   GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
319
    (char**) &opt_dump_date, (char**) &opt_dump_date, 0,
 
320
    GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
321
321
  {"skip-opt", OPT_SKIP_OPTIMIZATION,
322
 
   "Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
323
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
322
    "Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
 
323
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
324
324
  {"tab",'T',
325
 
   "Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if drizzledump is run on the same machine as the drizzled daemon.",
326
 
   (char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
325
    "Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if drizzledump is run on the same machine as the drizzled daemon.",
 
326
    (char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
327
327
  {"tables", OPT_TABLES, "Overrides option --databases (-B).",
328
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
328
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
329
329
  {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of rows before each output progress report (requires --verbose)."),
330
 
   (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
331
 
   10000, 0, 0, 0, 0, 0},
 
330
    (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
 
331
    10000, 0, 0, 0, 0, 0},
332
332
  {"user", 'u', "User for login if not current user.",
333
 
   (char**) &current_user, (char**) &current_user, 0, GET_STR, REQUIRED_ARG,
334
 
   0, 0, 0, 0, 0, 0},
 
333
    (char**) &current_user, (char**) &current_user, 0, GET_STR, REQUIRED_ARG,
 
334
    0, 0, 0, 0, 0, 0},
335
335
  {"verbose", 'v', "Print info about the various stages.",
336
 
   (char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
336
    (char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
337
337
  {"version",'V', "Output version information and exit.", 0, 0, 0,
338
 
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
338
    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
339
339
  {"where", 'w', "Dump only selected records; QUOTES mandatory!",
340
 
   (char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
340
    (char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
341
341
  {"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
342
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
342
    NO_ARG, 0, 0, 0, 0, 0, 0},
343
343
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
344
344
};
345
345
 
368
368
  Print the supplied message if in verbose mode
369
369
 
370
370
  SYNOPSIS
371
 
    verbose_msg()
372
 
    fmt   format specifier
373
 
    ...   variable number of parameters
 
371
  verbose_msg()
 
372
  fmt   format specifier
 
373
  ...   variable number of parameters
374
374
*/
375
375
static void verbose_msg(const char *fmt, ...)
376
376
{
389
389
  exit with message if ferror(file)
390
390
 
391
391
  SYNOPSIS
392
 
    check_io()
393
 
    file        - checked file
 
392
  check_io()
 
393
  file        - checked file
394
394
*/
395
395
 
396
396
static void check_io(FILE *file)
441
441
    fputs("<?xml version=\"1.0\"?>\n", sql_file);
442
442
    /*
443
443
      Schema reference.  Allows use of xsi:nil for NULL values and
444
 
      xsi:type to define an element's data type.
 
444
xsi:type to define an element's data type.
445
445
    */
446
446
    fputs("<drizzledump ", sql_file);
447
447
    fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
466
466
    }
467
467
    if (opt_set_charset)
468
468
      fprintf(sql_file,
469
 
"\nSET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;\n");
 
469
              "\nSET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;\n");
470
470
 
471
471
    if (path == NULL)
472
472
    {
473
473
      fprintf(md_result_file,"\
474
 
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;\n\
475
 
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\n\
476
 
");
 
474
              SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;\n\
 
475
              SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\n\
 
476
              ");
477
477
    }
478
478
    check_io(sql_file);
479
479
  }
492
492
    if (path == NULL)
493
493
    {
494
494
      fprintf(md_result_file,"\
495
 
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;\n\
496
 
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;\n");
 
495
              SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;\n\
 
496
              SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;\n");
497
497
    }
498
498
    if (opt_set_charset)
499
499
      fprintf(sql_file, "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;\n");
529
529
      return EXIT_ARGUMENT_INVALID;
530
530
    }
531
531
    /* If the port number is > 65535 it is not a valid port
532
 
 *        This also helps with potential data loss casting unsigned long to a
533
 
 *               uint32_t. */
 
532
     *        This also helps with potential data loss casting unsigned long to a
 
533
     *               uint32_t. */
534
534
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
535
535
    {
536
536
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
551
551
      if (opt_password == NULL)
552
552
      {
553
553
        fprintf(stderr, _("Memory allocation error while copying password. "
554
 
                        "Aborting.\n"));
 
554
                          "Aborting.\n"));
555
555
        return EXIT_OUT_OF_MEMORY;
556
556
      }
557
557
      while (*argument)
596
596
    break;
597
597
  case 'V': print_version(); exit(0);
598
598
  case 'X':
599
 
    opt_xml= 1;
600
 
    extended_insert= opt_drop=
601
 
      opt_disable_keys= opt_autocommit= opt_create_db= 0;
602
 
    break;
 
599
            opt_xml= 1;
 
600
            extended_insert= opt_drop=
 
601
              opt_disable_keys= opt_autocommit= opt_create_db= 0;
 
602
            break;
603
603
  case 'I':
604
604
  case '?':
605
 
    usage();
606
 
    exit(0);
 
605
            usage();
 
606
            exit(0);
607
607
  case (int) OPT_OPTIMIZE:
608
 
    extended_insert= opt_drop= quick= create_options=
609
 
      opt_disable_keys= opt_set_charset= 1;
610
 
    break;
 
608
            extended_insert= opt_drop= quick= create_options=
 
609
              opt_disable_keys= opt_set_charset= 1;
 
610
            break;
611
611
  case (int) OPT_SKIP_OPTIMIZATION:
612
 
    extended_insert= opt_drop= quick= create_options=
613
 
      opt_disable_keys= opt_set_charset= 0;
614
 
    break;
 
612
            extended_insert= opt_drop= quick= create_options=
 
613
              opt_disable_keys= opt_set_charset= 0;
 
614
            break;
615
615
  case (int) OPT_COMPACT:
616
 
  if (opt_compact)
617
 
  {
618
 
    opt_comments= opt_drop= opt_disable_keys= 0;
619
 
    opt_set_charset= 0;
620
 
  }
 
616
            if (opt_compact)
 
617
            {
 
618
              opt_comments= opt_drop= opt_disable_keys= 0;
 
619
              opt_set_charset= 0;
 
620
            }
621
621
  case (int) OPT_TABLES:
622
 
    opt_databases=0;
623
 
    break;
 
622
            opt_databases=0;
 
623
            break;
624
624
  case (int) OPT_IGNORE_TABLE:
625
 
  {
626
 
    if (!strchr(argument, '.'))
627
 
    {
628
 
      fprintf(stderr, _("Illegal use of option --ignore-table=<database>.<table>\n"));
629
 
      return EXIT_ARGUMENT_INVALID;
630
 
    }
631
 
    string tmpptr(argument);
632
 
    ignore_table.insert(tmpptr); 
633
 
    break;
634
 
  }
 
625
            {
 
626
              if (!strchr(argument, '.'))
 
627
              {
 
628
                fprintf(stderr, _("Illegal use of option --ignore-table=<database>.<table>\n"));
 
629
                return EXIT_ARGUMENT_INVALID;
 
630
              }
 
631
              string tmpptr(argument);
 
632
              ignore_table.insert(tmpptr); 
 
633
              break;
 
634
            }
635
635
  case (int) OPT_COMPATIBLE:
636
 
    {
637
 
      char buff[255];
638
 
      char *end= compatible_mode_normal_str;
639
 
      uint32_t i;
640
 
      uint32_t mode;
641
 
      uint32_t error_len;
 
636
            {
 
637
              char buff[255];
 
638
              char *end= compatible_mode_normal_str;
 
639
              uint32_t i;
 
640
              uint32_t mode;
 
641
              uint32_t error_len;
642
642
 
643
 
      opt_quoted= 1;
644
 
      opt_set_charset= 0;
645
 
      opt_compatible_mode_str= argument;
646
 
      opt_compatible_mode= find_set(&compatible_mode_typelib,
647
 
                                    argument, strlen(argument),
648
 
                                    &err_ptr, &error_len);
649
 
      if (error_len)
650
 
      {
651
 
        strncpy(buff, err_ptr, min((uint32_t)sizeof(buff), error_len+1));
652
 
        fprintf(stderr, _("Invalid mode to --compatible: %s\n"), buff);
653
 
        return EXIT_ARGUMENT_INVALID;
654
 
      }
655
 
      mode= opt_compatible_mode;
656
 
      for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++)
657
 
      {
658
 
        if (mode & 1)
659
 
        {
660
 
          uint32_t len = strlen(compatible_mode_names[i]);
661
 
          end= strcpy(end, compatible_mode_names[i]) + len;
662
 
          end= strcpy(end, ",")+1;
663
 
        }
664
 
      }
665
 
      if (end!=compatible_mode_normal_str)
666
 
        end[-1]= 0;
667
 
    }
 
643
              opt_quoted= 1;
 
644
              opt_set_charset= 0;
 
645
              opt_compatible_mode_str= argument;
 
646
              opt_compatible_mode= find_set(&compatible_mode_typelib,
 
647
                                            argument, strlen(argument),
 
648
                                            &err_ptr, &error_len);
 
649
              if (error_len)
 
650
              {
 
651
                strncpy(buff, err_ptr, min((uint32_t)sizeof(buff), error_len+1));
 
652
                fprintf(stderr, _("Invalid mode to --compatible: %s\n"), buff);
 
653
                return EXIT_ARGUMENT_INVALID;
 
654
              }
 
655
              mode= opt_compatible_mode;
 
656
              for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++)
 
657
              {
 
658
                if (mode & 1)
 
659
                {
 
660
                  uint32_t len = strlen(compatible_mode_names[i]);
 
661
                  end= strcpy(end, compatible_mode_names[i]) + len;
 
662
                  end= strcpy(end, ",")+1;
 
663
                }
 
664
              }
 
665
              if (end!=compatible_mode_normal_str)
 
666
                end[-1]= 0;
 
667
            }
668
668
  }
669
669
  return 0;
670
670
}
691
691
  if (opt_single_transaction && opt_lock_all_tables)
692
692
  {
693
693
    fprintf(stderr, _("%s: You can't use --single-transaction and "
694
 
            "--lock-all-tables at the same time.\n"), internal::my_progname);
 
694
                      "--lock-all-tables at the same time.\n"), internal::my_progname);
695
695
    return(EX_USAGE);
696
696
  }
697
697
  if (enclosed && opt_enclosed)
718
718
 
719
719
 
720
720
/*
721
 
** DB_error -- prints DRIZZLE error message and exits the program.
 
721
 ** DB_error -- prints DRIZZLE error message and exits the program.
722
722
*/
723
723
static void DB_error(drizzle_result_st *res, drizzle_return_t ret,
724
724
                     const char *when)
727
727
  {
728
728
    maybe_die(EX_DRIZZLEERR, _("Got error: %s (%d) %s"),
729
729
              drizzle_result_error(res),
730
 
              drizzle_result_error_code(res),
731
 
              when);
 
730
              drizzle_result_error_code(res),
 
731
              when);
732
732
    drizzle_result_free(res);
733
733
  }
734
734
  else
743
743
  Prints out an error message and kills the process.
744
744
 
745
745
  SYNOPSIS
746
 
    die()
747
 
    error_num   - process return value
748
 
    fmt_reason  - a format string for use by vsnprintf.
749
 
    ...         - variable arguments for above fmt_reason string
 
746
  die()
 
747
  error_num   - process return value
 
748
  fmt_reason  - a format string for use by vsnprintf.
 
749
  ...         - variable arguments for above fmt_reason string
750
750
 
751
751
  DESCRIPTION
752
 
    This call prints out the formatted error message to stderr and then
753
 
    terminates the process.
 
752
  This call prints out the formatted error message to stderr and then
 
753
  terminates the process.
754
754
*/
755
755
static void die(int error_num, const char* fmt_reason, ...)
756
756
{
772
772
  Prints out an error message and maybe kills the process.
773
773
 
774
774
  SYNOPSIS
775
 
    maybe_die()
776
 
    error_num   - process return value
777
 
    fmt_reason  - a format string for use by vsnprintf.
778
 
    ...         - variable arguments for above fmt_reason string
 
775
  maybe_die()
 
776
  error_num   - process return value
 
777
  fmt_reason  - a format string for use by vsnprintf.
 
778
  ...         - variable arguments for above fmt_reason string
779
779
 
780
780
  DESCRIPTION
781
 
    This call prints out the formatted error message to stderr and then
782
 
    terminates the process, unless the --force command line option is used.
 
781
  This call prints out the formatted error message to stderr and then
 
782
  terminates the process, unless the --force command line option is used.
783
783
 
784
 
    This call should be used for non-fatal errors (such as database
785
 
    errors) that the code may still be able to continue to the next unit
786
 
    of work.
 
784
  This call should be used for non-fatal errors (such as database
 
785
  errors) that the code may still be able to continue to the next unit
 
786
  of work.
787
787
 
788
788
*/
789
789
static void maybe_die(int error_num, const char* fmt_reason, ...)
807
807
  some.
808
808
 
809
809
  SYNOPSIS
810
 
    drizzleclient_query_with_error_report()
811
 
    drizzle_con       connection to use
812
 
    res             if non zero, result will be put there with
813
 
                    drizzleclient_store_result()
814
 
    query           query to send to server
 
810
  drizzleclient_query_with_error_report()
 
811
  drizzle_con       connection to use
 
812
  res             if non zero, result will be put there with
 
813
  drizzleclient_store_result()
 
814
  query           query to send to server
815
815
 
816
816
  RETURN VALUES
817
 
    0               query sending and (if res!=0) result reading went ok
818
 
    1               error
 
817
  0               query sending and (if res!=0) result reading went ok
 
818
  1               error
819
819
*/
820
820
 
821
821
static int drizzleclient_query_with_error_report(drizzle_con_st *con,
862
862
  Open a new .sql file to dump the table or view into
863
863
 
864
864
  SYNOPSIS
865
 
    open_sql_file_for_table
866
 
    name      name of the table or view
 
865
  open_sql_file_for_table
 
866
  name      name of the table or view
867
867
 
868
868
  RETURN VALUES
869
 
    0        Failed to open file
870
 
    > 0      Handle of the open file
 
869
  0        Failed to open file
 
870
  > 0      Handle of the open file
871
871
*/
872
872
static FILE* open_sql_file_for_table(const char* table)
873
873
{
931
931
 
932
932
 
933
933
/*
934
 
** dbDisconnect -- disconnects from the host.
 
934
 ** dbDisconnect -- disconnects from the host.
935
935
*/
936
936
static void dbDisconnect(char *host)
937
937
{
1008
1008
  Quote a table name so it can be used in "SHOW TABLES LIKE <tabname>"
1009
1009
 
1010
1010
  SYNOPSIS
1011
 
    quote_for_like()
1012
 
    name     name of the table
1013
 
    buff     quoted name of the table
 
1011
  quote_for_like()
 
1012
  name     name of the table
 
1013
  buff     quoted name of the table
1014
1014
 
1015
1015
  DESCRIPTION
1016
 
    Quote \, _, ' and % characters
1017
 
 
1018
 
    Note: Because DRIZZLE uses the C escape syntax in strings
1019
 
    (for example, '\n' to represent newline), you must double
1020
 
    any '\' that you use in your LIKE  strings. For example, to
1021
 
    search for '\n', specify it as '\\n'. To search for '\', specify
1022
 
    it as '\\\\' (the backslashes are stripped once by the parser
1023
 
    and another time when the pattern match is done, leaving a
1024
 
    single backslash to be matched).
1025
 
 
1026
 
    Example: "t\1" => "t\\\\1"
 
1016
  Quote \, _, ' and % characters
 
1017
 
 
1018
Note: Because DRIZZLE uses the C escape syntax in strings
 
1019
(for example, '\n' to represent newline), you must double
 
1020
any '\' that you use in your LIKE  strings. For example, to
 
1021
search for '\n', specify it as '\\n'. To search for '\', specify
 
1022
it as '\\\\' (the backslashes are stripped once by the parser
 
1023
and another time when the pattern match is done, leaving a
 
1024
single backslash to be matched).
 
1025
 
 
1026
Example: "t\1" => "t\\\\1"
1027
1027
 
1028
1028
*/
1029
1029
static char *quote_for_like(const char *name, char *buff)
1052
1052
  Quote and print a string.
1053
1053
 
1054
1054
  SYNOPSIS
1055
 
    print_quoted_xml()
1056
 
    xml_file    - output file
1057
 
    str         - string to print
1058
 
    len         - its length
 
1055
  print_quoted_xml()
 
1056
  xml_file    - output file
 
1057
  str         - string to print
 
1058
  len         - its length
1059
1059
 
1060
1060
  DESCRIPTION
1061
 
    Quote '<' '>' '&' '\"' chars and print a string to the xml_file.
 
1061
  Quote '<' '>' '&' '\"' chars and print a string to the xml_file.
1062
1062
*/
1063
1063
 
1064
1064
static void print_quoted_xml(FILE *xml_file, const char *str, uint32_t len)
1077
1077
    case '&':
1078
1078
      fputs("&amp;", xml_file);
1079
1079
      break;
1080
 
    case '\"':
1081
 
      fputs("&quot;", xml_file);
 
1080
      case '\"':
 
1081
        fputs("&quot;", xml_file);
1082
1082
      break;
1083
1083
    default:
1084
1084
      fputc(*str, xml_file);
1093
1093
  Print xml tag. Optionally add attribute(s).
1094
1094
 
1095
1095
  SYNOPSIS
1096
 
    print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name,
1097
 
                    ..., attribute_name_n, attribute_value_n, NULL)
1098
 
    xml_file              - output file
1099
 
    sbeg                  - line beginning
1100
 
    line_end              - line ending
1101
 
    tag_name              - XML tag name.
1102
 
    first_attribute_name  - tag and first attribute
1103
 
    first_attribute_value - (Implied) value of first attribute
1104
 
    attribute_name_n      - attribute n
1105
 
    attribute_value_n     - value of attribute n
 
1096
  print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name,
 
1097
  ..., attribute_name_n, attribute_value_n, NULL)
 
1098
  xml_file              - output file
 
1099
  sbeg                  - line beginning
 
1100
  line_end              - line ending
 
1101
  tag_name              - XML tag name.
 
1102
  first_attribute_name  - tag and first attribute
 
1103
  first_attribute_value - (Implied) value of first attribute
 
1104
  attribute_name_n      - attribute n
 
1105
  attribute_value_n     - value of attribute n
1106
1106
 
1107
1107
  DESCRIPTION
1108
 
    Print XML tag with any number of attribute="value" pairs to the xml_file.
 
1108
  Print XML tag with any number of attribute="value" pairs to the xml_file.
1109
1109
 
1110
 
    Format is:
1111
 
      sbeg<tag_name first_attribute_name="first_attribute_value" ...
1112
 
      attribute_name_n="attribute_value_n">send
 
1110
  Format is:
 
1111
  sbeg<tag_name first_attribute_name="first_attribute_value" ...
 
1112
  attribute_name_n="attribute_value_n">send
1113
1113
  NOTE
1114
 
    Additional arguments must be present in attribute/value pairs.
1115
 
    The last argument should be the null character pointer.
1116
 
    All attribute_value arguments MUST be NULL terminated strings.
1117
 
    All attribute_value arguments will be quoted before output.
 
1114
  Additional arguments must be present in attribute/value pairs.
 
1115
  The last argument should be the null character pointer.
 
1116
  All attribute_value arguments MUST be NULL terminated strings.
 
1117
  All attribute_value arguments will be quoted before output.
1118
1118
*/
1119
1119
 
1120
1120
static void print_xml_tag(FILE * xml_file, const char* sbeg,
1157
1157
  Print xml tag with for a field that is null
1158
1158
 
1159
1159
  SYNOPSIS
1160
 
    print_xml_null_tag()
1161
 
    xml_file    - output file
1162
 
    sbeg        - line beginning
1163
 
    stag_atr    - tag and attribute
1164
 
    sval        - value of attribute
1165
 
    line_end        - line ending
 
1160
  print_xml_null_tag()
 
1161
  xml_file    - output file
 
1162
  sbeg        - line beginning
 
1163
  stag_atr    - tag and attribute
 
1164
  sval        - value of attribute
 
1165
  line_end        - line ending
1166
1166
 
1167
1167
  DESCRIPTION
1168
 
    Print tag with one attribute to the xml_file. Format is:
1169
 
      <stag_atr="sval" xsi:nil="true"/>
 
1168
  Print tag with one attribute to the xml_file. Format is:
 
1169
  <stag_atr="sval" xsi:nil="true"/>
1170
1170
  NOTE
1171
 
    sval MUST be a NULL terminated string.
1172
 
    sval string will be qouted before output.
 
1171
  sval MUST be a NULL terminated string.
 
1172
  sval string will be qouted before output.
1173
1173
*/
1174
1174
 
1175
1175
static void print_xml_null_tag(FILE * xml_file, const char* sbeg,
1191
1191
  Print xml tag with many attributes.
1192
1192
 
1193
1193
  SYNOPSIS
1194
 
    print_xml_row()
1195
 
    xml_file    - output file
1196
 
    row_name    - xml tag name
1197
 
    tableRes    - query result
1198
 
    row         - result row
 
1194
  print_xml_row()
 
1195
  xml_file    - output file
 
1196
  row_name    - xml tag name
 
1197
  tableRes    - query result
 
1198
  row         - result row
1199
1199
 
1200
1200
  DESCRIPTION
1201
 
    Print tag with many attribute to the xml_file. Format is:
1202
 
      \t\t<row_name Atr1="Val1" Atr2="Val2"... />
 
1201
  Print tag with many attribute to the xml_file. Format is:
 
1202
  \t\t<row_name Atr1="Val1" Atr2="Val2"... />
1203
1203
  NOTE
1204
 
    All atributes and values will be quoted before output.
 
1204
  All atributes and values will be quoted before output.
1205
1205
*/
1206
1206
 
1207
1207
static void print_xml_row(FILE *xml_file, const char *row_name,
1236
1236
  Print hex value for blob data.
1237
1237
 
1238
1238
  SYNOPSIS
1239
 
    print_blob_as_hex()
1240
 
    output_file         - output file
1241
 
    str                 - string to print
1242
 
    len                 - its length
 
1239
  print_blob_as_hex()
 
1240
  output_file         - output file
 
1241
  str                 - string to print
 
1242
  len                 - its length
1243
1243
 
1244
1244
  DESCRIPTION
1245
 
    Print hex value for blob data.
 
1245
  Print hex value for blob data.
1246
1246
*/
1247
1247
 
1248
1248
static void print_blob_as_hex(FILE *output_file, const char *str, uint32_t len)
1249
1249
{
1250
 
    /* sakaik got the idea to to provide blob's in hex notation. */
1251
 
    const char *ptr= str, *end= ptr + len;
1252
 
    for (; ptr < end ; ptr++)
1253
 
      fprintf(output_file, "%02X", *((unsigned char *)ptr));
1254
 
    check_io(output_file);
 
1250
  /* sakaik got the idea to to provide blob's in hex notation. */
 
1251
  const char *ptr= str, *end= ptr + len;
 
1252
  for (; ptr < end ; ptr++)
 
1253
    fprintf(output_file, "%02X", *((unsigned char *)ptr));
 
1254
  check_io(output_file);
1255
1255
}
1256
1256
 
1257
1257
/*
1260
1260
  be dumping.
1261
1261
 
1262
1262
  ARGS
1263
 
    table       - table name
1264
 
    db          - db name
1265
 
    table_type  - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW"
1266
 
    ignore_flag - what we must particularly ignore - see IGNORE_ defines above
1267
 
    num_fields  - number of fields in the table
 
1263
  table       - table name
 
1264
  db          - db name
 
1265
  table_type  - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW"
 
1266
  ignore_flag - what we must particularly ignore - see IGNORE_ defines above
 
1267
  num_fields  - number of fields in the table
1268
1268
 
1269
1269
  RETURN
1270
 
    true if success, false if error
 
1270
  true if success, false if error
1271
1271
*/
1272
1272
 
1273
1273
static bool get_table_structure(char *table, char *db, char *table_type,
1291
1291
  {
1292
1292
    delayed= 0;
1293
1293
    verbose_msg(_("-- Warning: Unable to use delayed inserts for table '%s' "
1294
 
                "because it's of type %s\n"), table, table_type);
 
1294
                  "because it's of type %s\n"), table, table_type);
1295
1295
  }
1296
1296
 
1297
1297
  complete_insert= 0;
1347
1347
      }
1348
1348
      if (opt_drop)
1349
1349
      {
1350
 
      /*
1351
 
        Even if the "table" is a view, we do a DROP TABLE here.
1352
 
       */
 
1350
        /*
 
1351
          Even if the "table" is a view, we do a DROP TABLE here.
 
1352
        */
1353
1353
        fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table);
1354
1354
        check_io(sql_file);
1355
1355
      }
1447
1447
        fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
1448
1448
      else
1449
1449
        print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table,
1450
 
                NULL);
 
1450
                      NULL);
1451
1451
      check_io(sql_file);
1452
1452
    }
1453
1453
 
1710
1710
 
1711
1711
/*
1712
1712
 
1713
 
 SYNOPSIS
 
1713
  SYNOPSIS
1714
1714
  dump_table()
1715
1715
 
1716
1716
  dump_table saves database contents as a series of INSERT statements.
1717
1717
 
1718
1718
  ARGS
1719
 
   table - table name
1720
 
   db    - db name
 
1719
  table - table name
 
1720
  db    - db name
1721
1721
 
1722
 
   RETURNS
1723
 
    void
 
1722
  RETURNS
 
1723
  void
1724
1724
*/
1725
1725
 
1726
1726
 
1760
1760
 
1761
1761
  /*
1762
1762
    If the table type is a merge table or any type that has to be
1763
 
     _completely_ ignored and no data dumped
 
1763
    _completely_ ignored and no data dumped
1764
1764
  */
1765
1765
  if (ignore_flag & IGNORE_DATA)
1766
1766
  {
1767
1767
    verbose_msg(_("-- Warning: Skipping data for table '%s' because " \
1768
 
                "it's of type %s\n"), table, table_type);
 
1768
                  "it's of type %s\n"), table, table_type);
1769
1769
    return;
1770
1770
  }
1771
1771
  /* Check that there are any fields in the table */
1898
1898
    if (opt_disable_keys)
1899
1899
    {
1900
1900
      fprintf(md_result_file, "ALTER TABLE %s DISABLE KEYS;\n",
1901
 
              opt_quoted_table);
 
1901
              opt_quoted_table);
1902
1902
      check_io(md_result_file);
1903
1903
    }
1904
1904
 
1908
1908
    init_length=(uint32_t) insert_pat.length()+4;
1909
1909
    if (opt_xml)
1910
1910
      print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
1911
 
              NULL);
 
1911
                    NULL);
1912
1912
    if (opt_autocommit)
1913
1913
    {
1914
1914
      fprintf(md_result_file, "set autocommit=0;\n");
1931
1931
        if (ret != DRIZZLE_RETURN_OK)
1932
1932
        {
1933
1933
          fprintf(stderr,
1934
 
                _("%s: Error reading rows for table: %s (%d:%s) ! Aborting.\n"),
 
1934
                  _("%s: Error reading rows for table: %s (%d:%s) ! Aborting.\n"),
1935
1935
                  internal::my_progname, result_table, ret, drizzle_con_error(&dcon));
1936
1936
          drizzle_result_free(&result);
1937
1937
          goto err;
1970
1970
 
1971
1971
        if (!(column= drizzle_column_next(&result)))
1972
1972
          die(EX_CONSCHECK,
1973
 
                      _("Not enough fields from table %s! Aborting.\n"),
1974
 
                      result_table);
 
1973
              _("Not enough fields from table %s! Aborting.\n"),
 
1974
              result_table);
1975
1975
 
1976
1976
        /*
1977
 
           63 is my_charset_bin. If charsetnr is not 63,
1978
 
           we have not a BLOB but a TEXT column.
1979
 
           we'll dump in hex only BLOB columns.
 
1977
          63 is my_charset_bin. If charsetnr is not 63,
 
1978
          we have not a BLOB but a TEXT column.
 
1979
          we'll dump in hex only BLOB columns.
1980
1980
        */
1981
1981
        is_blob= (opt_hex_blob && drizzle_column_charset(column) == 63 &&
1982
1982
                  (drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_VARCHAR ||
2027
2027
                /* change any strings ("inf", "-inf", "nan") into NULL */
2028
2028
                char *ptr= row[i];
2029
2029
                if (my_isalpha(charset_info, *ptr) || (*ptr == '-' &&
2030
 
                    my_isalpha(charset_info, ptr[1])))
 
2030
                                                       my_isalpha(charset_info, ptr[1])))
2031
2031
                  extended_row.append( "NULL");
2032
2032
                else
2033
2033
                {
2084
2084
              if (opt_xml)
2085
2085
              {
2086
2086
                print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2087
 
                        drizzle_column_name(column), NULL);
 
2087
                              drizzle_column_name(column), NULL);
2088
2088
                fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
2089
2089
                      md_result_file);
2090
2090
                fputs("</field>\n", md_result_file);
2147
2147
 
2148
2148
    /* XML - close table tag and supress regular output */
2149
2149
    if (opt_xml)
2150
 
        fputs("\t</table_data>\n", md_result_file);
 
2150
      fputs("\t</table_data>\n", md_result_file);
2151
2151
    else if (extended_insert && row_break)
2152
2152
      fputs(";\n", md_result_file);             /* If not empty table */
2153
2153
    fflush(md_result_file);
2237
2237
 
2238
2238
 
2239
2239
/*
2240
 
Table Specific database initalization.
 
2240
  Table Specific database initalization.
2241
2241
 
2242
 
SYNOPSIS
 
2242
  SYNOPSIS
2243
2243
  init_dumping_tables
2244
2244
  qdatabase      quoted name of the database
2245
2245
 
2246
 
RETURN VALUES
 
2246
  RETURN VALUES
2247
2247
  0        Success.
2248
2248
  1        Failure.
2249
2249
*/
2306
2306
    return 1;
2307
2307
 
2308
2308
  if (drizzle_select_db(&dcon, &result, database, &ret) == NULL ||
2309
 
        ret != DRIZZLE_RETURN_OK)
 
2309
      ret != DRIZZLE_RETURN_OK)
2310
2310
  {
2311
2311
    DB_error(&result, ret, _("when executing 'SELECT INTO OUTFILE'"));
2312
2312
    return 1;                   /* If --force */
2405
2405
  different case (e.g.  T1 vs t1)
2406
2406
 
2407
2407
  RETURN
2408
 
    pointer to the table name
2409
 
    0 if error
 
2408
  pointer to the table name
 
2409
  0 if error
2410
2410
*/
2411
2411
 
2412
2412
static char *get_actual_table_name(const char *old_table_name,
2434
2434
    size_t *lengths;
2435
2435
    /*
2436
2436
      Return first row
2437
 
      TODO: Return all matching rows
 
2437
      TODO-> Return all matching rows
2438
2438
    */
2439
2439
    row= drizzle_row_next(&result);
2440
2440
    lengths= drizzle_row_field_sizes(&result);
2459
2459
 
2460
2460
  init_alloc_root(&root, 8192);
2461
2461
  if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
2462
 
     die(EX_EOM, _("alloc_root failure."));
 
2462
    die(EX_EOM, _("alloc_root failure."));
2463
2463
 
2464
2464
  for (; tables > 0 ; tables-- , table_names++)
2465
2465
  {
2524
2524
  return
2525
2525
    ( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES", false) ||
2526
2526
      drizzleclient_query_with_error_report(drizzle_con, 0,
2527
 
                                    "FLUSH TABLES WITH READ LOCK", false) );
 
2527
                                            "FLUSH TABLES WITH READ LOCK", false) );
2528
2528
}
2529
2529
 
2530
2530
static int do_unlock_tables(drizzle_con_st *drizzle_con)
2535
2535
static int start_transaction(drizzle_con_st *drizzle_con)
2536
2536
{
2537
2537
  return (drizzleclient_query_with_error_report(drizzle_con, 0,
2538
 
                                        "SET SESSION TRANSACTION ISOLATION "
2539
 
                                        "LEVEL REPEATABLE READ", false) ||
 
2538
                                                "SET SESSION TRANSACTION ISOLATION "
 
2539
                                                "LEVEL REPEATABLE READ", false) ||
2540
2540
          drizzleclient_query_with_error_report(drizzle_con, 0,
2541
 
                                        "START TRANSACTION "
2542
 
                                        "WITH CONSISTENT SNAPSHOT", false));
 
2541
                                                "START TRANSACTION "
 
2542
                                                "WITH CONSISTENT SNAPSHOT", false));
2543
2543
}
2544
2544
 
2545
2545
 
2546
2546
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
2547
 
                      char **err_pos, uint32_t *err_len)
 
2547
                         char **err_pos, uint32_t *err_len)
2548
2548
{
2549
2549
  const char *end= x + length;
2550
2550
  uint32_t found= 0;
2650
2650
 
2651
2651
  ARGS
2652
2652
 
2653
 
    check_if_ignore_table()
2654
 
    table_name                  Table name to check
2655
 
    table_type                  Type of table
 
2653
  check_if_ignore_table()
 
2654
  table_name                  Table name to check
 
2655
  table_type                  Type of table
2656
2656
 
2657
2657
  GLOBAL VARIABLES
2658
 
    drizzle                       Drizzle connection
2659
 
    verbose                     Write warning messages
 
2658
  drizzle                       Drizzle connection
 
2659
  verbose                     Write warning messages
2660
2660
 
2661
2661
  RETURN
2662
 
    char (bit value)            See IGNORE_ values at top
 
2662
  char (bit value)            See IGNORE_ values at top
2663
2663
*/
2664
2664
 
2665
2665
char check_if_ignore_table(const char *table_name, char *table_type)
2695
2695
  }
2696
2696
  /*
2697
2697
    If the table type matches any of these, we do support delayed inserts.
2698
 
    Note: we do not want to skip dumping this table if if is not one of
 
2698
    Note-> we do not want to skip dumping this table if if is not one of
2699
2699
    these types, but we do want to use delayed inserts in the dump if
2700
2700
    the table type is _NOT_ one of these types
2701
 
    */
 
2701
  */
2702
2702
  {
2703
2703
    strncpy(table_type, row[1], DRIZZLE_MAX_TABLE_SIZE-1);
2704
2704
    if (opt_delayed)
2719
2719
  Get string of comma-separated primary key field names
2720
2720
 
2721
2721
  SYNOPSIS
2722
 
    char *primary_key_fields(const char *table_name)
2723
 
    RETURNS     pointer to allocated buffer (must be freed by caller)
2724
 
    table_name  quoted table name
 
2722
  char *primary_key_fields(const char *table_name)
 
2723
  RETURNS     pointer to allocated buffer (must be freed by caller)
 
2724
  table_name  quoted table name
2725
2725
 
2726
2726
  DESCRIPTION
2727
 
    Use SHOW KEYS FROM table_name, allocate a buffer to hold the
2728
 
    field names, and then build that string and return the pointer
2729
 
    to that buffer.
 
2727
  Use SHOW KEYS FROM table_name, allocate a buffer to hold the
 
2728
  field names, and then build that string and return the pointer
 
2729
  to that buffer.
2730
2730
 
2731
 
    Returns NULL if there is no PRIMARY or UNIQUE key on the table,
2732
 
    or if there is some failure.  It is better to continue to dump
2733
 
    the table unsorted, rather than exit without dumping the data.
 
2731
  Returns NULL if there is no PRIMARY or UNIQUE key on the table,
 
2732
  or if there is some failure.  It is better to continue to dump
 
2733
  the table unsorted, rather than exit without dumping the data.
2734
2734
*/
2735
2735
 
2736
2736
static char *primary_key_fields(const char *table_name)
2753
2753
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
2754
2754
    {
2755
2755
      fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
2756
 
              " records are NOT sorted (%s)\n"),
 
2756
                        " records are NOT sorted (%s)\n"),
2757
2757
              table_name, drizzle_result_error(&res));
2758
2758
      drizzle_result_free(&res);
2759
2759
    }
2760
2760
    else
2761
2761
    {
2762
2762
      fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
2763
 
              " records are NOT sorted (%s)\n"),
 
2763
                        " records are NOT sorted (%s)\n"),
2764
2764
              table_name, drizzle_con_error(&dcon));
2765
2765
    }
2766
2766
 
2770
2770
  if (drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
2771
2771
  {
2772
2772
    fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
2773
 
            " records are NOT sorted (%s)\n"),
 
2773
                      " records are NOT sorted (%s)\n"),
2774
2774
            table_name, drizzle_con_error(&dcon));
2775
2775
    return result;
2776
2776
  }
2780
2780
   * Note that SHOW KEYS is ordered:  a PRIMARY key is always the first
2781
2781
   * row, and UNIQUE keys come before others.  So we only need to check
2782
2782
   * the first key, not all keys.
2783
 
   */
 
2783
 */
2784
2784
  if ((row= drizzle_row_next(&res)) && atoi(row[1]) == 0)
2785
2785
  {
2786
2786
    /* Key is unique */
2796
2796
  {
2797
2797
    char *end;
2798
2798
    /* result (terminating \0 is already in result_length) */
2799
 
    result= (char *)malloc(result_length + 10);
 
2799
    size_t result_length_alloc = result_length + 10;
 
2800
    result= (char *)malloc(result_length_alloc);
2800
2801
    if (!result)
2801
2802
    {
2802
2803
      fprintf(stderr, _("Error: Not enough memory to store ORDER BY clause\n"));
2807
2808
    row= drizzle_row_next(&res);
2808
2809
    quoted_field= quote_name(row[4], buff, 0);
2809
2810
    end= strcpy(result, quoted_field) + strlen(quoted_field);
 
2811
    result_length_alloc -= strlen(quoted_field);
2810
2812
    while ((row= drizzle_row_next(&res)) && atoi(row[3]) > 1)
2811
2813
    {
2812
2814
      quoted_field= quote_name(row[4], buff, 0);
2813
 
      end+= sprintf(end,",%s",quoted_field);
 
2815
      end+= snprintf(end, result_length_alloc, ",%s",quoted_field);
 
2816
      result_length_alloc -= strlen(quoted_field);
2814
2817
    }
2815
2818
  }
2816
2819
 
2845
2848
  if ((opt_lock_all_tables) && do_flush_tables_read_lock(&dcon))
2846
2849
    goto err;
2847
2850
  if (opt_single_transaction && start_transaction(&dcon))
2848
 
      goto err;
 
2851
    goto err;
2849
2852
  if (opt_lock_all_tables)
2850
2853
  {
2851
2854
    if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))