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

Proposed by Vijay Samuel
Status: Superseded
Proposed branch: lp:~vjsamuel/drizzle/refactor-drizzle
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 1213 lines (+452/-436)
2 files modified
client/drizzle.cc (+451/-435)
client/include.am (+1/-1)
To merge this branch: bzr merge lp:~vjsamuel/drizzle/refactor-drizzle
Reviewer Review Type Date Requested Status
Monty Taylor Needs Fixing
Jay Pipes (community) Needs Fixing
Brian Aker Pending
Review via email: mp+26682@code.launchpad.net

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

This proposal has been superseded by a proposal from 2010-06-03.

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote :

Hi Vijay!

Great work on refactoring the client to use program_options! It's great to see the use of mysys (drizzled::internal::) removed here.

Most of my comments are about naming and style. I've noticed you're a bit inconsistent in that area, so I'll try to point out a few things that need fixed :)

1)

put one and only one space between if|else|else if and the left parentheses.
put one space before and one space after comparison operators (==, !=, >, >=, etc)
put one space after negation operators (use if (! some_bool) or if (not some_bool))

You use a mix of a number of styles. For instance:

118 + if(in_connect_timeout>3600*12)
129 + if( in_max_input_line<4096 || in_max_input_line>(int64_t)2*1024L*1024L*1024L)
140 + if (s.find("--password")==0)
154 + if(s.substr(10)=="=")

Please go through and make sure you follow the style guidelines regarding proper spacing :)

Also, please be consistent in comment spacing...you use both this:

144 + //check if no argument is passed.
and
62 + // check if --password has quotes, remove quotes and return the value

Please use a space between // and the start of the comment

2.

Consider renaming the reg_password() function to something more descriptive, and placing a comment block before the function to indicate *why* that function exists and what it's doing so that developers hacking on the client can properly avoid all the pain you worked hard with Monty to work through! :)

Cheers!
jay

review: Needs Fixing
Revision history for this message
Monty Taylor (mordred) wrote :

Mentioned on IRC, but for the record:

  error=sql_connect((char *)current_host.c_str(), (char *)current_db.c_str(), (char *)current_user.c_str(), (char *)opt_password.c_str(),0);

it might be nicer to change the sql_connect function to take arguments of const string& for host, db and current_user.

review: Needs Fixing
1583. By Vijay Samuel <vijay@vijay>

Merge patch for sql_connect() and style issue.

Revision history for this message
Stewart Smith (stewart) wrote :

On Thu, 03 Jun 2010 10:41:05 -0000, Vijay Samuel <email address hidden> wrote:
> + return make_pair("password", "☃PASSWORD☃");

snowman? special characters probably shouldn't be in source.

--
Stewart Smith

Revision history for this message
Monty Taylor (mordred) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/03/2010 04:10 PM, Stewart Smith wrote:
> On Thu, 03 Jun 2010 10:41:05 -0000, Vijay Samuel <email address hidden> wrote:
>> + return make_pair("password", "☃PASSWORD☃");
>
> snowman? special characters probably shouldn't be in source.

We needed a sentinel string that was very unlikely to actually be used
in a password string. (side effect to how the program_options works) ...
This is our work around to mark the option as "didn't provide an option
- - please prompt for password"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwIQKMACgkQ2Jv7/VK1RgE87gCghfiHJ1+1tmhpZYg+kXdmPACv
GjMAoMV/0x9mvIEwhP9CBfm/JbXih64b
=QFpi
-----END PGP SIGNATURE-----

1584. By Vijay Samuel <vijay@vijay>

