159
158
#define vidattr(A) {} // Can't get this to work
161
160
#include <boost/program_options.hpp>
162
#include <boost/scoped_ptr.hpp>
163
#include "drizzled/program_options/config_file.h"
165
162
using namespace std;
166
163
namespace po=boost::program_options;
167
namespace dpo=drizzled::program_options;
169
165
/* Don't try to make a nice table if the data is too big */
170
166
const uint32_t MAX_COLUMN_LENGTH= 1024;
181
177
Status(int in_exit_status,
182
178
uint32_t in_query_start_line,
184
180
LineBuffer *in_line_buff,
186
bool in_add_to_history)
182
bool in_add_to_history)
188
184
exit_status(in_exit_status),
189
185
query_start_line(in_query_start_line),
290
287
connected= false, opt_raw_data= false, unbuffered= false,
291
288
output_tables= false, opt_rehash= true, skip_updates= false,
292
289
safe_updates= false, one_database= false,
293
opt_shutdown= false, opt_ping= false,
290
opt_compress= false, opt_shutdown= false, opt_ping= false,
294
291
vertical= false, line_numbers= true, column_names= true,
295
292
opt_nopager= true, opt_outfile= false, named_cmds= false,
296
293
opt_nobeep= false, opt_reconnect= true,
341
338
static uint32_t delimiter_length= 1;
342
339
unsigned short terminal_width= 80;
344
int drizzleclient_real_query_for_lazy(const char *buf, size_t length,
341
int drizzleclient_real_query_for_lazy(const char *buf, int length,
345
342
drizzle_result_st *result,
346
343
uint32_t *error_code);
347
344
int drizzleclient_store_result_for_lazy(drizzle_result_st *result);
360
357
com_help(string *str,const char*), com_clear(string *str,const char*),
361
358
com_connect(string *str,const char*), com_status(string *str,const char*),
362
359
com_use(string *str,const char*), com_source(string *str, const char*),
363
com_shutdown(string *str,const char*),
364
360
com_rehash(string *str, const char*), com_tee(string *str, const char*),
365
361
com_notee(string *str, const char*),
366
362
com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
492
488
N_("Set outfile [to_outfile]. Append everything into given outfile.") ),
493
489
Commands( "use", 'u', com_use, 1,
494
490
N_("Use another database. Takes database name as argument.") ),
495
Commands( "shutdown", 'u', com_shutdown, 1,
496
N_("Shutdown the instance you are connected too.") ),
497
491
Commands( "warnings", 'W', com_warnings, 0,
498
492
N_("Show warnings after every statement.") ),
499
493
Commands( "nowarning", 'w', com_nowarnings, 0,
1293
1287
N_("Display column type information."))
1294
1288
("comments,c", po::value<bool>(&preserve_comments)->default_value(false)->zero_tokens(),
1295
1289
N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"))
1290
("compress,C", po::value<bool>(&opt_compress)->default_value(false)->zero_tokens(),
1291
N_("Use compression in server/client protocol."))
1296
1292
("vertical,E", po::value<bool>(&vertical)->default_value(false)->zero_tokens(),
1297
1293
N_("Print the output of a query (rows) vertically."))
1298
1294
("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
1331
1327
po::options_description drizzle_options(N_("Options specific to the drizzle client"));
1332
1328
drizzle_options.add_options()
1333
("disable-auto-rehash,A",
1329
("disable-auto-rehash",
1334
1330
N_("Disable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time."))
1335
1331
("auto-vertical-output", po::value<bool>(&auto_vertical_output)->default_value(false)->zero_tokens(),
1336
1332
N_("Automatically switch to vertical output mode if the result is wider than the terminal width."))
1361
1357
("raw,r", po::value<bool>(&opt_raw_data)->default_value(false)->zero_tokens(),
1362
1358
N_("Write fields without conversion. Used with --batch."))
1363
1359
("disable-reconnect", N_("Do not reconnect if the connection is lost."))
1364
("shutdown", po::value<bool>()->zero_tokens(),
1360
("shutdown", po::value<bool>(&opt_shutdown)->default_value(false)->zero_tokens(),
1365
1361
N_("Shutdown the server"))
1366
1362
("silent,s", N_("Be more silent. Print results with a tab as separator, each row on new line."))
1367
1363
("tee", po::value<string>(),
1368
1364
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."))
1369
1365
("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(),
1370
1366
N_("Disable outfile. See interactive help (\\h) also."))
1371
("connect-timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
1367
("connect_timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
1372
1368
N_("Number of seconds before connection timeout."))
1373
("max-input-line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
1369
("max_input_line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
1374
1370
N_("Max length of input line"))
1375
("select-limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
1371
("select_limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
1376
1372
N_("Automatic limit for SELECT when using --safe-updates"))
1377
("max-join-size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
1373
("max_join_size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
1378
1374
N_("Automatic limit for rows in a join when using --safe-updates"))
1386
1382
N_("Password to use when connecting to server. If password is not given it's asked from the tty."))
1387
1383
("port,p", po::value<uint32_t>()->default_value(0),
1388
1384
N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default"))
1389
#ifdef DRIZZLE_ADMIN_TOOL
1390
("user,u", po::value<string>(¤t_user)->default_value("root"),
1392
1385
("user,u", po::value<string>(¤t_user)->default_value(""),
1394
1386
N_("User for login if not current user."))
1395
1387
("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
1396
1388
N_("The protocol of connection (mysql or drizzle)."))
1406
1398
system_config_dir_client.append("/drizzle/client.cnf");
1408
1400
std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
1410
if (user_config_dir.compare(0, 2, "~/") == 0)
1413
homedir= getenv("HOME");
1414
if (homedir != NULL)
1415
user_config_dir.replace(0, 1, homedir);
1418
1402
po::variables_map vm;
1420
1404
po::positional_options_description p;
1436
1420
user_config_dir_client.append("/drizzle/client.cnf");
1438
1422
ifstream user_drizzle_ifs(user_config_dir_drizzle.c_str());
1439
po::store(dpo::parse_config_file(user_drizzle_ifs, drizzle_options), vm);
1423
po::store(parse_config_file(user_drizzle_ifs, drizzle_options), vm);
1441
1425
ifstream user_client_ifs(user_config_dir_client.c_str());
1442
po::store(dpo::parse_config_file(user_client_ifs, client_options), vm);
1426
po::store(parse_config_file(user_client_ifs, client_options), vm);
1444
1428
ifstream system_drizzle_ifs(system_config_dir_drizzle.c_str());
1445
store(dpo::parse_config_file(system_drizzle_ifs, drizzle_options), vm);
1429
store(parse_config_file(system_drizzle_ifs, drizzle_options), vm);
1447
1431
ifstream system_client_ifs(system_config_dir_client.c_str());
1448
po::store(dpo::parse_config_file(system_client_ifs, client_options), vm);
1432
po::store(parse_config_file(system_client_ifs, client_options), vm);
1451
1435
po::notify(vm);
1453
#ifdef DRIZZLE_ADMIN_TOOL
1454
default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1455
getenv("DRIZZLE_PS1") :
1458
1437
default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1459
1438
getenv("DRIZZLE_PS1") :
1462
1440
if (default_prompt == NULL)
1464
1442
fprintf(stderr, _("Memory allocation error while constructing initial "
1517
1495
opt_rehash= (vm.count("disable-auto-rehash")) ? false : true;
1518
1496
opt_reconnect= (vm.count("disable-reconnect")) ? false : true;
1520
/* Don't rehash with --shutdown */
1521
if (vm.count("shutdown"))
1527
1498
if (vm.count("delimiter"))
1529
1500
/* Check that delimiter does not contain a backslash */
1860
if (drizzle_con_add_tcp(&drizzle, kill_drizzle.get(), current_host.c_str(),
1833
if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host.c_str(),
1861
1834
opt_drizzle_port, current_user.c_str(), opt_password.c_str(), NULL,
1862
1835
use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
1868
1841
sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u",
1869
1842
drizzle_con_thread_id(&con));
1871
if (drizzle_query_str(kill_drizzle.get(), &res, kill_buffer, &ret) != NULL)
1844
if (drizzle_query_str(&kill_drizzle, &res, kill_buffer, &ret) != NULL)
1872
1845
drizzle_result_free(&res);
1874
drizzle_con_free(kill_drizzle.get());
1847
drizzle_con_free(&kill_drizzle);
1875
1848
tee_fprintf(stdout, _("Query aborted by Ctrl+C\n"));
1877
1850
interrupted_query= 1;
2344
2317
uint32_t length=(uint32_t) (out-line);
2345
if ((buffer->length() + length) > opt_max_input_line)
2347
status.setExitStatus(1);
2348
put_info(_("Not found a delimiter within max_input_line of input"), INFO_ERROR, 0, 0);
2351
2318
if ((!*ml_comment || preserve_comments))
2352
2319
buffer->append(line, length);
2626
query.append("show fields in `");
2593
query.append("show fields in '");
2627
2594
query.append(table_row[0]);
2630
2597
if (drizzle_query(&con, &fields, query.c_str(), query.length(),
2695
2662
The different commands
2696
2663
***************************************************************************/
2698
int drizzleclient_real_query_for_lazy(const char *buf, size_t length,
2665
int drizzleclient_real_query_for_lazy(const char *buf, int length,
2699
2666
drizzle_result_st *result,
2700
2667
uint32_t *error_code)
3612
3579
/* Skip the spaces between the command and the argument */
3613
3580
while (param && isspace(*param))
3615
if (!param || (*param == '\0')) // if pager was not given, use the default
3582
if (!param || !strlen(param)) // if pager was not given, use the default
3617
3584
if (!default_pager_set)
3920
static int com_shutdown(string *, const char *)
3922
drizzle_result_st result;
3923
drizzle_return_t ret;
3927
printf(_("shutting down drizzled"));
3928
if (opt_drizzle_port > 0)
3929
printf(_(" on port %d"), opt_drizzle_port);
3933
if (drizzle_shutdown(&con, &result, DRIZZLE_SHUTDOWN_DEFAULT,
3934
&ret) == NULL || ret != DRIZZLE_RETURN_OK)
3936
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3938
fprintf(stderr, _("shutdown failed; error: '%s'"),
3939
drizzle_result_error(&result));
3940
drizzle_result_free(&result);
3944
fprintf(stderr, _("shutdown failed; error: '%s'"),
3945
drizzle_con_error(&con));
3950
drizzle_result_free(&result);
3953
printf(_("done\n"));
3959
3888
com_warnings(string *, const char *)
4045
3974
drizzle_free(&drizzle);
4047
3976
drizzle_create(&drizzle);
4049
#ifdef DRIZZLE_ADMIN_TOOL
4050
drizzle_con_options_t options= (drizzle_con_options_t) (DRIZZLE_CON_ADMIN | (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL));
4052
drizzle_con_options_t options= (drizzle_con_options_t) (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
4055
3977
if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(),
4056
3978
opt_drizzle_port, (char *)user.c_str(),
4057
3979
(char *)password.c_str(), (char *)database.c_str(),
3980
use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
4060
3982
(void) put_error(&con, NULL);
4061
3983
(void) fflush(stdout);