Merge lp:~vjsamuel/drizzle/refactor-drizzledump into lp:~drizzle-trunk/drizzle/development

Proposed by Vijay Samuel
Status: Merged
Approved by: Brian Aker
Approved revision: 1640
Merged at revision: 1639
Proposed branch: lp:~vjsamuel/drizzle/refactor-drizzledump
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 1580 lines (+525/-561)
5 files modified
client/drizzledump.cc (+493/-503)
client/drizzleimport.cc (+12/-19)
client/drizzleslap.cc (+18/-26)
client/drizzletest.cc (+1/-12)
client/include.am (+1/-1)
To merge this branch: bzr merge lp:~vjsamuel/drizzle/refactor-drizzledump
Reviewer Review Type Date Requested Status
Brian Aker Pending
Padraig O'Sullivan Pending
Review via email: mp+28420@code.launchpad.net

This proposal supersedes a proposal from 2010-06-23.

To post a comment you must log in.
Revision history for this message
Padraig O'Sullivan (posulliv) wrote : Posted in a previous version of this proposal

Hey Vijay,

Looks like some good work. I do have a few comments though:

1) Why are the parameters to the dump_selected_tables function passed by value?

Is it possible to change this:

static int dump_selected_tables(string db, vector<string> table_names)

to passing parameters by reference to const:

static int dump_selected_tables(const string &db, const vector<string> &table_names)

2) There is a bunch of functions where you pass a .c_str() to represent a char* argument to a function, for example, the init_dumping function. Why not modify the init_dumping function to take a const std::string& parameter instead? Then init_dumping would look like:

static int init_dumping(const string &database, int init_func(char*))

and you wouldn't have to pass char* to this function when you already have a std::string.

Other functions where I would look into doing the same are:

 * get_actual_table_name
 * dbDisconnect
 * dump_table

There is actually probably a lot of functions that could be modified to use std::string instead of char pointers.

3) Is it always necessary to cast the .c_str() member of std::string to char* I would try and remove these casts if possible and if you really need to use a cast, please try and use the C++ style static_cast directive.

4) There is places in this patch where you mix usage of printf and cout. What is our standard to use for output in drizzle? I'm actually not sure but it might be worth asking.

5) A few style issues in your patch:

 * try to use a space after a ! in statements like if or while
 * make sure you have a space after if statements (I see a bunch of places where there is no space between an if and the opening bracket)
 * use the correct indentation. There is a catch statement where the indentation is incorrect

Nice work in general though!

-Padraig

review: Needs Fixing
Revision history for this message
Vijay Samuel (vjsamuel) wrote : Posted in a previous version of this proposal

Hi Padraig,
  I can clear up the issue of "cout or printf()" for you. I 've used cout mainly because the long_options which is an object of the options_description class can be printed only by using a cout and not a printf() I guess.

  As far as the functions, I 'll look into them immediately and correct all the style issues along the way. Thanks for the review.

Cheers,
 -Vijay

Revision history for this message
Vijay Samuel (vjsamuel) wrote : Posted in a previous version of this proposal

Hi Padraig,
  I have 'nt gone into the get_actual_table_name and dump_table since they take arguments which are data members of drizzle_row_t which are probably c strings. Other than that I 've made all the requested changes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/drizzledump.cc'
