Merge lp:~vjsamuel/drizzle/refactor-drizzle into lp:~drizzle-trunk/drizzle/development
- refactor-drizzle
- Merge into development
Status: | Merged |
---|---|
Approved by: | Brian Aker |
Approved revision: | 1584 |
Merged at revision: | 1594 |
Proposed branch: | lp:~vjsamuel/drizzle/refactor-drizzle |
Merge into: | lp:~drizzle-trunk/drizzle/development |
Diff against target: |
1221 lines (+458/-436) 2 files modified
client/drizzle.cc (+457/-435) client/include.am (+1/-1) |
To merge this branch: | bzr merge lp:~vjsamuel/drizzle/refactor-drizzle |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jay Pipes | Pending | ||
Brian Aker | Pending | ||
Monty Taylor | Pending | ||
Review via email:
|
This proposal supersedes a proposal from 2010-06-03.
Commit message
Description of the change
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Jay Pipes (jaypipes) wrote : Posted in a previous version of this proposal | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Monty Taylor (mordred) wrote : Posted in a previous version of this proposal | # |
Mentioned on IRC, but for the record:
error=
it might be nicer to change the sql_connect function to take arguments of const string& for host, db and current_user.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Stewart Smith (stewart) wrote : Posted in a previous version of this proposal | # |
On Thu, 03 Jun 2010 10:41:05 -0000, Vijay Samuel <email address hidden> wrote:
> + return make_pair(
snowman? special characters probably shouldn't be in source.
--
Stewart Smith
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Monty Taylor (mordred) wrote : Posted in a previous version of this proposal | # |
-----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(
>
> 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://
iEYEARECAAYFAkw
GjMAoMV/
=QFpi
-----END PGP SIGNATURE-----
- 1584. By Vijay Samuel <vijay@vijay>
-
Merge fix for additional parser for --password.
Preview Diff
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-04 16:41:24 +0000 | |||
4 | @@ -37,6 +37,7 @@ | |||
5 | 37 | #include <string> | 37 | #include <string> |
6 | 38 | #include <drizzled/gettext.h> | 38 | #include <drizzled/gettext.h> |
7 | 39 | #include <iostream> | 39 | #include <iostream> |
8 | 40 | #include <fstream> | ||
9 | 40 | #include <map> | 41 | #include <map> |
10 | 41 | #include <algorithm> | 42 | #include <algorithm> |
11 | 42 | #include <limits.h> | 43 | #include <limits.h> |
12 | @@ -139,9 +140,11 @@ | |||
13 | 139 | #undef vidattr | 140 | #undef vidattr |
14 | 140 | #define vidattr(A) {} // Can't get this to work | 141 | #define vidattr(A) {} // Can't get this to work |
15 | 141 | #endif | 142 | #endif |
16 | 143 | #include <boost/program_options.hpp> | ||
17 | 142 | 144 | ||
18 | 143 | using namespace drizzled; | 145 | using namespace drizzled; |
19 | 144 | using namespace std; | 146 | using namespace std; |
20 | 147 | namespace po=boost::program_options; | ||
21 | 145 | 148 | ||
22 | 146 | const string VER("14.14"); | 149 | const string VER("14.14"); |
23 | 147 | /* Don't try to make a nice table if the data is too big */ | 150 | /* Don't try to make a nice table if the data is too big */ |
24 | @@ -149,9 +152,9 @@ | |||
25 | 149 | 152 | ||
26 | 150 | /* Buffer to hold 'version' and 'version_comment' */ | 153 | /* Buffer to hold 'version' and 'version_comment' */ |
27 | 151 | const int MAX_SERVER_VERSION_LENGTH= 128; | 154 | const int MAX_SERVER_VERSION_LENGTH= 128; |
28 | 155 | const string PASSWORD_SENTINEL("\0\0\0\0\0", 5); | ||
29 | 152 | 156 | ||
30 | 153 | #define PROMPT_CHAR '\\' | 157 | #define PROMPT_CHAR '\\' |
31 | 154 | #define DEFAULT_DELIMITER ";" | ||
32 | 155 | 158 | ||
33 | 156 | class Status | 159 | class Status |
34 | 157 | { | 160 | { |
35 | @@ -260,7 +263,6 @@ | |||
36 | 260 | static map<string, string> completion_map; | 263 | static map<string, string> completion_map; |
37 | 261 | static string completion_string; | 264 | static string completion_string; |
38 | 262 | 265 | ||
39 | 263 | static char **defaults_argv; | ||
40 | 264 | 266 | ||
41 | 265 | enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT}; | 267 | enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT}; |
42 | 266 | typedef enum enum_info_type INFO_TYPE; | 268 | typedef enum enum_info_type INFO_TYPE; |
43 | @@ -279,15 +281,14 @@ | |||
44 | 279 | default_pager_set= false, opt_sigint_ignore= false, | 281 | default_pager_set= false, opt_sigint_ignore= false, |
45 | 280 | auto_vertical_output= false, | 282 | auto_vertical_output= false, |
46 | 281 | show_warnings= false, executing_query= false, interrupted_query= false, | 283 | show_warnings= false, executing_query= false, interrupted_query= false, |
49 | 282 | opt_mysql= false; | 284 | opt_mysql= false, opt_local_infile; |
50 | 283 | static uint32_t show_progress_size= 0; | 285 | static uint32_t show_progress_size= 0; |
51 | 284 | static bool column_types_flag; | 286 | static bool column_types_flag; |
52 | 285 | static bool preserve_comments= false; | 287 | static bool preserve_comments= false; |
55 | 286 | static uint32_t opt_max_input_line, opt_drizzle_port= 0; | 288 | static uint32_t opt_max_input_line; |
56 | 287 | static int verbose= 0, opt_silent= 0, opt_local_infile= 0; | 289 | static uint32_t opt_drizzle_port= 0; |
57 | 290 | static int opt_silent, verbose= 0; | ||
58 | 288 | static drizzle_capabilities_t connect_flag= DRIZZLE_CAPABILITIES_NONE; | 291 | static drizzle_capabilities_t connect_flag= DRIZZLE_CAPABILITIES_NONE; |
59 | 289 | static char *current_host, *current_db, *current_user= NULL, | ||
60 | 290 | *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL; | ||
61 | 291 | static char *histfile; | 292 | static char *histfile; |
62 | 292 | static char *histfile_tmp; | 293 | static char *histfile_tmp; |
63 | 293 | static string *glob_buffer; | 294 | static string *glob_buffer; |
64 | @@ -298,6 +299,14 @@ | |||
65 | 298 | static uint32_t select_limit; | 299 | static uint32_t select_limit; |
66 | 299 | static uint32_t max_join_size; | 300 | static uint32_t max_join_size; |
67 | 300 | static uint32_t opt_connect_timeout= 0; | 301 | static uint32_t opt_connect_timeout= 0; |
68 | 302 | std::string current_db, | ||
69 | 303 | delimiter_str, | ||
70 | 304 | current_host, | ||
71 | 305 | current_prompt, | ||
72 | 306 | current_user, | ||
73 | 307 | opt_verbose, | ||
74 | 308 | current_password, | ||
75 | 309 | opt_password; | ||
76 | 301 | // TODO: Need to i18n these | 310 | // TODO: Need to i18n these |
77 | 302 | static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; | 311 | static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; |
78 | 303 | static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul", | 312 | static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul", |
79 | @@ -306,7 +315,7 @@ | |||
80 | 306 | static char pager[FN_REFLEN], outfile[FN_REFLEN]; | 315 | static char pager[FN_REFLEN], outfile[FN_REFLEN]; |
81 | 307 | static FILE *PAGER, *OUTFILE; | 316 | static FILE *PAGER, *OUTFILE; |
82 | 308 | static uint32_t prompt_counter; | 317 | static uint32_t prompt_counter; |
84 | 309 | static char delimiter[16]= DEFAULT_DELIMITER; | 318 | static char *delimiter= NULL; |
85 | 310 | static uint32_t delimiter_length= 1; | 319 | static uint32_t delimiter_length= 1; |
86 | 311 | unsigned short terminal_width= 80; | 320 | unsigned short terminal_width= 80; |
87 | 312 | 321 | ||
88 | @@ -324,7 +333,7 @@ | |||
89 | 324 | void tee_putc(int c, FILE *file); | 333 | void tee_putc(int c, FILE *file); |
90 | 325 | static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool); | 334 | static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool); |
91 | 326 | /* The names of functions that actually do the manipulation. */ | 335 | /* The names of functions that actually do the manipulation. */ |
93 | 327 | static int get_options(int argc,char **argv); | 336 | static int process_options(void); |
94 | 328 | static int com_quit(string *str,const char*), | 337 | static int com_quit(string *str,const char*), |
95 | 329 | com_go(string *str,const char*), com_ego(string *str,const char*), | 338 | com_go(string *str,const char*), com_ego(string *str,const char*), |
96 | 330 | com_print(string *str,const char*), | 339 | com_print(string *str,const char*), |
97 | @@ -338,7 +347,7 @@ | |||
98 | 338 | com_nopager(string *str, const char*), com_pager(string *str, const char*); | 347 | com_nopager(string *str, const char*), com_pager(string *str, const char*); |
99 | 339 | 348 | ||
100 | 340 | static int read_and_execute(bool interactive); | 349 | static int read_and_execute(bool interactive); |
102 | 341 | static int sql_connect(char *host,char *database,char *user,char *password, | 350 | static int sql_connect(const string &host, const string &database, const string &user, const string &password, |
103 | 342 | uint32_t silent); | 351 | uint32_t silent); |
104 | 343 | static const char *server_version_string(drizzle_con_st *con); | 352 | static const char *server_version_string(drizzle_con_st *con); |
105 | 344 | static int put_info(const char *str,INFO_TYPE info,uint32_t error, | 353 | static int put_info(const char *str,INFO_TYPE info,uint32_t error, |
106 | @@ -1157,7 +1166,6 @@ | |||
107 | 1157 | Commands((char *)NULL, 0, 0, 0, "") | 1166 | Commands((char *)NULL, 0, 0, 0, "") |
108 | 1158 | }; | 1167 | }; |
109 | 1159 | 1168 | ||
110 | 1160 | static const char *load_default_groups[]= { "drizzle","client",0 }; | ||
111 | 1161 | 1169 | ||
112 | 1162 | int history_length; | 1170 | int history_length; |
113 | 1163 | static int not_in_history(const char *line); | 1171 | static int not_in_history(const char *line); |
114 | @@ -1300,8 +1308,72 @@ | |||
115 | 1300 | return executed; | 1308 | return executed; |
116 | 1301 | } | 1309 | } |
117 | 1302 | 1310 | ||
118 | 1311 | static void check_timeout_value(uint32_t in_connect_timeout) | ||
119 | 1312 | { | ||
120 | 1313 | opt_connect_timeout= 0; | ||
121 | 1314 | if (in_connect_timeout > 3600*12) | ||
122 | 1315 | { | ||
123 | 1316 | cout<<N_("Error: Invalid Value for connect_timeout"); | ||
124 | 1317 | exit(-1); | ||
125 | 1318 | } | ||
126 | 1319 | opt_connect_timeout= in_connect_timeout; | ||
127 | 1320 | } | ||
128 | 1321 | |||
129 | 1322 | static void check_max_input_line(uint32_t in_max_input_line) | ||
130 | 1323 | { | ||
131 | 1324 | opt_max_input_line= 0; | ||
132 | 1325 | if (in_max_input_line<4096 || in_max_input_line>(int64_t)2*1024L*1024L*1024L) | ||
133 | 1326 | { | ||
134 | 1327 | cout<<N_("Error: Invalid Value for max_input_line"); | ||
135 | 1328 | exit(-1); | ||
136 | 1329 | } | ||
137 | 1330 | opt_max_input_line= in_max_input_line/1024; | ||
138 | 1331 | opt_max_input_line*=1024; | ||
139 | 1332 | } | ||
140 | 1333 | |||
141 | 1334 | static pair<string, string> parse_password_arg(std::string s) | ||
142 | 1335 | { | ||
143 | 1336 | if (s.find("--password") == 0) | ||
144 | 1337 | { | ||
145 | 1338 | if (s == "--password") | ||
146 | 1339 | { | ||
147 | 1340 | tty_password= true; | ||
148 | 1341 | //check if no argument is passed. | ||
149 | 1342 | return make_pair("password", PASSWORD_SENTINEL); | ||
150 | 1343 | } | ||
151 | 1344 | |||
152 | 1345 | if (s.substr(10,3) == "=\"\"" || s.substr(10,3) == "=''") | ||
153 | 1346 | { | ||
154 | 1347 | // Check if --password="" or --password='' | ||
155 | 1348 | return make_pair("password", PASSWORD_SENTINEL); | ||
156 | 1349 | } | ||
157 | 1350 | |||
158 | 1351 | if(s.substr(10) == "=" && s.length() == 11) | ||
159 | 1352 | { | ||
160 | 1353 | // check if --password= and return a default value | ||
161 | 1354 | return make_pair("password", PASSWORD_SENTINEL); | ||
162 | 1355 | } | ||
163 | 1356 | |||
164 | 1357 | if(s.length()>12 && (s[10] == '"' || s[10] == '\'')) | ||
165 | 1358 | { | ||
166 | 1359 | // check if --password has quotes, remove quotes and return the value | ||
167 | 1360 | return make_pair("password", s.substr(11,s.length()-1)); | ||
168 | 1361 | } | ||
169 | 1362 | |||
170 | 1363 | // if all above are false, it implies that --password=value, return value. | ||
171 | 1364 | return make_pair("password", s.substr(11)); | ||
172 | 1365 | } | ||
173 | 1366 | |||
174 | 1367 | else | ||
175 | 1368 | { | ||
176 | 1369 | return make_pair(string(""), string("")); | ||
177 | 1370 | } | ||
178 | 1371 | } | ||
179 | 1372 | |||
180 | 1303 | int main(int argc,char *argv[]) | 1373 | int main(int argc,char *argv[]) |
181 | 1304 | { | 1374 | { |
182 | 1375 | try | ||
183 | 1376 | { | ||
184 | 1305 | #if defined(ENABLE_NLS) | 1377 | #if defined(ENABLE_NLS) |
185 | 1306 | # if defined(HAVE_LOCALE_H) | 1378 | # if defined(HAVE_LOCALE_H) |
186 | 1307 | setlocale(LC_ALL, ""); | 1379 | setlocale(LC_ALL, ""); |
187 | @@ -1310,12 +1382,160 @@ | |||
188 | 1310 | textdomain("drizzle"); | 1382 | textdomain("drizzle"); |
189 | 1311 | #endif | 1383 | #endif |
190 | 1312 | 1384 | ||
193 | 1313 | MY_INIT(argv[0]); | 1385 | po::options_description commandline_options("Options used only in command line"); |
194 | 1314 | delimiter_str= delimiter; | 1386 | commandline_options.add_options() |
195 | 1387 | ("help,?",N_("Displays this help and exit.")) | ||
196 | 1388 | ("batch,B",N_("Don't use history file. Disable interactive behavior. (Enables --silent)")) | ||
197 | 1389 | ("column-type-info", po::value<bool>(&column_types_flag)->default_value(false)->zero_tokens(), | ||
198 | 1390 | N_("Display column type information.")) | ||
199 | 1391 | ("comments,c", po::value<bool>(&preserve_comments)->default_value(false)->zero_tokens(), | ||
200 | 1392 | N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments")) | ||
201 | 1393 | ("compress,C", po::value<bool>(&opt_compress)->default_value(false)->zero_tokens(), | ||
202 | 1394 | N_("Use compression in server/client protocol.")) | ||
203 | 1395 | ("vertical,E", po::value<bool>(&vertical)->default_value(false)->zero_tokens(), | ||
204 | 1396 | N_("Print the output of a query (rows) vertically.")) | ||
205 | 1397 | ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(), | ||
206 | 1398 | N_("Continue even if we get an sql error.")) | ||
207 | 1399 | ("named-commands,G", po::value<bool>(&named_cmds)->default_value(false)->zero_tokens(), | ||
208 | 1400 | 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.")) | ||
209 | 1401 | ("no-named-commands,g", | ||
210 | 1402 | 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.")) | ||
211 | 1403 | ("ignore-spaces,i", N_("Ignore space after function names.")) | ||
212 | 1404 | ("no-beep,b", po::value<bool>(&opt_nobeep)->default_value(false)->zero_tokens(), | ||
213 | 1405 | N_("Turn off beep on error.")) | ||
214 | 1406 | ("line-numbers", po::value<bool>(&line_numbers)->default_value(true)->zero_tokens(), | ||
215 | 1407 | N_("Write line numbers for errors.")) | ||
216 | 1408 | ("skip-line-numbers,L", | ||
217 | 1409 | N_("Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead.")) | ||
218 | 1410 | ("column-name", po::value<bool>(&column_names)->default_value(true)->zero_tokens(), | ||
219 | 1411 | N_("Write column names in results.")) | ||
220 | 1412 | ("skip-column-names,N", | ||
221 | 1413 | N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead.")) | ||
222 | 1414 | ("set-variable,O", po::value<string>(), | ||
223 | 1415 | N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.")) | ||
224 | 1416 | ("table,t", po::value<bool>(&output_tables)->default_value(false)->zero_tokens(), | ||
225 | 1417 | N_("Output in table format.")) | ||
226 | 1418 | ("safe-updates,U", po::value<bool>(&safe_updates)->default_value(0)->zero_tokens(), | ||
227 | 1419 | N_("Only allow UPDATE and DELETE that uses keys.")) | ||
228 | 1420 | ("i-am-a-dummy,U", po::value<bool>(&safe_updates)->default_value(0)->zero_tokens(), | ||
229 | 1421 | N_("Synonym for option --safe-updates, -U.")) | ||
230 | 1422 | ("verbose,v", po::value<string>(&opt_verbose)->default_value(""), | ||
231 | 1423 | N_("-v vvv implies that verbose= 3, Used to specify verbose")) | ||
232 | 1424 | ("version,V", N_("Output version information and exit.")) | ||
233 | 1425 | ("secure-auth", po::value<bool>(&opt_secure_auth)->default_value(false)->zero_tokens(), | ||
234 | 1426 | N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol")) | ||
235 | 1427 | ("show-warnings", po::value<bool>(&show_warnings)->default_value(false)->zero_tokens(), | ||
236 | 1428 | N_("Show warnings after every statement.")) | ||
237 | 1429 | ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(0), | ||
238 | 1430 | N_("Number of lines before each import progress report.")) | ||
239 | 1431 | ("ping", po::value<bool>(&opt_ping)->default_value(false)->zero_tokens(), | ||
240 | 1432 | N_("Ping the server to check if it's alive.")) | ||
241 | 1433 | ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(), | ||
242 | 1434 | N_("Configuration file defaults are not used if no-defaults is set")) | ||
243 | 1435 | ; | ||
244 | 1436 | |||
245 | 1437 | po::options_description drizzle_options("Options specific to the drizzle client"); | ||
246 | 1438 | drizzle_options.add_options() | ||
247 | 1439 | ("auto-rehash", po::value<bool>(&opt_rehash)->default_value(true)->zero_tokens(), | ||
248 | 1440 | 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.")) | ||
249 | 1441 | ("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.")) | ||
250 | 1442 | ("auto-vertical-output", po::value<bool>(&auto_vertical_output)->default_value(false)->zero_tokens(), | ||
251 | 1443 | N_("Automatically switch to vertical output mode if the result is wider than the terminal width.")) | ||
252 | 1444 | ("database,D", po::value<string>(¤t_db)->default_value("test"), | ||
253 | 1445 | N_("Database to use.")) | ||
254 | 1446 | ("default-character-set",po::value<string>(), | ||
255 | 1447 | N_("(not used)")) | ||
256 | 1448 | ("delimiter", po::value<string>(&delimiter_str)->default_value(";"), | ||
257 | 1449 | N_("Delimiter to be used.")) | ||
258 | 1450 | ("execute,e", po::value<string>(), | ||
259 | 1451 | N_("Execute command and quit. (Disables --force and history file)")) | ||
260 | 1452 | ("local-infile", po::value<bool>(&opt_local_infile)->default_value(false)->zero_tokens(), | ||
261 | 1453 | N_("Enable/disable LOAD DATA LOCAL INFILE.")) | ||
262 | 1454 | ("unbuffered,n", po::value<bool>(&unbuffered)->default_value(false)->zero_tokens(), | ||
263 | 1455 | N_("Flush buffer after each query.")) | ||
264 | 1456 | ("sigint-ignore", po::value<bool>(&opt_sigint_ignore)->default_value(false)->zero_tokens(), | ||
265 | 1457 | N_("Ignore SIGINT (CTRL-C)")) | ||
266 | 1458 | ("one-database,o", po::value<bool>(&one_database)->default_value(false)->zero_tokens(), | ||
267 | 1459 | N_("Only update the default database. This is useful for skipping updates to other database in the update log.")) | ||
268 | 1460 | ("pager", po::value<string>(), | ||
269 | 1461 | 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.")) | ||
270 | 1462 | ("disable-pager", po::value<bool>(&opt_nopager)->default_value(false)->zero_tokens(), | ||
271 | 1463 | N_("Disable pager and print to stdout. See interactive help (\\h) also.")) | ||
272 | 1464 | ("prompt", po::value<string>(¤t_prompt)->default_value(""), | ||
273 | 1465 | N_("Set the drizzle prompt to this value.")) | ||
274 | 1466 | ("quick,q", po::value<bool>(&quick)->default_value(false)->zero_tokens(), | ||
275 | 1467 | 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.")) | ||
276 | 1468 | ("raw,r", po::value<bool>(&opt_raw_data)->default_value(false)->zero_tokens(), | ||
277 | 1469 | N_("Write fields without conversion. Used with --batch.")) | ||
278 | 1470 | ("reconnect", po::value<bool>(&opt_reconnect)->default_value(true)->zero_tokens(), | ||
279 | 1471 | N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default.")) | ||
280 | 1472 | ("shutdown", po::value<bool>(&opt_shutdown)->default_value(false)->zero_tokens(), | ||
281 | 1473 | N_("Shutdown the server")) | ||
282 | 1474 | ("silent,s", N_("Be more silent. Print results with a tab as separator, each row on new line.")) | ||
283 | 1475 | ("tee", po::value<string>(), | ||
284 | 1476 | 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.")) | ||
285 | 1477 | ("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(), | ||
286 | 1478 | N_("Disable outfile. See interactive help (\\h) also.")) | ||
287 | 1479 | ("wait,w", N_("Wait and retry if connection is down.")) | ||
288 | 1480 | ("connect_timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value), | ||
289 | 1481 | N_("Number of seconds before connection timeout.")) | ||
290 | 1482 | ("max_input_line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line), | ||
291 | 1483 | N_("Max length of input line")) | ||
292 | 1484 | ("select_limit", po::value<uint32_t>(&select_limit)->default_value(1000L), | ||
293 | 1485 | N_("Automatic limit for SELECT when using --safe-updates")) | ||
294 | 1486 | ("max_join_size", po::value<uint32_t>(&max_join_size)->default_value(1000000L), | ||
295 | 1487 | N_("Automatic limit for rows in a join when using --safe-updates")) | ||
296 | 1488 | ; | ||
297 | 1489 | |||
298 | 1490 | po::options_description client_options("Options specific to the client"); | ||
299 | 1491 | client_options.add_options() | ||
300 | 1492 | ("mysql,m", po::value<bool>(&opt_mysql)->default_value(true)->zero_tokens(), | ||
301 | 1493 | N_("Use MySQL Protocol.")) | ||
302 | 1494 | ("host,h", po::value<string>(¤t_host)->default_value("localhost"), | ||
303 | 1495 | N_("Connect to host")) | ||
304 | 1496 | ("password,P", po::value<string>(¤t_password)->default_value(PASSWORD_SENTINEL), | ||
305 | 1497 | N_("Password to use when connecting to server. If password is not given it's asked from the tty.")) | ||
306 | 1498 | ("port,p", po::value<uint32_t>()->default_value(3306), | ||
307 | 1499 | N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default")) | ||
308 | 1500 | ("user,u", po::value<string>(¤t_user)->default_value(""), | ||
309 | 1501 | N_("User for login if not current user.")) | ||
310 | 1502 | ("protocol",po::value<string>(), | ||
311 | 1503 | N_("The protocol of connection (tcp,socket,pipe,memory).")) | ||
312 | 1504 | ; | ||
313 | 1505 | |||
314 | 1506 | po::options_description long_options("Allowed Options"); | ||
315 | 1507 | long_options.add(commandline_options).add(drizzle_options).add(client_options); | ||
316 | 1508 | |||
317 | 1509 | std::string system_config_dir_drizzle(SYSCONFDIR); | ||
318 | 1510 | system_config_dir_drizzle.append("/drizzle/drizzle.cnf"); | ||
319 | 1511 | |||
320 | 1512 | std::string system_config_dir_client(SYSCONFDIR); | ||
321 | 1513 | system_config_dir_client.append("/drizzle/client.cnf"); | ||
322 | 1514 | |||
323 | 1515 | po::variables_map vm; | ||
324 | 1516 | |||
325 | 1517 | po::store(po::command_line_parser(argc, argv).options(long_options).extra_parser(parse_password_arg).run(), vm); | ||
326 | 1518 | |||
327 | 1519 | if (! vm["no-defaults"].as<bool>()) | ||
328 | 1520 | { | ||
329 | 1521 | ifstream user_drizzle_ifs("~/.drizzle/drizzleslap.cnf"); | ||
330 | 1522 | po::store(parse_config_file(user_drizzle_ifs, drizzle_options), vm); | ||
331 | 1523 | |||
332 | 1524 | ifstream system_drizzle_ifs(system_config_dir_drizzle.c_str()); | ||
333 | 1525 | store(parse_config_file(system_drizzle_ifs, drizzle_options), vm); | ||
334 | 1526 | |||
335 | 1527 | ifstream user_client_ifs("~/.drizzle/client.cnf"); | ||
336 | 1528 | po::store(parse_config_file(user_client_ifs, client_options), vm); | ||
337 | 1529 | |||
338 | 1530 | ifstream system_client_ifs(system_config_dir_client.c_str()); | ||
339 | 1531 | po::store(parse_config_file(system_client_ifs, client_options), vm); | ||
340 | 1532 | } | ||
341 | 1533 | |||
342 | 1534 | po::notify(vm); | ||
343 | 1535 | |||
344 | 1315 | default_prompt= strdup(getenv("DRIZZLE_PS1") ? | 1536 | default_prompt= strdup(getenv("DRIZZLE_PS1") ? |
345 | 1316 | getenv("DRIZZLE_PS1") : | 1537 | getenv("DRIZZLE_PS1") : |
346 | 1317 | "drizzle> "); | 1538 | "drizzle> "); |
347 | 1318 | |||
348 | 1319 | if (default_prompt == NULL) | 1539 | if (default_prompt == NULL) |
349 | 1320 | { | 1540 | { |
350 | 1321 | fprintf(stderr, _("Memory allocation error while constructing initial " | 1541 | fprintf(stderr, _("Memory allocation error while constructing initial " |
351 | @@ -1323,7 +1543,7 @@ | |||
352 | 1323 | exit(ENOMEM); | 1543 | exit(ENOMEM); |
353 | 1324 | } | 1544 | } |
354 | 1325 | current_prompt= strdup(default_prompt); | 1545 | current_prompt= strdup(default_prompt); |
356 | 1326 | if (current_prompt == NULL) | 1546 | if (current_prompt.empty()) |
357 | 1327 | { | 1547 | { |
358 | 1328 | fprintf(stderr, _("Memory allocation error while constructing initial " | 1548 | fprintf(stderr, _("Memory allocation error while constructing initial " |
359 | 1329 | "prompt. Aborting.\n")); | 1549 | "prompt. Aborting.\n")); |
360 | @@ -1344,7 +1564,7 @@ | |||
361 | 1344 | strcpy(default_pager, tmp); | 1564 | strcpy(default_pager, tmp); |
362 | 1345 | } | 1565 | } |
363 | 1346 | } | 1566 | } |
365 | 1347 | if (!isatty(0) || !isatty(1)) | 1567 | if (! isatty(0) || ! isatty(1)) |
366 | 1348 | { | 1568 | { |
367 | 1349 | status.setBatch(1); opt_silent=1; | 1569 | status.setBatch(1); opt_silent=1; |
368 | 1350 | ignore_errors=0; | 1570 | ignore_errors=0; |
369 | @@ -1367,18 +1587,187 @@ | |||
370 | 1367 | close(stdout_fileno_copy); /* Clean up dup(). */ | 1587 | close(stdout_fileno_copy); /* Clean up dup(). */ |
371 | 1368 | } | 1588 | } |
372 | 1369 | 1589 | ||
379 | 1370 | internal::load_defaults("drizzle",load_default_groups,&argc,&argv); | 1590 | if (vm.count("default-character-set")) |
380 | 1371 | defaults_argv=argv; | 1591 | default_charset_used= 1; |
381 | 1372 | if (get_options(argc, (char **) argv)) | 1592 | |
382 | 1373 | { | 1593 | if (vm.count("delimiter")) |
383 | 1374 | internal::free_defaults(defaults_argv); | 1594 | { |
384 | 1375 | internal::my_end(); | 1595 | /* Check that delimiter does not contain a backslash */ |
385 | 1596 | if (! strstr(delimiter_str.c_str(), "\\")) | ||
386 | 1597 | { | ||
387 | 1598 | delimiter= (char *)delimiter_str.c_str(); | ||
388 | 1599 | } | ||
389 | 1600 | else | ||
390 | 1601 | { | ||
391 | 1602 | put_info(_("DELIMITER cannot contain a backslash character"), | ||
392 | 1603 | INFO_ERROR,0,0); | ||
393 | 1604 | exit(-1); | ||
394 | 1605 | } | ||
395 | 1606 | |||
396 | 1607 | delimiter_length= (uint32_t)strlen(delimiter); | ||
397 | 1608 | } | ||
398 | 1609 | if (vm.count("tee")) | ||
399 | 1610 | { | ||
400 | 1611 | if (vm["tee"].as<string>().empty()) | ||
401 | 1612 | { | ||
402 | 1613 | if (opt_outfile) | ||
403 | 1614 | end_tee(); | ||
404 | 1615 | } | ||
405 | 1616 | else | ||
406 | 1617 | init_tee(vm["tee"].as<string>().c_str()); | ||
407 | 1618 | } | ||
408 | 1619 | if (vm["disable-tee"].as<bool>() == true) | ||
409 | 1620 | { | ||
410 | 1621 | if (opt_outfile) | ||
411 | 1622 | end_tee(); | ||
412 | 1623 | } | ||
413 | 1624 | if (vm.count("pager")) | ||
414 | 1625 | { | ||
415 | 1626 | if (vm["pager"].as<string>().empty()) | ||
416 | 1627 | opt_nopager= 1; | ||
417 | 1628 | else | ||
418 | 1629 | { | ||
419 | 1630 | opt_nopager= 0; | ||
420 | 1631 | if (vm[pager].as<string>().length()) | ||
421 | 1632 | { | ||
422 | 1633 | default_pager_set= 1; | ||
423 | 1634 | strncpy(pager, vm["pager"].as<string>().c_str(), sizeof(pager) - 1); | ||
424 | 1635 | strcpy(default_pager, pager); | ||
425 | 1636 | } | ||
426 | 1637 | else if (default_pager_set) | ||
427 | 1638 | strcpy(pager, default_pager); | ||
428 | 1639 | else | ||
429 | 1640 | opt_nopager= 1; | ||
430 | 1641 | } | ||
431 | 1642 | } | ||
432 | 1643 | if (vm.count("disable-pager")) | ||
433 | 1644 | { | ||
434 | 1645 | opt_nopager= 1; | ||
435 | 1646 | } | ||
436 | 1647 | |||
437 | 1648 | if (vm.count("no-auto-rehash")) | ||
438 | 1649 | opt_rehash= 0; | ||
439 | 1650 | |||
440 | 1651 | if (vm.count("skip-column-names")) | ||
441 | 1652 | column_names= 0; | ||
442 | 1653 | |||
443 | 1654 | if (vm.count("execute")) | ||
444 | 1655 | { | ||
445 | 1656 | status.setBatch(1); | ||
446 | 1657 | status.setAddToHistory(1); | ||
447 | 1658 | if (status.getLineBuff() == NULL) | ||
448 | 1659 | status.setLineBuff(opt_max_input_line,NULL); | ||
449 | 1660 | if (status.getLineBuff() == NULL) | ||
450 | 1661 | { | ||
451 | 1662 | internal::my_end(); | ||
452 | 1663 | exit(1); | ||
453 | 1664 | } | ||
454 | 1665 | status.getLineBuff()->addString(vm["execute"].as<string>().c_str()); | ||
455 | 1666 | } | ||
456 | 1667 | |||
457 | 1668 | if (one_database) | ||
458 | 1669 | skip_updates= true; | ||
459 | 1670 | |||
460 | 1671 | if (vm.count("port")) | ||
461 | 1672 | { | ||
462 | 1673 | opt_drizzle_port= vm["port"].as<uint32_t>(); | ||
463 | 1674 | |||
464 | 1675 | /* If the port number is > 65535 it is not a valid port | ||
465 | 1676 | This also helps with potential data loss casting unsigned long to a | ||
466 | 1677 | uint32_t. */ | ||
467 | 1678 | if ((opt_drizzle_port == 0) || (opt_drizzle_port > 65535)) | ||
468 | 1679 | { | ||
469 | 1680 | printf(_("Error: Value of %" PRIu32 " supplied for port is not valid.\n"), opt_drizzle_port); | ||
470 | 1681 | exit(-1); | ||
471 | 1682 | } | ||
472 | 1683 | } | ||
473 | 1684 | |||
474 | 1685 | if (vm.count("password")) | ||
475 | 1686 | { | ||
476 | 1687 | if (!opt_password.empty()) | ||
477 | 1688 | opt_password.erase(); | ||
478 | 1689 | if (current_password == PASSWORD_SENTINEL) | ||
479 | 1690 | { | ||
480 | 1691 | opt_password= ""; | ||
481 | 1692 | } | ||
482 | 1693 | else | ||
483 | 1694 | { | ||
484 | 1695 | opt_password= current_password; | ||
485 | 1696 | tty_password= false; | ||
486 | 1697 | } | ||
487 | 1698 | char *start= (char *)current_password.c_str(); | ||
488 | 1699 | char *temp_pass= (char *)current_password.c_str(); | ||
489 | 1700 | while (*temp_pass) | ||
490 | 1701 | { | ||
491 | 1702 | /* Overwriting password with 'x' */ | ||
492 | 1703 | *temp_pass++= 'x'; | ||
493 | 1704 | } | ||
494 | 1705 | if (*start) | ||
495 | 1706 | { | ||
496 | 1707 | start[1]= 0; | ||
497 | 1708 | } | ||
498 | 1709 | } | ||
499 | 1710 | else | ||
500 | 1711 | { | ||
501 | 1712 | tty_password= true; | ||
502 | 1713 | } | ||
503 | 1714 | |||
504 | 1715 | |||
505 | 1716 | if (!opt_verbose.empty()) | ||
506 | 1717 | { | ||
507 | 1718 | verbose= opt_verbose.length(); | ||
508 | 1719 | } | ||
509 | 1720 | |||
510 | 1721 | if (vm.count("batch")) | ||
511 | 1722 | { | ||
512 | 1723 | status.setBatch(1); | ||
513 | 1724 | status.setAddToHistory(0); | ||
514 | 1725 | set_if_bigger(opt_silent,1); // more silent | ||
515 | 1726 | } | ||
516 | 1727 | if (vm.count("silent")) | ||
517 | 1728 | { | ||
518 | 1729 | opt_silent++; | ||
519 | 1730 | } | ||
520 | 1731 | if (vm.count("version")) | ||
521 | 1732 | { | ||
522 | 1733 | printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"), | ||
523 | 1734 | internal::my_progname, VER.c_str(), drizzle_version(), | ||
524 | 1735 | HOST_VENDOR, HOST_OS, HOST_CPU, | ||
525 | 1736 | rl_library_version); | ||
526 | 1737 | |||
527 | 1738 | exit(0); | ||
528 | 1739 | } | ||
529 | 1740 | |||
530 | 1741 | if (vm.count("help")) | ||
531 | 1742 | { | ||
532 | 1743 | printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"), | ||
533 | 1744 | internal::my_progname, VER.c_str(), drizzle_version(), | ||
534 | 1745 | HOST_VENDOR, HOST_OS, HOST_CPU, | ||
535 | 1746 | rl_library_version); | ||
536 | 1747 | printf(_("Copyright (C) 2008 Sun Microsystems\n" | ||
537 | 1748 | "This software comes with ABSOLUTELY NO WARRANTY. " | ||
538 | 1749 | "This is free software,\n" | ||
539 | 1750 | "and you are welcome to modify and redistribute it " | ||
540 | 1751 | "under the GPL license\n")); | ||
541 | 1752 | printf(_("Usage: %s [OPTIONS] [database]\n"), internal::my_progname); | ||
542 | 1753 | cout<<long_options; | ||
543 | 1754 | exit(0); | ||
544 | 1755 | } | ||
545 | 1756 | |||
546 | 1757 | |||
547 | 1758 | if (process_options()) | ||
548 | 1759 | { | ||
549 | 1376 | exit(1); | 1760 | exit(1); |
550 | 1377 | } | 1761 | } |
551 | 1378 | 1762 | ||
552 | 1763 | if (argc == 1) | ||
553 | 1764 | { | ||
554 | 1765 | skip_updates= 0; | ||
555 | 1766 | current_db.erase(); | ||
556 | 1767 | current_db= strdup(*argv); | ||
557 | 1768 | } | ||
558 | 1379 | memset(&drizzle, 0, sizeof(drizzle)); | 1769 | memset(&drizzle, 0, sizeof(drizzle)); |
561 | 1380 | if (sql_connect(current_host,current_db,current_user,opt_password, | 1770 | if (sql_connect(current_host, current_db, current_user, opt_password,opt_silent)) |
560 | 1381 | opt_silent)) | ||
562 | 1382 | { | 1771 | { |
563 | 1383 | quick= 1; // Avoid history | 1772 | quick= 1; // Avoid history |
564 | 1384 | status.setExitStatus(1); | 1773 | status.setExitStatus(1); |
565 | @@ -1389,8 +1778,6 @@ | |||
566 | 1389 | if (execute_commands(&command_error) != false) | 1778 | if (execute_commands(&command_error) != false) |
567 | 1390 | { | 1779 | { |
568 | 1391 | /* we've executed a command so exit before we go into readline mode */ | 1780 | /* we've executed a command so exit before we go into readline mode */ |
569 | 1392 | internal::free_defaults(defaults_argv); | ||
570 | 1393 | internal::my_end(); | ||
571 | 1394 | exit(command_error); | 1781 | exit(command_error); |
572 | 1395 | } | 1782 | } |
573 | 1396 | 1783 | ||
574 | @@ -1399,8 +1786,6 @@ | |||
575 | 1399 | status.setLineBuff(opt_max_input_line, stdin); | 1786 | status.setLineBuff(opt_max_input_line, stdin); |
576 | 1400 | if (status.getLineBuff() == NULL) | 1787 | if (status.getLineBuff() == NULL) |
577 | 1401 | { | 1788 | { |
578 | 1402 | internal::free_defaults(defaults_argv); | ||
579 | 1403 | internal::my_end(); | ||
580 | 1404 | exit(1); | 1789 | exit(1); |
581 | 1405 | } | 1790 | } |
582 | 1406 | } | 1791 | } |
583 | @@ -1436,7 +1821,7 @@ | |||
584 | 1436 | server_version_string(&con)); | 1821 | server_version_string(&con)); |
585 | 1437 | put_info(output_buff, INFO_INFO, 0, 0); | 1822 | put_info(output_buff, INFO_INFO, 0, 0); |
586 | 1438 | 1823 | ||
588 | 1439 | initialize_readline(current_prompt); | 1824 | initialize_readline((char *)current_prompt.c_str()); |
589 | 1440 | if (!status.getBatch() && !quick) | 1825 | if (!status.getBatch() && !quick) |
590 | 1441 | { | 1826 | { |
591 | 1442 | /* read-history from file, default ~/.drizzle_history*/ | 1827 | /* read-history from file, default ~/.drizzle_history*/ |
592 | @@ -1480,7 +1865,12 @@ | |||
593 | 1480 | if (opt_outfile) | 1865 | if (opt_outfile) |
594 | 1481 | end_tee(); | 1866 | end_tee(); |
595 | 1482 | drizzle_end(0); | 1867 | drizzle_end(0); |
596 | 1868 | } | ||
597 | 1483 | 1869 | ||
598 | 1870 | catch(exception &err) | ||
599 | 1871 | { | ||
600 | 1872 | cerr<<"Error:"<<err.what()<<endl; | ||
601 | 1873 | } | ||
602 | 1484 | return(0); // Keep compiler happy | 1874 | return(0); // Keep compiler happy |
603 | 1485 | } | 1875 | } |
604 | 1486 | 1876 | ||
605 | @@ -1505,18 +1895,16 @@ | |||
606 | 1505 | delete glob_buffer; | 1895 | delete glob_buffer; |
607 | 1506 | if (processed_prompt) | 1896 | if (processed_prompt) |
608 | 1507 | delete processed_prompt; | 1897 | delete processed_prompt; |
610 | 1508 | free(opt_password); | 1898 | opt_password.erase(); |
611 | 1509 | free(histfile); | 1899 | free(histfile); |
612 | 1510 | free(histfile_tmp); | 1900 | free(histfile_tmp); |
616 | 1511 | free(current_db); | 1901 | current_db.erase(); |
617 | 1512 | free(current_host); | 1902 | current_host.erase(); |
618 | 1513 | free(current_user); | 1903 | current_user.erase(); |
619 | 1514 | free(full_username); | 1904 | free(full_username); |
620 | 1515 | free(part_username); | 1905 | free(part_username); |
621 | 1516 | free(default_prompt); | 1906 | free(default_prompt); |
625 | 1517 | free(current_prompt); | 1907 | current_prompt.erase(); |
623 | 1518 | internal::free_defaults(defaults_argv); | ||
624 | 1519 | internal::my_end(); | ||
626 | 1520 | exit(status.getExitStatus()); | 1908 | exit(status.getExitStatus()); |
627 | 1521 | } | 1909 | } |
628 | 1522 | 1910 | ||
629 | @@ -1539,8 +1927,8 @@ | |||
630 | 1539 | goto err; | 1927 | goto err; |
631 | 1540 | } | 1928 | } |
632 | 1541 | 1929 | ||
635 | 1542 | if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host, | 1930 | if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host.c_str(), |
636 | 1543 | opt_drizzle_port, current_user, opt_password, NULL, | 1931 | opt_drizzle_port, current_user.c_str(), opt_password.c_str(), NULL, |
637 | 1544 | opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL) | 1932 | opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL) |
638 | 1545 | { | 1933 | { |
639 | 1546 | goto err; | 1934 | goto err; |
640 | @@ -1575,369 +1963,12 @@ | |||
641 | 1575 | } | 1963 | } |
642 | 1576 | #endif | 1964 | #endif |
643 | 1577 | 1965 | ||
1004 | 1578 | static struct option my_long_options[] = | 1966 | |
1005 | 1579 | { | 1967 | |
1006 | 1580 | {"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, | 1968 | static int process_options(void) |
647 | 1581 | 0, 0, 0, 0, 0}, | ||
648 | 1582 | {"help", 'I', N_("Synonym for -?"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, | ||
649 | 1583 | 0, 0, 0, 0, 0}, | ||
650 | 1584 | {"auto-rehash", OPT_AUTO_REHASH, | ||
651 | 1585 | 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."), | ||
652 | 1586 | (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, | ||
653 | 1587 | 0, 0}, | ||
654 | 1588 | {"no-auto-rehash", 'A', | ||
655 | 1589 | 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."), | ||
656 | 1590 | 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
657 | 1591 | {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT, | ||
658 | 1592 | N_("Automatically switch to vertical output mode if the result is wider than the terminal width."), | ||
659 | 1593 | (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
660 | 1594 | {"batch", 'B', | ||
661 | 1595 | 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}, | ||
662 | 1596 | {"column-type-info", OPT_COLUMN_TYPES, N_("Display column type information."), | ||
663 | 1597 | (char**) &column_types_flag, (char**) &column_types_flag, | ||
664 | 1598 | 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
665 | 1599 | {"comments", 'c', N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"), | ||
666 | 1600 | (char**) &preserve_comments, (char**) &preserve_comments, | ||
667 | 1601 | 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
668 | 1602 | {"compress", 'C', N_("Use compression in server/client protocol."), | ||
669 | 1603 | (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, | ||
670 | 1604 | 0, 0, 0}, | ||
671 | 1605 | {"database", 'D', N_("Database to use."), (char**) ¤t_db, | ||
672 | 1606 | (char**) ¤t_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
673 | 1607 | {"default-character-set", OPT_DEFAULT_CHARSET, | ||
674 | 1608 | N_("(not used)"), 0, | ||
675 | 1609 | 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
676 | 1610 | {"delimiter", OPT_DELIMITER, N_("Delimiter to be used."), (char**) &delimiter_str, | ||
677 | 1611 | (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
678 | 1612 | {"execute", 'e', N_("Execute command and quit. (Disables --force and history file)"), 0, | ||
679 | 1613 | 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
680 | 1614 | {"vertical", 'E', N_("Print the output of a query (rows) vertically."), | ||
681 | 1615 | (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, | ||
682 | 1616 | 0}, | ||
683 | 1617 | {"force", 'f', N_("Continue even if we get an sql error."), | ||
684 | 1618 | (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0, | ||
685 | 1619 | 0, 0, 0, 0}, | ||
686 | 1620 | {"named-commands", 'G', | ||
687 | 1621 | 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."), | ||
688 | 1622 | (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, | ||
689 | 1623 | 0, 0}, | ||
690 | 1624 | {"no-named-commands", 'g', | ||
691 | 1625 | 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."), | ||
692 | 1626 | 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
693 | 1627 | {"ignore-spaces", 'i', N_("Ignore space after function names."), 0, 0, 0, | ||
694 | 1628 | GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
695 | 1629 | {"local-infile", OPT_LOCAL_INFILE, N_("Enable/disable LOAD DATA LOCAL INFILE."), | ||
696 | 1630 | (char**) &opt_local_infile, | ||
697 | 1631 | (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, | ||
698 | 1632 | {"no-beep", 'b', N_("Turn off beep on error."), (char**) &opt_nobeep, | ||
699 | 1633 | (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
700 | 1634 | {"host", 'h', N_("Connect to host."), (char**) ¤t_host, | ||
701 | 1635 | (char**) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
702 | 1636 | {"line-numbers", OPT_LINE_NUMBERS, N_("Write line numbers for errors."), | ||
703 | 1637 | (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL, | ||
704 | 1638 | NO_ARG, 1, 0, 0, 0, 0, 0}, | ||
705 | 1639 | {"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, | ||
706 | 1640 | NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
707 | 1641 | {"unbuffered", 'n', N_("Flush buffer after each query."), (char**) &unbuffered, | ||
708 | 1642 | (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
709 | 1643 | {"column-names", OPT_COLUMN_NAMES, N_("Write column names in results."), | ||
710 | 1644 | (char**) &column_names, (char**) &column_names, 0, GET_BOOL, | ||
711 | 1645 | NO_ARG, 1, 0, 0, 0, 0, 0}, | ||
712 | 1646 | {"skip-column-names", 'N', | ||
713 | 1647 | N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."), | ||
714 | 1648 | 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
715 | 1649 | {"set-variable", 'O', | ||
716 | 1650 | N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."), | ||
717 | 1651 | 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
718 | 1652 | {"sigint-ignore", OPT_SIGINT_IGNORE, N_("Ignore SIGINT (CTRL-C)"), | ||
719 | 1653 | (char**) &opt_sigint_ignore, (char**) &opt_sigint_ignore, 0, GET_BOOL, | ||
720 | 1654 | NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
721 | 1655 | {"one-database", 'o', | ||
722 | 1656 | N_("Only update the default database. This is useful for skipping updates to other database in the update log."), | ||
723 | 1657 | 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
724 | 1658 | {"pager", OPT_PAGER, | ||
725 | 1659 | 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."), | ||
726 | 1660 | 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, | ||
727 | 1661 | {"no-pager", OPT_NOPAGER, | ||
728 | 1662 | N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."), | ||
729 | 1663 | 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
730 | 1664 | {"password", 'P', | ||
731 | 1665 | N_("Password to use when connecting to server. If password is not given it's asked from the tty."), | ||
732 | 1666 | 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, | ||
733 | 1667 | {"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ") | ||
734 | 1668 | N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").", | ||
735 | 1669 | 0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
736 | 1670 | {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."), | ||
737 | 1671 | (char**) ¤t_prompt, (char**) ¤t_prompt, 0, GET_STR_ALLOC, | ||
738 | 1672 | REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
739 | 1673 | {"quick", 'q', | ||
740 | 1674 | 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."), | ||
741 | 1675 | (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
742 | 1676 | {"raw", 'r', N_("Write fields without conversion. Used with --batch."), | ||
743 | 1677 | (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, | ||
744 | 1678 | 0, 0, 0}, | ||
745 | 1679 | {"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."), | ||
746 | 1680 | (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, | ||
747 | 1681 | {"shutdown", OPT_SHUTDOWN, N_("Shutdown the server."), | ||
748 | 1682 | (char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
749 | 1683 | {"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, | ||
750 | 1684 | 0, 0}, | ||
751 | 1685 | {"table", 't', N_("Output in table format."), (char**) &output_tables, | ||
752 | 1686 | (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
753 | 1687 | {"tee", OPT_TEE, | ||
754 | 1688 | 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."), | ||
755 | 1689 | 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
756 | 1690 | {"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, | ||
757 | 1691 | NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
758 | 1692 | {"user", 'u', N_("User for login if not current user."), (char**) ¤t_user, | ||
759 | 1693 | (char**) ¤t_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
760 | 1694 | {"safe-updates", 'U', N_("Only allow UPDATE and DELETE that uses keys."), | ||
761 | 1695 | (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0, | ||
762 | 1696 | 0, 0, 0, 0}, | ||
763 | 1697 | {"i-am-a-dummy", 'U', N_("Synonym for option --safe-updates, -U."), | ||
764 | 1698 | (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0, | ||
765 | 1699 | 0, 0, 0, 0}, | ||
766 | 1700 | {"verbose", 'v', N_("Write more. (-v -v -v gives the table output format)."), 0, | ||
767 | 1701 | 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
768 | 1702 | {"version", 'V', N_("Output version information and exit."), 0, 0, 0, | ||
769 | 1703 | GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
770 | 1704 | {"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_NO_ARG, | ||
771 | 1705 | NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
772 | 1706 | {"connect_timeout", OPT_CONNECT_TIMEOUT, | ||
773 | 1707 | N_("Number of seconds before connection timeout."), | ||
774 | 1708 | (char**) &opt_connect_timeout, | ||
775 | 1709 | (char**) &opt_connect_timeout, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 3600*12, 0, | ||
776 | 1710 | 0, 0}, | ||
777 | 1711 | {"max_input_line", OPT_MAX_INPUT_LINE, | ||
778 | 1712 | N_("Max length of input line"), | ||
779 | 1713 | (char**) &opt_max_input_line, (char**) &opt_max_input_line, 0, | ||
780 | 1714 | GET_UINT32, REQUIRED_ARG, 16 *1024L*1024L, 4096, | ||
781 | 1715 | (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0}, | ||
782 | 1716 | {"select_limit", OPT_SELECT_LIMIT, | ||
783 | 1717 | N_("Automatic limit for SELECT when using --safe-updates"), | ||
784 | 1718 | (char**) &select_limit, | ||
785 | 1719 | (char**) &select_limit, 0, GET_UINT32, REQUIRED_ARG, 1000L, 1, ULONG_MAX, | ||
786 | 1720 | 0, 1, 0}, | ||
787 | 1721 | {"max_join_size", OPT_MAX_JOIN_SIZE, | ||
788 | 1722 | N_("Automatic limit for rows in a join when using --safe-updates"), | ||
789 | 1723 | (char**) &max_join_size, | ||
790 | 1724 | (char**) &max_join_size, 0, GET_UINT32, REQUIRED_ARG, 1000000L, 1, ULONG_MAX, | ||
791 | 1725 | 0, 1, 0}, | ||
792 | 1726 | {"secure-auth", OPT_SECURE_AUTH, N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"), (char**) &opt_secure_auth, | ||
793 | 1727 | (char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
794 | 1728 | {"show-warnings", OPT_SHOW_WARNINGS, N_("Show warnings after every statement."), | ||
795 | 1729 | (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG, | ||
796 | 1730 | 0, 0, 0, 0, 0, 0}, | ||
797 | 1731 | {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of lines before each import progress report."), | ||
798 | 1732 | (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG, | ||
799 | 1733 | 0, 0, 0, 0, 0, 0}, | ||
800 | 1734 | {"ping", OPT_PING, N_("Ping the server to check if it's alive."), | ||
801 | 1735 | (char**) &opt_ping, (char**) &opt_ping, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
802 | 1736 | {"mysql", 'm', N_("Use MySQL Protocol."), | ||
803 | 1737 | (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0, | ||
804 | 1738 | 0, 0, 0}, | ||
805 | 1739 | { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} | ||
806 | 1740 | }; | ||
807 | 1741 | |||
808 | 1742 | |||
809 | 1743 | static void usage(int version) | ||
810 | 1744 | { | ||
811 | 1745 | const char* readline= "readline"; | ||
812 | 1746 | |||
813 | 1747 | printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using %s %s\n"), | ||
814 | 1748 | internal::my_progname, VER.c_str(), drizzle_version(), | ||
815 | 1749 | HOST_VENDOR, HOST_OS, HOST_CPU, | ||
816 | 1750 | readline, rl_library_version); | ||
817 | 1751 | |||
818 | 1752 | if (version) | ||
819 | 1753 | return; | ||
820 | 1754 | printf(_("Copyright (C) 2008 Sun Microsystems\n" | ||
821 | 1755 | "This software comes with ABSOLUTELY NO WARRANTY. " | ||
822 | 1756 | "This is free software,\n" | ||
823 | 1757 | "and you are welcome to modify and redistribute it " | ||
824 | 1758 | "under the GPL license\n")); | ||
825 | 1759 | printf(_("Usage: %s [OPTIONS] [database]\n"), internal::my_progname); | ||
826 | 1760 | my_print_help(my_long_options); | ||
827 | 1761 | internal::print_defaults("drizzle", load_default_groups); | ||
828 | 1762 | my_print_variables(my_long_options); | ||
829 | 1763 | } | ||
830 | 1764 | |||
831 | 1765 | |||
832 | 1766 | static int get_one_option(int optid, const struct option *, char *argument) | ||
833 | 1767 | { | ||
834 | 1768 | char *endchar= NULL; | ||
835 | 1769 | uint64_t temp_drizzle_port= 0; | ||
836 | 1770 | |||
837 | 1771 | switch(optid) { | ||
838 | 1772 | case OPT_DEFAULT_CHARSET: | ||
839 | 1773 | default_charset_used= 1; | ||
840 | 1774 | break; | ||
841 | 1775 | case OPT_DELIMITER: | ||
842 | 1776 | if (argument == disabled_my_option) | ||
843 | 1777 | { | ||
844 | 1778 | strcpy(delimiter, DEFAULT_DELIMITER); | ||
845 | 1779 | } | ||
846 | 1780 | else | ||
847 | 1781 | { | ||
848 | 1782 | /* Check that delimiter does not contain a backslash */ | ||
849 | 1783 | if (!strstr(argument, "\\")) | ||
850 | 1784 | { | ||
851 | 1785 | strncpy(delimiter, argument, sizeof(delimiter) - 1); | ||
852 | 1786 | } | ||
853 | 1787 | else | ||
854 | 1788 | { | ||
855 | 1789 | put_info(_("DELIMITER cannot contain a backslash character"), | ||
856 | 1790 | INFO_ERROR,0,0); | ||
857 | 1791 | return false; | ||
858 | 1792 | } | ||
859 | 1793 | } | ||
860 | 1794 | delimiter_length= (uint32_t)strlen(delimiter); | ||
861 | 1795 | delimiter_str= delimiter; | ||
862 | 1796 | break; | ||
863 | 1797 | case OPT_TEE: | ||
864 | 1798 | if (argument == disabled_my_option) | ||
865 | 1799 | { | ||
866 | 1800 | if (opt_outfile) | ||
867 | 1801 | end_tee(); | ||
868 | 1802 | } | ||
869 | 1803 | else | ||
870 | 1804 | init_tee(argument); | ||
871 | 1805 | break; | ||
872 | 1806 | case OPT_NOTEE: | ||
873 | 1807 | printf(_("WARNING: option deprecated; use --disable-tee instead.\n")); | ||
874 | 1808 | if (opt_outfile) | ||
875 | 1809 | end_tee(); | ||
876 | 1810 | break; | ||
877 | 1811 | case OPT_PAGER: | ||
878 | 1812 | if (argument == disabled_my_option) | ||
879 | 1813 | opt_nopager= 1; | ||
880 | 1814 | else | ||
881 | 1815 | { | ||
882 | 1816 | opt_nopager= 0; | ||
883 | 1817 | if (argument && strlen(argument)) | ||
884 | 1818 | { | ||
885 | 1819 | default_pager_set= 1; | ||
886 | 1820 | strncpy(pager, argument, sizeof(pager) - 1); | ||
887 | 1821 | strcpy(default_pager, pager); | ||
888 | 1822 | } | ||
889 | 1823 | else if (default_pager_set) | ||
890 | 1824 | strcpy(pager, default_pager); | ||
891 | 1825 | else | ||
892 | 1826 | opt_nopager= 1; | ||
893 | 1827 | } | ||
894 | 1828 | break; | ||
895 | 1829 | case OPT_NOPAGER: | ||
896 | 1830 | printf(_("WARNING: option deprecated; use --disable-pager instead.\n")); | ||
897 | 1831 | opt_nopager= 1; | ||
898 | 1832 | break; | ||
899 | 1833 | case OPT_SERVER_ARG: | ||
900 | 1834 | printf(_("WARNING: --server-arg option not supported in this configuration.\n")); | ||
901 | 1835 | break; | ||
902 | 1836 | case 'A': | ||
903 | 1837 | opt_rehash= 0; | ||
904 | 1838 | break; | ||
905 | 1839 | case 'N': | ||
906 | 1840 | column_names= 0; | ||
907 | 1841 | break; | ||
908 | 1842 | case 'e': | ||
909 | 1843 | status.setBatch(1); | ||
910 | 1844 | status.setAddToHistory(1); | ||
911 | 1845 | if (status.getLineBuff() == NULL) | ||
912 | 1846 | status.setLineBuff(opt_max_input_line,NULL); | ||
913 | 1847 | if (status.getLineBuff() == NULL) | ||
914 | 1848 | { | ||
915 | 1849 | internal::my_end(); | ||
916 | 1850 | exit(1); | ||
917 | 1851 | } | ||
918 | 1852 | status.getLineBuff()->addString(argument); | ||
919 | 1853 | break; | ||
920 | 1854 | case 'o': | ||
921 | 1855 | if (argument == disabled_my_option) | ||
922 | 1856 | one_database= 0; | ||
923 | 1857 | else | ||
924 | 1858 | one_database= skip_updates= 1; | ||
925 | 1859 | break; | ||
926 | 1860 | case 'p': | ||
927 | 1861 | temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10); | ||
928 | 1862 | /* if there is an alpha character this is not a valid port */ | ||
929 | 1863 | if (strlen(endchar) != 0) | ||
930 | 1864 | { | ||
931 | 1865 | put_info(_("Non-integer value supplied for port. If you are trying to enter a password please use --password instead."), INFO_ERROR, 0, 0); | ||
932 | 1866 | return false; | ||
933 | 1867 | } | ||
934 | 1868 | /* If the port number is > 65535 it is not a valid port | ||
935 | 1869 | This also helps with potential data loss casting unsigned long to a | ||
936 | 1870 | uint32_t. */ | ||
937 | 1871 | if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535)) | ||
938 | 1872 | { | ||
939 | 1873 | put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0); | ||
940 | 1874 | return false; | ||
941 | 1875 | } | ||
942 | 1876 | else | ||
943 | 1877 | { | ||
944 | 1878 | opt_drizzle_port= (uint32_t) temp_drizzle_port; | ||
945 | 1879 | } | ||
946 | 1880 | break; | ||
947 | 1881 | case 'P': | ||
948 | 1882 | /* Don't require password */ | ||
949 | 1883 | if (argument == disabled_my_option) | ||
950 | 1884 | { | ||
951 | 1885 | argument= (char*) ""; | ||
952 | 1886 | } | ||
953 | 1887 | if (argument) | ||
954 | 1888 | { | ||
955 | 1889 | char *start= argument; | ||
956 | 1890 | free(opt_password); | ||
957 | 1891 | opt_password= strdup(argument); | ||
958 | 1892 | while (*argument) | ||
959 | 1893 | { | ||
960 | 1894 | /* Overwriting password with 'x' */ | ||
961 | 1895 | *argument++= 'x'; | ||
962 | 1896 | } | ||
963 | 1897 | if (*start) | ||
964 | 1898 | { | ||
965 | 1899 | start[1]= 0; | ||
966 | 1900 | } | ||
967 | 1901 | tty_password= 0; | ||
968 | 1902 | } | ||
969 | 1903 | else | ||
970 | 1904 | { | ||
971 | 1905 | tty_password= 1; | ||
972 | 1906 | } | ||
973 | 1907 | break; | ||
974 | 1908 | case 's': | ||
975 | 1909 | if (argument == disabled_my_option) | ||
976 | 1910 | opt_silent= 0; | ||
977 | 1911 | else | ||
978 | 1912 | opt_silent++; | ||
979 | 1913 | break; | ||
980 | 1914 | case 'v': | ||
981 | 1915 | if (argument == disabled_my_option) | ||
982 | 1916 | verbose= 0; | ||
983 | 1917 | else | ||
984 | 1918 | verbose++; | ||
985 | 1919 | break; | ||
986 | 1920 | case 'B': | ||
987 | 1921 | status.setBatch(1); | ||
988 | 1922 | status.setAddToHistory(0); | ||
989 | 1923 | set_if_bigger(opt_silent,1); // more silent | ||
990 | 1924 | break; | ||
991 | 1925 | case 'V': | ||
992 | 1926 | usage(1); | ||
993 | 1927 | exit(0); | ||
994 | 1928 | case 'I': | ||
995 | 1929 | case '?': | ||
996 | 1930 | usage(0); | ||
997 | 1931 | exit(0); | ||
998 | 1932 | } | ||
999 | 1933 | return 0; | ||
1000 | 1934 | } | ||
1001 | 1935 | |||
1002 | 1936 | |||
1003 | 1937 | static int get_options(int argc, char **argv) | ||
1007 | 1938 | { | 1969 | { |
1008 | 1939 | char *tmp, *pagpoint; | 1970 | char *tmp, *pagpoint; |
1010 | 1940 | int ho_error; | 1971 | |
1011 | 1941 | 1972 | ||
1012 | 1942 | tmp= (char *) getenv("DRIZZLE_HOST"); | 1973 | tmp= (char *) getenv("DRIZZLE_HOST"); |
1013 | 1943 | if (tmp) | 1974 | if (tmp) |
1014 | @@ -1953,8 +1984,7 @@ | |||
1015 | 1953 | strcpy(pager, pagpoint); | 1984 | strcpy(pager, pagpoint); |
1016 | 1954 | strcpy(default_pager, pager); | 1985 | strcpy(default_pager, pager); |
1017 | 1955 | 1986 | ||
1020 | 1956 | if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) | 1987 | // |
1019 | 1957 | exit(ho_error); | ||
1021 | 1958 | 1988 | ||
1022 | 1959 | if (status.getBatch()) /* disable pager and outfile in this case */ | 1989 | if (status.getBatch()) /* disable pager and outfile in this case */ |
1023 | 1960 | { | 1990 | { |
1024 | @@ -1967,20 +1997,8 @@ | |||
1025 | 1967 | connect_flag= DRIZZLE_CAPABILITIES_NONE; /* Not in interactive mode */ | 1997 | connect_flag= DRIZZLE_CAPABILITIES_NONE; /* Not in interactive mode */ |
1026 | 1968 | } | 1998 | } |
1027 | 1969 | 1999 | ||
1028 | 1970 | if (argc > 1) | ||
1029 | 1971 | { | ||
1030 | 1972 | usage(0); | ||
1031 | 1973 | exit(1); | ||
1032 | 1974 | } | ||
1033 | 1975 | if (argc == 1) | ||
1034 | 1976 | { | ||
1035 | 1977 | skip_updates= 0; | ||
1036 | 1978 | free(current_db); | ||
1037 | 1979 | current_db= strdup(*argv); | ||
1038 | 1980 | } | ||
1039 | 1981 | if (tty_password) | 2000 | if (tty_password) |
1040 | 1982 | opt_password= client_get_tty_password(NULL); | 2001 | opt_password= client_get_tty_password(NULL); |
1041 | 1983 | |||
1042 | 1984 | return(0); | 2002 | return(0); |
1043 | 1985 | } | 2003 | } |
1044 | 1986 | 2004 | ||
1045 | @@ -2582,7 +2600,7 @@ | |||
1046 | 2582 | drizzle_column_st *sql_field; | 2600 | drizzle_column_st *sql_field; |
1047 | 2583 | string tmp_str, tmp_str_lower; | 2601 | string tmp_str, tmp_str_lower; |
1048 | 2584 | 2602 | ||
1050 | 2585 | if (status.getBatch() || quick || !current_db) | 2603 | if (status.getBatch() || quick || current_db.empty()) |
1051 | 2586 | return; // We don't need completion in batches | 2604 | return; // We don't need completion in batches |
1052 | 2587 | if (!rehash) | 2605 | if (!rehash) |
1053 | 2588 | return; | 2606 | return; |
1054 | @@ -2717,8 +2735,8 @@ | |||
1055 | 2717 | drizzle_return_t ret; | 2735 | drizzle_return_t ret; |
1056 | 2718 | drizzle_result_st res; | 2736 | drizzle_result_st res; |
1057 | 2719 | 2737 | ||
1060 | 2720 | free(current_db); | 2738 | current_db.erase(); |
1061 | 2721 | current_db= NULL; | 2739 | current_db= ""; |
1062 | 2722 | /* In case of error below current_db will be NULL */ | 2740 | /* In case of error below current_db will be NULL */ |
1063 | 2723 | if (drizzle_query_str(&con, &res, "SELECT DATABASE()", &ret) != NULL) | 2741 | if (drizzle_query_str(&con, &res, "SELECT DATABASE()", &ret) != NULL) |
1064 | 2724 | { | 2742 | { |
1065 | @@ -3746,12 +3764,12 @@ | |||
1066 | 3746 | tmp= get_arg(buff, 0); | 3764 | tmp= get_arg(buff, 0); |
1067 | 3747 | if (tmp && *tmp) | 3765 | if (tmp && *tmp) |
1068 | 3748 | { | 3766 | { |
1070 | 3749 | free(current_db); | 3767 | current_db.erase(); |
1071 | 3750 | current_db= strdup(tmp); | 3768 | current_db= strdup(tmp); |
1072 | 3751 | tmp= get_arg(buff, 1); | 3769 | tmp= get_arg(buff, 1); |
1073 | 3752 | if (tmp) | 3770 | if (tmp) |
1074 | 3753 | { | 3771 | { |
1076 | 3754 | free(current_host); | 3772 | current_host.erase(); |
1077 | 3755 | current_host=strdup(tmp); | 3773 | current_host=strdup(tmp); |
1078 | 3756 | } | 3774 | } |
1079 | 3757 | } | 3775 | } |
1080 | @@ -3766,7 +3784,7 @@ | |||
1081 | 3766 | } | 3784 | } |
1082 | 3767 | else | 3785 | else |
1083 | 3768 | opt_rehash= 0; | 3786 | opt_rehash= 0; |
1085 | 3769 | error=sql_connect(current_host,current_db,current_user,opt_password,0); | 3787 | error=sql_connect(current_host, current_db, current_user, opt_password,0); |
1086 | 3770 | opt_rehash= save_rehash; | 3788 | opt_rehash= save_rehash; |
1087 | 3771 | 3789 | ||
1088 | 3772 | if (connected) | 3790 | if (connected) |
1089 | @@ -3774,7 +3792,7 @@ | |||
1090 | 3774 | sprintf(buff,"Connection id: %u",drizzle_con_thread_id(&con)); | 3792 | sprintf(buff,"Connection id: %u",drizzle_con_thread_id(&con)); |
1091 | 3775 | put_info(buff,INFO_INFO,0,0); | 3793 | put_info(buff,INFO_INFO,0,0); |
1092 | 3776 | sprintf(buff,"Current database: %.128s\n", | 3794 | sprintf(buff,"Current database: %.128s\n", |
1094 | 3777 | current_db ? current_db : "*** NONE ***"); | 3795 | !current_db.empty() ? current_db.c_str() : "*** NONE ***"); |
1095 | 3778 | put_info(buff,INFO_INFO,0,0); | 3796 | put_info(buff,INFO_INFO,0,0); |
1096 | 3779 | } | 3797 | } |
1097 | 3780 | return error; | 3798 | return error; |
1098 | @@ -3896,7 +3914,7 @@ | |||
1099 | 3896 | */ | 3914 | */ |
1100 | 3897 | get_current_db(); | 3915 | get_current_db(); |
1101 | 3898 | 3916 | ||
1103 | 3899 | if (!current_db || strcmp(current_db,tmp)) | 3917 | if (current_db.empty() || strcmp(current_db.c_str(),tmp)) |
1104 | 3900 | { | 3918 | { |
1105 | 3901 | if (one_database) | 3919 | if (one_database) |
1106 | 3902 | { | 3920 | { |
1107 | @@ -3948,7 +3966,7 @@ | |||
1108 | 3948 | else | 3966 | else |
1109 | 3949 | drizzle_result_free(&result); | 3967 | drizzle_result_free(&result); |
1110 | 3950 | } | 3968 | } |
1112 | 3951 | free(current_db); | 3969 | current_db.erase(); |
1113 | 3952 | current_db= strdup(tmp); | 3970 | current_db= strdup(tmp); |
1114 | 3953 | if (select_db > 1) | 3971 | if (select_db > 1) |
1115 | 3954 | build_completion_hash(opt_rehash, 1); | 3972 | build_completion_hash(opt_rehash, 1); |
1116 | @@ -4037,11 +4055,10 @@ | |||
1117 | 4037 | 4055 | ||
1118 | 4038 | 4056 | ||
1119 | 4039 | static int | 4057 | static int |
1121 | 4040 | sql_connect(char *host,char *database,char *user,char *password, | 4058 | sql_connect(const string &host, const string &database, const string &user, const string &password, |
1122 | 4041 | uint32_t silent) | 4059 | uint32_t silent) |
1123 | 4042 | { | 4060 | { |
1124 | 4043 | drizzle_return_t ret; | 4061 | drizzle_return_t ret; |
1125 | 4044 | |||
1126 | 4045 | if (connected) | 4062 | if (connected) |
1127 | 4046 | { | 4063 | { |
1128 | 4047 | connected= 0; | 4064 | connected= 0; |
1129 | @@ -4049,8 +4066,8 @@ | |||
1130 | 4049 | drizzle_free(&drizzle); | 4066 | drizzle_free(&drizzle); |
1131 | 4050 | } | 4067 | } |
1132 | 4051 | drizzle_create(&drizzle); | 4068 | drizzle_create(&drizzle); |
1135 | 4052 | if (drizzle_con_add_tcp(&drizzle, &con, host, opt_drizzle_port, user, | 4069 | if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(), opt_drizzle_port, (char *)user.c_str(), |
1136 | 4053 | password, database, opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL) | 4070 | (char *)password.c_str(), (char *)database.c_str(), opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL) |
1137 | 4054 | { | 4071 | { |
1138 | 4055 | (void) put_error(&con, NULL); | 4072 | (void) put_error(&con, NULL); |
1139 | 4056 | (void) fflush(stdout); | 4073 | (void) fflush(stdout); |
1140 | @@ -4106,7 +4123,12 @@ | |||
1141 | 4106 | drizzle_return_t ret; | 4123 | drizzle_return_t ret; |
1142 | 4107 | 4124 | ||
1143 | 4108 | tee_puts("--------------", stdout); | 4125 | tee_puts("--------------", stdout); |
1145 | 4109 | usage(1); /* Print version */ | 4126 | printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"), |
1146 | 4127 | internal::my_progname, VER.c_str(), drizzle_version(), | ||
1147 | 4128 | HOST_VENDOR, HOST_OS, HOST_CPU, | ||
1148 | 4129 | rl_library_version); /* Print version */ | ||
1149 | 4130 | |||
1150 | 4131 | |||
1151 | 4110 | if (connected) | 4132 | if (connected) |
1152 | 4111 | { | 4133 | { |
1153 | 4112 | tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_con_thread_id(&con)); | 4134 | tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_con_thread_id(&con)); |
1154 | @@ -4452,7 +4474,7 @@ | |||
1155 | 4452 | struct tm *t = localtime(&lclock); | 4474 | struct tm *t = localtime(&lclock); |
1156 | 4453 | 4475 | ||
1157 | 4454 | /* parse thru the settings for the prompt */ | 4476 | /* parse thru the settings for the prompt */ |
1159 | 4455 | for (char *c= current_prompt; *c; (void)*c++) | 4477 | for (char *c= (char *)current_prompt.c_str(); *c; (void)*c++) |
1160 | 4456 | { | 4478 | { |
1161 | 4457 | if (*c != PROMPT_CHAR) | 4479 | if (*c != PROMPT_CHAR) |
1162 | 4458 | { | 4480 | { |
1163 | @@ -4479,7 +4501,7 @@ | |||
1164 | 4479 | processed_prompt->append("not_connected"); | 4501 | processed_prompt->append("not_connected"); |
1165 | 4480 | break; | 4502 | break; |
1166 | 4481 | case 'd': | 4503 | case 'd': |
1168 | 4482 | processed_prompt->append(current_db ? current_db : "(none)"); | 4504 | processed_prompt->append(!current_db.empty() ? current_db.c_str() : "(none)"); |
1169 | 4483 | break; | 4505 | break; |
1170 | 4484 | case 'h': | 4506 | case 'h': |
1171 | 4485 | { | 4507 | { |
1172 | @@ -4516,13 +4538,13 @@ | |||
1173 | 4516 | if (!full_username) | 4538 | if (!full_username) |
1174 | 4517 | init_username(); | 4539 | init_username(); |
1175 | 4518 | processed_prompt->append(full_username ? full_username : | 4540 | processed_prompt->append(full_username ? full_username : |
1177 | 4519 | (current_user ? current_user : "(unknown)")); | 4541 | (!current_user.empty() ? current_user.c_str() : "(unknown)")); |
1178 | 4520 | break; | 4542 | break; |
1179 | 4521 | case 'u': | 4543 | case 'u': |
1180 | 4522 | if (!full_username) | 4544 | if (!full_username) |
1181 | 4523 | init_username(); | 4545 | init_username(); |
1182 | 4524 | processed_prompt->append(part_username ? part_username : | 4546 | processed_prompt->append(part_username ? part_username : |
1184 | 4525 | (current_user ? current_user : "(unknown)")); | 4547 | (!current_user.empty() ? current_user.c_str() : "(unknown)")); |
1185 | 4526 | break; | 4548 | break; |
1186 | 4527 | case PROMPT_CHAR: | 4549 | case PROMPT_CHAR: |
1187 | 4528 | { | 4550 | { |
1188 | @@ -4601,7 +4623,7 @@ | |||
1189 | 4601 | processed_prompt->append("\t"); | 4623 | processed_prompt->append("\t"); |
1190 | 4602 | break; | 4624 | break; |
1191 | 4603 | case 'l': | 4625 | case 'l': |
1193 | 4604 | processed_prompt->append(delimiter_str); | 4626 | processed_prompt->append(delimiter_str.c_str()); |
1194 | 4605 | break; | 4627 | break; |
1195 | 4606 | default: | 4628 | default: |
1196 | 4607 | processed_prompt->append(c, 1); | 4629 | processed_prompt->append(c, 1); |
1197 | @@ -4649,9 +4671,9 @@ | |||
1198 | 4649 | tee_fprintf(stdout, "Memory allocation error. Not changing prompt\n"); | 4671 | tee_fprintf(stdout, "Memory allocation error. Not changing prompt\n"); |
1199 | 4650 | else | 4672 | else |
1200 | 4651 | { | 4673 | { |
1202 | 4652 | free(current_prompt); | 4674 | current_prompt.erase(); |
1203 | 4653 | current_prompt= tmpptr; | 4675 | current_prompt= tmpptr; |
1205 | 4654 | tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt); | 4676 | tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt.c_str()); |
1206 | 4655 | } | 4677 | } |
1207 | 4656 | return 0; | 4678 | return 0; |
1208 | 4657 | } | 4679 | } |
1209 | 4658 | 4680 | ||
1210 | === modified file 'client/include.am' | |||
1211 | --- client/include.am 2010-06-02 16:51:50 +0000 | |||
1212 | +++ client/include.am 2010-06-04 16:41:24 +0000 | |||
1213 | @@ -45,7 +45,7 @@ | |||
1214 | 45 | 45 | ||
1215 | 46 | 46 | ||
1216 | 47 | client_drizzle_SOURCES= client/drizzle.cc client/linebuffer.cc | 47 | client_drizzle_SOURCES= client/drizzle.cc client/linebuffer.cc |
1218 | 48 | client_drizzle_LDADD= ${CLIENT_LDADD} ${READLINE_LIBS} | 48 | client_drizzle_LDADD= ${CLIENT_LDADD} ${READLINE_LIBS} ${BOOST_LIBS} |
1219 | 49 | client_drizzle_CXXFLAGS= ${CLIENT_CXXFLAGS} | 49 | client_drizzle_CXXFLAGS= ${CLIENT_CXXFLAGS} |
1220 | 50 | 50 | ||
1221 | 51 | client_drizzledump_SOURCES= client/drizzledump.cc | 51 | client_drizzledump_SOURCES= client/drizzledump.cc |
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) input_line< 4096 || in_max_ input_line> (int64_ t)2*1024L* 1024L*1024L) "--password" )==0) 10)=="= ")
129 + if( in_max_
140 + if (s.find(
154 + if(s.substr(
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