Merge fix for additional parser for --password.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/drizzle.cc' (properties changed: +x to -x)
2--- client/drizzle.cc 2010-05-25 15:23:24 +0000
3+++ client/drizzle.cc 2010-06-03 17:20:45 +0000
4@@ -37,6 +37,7 @@
5 #include <string>
6 #include <drizzled/gettext.h>
7 #include <iostream>
8+#include <fstream>
9 #include <map>
10 #include <algorithm>
11 #include <limits.h>
12@@ -139,9 +140,11 @@
13 #undef vidattr
14 #define vidattr(A) {} // Can't get this to work
15 #endif
16+#include <boost/program_options.hpp>
17
18 using namespace drizzled;
19 using namespace std;
20+namespace po=boost::program_options;
21
22 const string VER("14.14");
23 /* Don't try to make a nice table if the data is too big */
24@@ -151,7 +154,6 @@
25 const int MAX_SERVER_VERSION_LENGTH= 128;
26
27 #define PROMPT_CHAR '\\'
28-#define DEFAULT_DELIMITER ";"
29
30 class Status
31 {
32@@ -260,7 +262,6 @@
33 static map<string, string> completion_map;
34 static string completion_string;
35
36-static char **defaults_argv;
37
38 enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT};
39 typedef enum enum_info_type INFO_TYPE;
40@@ -279,15 +280,14 @@
41 default_pager_set= false, opt_sigint_ignore= false,
42 auto_vertical_output= false,
43 show_warnings= false, executing_query= false, interrupted_query= false,
44- opt_mysql= false;
45-static uint32_t show_progress_size= 0;
46+ opt_mysql= false, opt_local_infile;
47+static uint32_t show_progress_size= 0;
48 static bool column_types_flag;
49 static bool preserve_comments= false;
50-static uint32_t opt_max_input_line, opt_drizzle_port= 0;
51-static int verbose= 0, opt_silent= 0, opt_local_infile= 0;
52+static uint32_t opt_max_input_line;
53+static uint32_t opt_drizzle_port= 0;
54+static int opt_silent, verbose= 0;
55 static drizzle_capabilities_t connect_flag= DRIZZLE_CAPABILITIES_NONE;
56-static char *current_host, *current_db, *current_user= NULL,
57- *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
58 static char *histfile;
59 static char *histfile_tmp;
60 static string *glob_buffer;
61@@ -298,6 +298,14 @@
62 static uint32_t select_limit;
63 static uint32_t max_join_size;
64 static uint32_t opt_connect_timeout= 0;
65+std::string current_db,
66+ delimiter_str,
67+ current_host,
68+ current_prompt,
69+ current_user,
70+ opt_verbose,
71+ current_password,
72+ opt_password;
73 // TODO: Need to i18n these
74 static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
75 static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
76@@ -306,7 +314,7 @@
77 static char pager[FN_REFLEN], outfile[FN_REFLEN];
78 static FILE *PAGER, *OUTFILE;
79 static uint32_t prompt_counter;
80-static char delimiter[16]= DEFAULT_DELIMITER;
81+static char *delimiter= NULL;
82 static uint32_t delimiter_length= 1;
83 unsigned short terminal_width= 80;
84
85@@ -324,7 +332,7 @@
86 void tee_putc(int c, FILE *file);
87 static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
88 /* The names of functions that actually do the manipulation. */
89-static int get_options(int argc,char **argv);
90+static int process_options(void);
91 static int com_quit(string *str,const char*),
92 com_go(string *str,const char*), com_ego(string *str,const char*),
93 com_print(string *str,const char*),
94@@ -338,7 +346,7 @@
95 com_nopager(string *str, const char*), com_pager(string *str, const char*);
96
97 static int read_and_execute(bool interactive);
98-static int sql_connect(char *host,char *database,char *user,char *password,
99+static int sql_connect(const string &host, const string &database, const string &user, const string &password,
100 uint32_t silent);
101 static const char *server_version_string(drizzle_con_st *con);
102 static int put_info(const char *str,INFO_TYPE info,uint32_t error,
103@@ -1157,7 +1165,6 @@
104 Commands((char *)NULL, 0, 0, 0, "")
105 };
106
107-static const char *load_default_groups[]= { "drizzle","client",0 };
108
109 int history_length;
110 static int not_in_history(const char *line);
111@@ -1300,8 +1307,71 @@
112 return executed;
113 }
114
115+static void check_timeout_value(uint32_t in_connect_timeout)
116+{
117+ opt_connect_timeout= 0;
118+ if (in_connect_timeout > 3600*12)
119+ {
120+ cout<<N_("Error: Invalid Value for connect_timeout");
121+ exit(-1);
122+ }
123+ opt_connect_timeout= in_connect_timeout;
124+}
125+
126+static void check_max_input_line(uint32_t in_max_input_line)
127+{
128+ opt_max_input_line= 0;
129+ if (in_max_input_line<4096 || in_max_input_line>(int64_t)2*1024L*1024L*1024L)
130+ {
131+ cout<<N_("Error: Invalid Value for max_input_line");
132+ exit(-1);
133+ }
134+ opt_max_input_line= in_max_input_line/1024;
135+ opt_max_input_line*=1024;
136+}
137+
138+static pair<string, string> parse_password_arg(std::string s)
139+{
140+ if (s.find("--password") == 0)
141+ {
142+ if (s == "--password")
143+ {
144+ // Check if no argument is passed.
145+ return make_pair("password", "☃PASSWORD☃");
146+ }
147+
148+ if (s.substr(10,3) == "=\"\"")
149+ {
150+ // Check if --password=""
151+ return make_pair("password","☃PASSWORD☃");
152+ }
153+
154+ if (s.substr(10) == "=")
155+ {
156+ // check if --password= and return a default value
157+ return make_pair("password","☃PASSWORD☃");
158+ }
159+
160+ if (s.length()>12 && s[10] == '\"')
161+ {
162+ // check if --password has quotes, remove quotes and return the value
163+ return make_pair("password", s.substr(11,s.length()-1));
164+ }
165+
166+ // if all above are false, it implies that --password=value, return value.
167+ return make_pair("password", s.substr(11));
168+ }
169+
170+ else
171+ {
172+ return make_pair(string(""), string(""));
173+ }
174+}
175+
176 int main(int argc,char *argv[])
177 {
178+try
179+{
180 #if defined(ENABLE_NLS)
181 # if defined(HAVE_LOCALE_H)
182 setlocale(LC_ALL, "");
183@@ -1310,12 +1380,160 @@
184 textdomain("drizzle");
185 #endif
186
187- MY_INIT(argv[0]);
188- delimiter_str= delimiter;
189+ po::options_description commandline_options("Options used only in command line");
190+ commandline_options.add_options()
191+ ("help,?",N_("Displays this help and exit."))
192+ ("batch,B",N_("Don't use history file. Disable interactive behavior. (Enables --silent)"))
193+ ("column-type-info", po::value<bool>(&column_types_flag)->default_value(false)->zero_tokens(),
194+ N_("Display column type information."))
195+ ("comments,c", po::value<bool>(&preserve_comments)->default_value(false)->zero_tokens(),
196+ N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"))
197+ ("compress,C", po::value<bool>(&opt_compress)->default_value(false)->zero_tokens(),
198+ N_("Use compression in server/client protocol."))
199+ ("vertical,E", po::value<bool>(&vertical)->default_value(false)->zero_tokens(),
200+ N_("Print the output of a query (rows) vertically."))
201+ ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
202+ N_("Continue even if we get an sql error."))
203+ ("named-commands,G", po::value<bool>(&named_cmds)->default_value(false)->zero_tokens(),
204+ N_("Enable named commands. Named commands mean this program's internal commands; see drizzle> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default."))
205+ ("no-named-commands,g",
206+ N_("Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead."))
207+ ("ignore-spaces,i", N_("Ignore space after function names."))
208+ ("no-beep,b", po::value<bool>(&opt_nobeep)->default_value(false)->zero_tokens(),
209+ N_("Turn off beep on error."))
210+ ("line-numbers", po::value<bool>(&line_numbers)->default_value(true)->zero_tokens(),
211+ N_("Write line numbers for errors."))
212+ ("skip-line-numbers,L",
213+ N_("Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead."))
214+ ("column-name", po::value<bool>(&column_names)->default_value(true)->zero_tokens(),
215+ N_("Write column names in results."))
216+ ("skip-column-names,N",
217+ N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."))
218+ ("set-variable,O", po::value<string>(),
219+ N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."))
220+ ("table,t", po::value<bool>(&output_tables)->default_value(false)->zero_tokens(),
221+ N_("Output in table format."))
222+ ("safe-updates,U", po::value<bool>(&safe_updates)->default_value(0)->zero_tokens(),
223+ N_("Only allow UPDATE and DELETE that uses keys."))
224+ ("i-am-a-dummy,U", po::value<bool>(&safe_updates)->default_value(0)->zero_tokens(),
225+ N_("Synonym for option --safe-updates, -U."))
226+ ("verbose,v", po::value<string>(&opt_verbose)->default_value(""),
227+ N_("-v vvv implies that verbose= 3, Used to specify verbose"))
228+ ("version,V", N_("Output version information and exit."))
229+ ("secure-auth", po::value<bool>(&opt_secure_auth)->default_value(false)->zero_tokens(),
230+ N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"))
231+ ("show-warnings", po::value<bool>(&show_warnings)->default_value(false)->zero_tokens(),
232+ N_("Show warnings after every statement."))
233+ ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(0),
234+ N_("Number of lines before each import progress report."))
235+ ("ping", po::value<bool>(&opt_ping)->default_value(false)->zero_tokens(),
236+ N_("Ping the server to check if it's alive."))
237+ ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
238+ N_("Configuration file defaults are not used if no-defaults is set"))
239+ ;
240+
241+ po::options_description drizzle_options("Options specific to the drizzle client");
242+ drizzle_options.add_options()
243+ ("auto-rehash", po::value<bool>(&opt_rehash)->default_value(true)->zero_tokens(),
244+ N_("Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash."))
245+ ("no-auto-rehash,A",N_("No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of drizzle_st and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead."))
246+ ("auto-vertical-output", po::value<bool>(&auto_vertical_output)->default_value(false)->zero_tokens(),
247+ N_("Automatically switch to vertical output mode if the result is wider than the terminal width."))
248+ ("database,D", po::value<string>(&current_db)->default_value("test"),
249+ N_("Database to use."))
250+ ("default-character-set",po::value<string>(),
251+ N_("(not used)"))
252+ ("delimiter", po::value<string>(&delimiter_str)->default_value(";"),
253+ N_("Delimiter to be used."))
254+ ("execute,e", po::value<string>(),
255+ N_("Execute command and quit. (Disables --force and history file)"))
256+ ("local-infile", po::value<bool>(&opt_local_infile)->default_value(false)->zero_tokens(),
257+ N_("Enable/disable LOAD DATA LOCAL INFILE."))
258+ ("unbuffered,n", po::value<bool>(&unbuffered)->default_value(false)->zero_tokens(),
259+ N_("Flush buffer after each query."))
260+ ("sigint-ignore", po::value<bool>(&opt_sigint_ignore)->default_value(false)->zero_tokens(),
261+ N_("Ignore SIGINT (CTRL-C)"))
262+ ("one-database,o", po::value<bool>(&one_database)->default_value(false)->zero_tokens(),
263+ N_("Only update the default database. This is useful for skipping updates to other database in the update log."))
264+ ("pager", po::value<string>(),
265+ N_("Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default."))
266+ ("disable-pager", po::value<bool>(&opt_nopager)->default_value(false)->zero_tokens(),
267+ N_("Disable pager and print to stdout. See interactive help (\\h) also."))
268+ ("prompt", po::value<string>(&current_prompt)->default_value(""),
269+ N_("Set the drizzle prompt to this value."))
270+ ("quick,q", po::value<bool>(&quick)->default_value(false)->zero_tokens(),
271+ N_("Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file."))
272+ ("raw,r", po::value<bool>(&opt_raw_data)->default_value(false)->zero_tokens(),
273+ N_("Write fields without conversion. Used with --batch."))
274+ ("reconnect", po::value<bool>(&opt_reconnect)->default_value(true)->zero_tokens(),
275+ N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."))
276+ ("shutdown", po::value<bool>(&opt_shutdown)->default_value(false)->zero_tokens(),
277+ N_("Shutdown the server"))
278+ ("silent,s", N_("Be more silent. Print results with a tab as separator, each row on new line."))
279+ ("tee", po::value<string>(),
280+ N_("Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default."))
281+ ("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(),
282+ N_("Disable outfile. See interactive help (\\h) also."))
283+ ("wait,w", N_("Wait and retry if connection is down."))
284+ ("connect_timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
285+ N_("Number of seconds before connection timeout."))
286+ ("max_input_line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
287+ N_("Max length of input line"))
288+ ("select_limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
289+ N_("Automatic limit for SELECT when using --safe-updates"))
290+ ("max_join_size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
291+ N_("Automatic limit for rows in a join when using --safe-updates"))
292+ ;
293+
294+ po::options_description client_options("Options specific to the client");
295+ client_options.add_options()
296+ ("mysql,m", po::value<bool>(&opt_mysql)->default_value(true)->zero_tokens(),
297+ N_("Use MySQL Protocol."))
298+ ("host,h", po::value<string>(&current_host)->default_value("localhost"),
299+ N_("Connect to host"))
300+ ("password,P", po::value<string>(&current_password)->default_value(""),
301+ N_("Password to use when connecting to server. If password is not given it's asked from the tty."))
302+ ("port,p", po::value<uint32_t>()->default_value(0),
303+ N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default"))
304+ ("user,u", po::value<string>(&current_user)->default_value(""),
305+ N_("User for login if not current user."))
306+ ("protocol",po::value<string>(),
307+ N_("The protocol of connection (tcp,socket,pipe,memory)."))
308+ ;
309+
310+ po::options_description long_options("Allowed Options");
311+ long_options.add(commandline_options).add(drizzle_options).add(client_options);
312+
313+ std::string system_config_dir_drizzle(SYSCONFDIR);
314+ system_config_dir_drizzle.append("/drizzle/drizzle.cnf");
315+
316+ std::string system_config_dir_client(SYSCONFDIR);
317+ system_config_dir_client.append("/drizzle/client.cnf");
318+
319+ po::variables_map vm;
320+
321+ po::store(po::command_line_parser(argc, argv).options(long_options).extra_parser(parse_password_arg).run(), vm);
322+
323+ if (! vm["no-defaults"].as<bool>())
324+ {
325+ ifstream user_drizzle_ifs("~/.drizzle/drizzleslap.cnf");
326+ po::store(parse_config_file(user_drizzle_ifs, drizzle_options), vm);
327+
328+ ifstream system_drizzle_ifs(system_config_dir_drizzle.c_str());
329+ store(parse_config_file(system_drizzle_ifs, drizzle_options), vm);
330+
331+ ifstream user_client_ifs("~/.drizzle/client.cnf");
332+ po::store(parse_config_file(user_client_ifs, client_options), vm);
333+
334+ ifstream system_client_ifs(system_config_dir_client.c_str());
335+ po::store(parse_config_file(system_client_ifs, client_options), vm);
336+ }
337+
338+ po::notify(vm);
339+
340 default_prompt= strdup(getenv("DRIZZLE_PS1") ?
341 getenv("DRIZZLE_PS1") :
342 "drizzle> ");
343-
344 if (default_prompt == NULL)
345 {
346 fprintf(stderr, _("Memory allocation error while constructing initial "
347@@ -1323,7 +1541,7 @@
348 exit(ENOMEM);
349 }
350 current_prompt= strdup(default_prompt);
351- if (current_prompt == NULL)
352+ if (current_prompt.empty())
353 {
354 fprintf(stderr, _("Memory allocation error while constructing initial "
355 "prompt. Aborting.\n"));
356@@ -1344,7 +1562,7 @@
357 strcpy(default_pager, tmp);
358 }
359 }
360- if (!isatty(0) || !isatty(1))
361+ if (! isatty(0) || ! isatty(1))
362 {
363 status.setBatch(1); opt_silent=1;
364 ignore_errors=0;
365@@ -1367,18 +1585,183 @@
366 close(stdout_fileno_copy); /* Clean up dup(). */
367 }
368
369- internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
370- defaults_argv=argv;
371- if (get_options(argc, (char **) argv))
372- {
373- internal::free_defaults(defaults_argv);
374- internal::my_end();
375+ if (vm.count("default-character-set"))
376+ default_charset_used= 1;
377+
378+ if (vm.count("delimiter"))
379+ {
380+ /* Check that delimiter does not contain a backslash */
381+ if (! strstr(delimiter_str.c_str(), "\\"))
382+ {
383+ delimiter= (char *)delimiter_str.c_str();
384+ }
385+ else
386+ {
387+ put_info(_("DELIMITER cannot contain a backslash character"),
388+ INFO_ERROR,0,0);
389+ exit(-1);
390+ }
391+
392+ delimiter_length= (uint32_t)strlen(delimiter);
393+ }
394+ if (vm.count("tee"))
395+ {
396+ if (vm["tee"].as<string>().empty())
397+ {
398+ if (opt_outfile)
399+ end_tee();
400+ }
401+ else
402+ init_tee(vm["tee"].as<string>().c_str());
403+ }
404+ if (vm["disable-tee"].as<bool>() == true)
405+ {
406+ if (opt_outfile)
407+ end_tee();
408+ }
409+ if (vm.count("pager"))
410+ {
411+ if (vm["pager"].as<string>().empty())
412+ opt_nopager= 1;
413+ else
414+ {
415+ opt_nopager= 0;
416+ if (vm[pager].as<string>().length())
417+ {
418+ default_pager_set= 1;
419+ strncpy(pager, vm["pager"].as<string>().c_str(), sizeof(pager) - 1);
420+ strcpy(default_pager, pager);
421+ }
422+ else if (default_pager_set)
423+ strcpy(pager, default_pager);
424+ else
425+ opt_nopager= 1;
426+ }
427+ }
428+ if (vm.count("disable-pager"))
429+ {
430+ opt_nopager= 1;
431+ }
432+
433+ if (vm.count("no-auto-rehash"))
434+ opt_rehash= 0;
435+
436+ if (vm.count("skip-column-names"))
437+ column_names= 0;
438+
439+ if (vm.count("execute"))
440+ {
441+ status.setBatch(1);
442+ status.setAddToHistory(1);
443+ if (status.getLineBuff() == NULL)
444+ status.setLineBuff(opt_max_input_line,NULL);
445+ if (status.getLineBuff() == NULL)
446+ {
447+ internal::my_end();
448+ exit(1);
449+ }
450+ status.getLineBuff()->addString(vm["execute"].as<string>().c_str());
451+ }
452+
453+ if (one_database)
454+ skip_updates= true;
455+
456+ if (vm.count("port"))
457+ {
458+ opt_drizzle_port= vm["port"].as<uint32_t>();
459+
460+ /* If the port number is > 65535 it is not a valid port
461+ This also helps with potential data loss casting unsigned long to a
462+ uint32_t. */
463+ if ((opt_drizzle_port == 0) || (opt_drizzle_port > 65535))
464+ {
465+ printf(_("Error: Value of %" PRIu32 " supplied for port is not valid.\n"), opt_drizzle_port);
466+ exit(-1);
467+ }
468+ }
469+
470+ if (vm.count("password"))
471+ {
472+ if (!opt_password.empty())
473+ opt_password.erase();
474+ if (current_password=="☃PASSWORD☃")
475+ opt_password= "";
476+ else
477+ opt_password= current_password;
478+ char *start= (char *)current_password.c_str();
479+ char *temp_pass= (char *)current_password.c_str();
480+ while (*temp_pass)
481+ {
482+ /* Overwriting password with 'x' */
483+ *temp_pass++= 'x';
484+ }
485+ if (*start)
486+ {
487+ start[1]= 0;
488+ }
489+ tty_password= 0;
490+ }
491+ else
492+ {
493+ tty_password= 1;
494+ }
495+
496+
497+ if (!opt_verbose.empty())
498+ {
499+ verbose= opt_verbose.length();
500+ }
501+
502+ if (vm.count("batch"))
503+ {
504+ status.setBatch(1);
505+ status.setAddToHistory(0);
506+ set_if_bigger(opt_silent,1); // more silent
507+ }
508+ if (vm.count("silent"))
509+ {
510+ opt_silent++;
511+ }
512+ if (vm.count("version"))
513+ {
514+ printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
515+ internal::my_progname, VER.c_str(), drizzle_version(),
516+ HOST_VENDOR, HOST_OS, HOST_CPU,
517+ rl_library_version);
518+
519+ exit(0);
520+ }
521+
522+ if (vm.count("help"))
523+ {
524+ printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
525+ internal::my_progname, VER.c_str(), drizzle_version(),
526+ HOST_VENDOR, HOST_OS, HOST_CPU,
527+ rl_library_version);
528+ printf(_("Copyright (C) 2008 Sun Microsystems\n"
529+ "This software comes with ABSOLUTELY NO WARRANTY. "
530+ "This is free software,\n"
531+ "and you are welcome to modify and redistribute it "
532+ "under the GPL license\n"));
533+ printf(_("Usage: %s [OPTIONS] [database]\n"), internal::my_progname);
534+ cout<<long_options;
535+ exit(0);
536+ }
537+
538+
539+ if (process_options())
540+ {
541 exit(1);
542 }
543
544+ if (argc == 1)
545+ {
546+ skip_updates= 0;
547+ current_db.erase();
548+ current_db= strdup(*argv);
549+ }
550 memset(&drizzle, 0, sizeof(drizzle));
551- if (sql_connect(current_host,current_db,current_user,opt_password,
552- opt_silent))
553+ if (sql_connect(current_host, current_db, current_user, opt_password,opt_silent))
554 {
555 quick= 1; // Avoid history
556 status.setExitStatus(1);
557@@ -1389,8 +1772,6 @@
558 if (execute_commands(&command_error) != false)
559 {
560 /* we've executed a command so exit before we go into readline mode */
561- internal::free_defaults(defaults_argv);
562- internal::my_end();
563 exit(command_error);
564 }
565
566@@ -1399,8 +1780,6 @@
567 status.setLineBuff(opt_max_input_line, stdin);
568 if (status.getLineBuff() == NULL)
569 {
570- internal::free_defaults(defaults_argv);
571- internal::my_end();
572 exit(1);
573 }
574 }
575@@ -1436,7 +1815,7 @@
576 server_version_string(&con));
577 put_info(output_buff, INFO_INFO, 0, 0);
578
579- initialize_readline(current_prompt);
580+ initialize_readline((char *)current_prompt.c_str());
581 if (!status.getBatch() && !quick)
582 {
583 /* read-history from file, default ~/.drizzle_history*/
584@@ -1480,7 +1859,12 @@
585 if (opt_outfile)
586 end_tee();
587 drizzle_end(0);
588+}
589
590+ catch(exception &err)
591+ {
592+ cerr<<"Error:"<<err.what()<<endl;
593+ }
594 return(0); // Keep compiler happy
595 }
596
597@@ -1505,18 +1889,16 @@
598 delete glob_buffer;
599 if (processed_prompt)
600 delete processed_prompt;
601- free(opt_password);
602+ opt_password.erase();
603 free(histfile);
604 free(histfile_tmp);
605- free(current_db);
606- free(current_host);
607- free(current_user);
608+ current_db.erase();
609+ current_host.erase();
610+ current_user.erase();
611 free(full_username);
612 free(part_username);
613 free(default_prompt);
614- free(current_prompt);
615- internal::free_defaults(defaults_argv);
616- internal::my_end();
617+ current_prompt.erase();
618 exit(status.getExitStatus());
619 }
620
621@@ -1539,8 +1921,8 @@
622 goto err;
623 }
624
625- if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host,
626- opt_drizzle_port, current_user, opt_password, NULL,
627+ if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host.c_str(),
628+ opt_drizzle_port, current_user.c_str(), opt_password.c_str(), NULL,
629 opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
630 {
631 goto err;
632@@ -1575,369 +1957,12 @@
633 }
634 #endif
635
636-static struct option my_long_options[] =
637-{
638- {"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
639- 0, 0, 0, 0, 0},
640- {"help", 'I', N_("Synonym for -?"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
641- 0, 0, 0, 0, 0},
642- {"auto-rehash", OPT_AUTO_REHASH,
643- N_("Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash."),
644- (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
645- 0, 0},
646- {"no-auto-rehash", 'A',
647- N_("No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of drizzle_st and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead."),
648- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
649- {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
650- N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
651- (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
652- {"batch", 'B',
653- N_("Don't use history file. Disable interactive behavior. (Enables --silent)"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
654- {"column-type-info", OPT_COLUMN_TYPES, N_("Display column type information."),
655- (char**) &column_types_flag, (char**) &column_types_flag,
656- 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
657- {"comments", 'c', N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"),
658- (char**) &preserve_comments, (char**) &preserve_comments,
659- 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
660- {"compress", 'C', N_("Use compression in server/client protocol."),
661- (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
662- 0, 0, 0},
663- {"database", 'D', N_("Database to use."), (char**) &current_db,
664- (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
665- {"default-character-set", OPT_DEFAULT_CHARSET,
666- N_("(not used)"), 0,
667- 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
668- {"delimiter", OPT_DELIMITER, N_("Delimiter to be used."), (char**) &delimiter_str,
669- (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
670- {"execute", 'e', N_("Execute command and quit. (Disables --force and history file)"), 0,
671- 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
672- {"vertical", 'E', N_("Print the output of a query (rows) vertically."),
673- (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
674- 0},
675- {"force", 'f', N_("Continue even if we get an sql error."),
676- (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
677- 0, 0, 0, 0},
678- {"named-commands", 'G',
679- N_("Enable named commands. Named commands mean this program's internal commands; see drizzle> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default."),
680- (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
681- 0, 0},
682- {"no-named-commands", 'g',
683- N_("Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead."),
684- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
685- {"ignore-spaces", 'i', N_("Ignore space after function names."), 0, 0, 0,
686- GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
687- {"local-infile", OPT_LOCAL_INFILE, N_("Enable/disable LOAD DATA LOCAL INFILE."),
688- (char**) &opt_local_infile,
689- (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
690- {"no-beep", 'b', N_("Turn off beep on error."), (char**) &opt_nobeep,
691- (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
692- {"host", 'h', N_("Connect to host."), (char**) &current_host,
693- (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
694- {"line-numbers", OPT_LINE_NUMBERS, N_("Write line numbers for errors."),
695- (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
696- NO_ARG, 1, 0, 0, 0, 0, 0},
697- {"skip-line-numbers", 'L', N_("Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead."), 0, 0, 0, GET_NO_ARG,
698- NO_ARG, 0, 0, 0, 0, 0, 0},
699- {"unbuffered", 'n', N_("Flush buffer after each query."), (char**) &unbuffered,
700- (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
701- {"column-names", OPT_COLUMN_NAMES, N_("Write column names in results."),
702- (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
703- NO_ARG, 1, 0, 0, 0, 0, 0},
704- {"skip-column-names", 'N',
705- N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
706- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
707- {"set-variable", 'O',
708- N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."),
709- 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
710- {"sigint-ignore", OPT_SIGINT_IGNORE, N_("Ignore SIGINT (CTRL-C)"),
711- (char**) &opt_sigint_ignore, (char**) &opt_sigint_ignore, 0, GET_BOOL,
712- NO_ARG, 0, 0, 0, 0, 0, 0},
713- {"one-database", 'o',
714- N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
715- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
716- {"pager", OPT_PAGER,
717- N_("Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default."),
718- 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
719- {"no-pager", OPT_NOPAGER,
720- N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
721- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
722- {"password", 'P',
723- N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
724- 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
725- {"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
726- N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
727- 0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
728- {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
729- (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
730- REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
731- {"quick", 'q',
732- N_("Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file."),
733- (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
734- {"raw", 'r', N_("Write fields without conversion. Used with --batch."),
735- (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
736- 0, 0, 0},
737- {"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."),
738- (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
739- {"shutdown", OPT_SHUTDOWN, N_("Shutdown the server."),
740- (char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
741- {"silent", 's', N_("Be more silent. Print results with a tab as separator, each row on new line."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
742- 0, 0},
743- {"table", 't', N_("Output in table format."), (char**) &output_tables,
744- (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
745- {"tee", OPT_TEE,
746- N_("Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default."),
747- 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
748- {"no-tee", OPT_NOTEE, N_("Disable outfile. See interactive help (\\h) also. WARNING: option deprecated; use --disable-tee instead"), 0, 0, 0, GET_NO_ARG,
749- NO_ARG, 0, 0, 0, 0, 0, 0},
750- {"user", 'u', N_("User for login if not current user."), (char**) &current_user,
751- (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
752- {"safe-updates", 'U', N_("Only allow UPDATE and DELETE that uses keys."),
753- (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
754- 0, 0, 0, 0},
755- {"i-am-a-dummy", 'U', N_("Synonym for option --safe-updates, -U."),
756- (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
757- 0, 0, 0, 0},
758- {"verbose", 'v', N_("Write more. (-v -v -v gives the table output format)."), 0,
759- 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
760- {"version", 'V', N_("Output version information and exit."), 0, 0, 0,
761- GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
762- {"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_NO_ARG,
763- NO_ARG, 0, 0, 0, 0, 0, 0},
764- {"connect_timeout", OPT_CONNECT_TIMEOUT,
765- N_("Number of seconds before connection timeout."),
766- (char**) &opt_connect_timeout,
767- (char**) &opt_connect_timeout, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 3600*12, 0,
768- 0, 0},
769- {"max_input_line", OPT_MAX_INPUT_LINE,
770- N_("Max length of input line"),
771- (char**) &opt_max_input_line, (char**) &opt_max_input_line, 0,
772- GET_UINT32, REQUIRED_ARG, 16 *1024L*1024L, 4096,
773- (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
774- {"select_limit", OPT_SELECT_LIMIT,
775- N_("Automatic limit for SELECT when using --safe-updates"),
776- (char**) &select_limit,
777- (char**) &select_limit, 0, GET_UINT32, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
778- 0, 1, 0},
779- {"max_join_size", OPT_MAX_JOIN_SIZE,
780- N_("Automatic limit for rows in a join when using --safe-updates"),
781- (char**) &max_join_size,
782- (char**) &max_join_size, 0, GET_UINT32, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
783- 0, 1, 0},
784- {"secure-auth", OPT_SECURE_AUTH, N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"), (char**) &opt_secure_auth,
785- (char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
786- {"show-warnings", OPT_SHOW_WARNINGS, N_("Show warnings after every statement."),
787- (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
788- 0, 0, 0, 0, 0, 0},
789- {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of lines before each import progress report."),
790- (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
791- 0, 0, 0, 0, 0, 0},
792- {"ping", OPT_PING, N_("Ping the server to check if it's alive."),
793- (char**) &opt_ping, (char**) &opt_ping, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
794- {"mysql", 'm', N_("Use MySQL Protocol."),
795- (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
796- 0, 0, 0},
797- { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
798-};
799-
800-
801-static void usage(int version)
802-{
803- const char* readline= "readline";
804-
805- printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using %s %s\n"),
806- internal::my_progname, VER.c_str(), drizzle_version(),
807- HOST_VENDOR, HOST_OS, HOST_CPU,
808- readline, rl_library_version);
809-
810- if (version)
811- return;
812- printf(_("Copyright (C) 2008 Sun Microsystems\n"
813- "This software comes with ABSOLUTELY NO WARRANTY. "
814- "This is free software,\n"
815- "and you are welcome to modify and redistribute it "
816- "under the GPL license\n"));
817- printf(_("Usage: %s [OPTIONS] [database]\n"), internal::my_progname);
818- my_print_help(my_long_options);
819- internal::print_defaults("drizzle", load_default_groups);
820- my_print_variables(my_long_options);
821-}
822-
823-
824-static int get_one_option(int optid, const struct option *, char *argument)
825-{
826- char *endchar= NULL;
827- uint64_t temp_drizzle_port= 0;
828-
829- switch(optid) {
830- case OPT_DEFAULT_CHARSET:
831- default_charset_used= 1;
832- break;
833- case OPT_DELIMITER:
834- if (argument == disabled_my_option)
835- {
836- strcpy(delimiter, DEFAULT_DELIMITER);
837- }
838- else
839- {
840- /* Check that delimiter does not contain a backslash */
841- if (!strstr(argument, "\\"))
842- {
843- strncpy(delimiter, argument, sizeof(delimiter) - 1);
844- }
845- else
846- {
847- put_info(_("DELIMITER cannot contain a backslash character"),
848- INFO_ERROR,0,0);
849- return false;
850- }
851- }
852- delimiter_length= (uint32_t)strlen(delimiter);
853- delimiter_str= delimiter;
854- break;
855- case OPT_TEE:
856- if (argument == disabled_my_option)
857- {
858- if (opt_outfile)
859- end_tee();
860- }
861- else
862- init_tee(argument);
863- break;
864- case OPT_NOTEE:
865- printf(_("WARNING: option deprecated; use --disable-tee instead.\n"));
866- if (opt_outfile)
867- end_tee();
868- break;
869- case OPT_PAGER:
870- if (argument == disabled_my_option)
871- opt_nopager= 1;
872- else
873- {
874- opt_nopager= 0;
875- if (argument && strlen(argument))
876- {
877- default_pager_set= 1;
878- strncpy(pager, argument, sizeof(pager) - 1);
879- strcpy(default_pager, pager);
880- }
881- else if (default_pager_set)
882- strcpy(pager, default_pager);
883- else
884- opt_nopager= 1;
885- }
886- break;
887- case OPT_NOPAGER:
888- printf(_("WARNING: option deprecated; use --disable-pager instead.\n"));
889- opt_nopager= 1;
890- break;
891- case OPT_SERVER_ARG:
892- printf(_("WARNING: --server-arg option not supported in this configuration.\n"));
893- break;
894- case 'A':
895- opt_rehash= 0;
896- break;
897- case 'N':
898- column_names= 0;
899- break;
900- case 'e':
901- status.setBatch(1);
902- status.setAddToHistory(1);
903- if (status.getLineBuff() == NULL)
904- status.setLineBuff(opt_max_input_line,NULL);
905- if (status.getLineBuff() == NULL)
906- {
907- internal::my_end();
908- exit(1);
909- }
910- status.getLineBuff()->addString(argument);
911- break;
912- case 'o':
913- if (argument == disabled_my_option)
914- one_database= 0;
915- else
916- one_database= skip_updates= 1;
917- break;
918- case 'p':
919- temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
920- /* if there is an alpha character this is not a valid port */
921- if (strlen(endchar) != 0)
922- {
923- put_info(_("Non-integer value supplied for port. If you are trying to enter a password please use --password instead."), INFO_ERROR, 0, 0);
924- return false;
925- }
926- /* If the port number is > 65535 it is not a valid port
927- This also helps with potential data loss casting unsigned long to a
928- uint32_t. */
929- if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
930- {
931- put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0);
932- return false;
933- }
934- else
935- {
936- opt_drizzle_port= (uint32_t) temp_drizzle_port;
937- }
938- break;
939- case 'P':
940- /* Don't require password */
941- if (argument == disabled_my_option)
942- {
943- argument= (char*) "";
944- }
945- if (argument)
946- {
947- char *start= argument;
948- free(opt_password);
949- opt_password= strdup(argument);
950- while (*argument)
951- {
952- /* Overwriting password with 'x' */
953- *argument++= 'x';
954- }
955- if (*start)
956- {
957- start[1]= 0;
958- }
959- tty_password= 0;
960- }
961- else
962- {
963- tty_password= 1;
964- }
965- break;
966- case 's':
967- if (argument == disabled_my_option)
968- opt_silent= 0;
969- else
970- opt_silent++;
971- break;
972- case 'v':
973- if (argument == disabled_my_option)
974- verbose= 0;
975- else
976- verbose++;
977- break;
978- case 'B':
979- status.setBatch(1);
980- status.setAddToHistory(0);
981- set_if_bigger(opt_silent,1); // more silent
982- break;
983- case 'V':
984- usage(1);
985- exit(0);
986- case 'I':
987- case '?':
988- usage(0);
989- exit(0);
990- }
991- return 0;
992-}
993-
994-
995-static int get_options(int argc, char **argv)
996+
997+
998+static int process_options(void)
999 {
1000 char *tmp, *pagpoint;
1001- int ho_error;
1002+
1003
1004 tmp= (char *) getenv("DRIZZLE_HOST");
1005 if (tmp)
1006@@ -1953,8 +1978,7 @@
1007 strcpy(pager, pagpoint);
1008 strcpy(default_pager, pager);
1009
1010- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
1011- exit(ho_error);
1012+ //
1013
1014 if (status.getBatch()) /* disable pager and outfile in this case */
1015 {
1016@@ -1967,20 +1991,8 @@
1017 connect_flag= DRIZZLE_CAPABILITIES_NONE; /* Not in interactive mode */
1018 }
1019
1020- if (argc > 1)
1021- {
1022- usage(0);
1023- exit(1);
1024- }
1025- if (argc == 1)
1026- {
1027- skip_updates= 0;
1028- free(current_db);
1029- current_db= strdup(*argv);
1030- }
1031 if (tty_password)
1032 opt_password= client_get_tty_password(NULL);
1033-
1034 return(0);
1035 }
1036
1037@@ -2582,7 +2594,7 @@
1038 drizzle_column_st *sql_field;
1039 string tmp_str, tmp_str_lower;
1040
1041- if (status.getBatch() || quick || !current_db)
1042+ if (status.getBatch() || quick || current_db.empty())
1043 return; // We don't need completion in batches
1044 if (!rehash)
1045 return;
1046@@ -2717,8 +2729,8 @@
1047 drizzle_return_t ret;
1048 drizzle_result_st res;
1049
1050- free(current_db);
1051- current_db= NULL;
1052+ current_db.erase();
1053+ current_db= "";
1054 /* In case of error below current_db will be NULL */
1055 if (drizzle_query_str(&con, &res, "SELECT DATABASE()", &ret) != NULL)
1056 {
1057@@ -3746,12 +3758,12 @@
1058 tmp= get_arg(buff, 0);
1059 if (tmp && *tmp)
1060 {
1061- free(current_db);
1062+ current_db.erase();
1063 current_db= strdup(tmp);
1064 tmp= get_arg(buff, 1);
1065 if (tmp)
1066 {
1067- free(current_host);
1068+ current_host.erase();
1069 current_host=strdup(tmp);
1070 }
1071 }
1072@@ -3766,7 +3778,7 @@
1073 }
1074 else
1075 opt_rehash= 0;
1076- error=sql_connect(current_host,current_db,current_user,opt_password,0);
1077+ error=sql_connect(current_host, current_db, current_user, opt_password,0);
1078 opt_rehash= save_rehash;
1079
1080 if (connected)
1081@@ -3774,7 +3786,7 @@
1082 sprintf(buff,"Connection id: %u",drizzle_con_thread_id(&con));
1083 put_info(buff,INFO_INFO,0,0);
1084 sprintf(buff,"Current database: %.128s\n",
1085- current_db ? current_db : "*** NONE ***");
1086+ !current_db.empty() ? current_db.c_str() : "*** NONE ***");
1087 put_info(buff,INFO_INFO,0,0);
1088 }
1089 return error;
1090@@ -3896,7 +3908,7 @@
1091 */
1092 get_current_db();
1093
1094- if (!current_db || strcmp(current_db,tmp))
1095+ if (current_db.empty() || strcmp(current_db.c_str(),tmp))
1096 {
1097 if (one_database)
1098 {
1099@@ -3948,7 +3960,7 @@
1100 else
1101 drizzle_result_free(&result);
1102 }
1103- free(current_db);
1104+ current_db.erase();
1105 current_db= strdup(tmp);
1106 if (select_db > 1)
1107 build_completion_hash(opt_rehash, 1);
1108@@ -4037,11 +4049,10 @@
1109
1110
1111 static int
1112-sql_connect(char *host,char *database,char *user,char *password,
1113+sql_connect(const string &host, const string &database, const string &user, const string &password,
1114 uint32_t silent)
1115 {
1116 drizzle_return_t ret;
1117-
1118 if (connected)
1119 {
1120 connected= 0;
1121@@ -4049,8 +4060,8 @@
1122 drizzle_free(&drizzle);
1123 }
1124 drizzle_create(&drizzle);
1125- if (drizzle_con_add_tcp(&drizzle, &con, host, opt_drizzle_port, user,
1126- password, database, opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
1127+ if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(), opt_drizzle_port, (char *)user.c_str(),
1128+ (char *)password.c_str(), (char *)database.c_str(), opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
1129 {
1130 (void) put_error(&con, NULL);
1131 (void) fflush(stdout);
1132@@ -4106,7 +4117,12 @@
1133 drizzle_return_t ret;
1134
1135 tee_puts("--------------", stdout);
1136- usage(1); /* Print version */
1137+ printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
1138+ internal::my_progname, VER.c_str(), drizzle_version(),
1139+ HOST_VENDOR, HOST_OS, HOST_CPU,
1140+ rl_library_version); /* Print version */
1141+
1142+
1143 if (connected)
1144 {
1145 tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_con_thread_id(&con));
1146@@ -4452,7 +4468,7 @@
1147 struct tm *t = localtime(&lclock);
1148
1149 /* parse thru the settings for the prompt */
1150- for (char *c= current_prompt; *c; (void)*c++)
1151+ for (char *c= (char *)current_prompt.c_str(); *c; (void)*c++)
1152 {
1153 if (*c != PROMPT_CHAR)
1154 {
1155@@ -4479,7 +4495,7 @@
1156 processed_prompt->append("not_connected");
1157 break;
1158 case 'd':
1159- processed_prompt->append(current_db ? current_db : "(none)");
1160+ processed_prompt->append(!current_db.empty() ? current_db.c_str() : "(none)");
1161 break;
1162 case 'h':
1163 {
1164@@ -4516,13 +4532,13 @@
1165 if (!full_username)
1166 init_username();
1167 processed_prompt->append(full_username ? full_username :
1168- (current_user ? current_user : "(unknown)"));
1169+ (!current_user.empty() ? current_user.c_str() : "(unknown)"));
1170 break;
1171 case 'u':
1172 if (!full_username)
1173 init_username();
1174 processed_prompt->append(part_username ? part_username :
1175- (current_user ? current_user : "(unknown)"));
1176+ (!current_user.empty() ? current_user.c_str() : "(unknown)"));
1177 break;
1178 case PROMPT_CHAR:
1179 {
1180@@ -4601,7 +4617,7 @@
1181 processed_prompt->append("\t");
1182 break;
1183 case 'l':
1184- processed_prompt->append(delimiter_str);
1185+ processed_prompt->append(delimiter_str.c_str());
1186 break;
1187 default:
1188 processed_prompt->append(c, 1);
1189@@ -4649,9 +4665,9 @@
1190 tee_fprintf(stdout, "Memory allocation error. Not changing prompt\n");
1191 else
1192 {
1193- free(current_prompt);
1194+ current_prompt.erase();
1195 current_prompt= tmpptr;
1196- tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt);
1197+ tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt.c_str());
1198 }
1199 return 0;
1200 }
1201
1202=== modified file 'client/include.am'
1203--- client/include.am 2010-06-02 16:51:50 +0000
1204+++ client/include.am 2010-06-03 17:20:45 +0000
1205@@ -45,7 +45,7 @@
1206
1207
1208 client_drizzle_SOURCES= client/drizzle.cc client/linebuffer.cc
1209-client_drizzle_LDADD= ${CLIENT_LDADD} ${READLINE_LIBS}
1210+client_drizzle_LDADD= ${CLIENT_LDADD} ${READLINE_LIBS} ${BOOST_LIBS}
1211 client_drizzle_CXXFLAGS= ${CLIENT_CXXFLAGS}
1212
1213 client_drizzledump_SOURCES= client/drizzledump.cc