2--- client/drizzledump.cc 2010-06-19 16:36:52 +0000
3+++ client/drizzledump.cc 2010-06-24 15:13:36 +0000
4@@ -31,20 +31,22 @@
5
6 #include "client_priv.h"
7 #include <string>
8-
9+#include <iostream>
10 #include "drizzled/internal/my_sys.h"
11 #include "drizzled/internal/m_string.h"
12 #include "drizzled/charset_info.h"
13 #include <stdarg.h>
14 #include <drizzled/unordered_set.h>
15 #include <algorithm>
16-
17+#include <fstream>
18 #include <drizzled/gettext.h>
19-
20+#include <drizzled/configmake.h>
21 #include <drizzled/error.h>
22+#include <boost/program_options.hpp>
23
24 using namespace std;
25 using namespace drizzled;
26+namespace po= boost::program_options;
27
28 /* Exit codes */
29
30@@ -74,13 +76,13 @@
31 #define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
32
33 static void add_load_option(string &str, const char *option,
34- const char *option_value);
35+ const string &option_value);
36 static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
37 char **err_pos, uint32_t *err_len);
38
39-static void field_escape(string &in, const char *from);
40+static void field_escape(string &in, const string &from);
41 static bool verbose= false;
42-static bool opt_no_create_info= false;
43+static bool opt_no_create_info;
44 static bool opt_no_data= false;
45 static bool opt_mysql= false;
46 static bool quick= true;
47@@ -101,15 +103,15 @@
48 static bool opt_dump_date= true;
49 static bool opt_autocommit= false;
50 static bool opt_disable_keys= true;
51-static bool opt_xml= false;
52+static bool opt_xml;
53 static bool opt_single_transaction= false;
54-static bool opt_comments= false;
55-static bool opt_compact= false;
56+static bool opt_comments;
57+static bool opt_compact;
58 static bool opt_hex_blob= false;
59 static bool opt_order_by_primary=false;
60 static bool opt_ignore= false;
61 static bool opt_complete_insert= false;
62-static bool opt_drop_database= false;
63+static bool opt_drop_database;
64 static bool opt_replace_into= false;
65 static bool opt_routines= false;
66 static bool opt_alltspcs= false;
67@@ -118,20 +120,8 @@
68 static drizzle_st drizzle;
69 static drizzle_con_st dcon;
70 static string insert_pat;
71-static char *opt_password= NULL;
72-static char *current_user= NULL;
73-static char *current_host= NULL;
74-static char *path= NULL;
75-static char *fields_terminated= NULL;
76-static char *lines_terminated= NULL;
77-static char *enclosed= NULL;
78-static char *opt_enclosed= NULL;
79-static char *escaped= NULL;
80-static char *where= NULL;
81 static char *order_by= NULL;
82-static char *opt_compatible_mode_str= NULL;
83 static char *err_ptr= NULL;
84-static char **defaults_argv= NULL;
85 static char compatible_mode_normal_str[255];
86 static uint32_t opt_compatible_mode= 0;
87 static uint32_t opt_drizzle_port= 0;
88@@ -140,6 +130,19 @@
89 FILE *md_result_file= 0;
90 FILE *stderror_file= 0;
91
92+string password,
93+ opt_compatible_mode_str,
94+ enclosed,
95+ escaped,
96+ current_host,
97+ opt_enclosed,
98+ fields_terminated,
99+ path,
100+ lines_terminated,
101+ current_user,
102+ opt_password,
103+ where;
104+
105 static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
106
107 static const char *compatible_mode_names[]=
108@@ -154,196 +157,6 @@
109
110 unordered_set<string> ignore_table;
111
112-static struct option my_long_options[] =
113-{
114- {"all", 'a', "Deprecated. Use --create-options instead.",
115- (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
116- 0, 0, 0, 0, 0},
117- {"all-databases", 'A',
118- "Dump all the databases. This will be same as --databases with all databases selected.",
119- (char**) &opt_alldbs, (char**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
120- 0, 0},
121- {"all-tablespaces", 'Y',
122- "Dump all the tablespaces.",
123- (char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
124- 0, 0},
125- {"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
126- (char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
127- 0},
128- {"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
129- (char**) &opt_drop, (char**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
130- 0},
131- {"allow-keywords", OPT_KEYWORDS,
132- "Allow creation of column names that are keywords.", (char**) &opt_keywords,
133- (char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
134- {"comments", 'i', "Write additional information.",
135- (char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
136- 1, 0, 0, 0, 0, 0},
137- {"compatible", OPT_COMPATIBLE,
138- "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.",
139- (char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
140- GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
141- {"compact", OPT_COMPACT,
142- "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",
143- (char**) &opt_compact, (char**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
144- 0, 0},
145- {"complete-insert", 'c', "Use complete insert statements.",
146- (char**) &opt_complete_insert, (char**) &opt_complete_insert, 0, GET_BOOL,
147- NO_ARG, 0, 0, 0, 0, 0, 0},
148- {"compress", 'C', "Use compression in server/client protocol.",
149- (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
150- 0, 0, 0},
151- {"create-options", OPT_CREATE_OPTIONS,
152- "Include all DRIZZLE specific create options.",
153- (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
154- 0, 0, 0, 0, 0},
155- {"databases", 'B',
156- "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.",
157- (char**) &opt_databases, (char**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
158- 0, 0, 0, 0},
159- {"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
160- (char**) &opt_delayed, (char**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
161- 0, 0},
162- {"disable-keys", 'K',
163- "'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.", (char**) &opt_disable_keys,
164- (char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
165- {"extended-insert", 'e',
166- "Allows utilization of the new, much faster INSERT syntax.",
167- (char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
168- 1, 0, 0, 0, 0, 0},
169- {"fields-terminated-by", OPT_FTB,
170- "Fields in the textfile are terminated by ...", (char**) &fields_terminated,
171- (char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
172- {"fields-enclosed-by", OPT_ENC,
173- "Fields in the importfile are enclosed by ...", (char**) &enclosed,
174- (char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
175- {"fields-optionally-enclosed-by", OPT_O_ENC,
176- "Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
177- (char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
178- {"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
179- (char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
180- {"flush-logs", 'F', "Flush logs file in server before starting dump. "
181- "Note that if you dump many databases at once (using the option "
182- "--databases= or --all-databases), the logs will be flushed for "
183- "each database dumped. The exception is when using --lock-all-tables "
184- "in this case the logs will be flushed only once, corresponding "
185- "to the moment all tables are locked. So if you want your dump and "
186- "the log flush to happen at the same exact moment you should use "
187- "--lock-all-tables or --flush-logs",
188- (char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
189- 0, 0},
190- {"force", 'f', "Continue even if we get an sql-error.",
191- (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
192- 0, 0, 0, 0, 0, 0},
193- {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
194- NO_ARG, 0, 0, 0, 0, 0, 0},
195- {"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, "
196- "VARBINARY, BLOB) in hexadecimal format.",
197- (char**) &opt_hex_blob, (char**) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
198- {"host", 'h', "Connect to host.", (char**) &current_host,
199- (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
200- {"ignore-table", OPT_IGNORE_TABLE,
201- "Do not dump the specified table. To specify more than one table to ignore, "
202- "use the directive multiple times, once for each table. Each table must "
203- "be specified with both database and table names, e.g. --ignore-table=database.table",
204- 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
205- {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
206- (char**) &opt_ignore, (char**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
207- 0, 0},
208- {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
209- (char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
210- REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
211- {"lock-all-tables", 'x', "Locks all tables across all databases. This "
212- "is achieved by taking a global read lock for the duration of the whole "
213- "dump. Automatically turns --single-transaction and --lock-tables off.",
214- (char**) &opt_lock_all_tables, (char**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
215- 0, 0, 0, 0, 0, 0},
216- {"mysql", 'm', N_("Use MySQL Protocol."),
217- (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
218- 0, 0, 0},
219- {"no-autocommit", OPT_AUTOCOMMIT,
220- "Wrap tables with autocommit/commit statements.",
221- (char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
222- 0, 0, 0, 0, 0, 0},
223- {"no-create-db", 'n',
224- "'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.}.",
225- (char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
226- 0, 0, 0, 0},
227- {"no-create-info", 't', "Don't write table creation info.",
228- (char**) &opt_no_create_info, (char**) &opt_no_create_info, 0, GET_BOOL,
229- NO_ARG, 0, 0, 0, 0, 0, 0},
230- {"no-data", 'd', "No row information.", (char**) &opt_no_data,
231- (char**) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
232- {"no-set-names", 'N',
233- "Deprecated. Use --skip-set-charset instead.",
234- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
235- {"opt", OPT_OPTIMIZE,
236- "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.",
237- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
238- {"order-by-primary", OPT_ORDER_BY_PRIMARY,
239- "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.",
240- (char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
241- {"password", 'P',
242- "Password to use when connecting to server. If password is not given it's solicited on the tty.",
243- 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
244- {"port", 'p', "Port number to use for connection.",
245- 0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
246- {"quick", 'q', "Don't buffer query, dump directly to stdout.",
247- (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
248- {"quote-names",'Q', "Quote table and column names with backticks (`).",
249- (char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
250- 0, 0},
251- {"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
252- (char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
253- 0, 0},
254- {"result-file", 'r',
255- "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).",
256- 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
257- {"routines", 'R', "Dump stored routines (functions and procedures).",
258- (char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
259- NO_ARG, 0, 0, 0, 0, 0, 0},
260- {"single-transaction", OPT_TRANSACTION,
261- "Creates a consistent snapshot by dumping all tables in a single "
262- "transaction. Works ONLY for tables stored in storage engines which "
263- "support multiversioning (currently only InnoDB does); the dump is NOT "
264- "guaranteed to be consistent for other storage engines. "
265- "While a --single-transaction dump is in process, to ensure a valid "
266- "dump file (correct table contents), no other "
267- "connection should use the following statements: ALTER TABLE, DROP "
268- "TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not "
269- "isolated from them. Option automatically turns off --lock-tables.",
270- (char**) &opt_single_transaction, (char**) &opt_single_transaction, 0,
271- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
272- {"dump-date", OPT_DUMP_DATE, "Put a dump date to the end of the output.",
273- (char**) &opt_dump_date, (char**) &opt_dump_date, 0,
274- GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
275- {"skip-opt", OPT_SKIP_OPTIMIZATION,
276- "Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
277- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
278- {"tab",'T',
279- "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.",
280- (char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
281- {"tables", OPT_TABLES, "Overrides option --databases (-B).",
282- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
283- {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of rows before each output progress report (requires --verbose)."),
284- (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
285- 10000, 0, 0, 0, 0, 0},
286- {"user", 'u', "User for login if not current user.",
287- (char**) &current_user, (char**) &current_user, 0, GET_STR, REQUIRED_ARG,
288- 0, 0, 0, 0, 0, 0},
289- {"verbose", 'v', "Print info about the various stages.",
290- (char**) &verbose, (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
291- {"version",'V', "Output version information and exit.", 0, 0, 0,
292- GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
293- {"where", 'w', "Dump only selected records; QUOTES mandatory!",
294- (char**) &where, (char**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
295- {"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
296- NO_ARG, 0, 0, 0, 0, 0, 0},
297- {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
298-};
299-
300-static const char *load_default_groups[]= { "drizzledump","client",0 };
301-
302 static void maybe_exit(int error);
303 static void die(int error, const char* reason, ...);
304 static void maybe_die(int error, const char* reason, ...);
305@@ -353,11 +166,11 @@
306 int string_value);
307 static const char* fetch_named_row(drizzle_result_st *result, drizzle_row_t row,
308 const char* name);
309-static int dump_selected_tables(char *db, char **table_names, int tables);
310+static int dump_selected_tables(const string &db, const vector<string> &table_names);
311 static int dump_all_tables_in_db(char *db);
312 static int init_dumping_tables(char *);
313 static int init_dumping(char *, int init_func(char*));
314-static int dump_databases(char **);
315+static int dump_databases(const vector<string> &db_names);
316 static int dump_all_databases(void);
317 static char *quote_name(const char *name, char *buff, bool force);
318 char check_if_ignore_table(const char *table_name, char *table_type);
319@@ -371,6 +184,7 @@
320 fmt format specifier
321 ... variable number of parameters
322 */
323+
324 static void verbose_msg(const char *fmt, ...)
325 {
326 va_list args;
327@@ -398,41 +212,6 @@
328 die(EX_EOF, _("Got errno %d on write"), errno);
329 }
330
331-static void print_version(void)
332-{
333- printf(_("%s Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), internal::my_progname,
334- VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
335-} /* print_version */
336-
337-
338-static void short_usage_sub(void)
339-{
340- printf(_("Usage: %s [OPTIONS] database [tables]\n"), internal::my_progname);
341- printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
342- internal::my_progname);
343- printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), internal::my_progname);
344-}
345-
346-
347-static void usage(void)
348-{
349- print_version();
350- puts("");
351- 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"));
352- puts(_("Dumps definitions and data from a Drizzle database server"));
353- short_usage_sub();
354- internal::print_defaults("drizzle",load_default_groups);
355- my_print_help(my_long_options);
356- my_print_variables(my_long_options);
357-} /* usage */
358-
359-
360-static void short_usage(void)
361-{
362- short_usage_sub();
363- printf(_("For more options, use %s --help\n"), internal::my_progname);
364-}
365-
366 static void write_header(FILE *sql_file, char *db_name)
367 {
368 if (opt_xml)
369@@ -448,15 +227,15 @@
370 fputs(">\n", sql_file);
371 check_io(sql_file);
372 }
373- else if (!opt_compact)
374- {
375+ else if (! opt_compact)
376+ {
377 if (opt_comments)
378 {
379 fprintf(sql_file,
380 "-- drizzledump %s libdrizzle %s, for %s-%s (%s)\n--\n",
381 VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
382 fprintf(sql_file, "-- Host: %s Database: %s\n",
383- current_host ? current_host : "localhost", db_name ? db_name :
384+ ! current_host.empty() ? current_host.c_str() : "localhost", db_name ? db_name :
385 "");
386 fputs("-- ------------------------------------------------------\n",
387 sql_file);
388@@ -467,7 +246,7 @@
389 fprintf(sql_file,
390 "\nSET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;\n");
391
392- if (path == NULL)
393+ if (path.empty())
394 {
395 fprintf(md_result_file,"SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;\nSET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\n");
396 }
397@@ -483,9 +262,9 @@
398 fputs("</drizzledump>\n", sql_file);
399 check_io(sql_file);
400 }
401- else if (opt_compact == false)
402+ else if (! opt_compact)
403 {
404- if (path == NULL)
405+ if (path.empty())
406 {
407 fprintf(md_result_file,"SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;\nSET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;\n");
408 }
409@@ -507,175 +286,11 @@
410 }
411 } /* write_footer */
412
413-
414-static int get_one_option(int optid, const struct option *, char *argument)
415-{
416- char *endchar= NULL;
417- uint64_t temp_drizzle_port= 0;
418-
419- switch (optid) {
420- case 'p':
421- temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
422- /* if there is an alpha character this is not a valid port */
423- if (strlen(endchar) != 0)
424- {
425- fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
426- return EXIT_ARGUMENT_INVALID;
427- }
428- /* If the port number is > 65535 it is not a valid port
429- * This also helps with potential data loss casting unsigned long to a
430- * uint32_t. */
431- if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
432- {
433- fprintf(stderr, _("Value supplied for port is not valid.\n"));
434- return EXIT_ARGUMENT_INVALID;
435- }
436- else
437- {
438- opt_drizzle_port= (uint32_t) temp_drizzle_port;
439- }
440- break;
441- case 'P':
442- if (argument)
443- {
444- char *start= argument;
445- if (opt_password)
446- free(opt_password);
447- opt_password= strdup(argument);
448- if (opt_password == NULL)
449- {
450- fprintf(stderr, _("Memory allocation error while copying password. "
451- "Aborting.\n"));
452- return EXIT_OUT_OF_MEMORY;
453- }
454- while (*argument)
455- {
456- /* Overwriting password with 'x' */
457- *argument++= 'x';
458- }
459- if (*start)
460- {
461- /* Cut length of argument */
462- start[1]= 0;
463- }
464- tty_password= 0;
465- }
466- else
467- {
468- tty_password= 1;
469- }
470- break;
471- case 'r':
472- if (!(md_result_file= fopen(argument, "w")))
473- exit(1);
474- break;
475- case 'N':
476- opt_set_charset= 0;
477- break;
478- case 'T':
479- opt_disable_keys=0;
480-
481- if (strlen(argument) >= FN_REFLEN)
482- {
483- /*
484- This check is made because the some the file functions below
485- have FN_REFLEN sized stack allocated buffers and will cause
486- a crash even if the input destination buffer is large enough
487- to hold the output.
488- */
489- fprintf(stderr, _("Input filename too long: %s"), argument);
490- return EXIT_ARGUMENT_INVALID;
491- }
492-
493- break;
494- case 'V': print_version(); exit(0);
495- case 'X':
496- opt_xml= 1;
497- extended_insert= opt_drop=
498- opt_disable_keys= opt_autocommit= opt_create_db= 0;
499- break;
500- case 'I':
501- case '?':
502- usage();
503- exit(0);
504- case (int) OPT_OPTIMIZE:
505- extended_insert= opt_drop= quick= create_options=
506- opt_disable_keys= opt_set_charset= 1;
507- break;
508- case (int) OPT_SKIP_OPTIMIZATION:
509- extended_insert= opt_drop= quick= create_options=
510- opt_disable_keys= opt_set_charset= 0;
511- break;
512- case (int) OPT_COMPACT:
513- if (opt_compact)
514- {
515- opt_comments= opt_drop= opt_disable_keys= 0;
516- opt_set_charset= 0;
517- }
518- case (int) OPT_TABLES:
519- opt_databases=0;
520- break;
521- case (int) OPT_IGNORE_TABLE:
522- {
523- if (!strchr(argument, '.'))
524- {
525- fprintf(stderr, _("Illegal use of option --ignore-table=<database>.<table>\n"));
526- return EXIT_ARGUMENT_INVALID;
527- }
528- string tmpptr(argument);
529- ignore_table.insert(tmpptr);
530- break;
531- }
532- case (int) OPT_COMPATIBLE:
533- {
534- char buff[255];
535- char *end= compatible_mode_normal_str;
536- uint32_t i;
537- uint32_t mode;
538- uint32_t error_len;
539-
540- opt_quoted= 1;
541- opt_set_charset= 0;
542- opt_compatible_mode_str= argument;
543- opt_compatible_mode= find_set(&compatible_mode_typelib,
544- argument, strlen(argument),
545- &err_ptr, &error_len);
546- if (error_len)
547- {
548- strncpy(buff, err_ptr, min((uint32_t)sizeof(buff), error_len+1));
549- fprintf(stderr, _("Invalid mode to --compatible: %s\n"), buff);
550- return EXIT_ARGUMENT_INVALID;
551- }
552- mode= opt_compatible_mode;
553- for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++)
554- {
555- if (mode & 1)
556- {
557- uint32_t len = strlen(compatible_mode_names[i]);
558- end= strcpy(end, compatible_mode_names[i]) + len;
559- end= strcpy(end, ",")+1;
560- }
561- }
562- if (end!=compatible_mode_normal_str)
563- end[-1]= 0;
564- }
565- }
566- return 0;
567-}
568-
569-static int get_options(int *argc, char ***argv)
570-{
571- int ho_error;
572-
573- md_result_file= stdout;
574- internal::load_defaults("drizzle",load_default_groups,argc,argv);
575- defaults_argv= *argv;
576-
577- if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
578- return(ho_error);
579-
580- if (!path && (enclosed || opt_enclosed || escaped || lines_terminated ||
581- fields_terminated))
582+static int get_options(void)
583+{
584+
585+ if (path.empty() && (! enclosed.empty() || ! opt_enclosed.empty() || ! escaped.empty() || ! lines_terminated.empty() ||
586+ ! fields_terminated.empty()))
587 {
588 fprintf(stderr,
589 _("%s: You must use option --tab with --fields-...\n"), internal::my_progname);
590@@ -688,23 +303,19 @@
591 "--lock-all-tables at the same time.\n"), internal::my_progname);
592 return(EX_USAGE);
593 }
594- if (enclosed && opt_enclosed)
595+ if (! enclosed.empty() && ! opt_enclosed.empty())
596 {
597 fprintf(stderr, _("%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n"), internal::my_progname);
598 return(EX_USAGE);
599 }
600- if ((opt_databases || opt_alldbs) && path)
601+ if ((opt_databases || opt_alldbs) && ! path.empty())
602 {
603 fprintf(stderr,
604 _("%s: --databases or --all-databases can't be used with --tab.\n"),
605 internal::my_progname);
606 return(EX_USAGE);
607 }
608- if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs))
609- {
610- short_usage();
611- return EX_USAGE;
612- }
613+
614 if (tty_password)
615 opt_password=client_get_tty_password(NULL);
616 return(0);
617@@ -867,7 +478,7 @@
618 {
619 FILE* res;
620 char filename[FN_REFLEN], tmp_path[FN_REFLEN];
621- internal::convert_dirname(tmp_path,path,NULL);
622+ internal::convert_dirname(tmp_path,(char *)path.c_str(),NULL);
623 res= fopen(internal::fn_format(filename, table, tmp_path, ".sql", 4), "w");
624
625 return res;
626@@ -878,9 +489,7 @@
627 {
628 if (md_result_file && md_result_file != stdout)
629 fclose(md_result_file);
630- free(opt_password);
631- if (defaults_argv)
632- internal::free_defaults(defaults_argv);
633+ opt_password.erase();
634 internal::my_end();
635 }
636
637@@ -902,15 +511,15 @@
638 db_connect -- connects to the host and selects DB.
639 */
640
641-static int connect_to_db(char *host, char *user,char *passwd)
642+static int connect_to_db(string host, string user,string passwd)
643 {
644 drizzle_return_t ret;
645
646- verbose_msg(_("-- Connecting to %s...\n"), host ? host : "localhost");
647+ verbose_msg(_("-- Connecting to %s...\n"), ! host.empty() ? (char *)host.c_str() : "localhost");
648 drizzle_create(&drizzle);
649 drizzle_con_create(&drizzle, &dcon);
650- drizzle_con_set_tcp(&dcon, host, opt_drizzle_port);
651- drizzle_con_set_auth(&dcon, user, passwd);
652+ drizzle_con_set_tcp(&dcon, (char *)host.c_str(), opt_drizzle_port);
653+ drizzle_con_set_auth(&dcon, (char *)user.c_str(), (char *)passwd.c_str());
654 if (opt_mysql)
655 drizzle_con_add_options(&dcon, DRIZZLE_CON_MYSQL);
656 ret= drizzle_con_connect(&dcon);
657@@ -927,9 +536,9 @@
658 /*
659 ** dbDisconnect -- disconnects from the host.
660 */
661-static void dbDisconnect(char *host)
662+static void dbDisconnect(string &host)
663 {
664- verbose_msg(_("-- Disconnecting from %s...\n"), host ? host : "localhost");
665+ verbose_msg(_("-- Disconnecting from %s...\n"), ! host.empty() ? host.c_str() : "localhost");
666 drizzle_con_free(&dcon);
667 drizzle_free(&drizzle);
668 } /* dbDisconnect */
669@@ -1309,11 +918,11 @@
670 order_by= primary_key_fields(result_table);
671 }
672
673- if (!opt_xml)
674- {
675+ if (! opt_xml)
676+ {
677 /* using SHOW CREATE statement */
678- if (!opt_no_create_info)
679- {
680+ if (! opt_no_create_info)
681+ {
682 /* Make an sql-file, if path was given iow. option -T was given */
683 char buff[20+FN_REFLEN];
684 const drizzle_column_st *column;
685@@ -1323,7 +932,7 @@
686 if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
687 return false;
688
689- if (path)
690+ if (! path.empty())
691 {
692 if (!(sql_file= open_sql_file_for_table(table)))
693 {
694@@ -1340,7 +949,7 @@
695 check_io(sql_file);
696 }
697 if (opt_drop)
698- {
699+ {
700 /*
701 Even if the "table" is a view, we do a DROP TABLE here.
702 */
703@@ -1363,7 +972,7 @@
704
705 if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
706 {
707- if (path)
708+ if (! path.empty())
709 fclose(sql_file);
710 return false;
711 }
712@@ -1421,9 +1030,9 @@
713 return false;
714
715 /* Make an sql-file, if path was given iow. option -T was given */
716- if (!opt_no_create_info)
717+ if (! opt_no_create_info)
718 {
719- if (path)
720+ if (! path.empty())
721 {
722 if (!(sql_file= open_sql_file_for_table(table)))
723 {
724@@ -1521,7 +1130,7 @@
725 {
726 fprintf(stderr, _("%s: Can't get keys for table %s\n"),
727 internal::my_progname, result_table);
728- if (path)
729+ if (! path.empty())
730 fclose(sql_file);
731 return false;
732 }
733@@ -1640,9 +1249,9 @@
734 } /* get_table_structure */
735
736 static void add_load_option(string &str, const char *option,
737- const char *option_value)
738+ const string &option_value)
739 {
740- if (!option_value)
741+ if (option_value.empty())
742 {
743 /* Null value means we don't add this option. */
744 return;
745@@ -1650,7 +1259,7 @@
746
747 str.append(option);
748
749- if (strncmp(option_value, "0x", sizeof("0x")-1) == 0)
750+ if (option_value.compare(0, 2, "0x") == 0)
751 {
752 /* It's a hex constant, don't escape */
753 str.append(option_value);
754@@ -1670,28 +1279,29 @@
755 syntax errors from the SQL parser.
756 */
757
758-static void field_escape(string &in, const char *from)
759+static void field_escape(string &in, const string &from)
760 {
761 uint32_t end_backslashes= 0;
762
763 in.append("'");
764
765- while (*from)
766+ string::const_iterator it= from.begin();
767+ while (it != from.end())
768 {
769- in.append(from, 1);
770+ in.push_back(*it);
771
772- if (*from == '\\')
773- end_backslashes^=1; /* find odd number of backslashes */
774+ if (*it == '\\')
775+ end_backslashes^= 1; /* find odd number of backslashes */
776 else
777 {
778- if (*from == '\'' && !end_backslashes)
779+ if (*it == '\'' && !end_backslashes)
780 {
781 /* We want a duplicate of "'" for DRIZZLE */
782- in.append("\'");
783+ in.push_back('\'');
784 }
785 end_backslashes=0;
786 }
787- from++;
788+ ++it;
789 }
790 /* Add missing backslashes if user has specified odd number of backs.*/
791 if (end_backslashes)
792@@ -1778,7 +1388,7 @@
793 query_string.clear();
794 query_string.reserve(1024);
795
796- if (path)
797+ if (! path.empty())
798 {
799 char filename[FN_REFLEN], tmp_path[FN_REFLEN];
800
801@@ -1786,7 +1396,7 @@
802 Convert the path to native os format
803 and resolve to the full filepath.
804 */
805- internal::convert_dirname(tmp_path,path,NULL);
806+ internal::convert_dirname(tmp_path,(char *)path.c_str(),NULL);
807 internal::my_load_path(tmp_path, tmp_path, NULL);
808 internal::fn_format(filename, table, tmp_path, ".txt", MYF(MY_UNPACK_FILENAME));
809
810@@ -1799,7 +1409,7 @@
811 query_string.append( filename);
812 query_string.append( "'");
813
814- if (fields_terminated || enclosed || opt_enclosed || escaped)
815+ if (! fields_terminated.empty() || ! enclosed.empty() || ! opt_enclosed.empty() || ! escaped.empty())
816 query_string.append( " FIELDS");
817
818 add_load_option(query_string, " TERMINATED BY ", fields_terminated);
819@@ -1808,19 +1418,19 @@
820 add_load_option(query_string, " ESCAPED BY ", escaped);
821 add_load_option(query_string, " LINES TERMINATED BY ", lines_terminated);
822
823- query_string.append( " FROM ");
824- query_string.append( result_table);
825+ query_string.append(" FROM ");
826+ query_string.append(result_table);
827
828- if (where)
829+ if (! where.empty())
830 {
831- query_string.append( " WHERE ");
832- query_string.append( where);
833+ query_string.append(" WHERE ");
834+ query_string.append(where);
835 }
836
837 if (order_by)
838 {
839- query_string.append( " ORDER BY ");
840- query_string.append( order_by);
841+ query_string.append(" ORDER BY ");
842+ query_string.append(order_by);
843 }
844
845 if (drizzle_query(&dcon, &result, query_string.c_str(),
846@@ -1833,6 +1443,7 @@
847 }
848 drizzle_result_free(&result);
849 }
850+
851 else
852 {
853 if (!opt_xml && opt_comments)
854@@ -1845,16 +1456,16 @@
855 query_string.append( "SELECT * FROM ");
856 query_string.append( result_table);
857
858- if (where)
859+ if (! where.empty())
860 {
861 if (!opt_xml && opt_comments)
862 {
863- fprintf(md_result_file, "-- WHERE: %s\n", where);
864+ fprintf(md_result_file, "-- WHERE: %s\n", where.c_str());
865 check_io(md_result_file);
866 }
867
868 query_string.append( " WHERE ");
869- query_string.append( where);
870+ query_string.append( (char *)where.c_str());
871 }
872 if (order_by)
873 {
874@@ -1895,7 +1506,7 @@
875 opt_quoted_table);
876 check_io(md_result_file);
877 }
878-
879+
880 total_length= DRIZZLE_MAX_LINE_LENGTH; /* Force row break */
881 row_break=0;
882 rownr=0;
883@@ -2215,15 +1826,14 @@
884 /* dump_all_databases */
885
886
887-static int dump_databases(char **db_names)
888+static int dump_databases(const vector<string> &db_names)
889 {
890 int result=0;
891- char **db;
892-
893-
894- for (db= db_names ; *db ; db++)
895+ string temp;
896+ for (vector<string>::const_iterator it= db_names.begin(); it != db_names.end(); ++it)
897 {
898- if (dump_all_tables_in_db(*db))
899+ temp= *it;
900+ if (dump_all_tables_in_db((char *)temp.c_str()))
901 result=1;
902 }
903 return(result);
904@@ -2321,7 +1931,7 @@
905 }
906 drizzle_result_free(&result);
907
908- if (!path && !opt_xml)
909+ if (path.empty() && !opt_xml)
910 {
911 if (opt_databases || opt_alldbs)
912 {
913@@ -2454,7 +2064,7 @@
914 }
915
916
917-static int dump_selected_tables(char *db, char **table_names, int tables)
918+static int dump_selected_tables(const string &db, const vector<string> &table_names)
919 {
920 drizzled::memory::Root root;
921 char **dump_tables, **pos, **end;
922@@ -2462,17 +2072,18 @@
923 drizzle_return_t ret;
924
925
926- if (init_dumping(db, init_dumping_tables))
927+ if (init_dumping((char *)db.c_str(), init_dumping_tables))
928 return(1);
929
930 root.init_alloc_root(8192);
931- if (!(dump_tables= pos= (char**) root.alloc_root(tables * sizeof(char *))))
932+ if (!(dump_tables= pos= (char**) root.alloc_root(table_names.size() * sizeof(char *))))
933 die(EX_EOM, _("alloc_root failure."));
934
935- for (; tables > 0 ; tables-- , table_names++)
936+ for (vector<string>::const_iterator it= table_names.begin(); it != table_names.end(); ++it)
937 {
938+ string temp= *it;
939 /* the table name passed on commandline may be wrong case */
940- if ((*pos= get_actual_table_name(*table_names, &root)))
941+ if ((*pos= get_actual_table_name(temp.c_str(), &root)))
942 {
943 pos++;
944 }
945@@ -2482,7 +2093,7 @@
946 {
947 root.free_root(MYF(0));
948 }
949- maybe_die(EX_ILLEGAL_TABLE, _("Couldn't find table: \"%s\""), *table_names);
950+ maybe_die(EX_ILLEGAL_TABLE, _("Couldn't find table: \"%s\""),(char *) temp.c_str());
951 /* We shall countinue here, if --force was given */
952 }
953 }
954@@ -2502,11 +2113,11 @@
955 drizzle_result_free(&result);
956 }
957 if (opt_xml)
958- print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
959+ print_xml_tag(md_result_file, "", "\n", "database", "name=", (char *)db.c_str(), NULL);
960
961 /* Dump each selected table */
962 for (pos= dump_tables; pos < end; pos++)
963- dump_table(*pos, db);
964+ dump_table(*pos, (char *)db.c_str());
965
966 root.free_root(MYF(0));
967 free(order_by);
968@@ -2830,16 +2441,370 @@
969 return result;
970 }
971
972-
973 int main(int argc, char **argv)
974 {
975+try
976+{
977 int exit_code;
978 MY_INIT("drizzledump");
979 drizzle_result_st result;
980
981+ po::options_description commandline_options("Options used only in command line");
982+ commandline_options.add_options()
983+ ("all-databases,A", po::value<bool>(&opt_alldbs)->default_value(false)->zero_tokens(),
984+ "Dump all the databases. This will be same as --databases with all databases selected.")
985+ ("all-tablespaces,Y", po::value<bool>(&opt_alltspcs)->default_value(false)->zero_tokens(),
986+ "Dump all the tablespaces.")
987+ ("complete-insert,c", po::value<bool>(&opt_complete_insert)->default_value(false)->zero_tokens(),
988+ "Use complete insert statements.")
989+ ("compress,C", po::value<bool>(&opt_compress)->default_value(false)->zero_tokens(),
990+ "Use compression in server/client protocol.")
991+ ("flush-logs,F", po::value<bool>(&flush_logs)->default_value(false)->zero_tokens(),
992+ "Flush logs file in server before starting dump. Note that if you dump many databases at once (using the option --databases= or --all-databases), the logs will be flushed for each database dumped. The exception is when using --lock-all-tables in this case the logs will be flushed only once, corresponding to the moment all tables are locked. So if you want your dump and the log flush to happen at the same exact moment you should use --lock-all-tables or --flush-logs")
993+ ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
994+ "Continue even if we get an sql-error.")
995+ ("help,?", "Display this help message and exit.")
996+ ("lock-all-tables,x", po::value<bool>(&opt_lock_all_tables)->default_value(false)->zero_tokens(),
997+ "Locks all tables across all databases. This is achieved by taking a global read lock for the duration of the whole dump. Automatically turns --single-transaction and --lock-tables off.")
998+ ("order-by-primary", po::value<bool>(&opt_order_by_primary)->default_value(false)->zero_tokens(),
999+ "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.")
1000+ ("routines,R", po::value<bool>(&opt_routines)->default_value(false)->zero_tokens(),
1001+ "Dump stored routines (functions and procedures).")
1002+ ("single-transaction", po::value<bool>(&opt_single_transaction)->default_value(false)->zero_tokens(),
1003+ "Creates a consistent snapshot by dumping all tables in a single transaction. Works ONLY for tables stored in storage engines which support multiversioning (currently only InnoDB does); the dump is NOT guaranteed to be consistent for other storage engines. While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents), no other connection should use the following statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not isolated from them. Option automatically turns off --lock-tables.")
1004+ ("opt", "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.")
1005+ ("skip-opt",
1006+ "Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.")
1007+ ("tables", "Overrides option --databases (-B).")
1008+ ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(10000),
1009+ N_("Number of rows before each output progress report (requires --verbose)."))
1010+ ("verbose,v", po::value<bool>(&verbose)->default_value(false)->zero_tokens(),
1011+ "Print info about the various stages.")
1012+ ("version,V", "Output version information and exit.")
1013+ ("xml,X", "Dump a database as well formed XML.")
1014+ ("skip-comments", "Turn off Comments")
1015+ ("skip-create", "Turn off create-options")
1016+ ("skip-extended-insert", "Turn off extended-insert")
1017+ ("skip-dump-date", "Turn off dump-date")
1018+ ("no-defaults", "Do not read from the configuration files")
1019+ ;
1020+
1021+ po::options_description dump_options("Options specific to the drizzle client");
1022+ dump_options.add_options()
1023+ ("add-drop-database", po::value<bool>(&opt_drop_database)->default_value(false)->zero_tokens(),
1024+ "Add a 'DROP DATABASE' before each create.")
1025+ ("add-drop-table", po::value<bool>(&opt_drop)->default_value(true)->zero_tokens(),
1026+ "Add a 'drop table' before each create.")
1027+ ("allow-keywords", po::value<bool>(&opt_keywords)->default_value(false)->zero_tokens(),
1028+ "Allow creation of column names that are keywords.")
1029+ ("comments,i", po::value<bool>(&opt_comments)->default_value(true)->zero_tokens(),
1030+ "Write additional information.")
1031+ ("compatible", po::value<string>(&opt_compatible_mode_str)->default_value(""),
1032+ "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.")
1033+ ("compact", po::value<bool>(&opt_compact)->default_value(false)->zero_tokens(),
1034+ "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")
1035+ ("create-options", po::value<bool>(&create_options)->default_value(true)->zero_tokens(),
1036+ "Include all DRIZZLE specific create options.")
1037+ ("dump-date", po::value<bool>(&opt_dump_date)->default_value(true)->zero_tokens(),
1038+ "Put a dump date to the end of the output.")
1039+ ("databases,B", po::value<bool>(&opt_databases)->default_value(false)->zero_tokens(),
1040+ "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.")
1041+ ("delayed-insert", po::value<bool>(&opt_delayed)->default_value(false)->zero_tokens(),
1042+ "Insert rows with INSERT DELAYED; ")
1043+ ("disable-keys,K", po::value<bool>(&opt_disable_keys)->default_value(true)->zero_tokens(),
1044+ "'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.")
1045+ ("extended-insert,e", po::value<bool>(&extended_insert)->default_value(true)->zero_tokens(),
1046+ "Allows utilization of the new, much faster INSERT syntax.")
1047+ ("fields-terminated-by", po::value<string>(&fields_terminated)->default_value(""),
1048+ "Fields in the textfile are terminated by ...")
1049+ ("fields-enclosed-by", po::value<string>(&enclosed)->default_value(""),
1050+ "Fields in the importfile are enclosed by ...")
1051+ ("fields-optionally-enclosed-by", po::value<string>(&opt_enclosed)->default_value(""),
1052+ "Fields in the i.file are opt. enclosed by ...")
1053+ ("fields-escaped-by", po::value<string>(&escaped)->default_value(""),
1054+ "Fields in the i.file are escaped by ...")
1055+ ("hex-blob", po::value<bool>(&opt_hex_blob)->default_value(false)->zero_tokens(),
1056+ "Dump binary strings (BINARY, VARBINARY, BLOB) in hexadecimal format.")
1057+ ("ignore-table", po::value<string>(),
1058+ "Do not dump the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table. Each table must be specified with both database and table names, e.g. --ignore-table=database.table")
1059+ ("insert-ignore", po::value<bool>(&opt_ignore)->default_value(false)->zero_tokens(),
1060+ "Insert rows with INSERT IGNORE.")
1061+ ("lines-terminated-by", po::value<string>(&lines_terminated)->default_value(""),
1062+ "Lines in the i.file are terminated by ...")
1063+ ("no-autocommit", po::value<bool>(&opt_autocommit)->default_value(false)->zero_tokens(),
1064+ "Wrap tables with autocommit/commit statements.")
1065+ ("no-create-db,n", po::value<bool>(&opt_create_db)->default_value(false)->zero_tokens(),
1066+ "'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.}.")
1067+ ("no-create-info,t", po::value<bool>(&opt_no_create_info)->default_value(false)->zero_tokens(),
1068+ "Don't write table creation info.")
1069+ ("no-data,d", po::value<bool>(&opt_no_data)->default_value(false)->zero_tokens(),
1070+ "No row information.")
1071+ ("no-set-names,N", "Deprecated. Use --skip-set-charset instead.")
1072+ ("set-charset", po::value<bool>(&opt_set_charset)->default_value(false)->zero_tokens(),
1073+ "Enable set-name")
1074+ ("quick,q", po::value<bool>(&quick)->default_value(true)->zero_tokens(),
1075+ "Don't buffer query, dump directly to stdout.")
1076+ ("quote-names,Q", po::value<bool>(&opt_quoted)->default_value(true)->zero_tokens(),
1077+ "Quote table and column names with backticks (`).")
1078+ ("replace", po::value<bool>(&opt_replace_into)->default_value(false)->zero_tokens(),
1079+ "Use REPLACE INTO instead of INSERT INTO.")
1080+ ("result-file,r", po::value<string>(),
1081+ "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).")
1082+ ("tab,T", po::value<string>(&path)->default_value(""),
1083+ "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.")
1084+ ("where,w", po::value<string>(&where)->default_value(""),
1085+ "Dump only selected records; QUOTES mandatory!")
1086+ ;
1087+
1088+ po::options_description client_options("Options specific to the client");
1089+ client_options.add_options()
1090+ ("host,h", po::value<string>(&current_host)->default_value("localhost"),
1091+ "Connect to host.")
1092+ ("mysql,m", po::value<bool>(&opt_mysql)->default_value(true)->zero_tokens(),
1093+ N_("Use MySQL Protocol."))
1094+ ("password,P", po::value<string>(&password)->default_value(PASSWORD_SENTINEL),
1095+ "Password to use when connecting to server. If password is not given it's solicited on the tty.")
1096+ ("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
1097+ "Port number to use for connection.")
1098+ ("user,u", po::value<string>(&current_user)->default_value(""),
1099+ "User for login if not current user.")
1100+ ("protocol",po::value<string>(),
1101+ "The protocol of connection (tcp,socket,pipe,memory).")
1102+ ;
1103+
1104+ po::options_description hidden_options("Hidden Options");
1105+ hidden_options.add_options()
1106+ ("database-used", po::value<vector<string> >(), "Used to select the database")
1107+ ("Table-used", po::value<vector<string> >(), "Used to select the tables")
1108+ ;
1109+
1110+ po::options_description all_options("Allowed Options + Hidden Options");
1111+ all_options.add(commandline_options).add(dump_options).add(client_options).add(hidden_options);
1112+
1113+ po::options_description long_options("Allowed Options");
1114+ long_options.add(commandline_options).add(dump_options).add(client_options);
1115+
1116+ std::string system_config_dir_dump(SYSCONFDIR);
1117+ system_config_dir_dump.append("/drizzle/drizzledump.cnf");
1118+
1119+ std::string system_config_dir_client(SYSCONFDIR);
1120+ system_config_dir_client.append("/drizzle/client.cnf");
1121+
1122+ po::positional_options_description p;
1123+ p.add("database-used", 1);
1124+ p.add("Table-used",-1);
1125+
1126 compatible_mode_normal_str[0]= 0;
1127-
1128- exit_code= get_options(&argc, &argv);
1129+
1130+ md_result_file= stdout;
1131+
1132+ po::variables_map vm;
1133+
1134+ po::store(po::command_line_parser(argc, argv).options(all_options).
1135+ positional(p).extra_parser(parse_password_arg).run(), vm);
1136+
1137+ if (! vm.count("no-defaults"))
1138+ {
1139+ ifstream user_dump_ifs("~/.drizzle/drizzledump.cnf");
1140+ po::store(parse_config_file(user_dump_ifs, dump_options), vm);
1141+
1142+ ifstream system_dump_ifs(system_config_dir_dump.c_str());
1143+ store(parse_config_file(system_dump_ifs, dump_options), vm);
1144+
1145+ ifstream user_client_ifs("~/.drizzle/client.cnf");
1146+ po::store(parse_config_file(user_client_ifs, client_options), vm);
1147+
1148+ ifstream system_client_ifs(system_config_dir_client.c_str());
1149+ po::store(parse_config_file(system_client_ifs, client_options), vm);
1150+ }
1151+
1152+ po::notify(vm);
1153+
1154+ if ( ! vm.count("database-used") && ! vm.count("Table-used") && ! opt_alldbs && path.empty())
1155+ {
1156+ printf(_("Usage: %s [OPTIONS] database [tables]\n"), internal::my_progname);
1157+ printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
1158+ internal::my_progname);
1159+ printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), internal::my_progname);
1160+ exit(1);
1161+ }
1162+
1163+ if (vm.count("port"))
1164+ {
1165+ /* If the port number is > 65535 it is not a valid port
1166+ * This also helps with potential data loss casting unsigned long to a
1167+ * uint32_t.
1168+ */
1169+ if (opt_drizzle_port > 65535)
1170+ {
1171+ fprintf(stderr, _("Value supplied for port is not valid.\n"));
1172+ exit(-1);
1173+ }
1174+ }
1175+
1176+ if(vm.count("password"))
1177+ {
1178+ if (!opt_password.empty())
1179+ opt_password.erase();
1180+ if (password == PASSWORD_SENTINEL)
1181+ {
1182+ opt_password= "";
1183+ }
1184+ else
1185+ {
1186+ opt_password= password;
1187+ tty_password= false;
1188+ }
1189+ }
1190+ else
1191+ {
1192+ tty_password= true;
1193+ }
1194+
1195+ if (vm.count("result-file"))
1196+ {
1197+ if (!(md_result_file= fopen(vm["result-file"].as<string>().c_str(), "w")))
1198+ exit(1);
1199+ }
1200+
1201+ if (vm.count("no-set-names"))
1202+ {
1203+ opt_set_charset= 0;
1204+ }
1205+
1206+ if (! path.empty())
1207+ {
1208+ opt_disable_keys= 0;
1209+
1210+ if (vm["tab"].as<string>().length() >= FN_REFLEN)
1211+ {
1212+ /*
1213+ This check is made because the some the file functions below
1214+ have FN_REFLEN sized stack allocated buffers and will cause
1215+ a crash even if the input destination buffer is large enough
1216+ to hold the output.
1217+ */
1218+ fprintf(stderr, _("Input filename too long: %s"), vm["tab"].as<string>().c_str());
1219+ exit(EXIT_ARGUMENT_INVALID);
1220+ }
1221+ }
1222+
1223+ if (vm.count("version"))
1224+ {
1225+ printf(_("%s Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), internal::my_progname,
1226+ VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
1227+ }
1228+
1229+ if (vm.count("xml"))
1230+ {
1231+ opt_xml= 1;
1232+ extended_insert= opt_drop= opt_disable_keys= opt_autocommit= opt_create_db= 0;
1233+ }
1234+
1235+ if (vm.count("help"))
1236+ {
1237+ printf(_("%s Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), internal::my_progname,
1238+ VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
1239+ puts("");
1240+ 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"));
1241+ puts(_("Dumps definitions and data from a Drizzle database server"));
1242+ cout << long_options;
1243+ printf(_("Usage: %s [OPTIONS] database [tables]\n"), internal::my_progname);
1244+ printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
1245+ internal::my_progname);
1246+ printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), internal::my_progname);
1247+ exit(1);
1248+ }
1249+
1250+ if (vm.count("skip-opt"))
1251+ {
1252+ extended_insert= opt_drop= quick= create_options= 0;
1253+ opt_disable_keys= opt_set_charset= 0;
1254+ }
1255+
1256+ if (opt_compact)
1257+ {
1258+ opt_comments= opt_drop= opt_disable_keys= 0;
1259+ opt_set_charset= 0;
1260+ }
1261+
1262+ if (vm.count("opt"))
1263+ {
1264+ extended_insert= opt_drop= quick= create_options= 1;
1265+ opt_disable_keys= opt_set_charset= 1;
1266+ }
1267+
1268+ if (vm.count("tables"))
1269+ {
1270+ opt_databases= false;
1271+ }
1272+
1273+ if (vm.count("ignore-table"))
1274+ {
1275+ if (!strchr(vm["ignore-table"].as<string>().c_str(), '.'))
1276+ {
1277+ fprintf(stderr, _("Illegal use of option --ignore-table=<database>.<table>\n"));
1278+ exit(EXIT_ARGUMENT_INVALID);
1279+ }
1280+ string tmpptr(vm["ignore-table"].as<string>());
1281+ ignore_table.insert(tmpptr);
1282+ }
1283+
1284+ if (vm.count("skip-create"))
1285+ {
1286+ opt_create_db= opt_no_create_info= create_options= false;
1287+ }
1288+
1289+ if (vm.count("skip-comments"))
1290+ {
1291+ opt_comments= false;
1292+ }
1293+
1294+ if (vm.count("skip-extended-insert"))
1295+ {
1296+ extended_insert= false;
1297+ }
1298+
1299+ if (vm.count("skip-dump-date"))
1300+ {
1301+ opt_dump_date= false;
1302+ }
1303+
1304+ if (! opt_compatible_mode_str.empty())
1305+ {
1306+ char buff[255];
1307+ char *end= compatible_mode_normal_str;
1308+ uint32_t i;
1309+ uint32_t mode;
1310+ uint32_t error_len;
1311+
1312+ opt_quoted= 1;
1313+ opt_set_charset= 0;
1314+ opt_compatible_mode= find_set(&compatible_mode_typelib,
1315+ opt_compatible_mode_str.c_str(), opt_compatible_mode_str.length(),
1316+ &err_ptr, &error_len);
1317+ if (error_len)
1318+ {
1319+ strncpy(buff, err_ptr, min((uint32_t)sizeof(buff), error_len+1));
1320+ fprintf(stderr, _("Invalid mode to --compatible: %s\n"), buff);
1321+ exit(EXIT_ARGUMENT_INVALID);
1322+ }
1323+ mode= opt_compatible_mode;
1324+ for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++)
1325+ {
1326+ if (mode & 1)
1327+ {
1328+ uint32_t len = strlen(compatible_mode_names[i]);
1329+ end= strcpy(end, compatible_mode_names[i]) + len;
1330+ end= strcpy(end, ",")+1;
1331+ }
1332+ }
1333+ if (end!=compatible_mode_normal_str)
1334+ end[-1]= 0;
1335+ }
1336+
1337+
1338+ exit_code= get_options();
1339 if (exit_code)
1340 {
1341 free_resources();
1342@@ -2851,8 +2816,11 @@
1343 free_resources();
1344 exit(EX_DRIZZLEERR);
1345 }
1346- if (!path)
1347- write_header(md_result_file, *argv);
1348+ if (path.empty() && vm.count("database-used"))
1349+ {
1350+ string database_used= *vm["database-used"].as< vector<string> >().begin();
1351+ write_header(md_result_file, (char *)database_used.c_str());
1352+ }
1353
1354 if ((opt_lock_all_tables) && do_flush_tables_read_lock(&dcon))
1355 goto err;
1356@@ -2872,14 +2840,30 @@
1357 {
1358 dump_all_databases();
1359 }
1360- else if (argc > 1 && !opt_databases)
1361+ if (vm.count("database-used") && vm.count("Table-used") && ! opt_databases)
1362 {
1363+ string database_used= *vm["database-used"].as< vector<string> >().begin();
1364 /* Only one database and selected table(s) */
1365- dump_selected_tables(*argv, (argv + 1), (argc - 1));
1366- }
1367- else
1368- {
1369- dump_databases(argv);
1370+ dump_selected_tables(database_used, vm["Table-used"].as< vector<string> >());
1371+ }
1372+
1373+ if (vm.count("Table-used") && opt_databases)
1374+ {
1375+ vector<string> database_used= vm["database-used"].as< vector<string> >();
1376+ vector<string> table_used= vm["Table-used"].as< vector<string> >();
1377+
1378+ for (vector<string>::iterator it= table_used.begin();
1379+ it != table_used.end();
1380+ ++it)
1381+ {
1382+ database_used.insert(database_used.end(), *it);
1383+ }
1384+ dump_databases(database_used);
1385+ }
1386+
1387+ if (vm.count("database-used") && ! vm.count("Table-used"))
1388+ {
1389+ dump_databases(vm["database-used"].as< vector<string> >());
1390 }
1391
1392 /* ensure dumped data flushed */
1393@@ -2898,12 +2882,18 @@
1394 */
1395 err:
1396 dbDisconnect(current_host);
1397- if (!path)
1398+ if (path.empty())
1399 write_footer(md_result_file);
1400 free_resources();
1401
1402 if (stderror_file)
1403 fclose(stderror_file);
1404+}
1405
1406+ catch(exception &err)
1407+ {
1408+ cerr << err.what() << endl;
1409+ }
1410+
1411 return(first_error);
1412 } /* main */
1413
1414=== modified file 'client/drizzleimport.cc'
1415--- client/drizzleimport.cc 2010-06-19 16:36:52 +0000
1416+++ client/drizzleimport.cc 2010-06-24 15:13:36 +0000
1417@@ -469,7 +469,8 @@
1418 system_config_dir_client.append("/drizzle/client.cnf");
1419
1420 po::variables_map vm;
1421- po::store(po::command_line_parser(argc, argv).options(long_options).run(), vm);
1422+ po::store(po::command_line_parser(argc, argv).options(long_options).
1423+ extra_parser(parse_password_arg).run(), vm);
1424
1425 ifstream user_import_ifs("~/.drizzle/drizzleimport.cnf");
1426 po::store(parse_config_file(user_import_ifs, import_options), vm);
1427@@ -498,27 +499,18 @@
1428 }
1429 }
1430
1431- if (vm.count("password"))
1432+ if( vm.count("password") )
1433 {
1434 if (!opt_password.empty())
1435 opt_password.erase();
1436- opt_password= password;
1437- if (opt_password.c_str() == NULL)
1438- {
1439- fprintf(stderr, _("Memory allocation error while copying password. "
1440- "Aborting.\n"));
1441- exit(EXIT_OUT_OF_MEMORY);
1442- }
1443- char *start= (char *)password.c_str();
1444- char *temp_pass= (char *)password.c_str();
1445- while (*temp_pass)
1446- {
1447- /* Overwriting password with 'x' */
1448- *temp_pass++= 'x';
1449- }
1450- if (*start)
1451- {
1452- start[1]= 0;
1453+ if (password == PASSWORD_SENTINEL)
1454+ {
1455+ opt_password= "";
1456+ }
1457+ else
1458+ {
1459+ opt_password= password;
1460+ tty_password= false;
1461 }
1462 }
1463 else
1464@@ -526,6 +518,7 @@
1465 tty_password= true;
1466 }
1467
1468+
1469 if (vm.count("version"))
1470 {
1471 printf("%s Ver %s Distrib %s, for %s-%s (%s)\n" ,internal::my_progname,
1472
1473=== modified file 'client/drizzleslap.cc'
1474--- client/drizzleslap.cc 2010-06-20 05:00:42 +0000
1475+++ client/drizzleslap.cc 2010-06-24 15:13:36 +0000
1476@@ -986,7 +986,8 @@
1477
1478
1479 po::variables_map vm;
1480- po::store(po::parse_command_line(argc,argv,long_options),vm);
1481+ po::store(po::command_line_parser(argc, argv).options(long_options).
1482+ extra_parser(parse_password_arg).run(), vm);
1483
1484 ifstream user_slap_ifs("~/.drizzle/drizzleslap.cnf");
1485 po::store(parse_config_file(user_slap_ifs, slap_options), vm);
1486@@ -1033,34 +1034,25 @@
1487 }
1488 }
1489
1490- if( vm.count("password") )
1491+ if( vm.count("password") )
1492+ {
1493+ if (!opt_password.empty())
1494+ opt_password.erase();
1495+ if (password == PASSWORD_SENTINEL)
1496 {
1497- char *start= vm["password"].as<char *>();
1498- if (!opt_password.empty())
1499- opt_password.erase();
1500- opt_password = strdup(vm["password"].as<char *>());
1501- if (opt_password.c_str() == NULL)
1502- {
1503- fprintf(stderr, "Memory allocation error while copying password. "
1504- "Aborting.\n");
1505- exit(ENOMEM);
1506- }
1507-
1508- while (*password)
1509- {
1510- /* Overwriting password with 'x' */
1511- *password++= 'x';
1512- }
1513-
1514- if (*start)
1515- {
1516- /* Cut length of argument */
1517- start[1]= 0;
1518- }
1519- tty_password= 0;
1520+ opt_password= "";
1521 }
1522 else
1523- tty_password= 1;
1524+ {
1525+ opt_password= password;
1526+ tty_password= false;
1527+ }
1528+ }
1529+ else
1530+ {
1531+ tty_password= true;
1532+ }
1533+
1534
1535
1536 if( vm.count("version") )
1537
1538=== modified file 'client/drizzletest.cc'
1539--- client/drizzletest.cc 2010-06-19 16:36:52 +0000
1540+++ client/drizzletest.cc 2010-06-24 15:13:36 +0000
1541@@ -5588,7 +5588,7 @@
1542 }
1543 }
1544
1545- if (vm.count("password"))
1546+ if( vm.count("password") )
1547 {
1548 if (!opt_password.empty())
1549 opt_password.erase();
1550@@ -5601,17 +5601,6 @@
1551 opt_password= password;
1552 tty_password= false;
1553 }
1554- char *start= (char *)password.c_str();
1555- char *temp_pass= (char *)password.c_str();
1556- while (*temp_pass)
1557- {
1558- /* Overwriting password with 'x' */
1559- *temp_pass++= 'x';
1560- }
1561- if (*start)
1562- {
1563- start[1]= 0;
1564- }
1565 }
1566 else
1567 {
1568
1569=== modified file 'client/include.am'
1570--- client/include.am 2010-06-20 07:24:17 +0000
1571+++ client/include.am 2010-06-24 15:13:36 +0000
1572@@ -48,7 +48,7 @@
1573 client/libgetpassword.la
1574
1575 client_drizzledump_SOURCES= client/drizzledump.cc
1576-client_drizzledump_LDADD= ${CLIENT_LDADD}
1577+client_drizzledump_LDADD= ${CLIENT_LDADD} ${BOOST_LIBS}
1578
1579 client_drizzleimport_SOURCES= client/drizzleimport.cc
1580 client_drizzleimport_LDADD= ${CLIENT_LDADD} ${BOOST_LIBS}