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,
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(),
1299
1295
N_("Continue even if we get an sql error."))
1300
1296
("named-commands,G", po::value<bool>(&named_cmds)->default_value(false)->zero_tokens(),
1301
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."))
1297
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."))
1298
("no-named-commands,g",
1299
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."))
1300
("ignore-spaces,i", N_("Ignore space after function names."))
1302
1301
("no-beep,b", po::value<bool>(&opt_nobeep)->default_value(false)->zero_tokens(),
1303
1302
N_("Turn off beep on error."))
1304
("disable-line-numbers", N_("Do not write line numbers for errors."))
1305
("disable-column-names", N_("Do not write column names in results."))
1303
("line-numbers", po::value<bool>(&line_numbers)->default_value(true)->zero_tokens(),
1304
N_("Write line numbers for errors."))
1305
("skip-line-numbers,L",
1306
N_("Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead."))
1307
("column-name", po::value<bool>(&column_names)->default_value(true)->zero_tokens(),
1308
N_("Write column names in results."))
1306
1309
("skip-column-names,N",
1307
1310
N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."))
1308
1311
("set-variable,O", po::value<string>(),
1309
1312
N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."))
1310
1313
("table,t", po::value<bool>(&output_tables)->default_value(false)->zero_tokens(),
1311
1314
N_("Output in table format."))
1312
("safe-updates,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
1315
("safe-updates,U", po::value<bool>(&safe_updates)->default_value(0)->zero_tokens(),
1313
1316
N_("Only allow UPDATE and DELETE that uses keys."))
1314
("i-am-a-dummy,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
1317
("i-am-a-dummy,U", po::value<bool>(&safe_updates)->default_value(0)->zero_tokens(),
1315
1318
N_("Synonym for option --safe-updates, -U."))
1316
1319
("verbose,v", po::value<string>(&opt_verbose)->default_value(""),
1317
1320
N_("-v vvv implies that verbose= 3, Used to specify verbose"))
1331
1334
po::options_description drizzle_options(N_("Options specific to the drizzle client"));
1332
1335
drizzle_options.add_options()
1333
("disable-auto-rehash,A",
1334
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."))
1336
("auto-rehash", po::value<bool>(&opt_rehash)->default_value(true)->zero_tokens(),
1337
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."))
1338
("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."))
1335
1339
("auto-vertical-output", po::value<bool>(&auto_vertical_output)->default_value(false)->zero_tokens(),
1336
1340
N_("Automatically switch to vertical output mode if the result is wider than the terminal width."))
1337
1341
("database,D", po::value<string>(¤t_db)->default_value(""),
1343
1347
("execute,e", po::value<string>(),
1344
1348
N_("Execute command and quit. (Disables --force and history file)"))
1345
1349
("local-infile", po::value<bool>(&opt_local_infile)->default_value(false)->zero_tokens(),
1346
N_("Enable LOAD DATA LOCAL INFILE."))
1350
N_("Enable/disable LOAD DATA LOCAL INFILE."))
1347
1351
("unbuffered,n", po::value<bool>(&unbuffered)->default_value(false)->zero_tokens(),
1348
1352
N_("Flush buffer after each query."))
1349
1353
("sigint-ignore", po::value<bool>(&opt_sigint_ignore)->default_value(false)->zero_tokens(),
1360
1364
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."))
1361
1365
("raw,r", po::value<bool>(&opt_raw_data)->default_value(false)->zero_tokens(),
1362
1366
N_("Write fields without conversion. Used with --batch."))
1363
("disable-reconnect", N_("Do not reconnect if the connection is lost."))
1364
("shutdown", po::value<bool>()->zero_tokens(),
1367
("reconnect", po::value<bool>(&opt_reconnect)->default_value(true)->zero_tokens(),
1368
N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."))
1369
("shutdown", po::value<bool>(&opt_shutdown)->default_value(false)->zero_tokens(),
1365
1370
N_("Shutdown the server"))
1366
1371
("silent,s", N_("Be more silent. Print results with a tab as separator, each row on new line."))
1367
1372
("tee", po::value<string>(),
1368
1373
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
1374
("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(),
1370
1375
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),
1376
("wait,w", N_("Wait and retry if connection is down."))
1377
("connect_timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
1372
1378
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),
1379
("max_input_line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
1374
1380
N_("Max length of input line"))
1375
("select-limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
1381
("select_limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
1376
1382
N_("Automatic limit for SELECT when using --safe-updates"))
1377
("max-join-size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
1383
("max_join_size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
1378
1384
N_("Automatic limit for rows in a join when using --safe-updates"))
1386
1392
N_("Password to use when connecting to server. If password is not given it's asked from the tty."))
1387
1393
("port,p", po::value<uint32_t>()->default_value(0),
1388
1394
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
1395
("user,u", po::value<string>(¤t_user)->default_value(""),
1394
1396
N_("User for login if not current user."))
1395
1397
("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
1396
1398
N_("The protocol of connection (mysql or drizzle)."))
1406
1408
system_config_dir_client.append("/drizzle/client.cnf");
1408
1410
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
1412
po::variables_map vm;
1420
1414
po::positional_options_description p;
1421
1415
p.add("database", 1);
1423
// Disable allow_guessing
1424
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1426
1417
po::store(po::command_line_parser(argc, argv).options(long_options).
1427
style(style).positional(p).extra_parser(parse_password_arg).run(),
1418
positional(p).extra_parser(parse_password_arg).run(), vm);
1430
1420
if (! vm["no-defaults"].as<bool>())
1436
1426
user_config_dir_client.append("/drizzle/client.cnf");
1438
1428
ifstream user_drizzle_ifs(user_config_dir_drizzle.c_str());
1439
po::store(dpo::parse_config_file(user_drizzle_ifs, drizzle_options), vm);
1429
po::store(parse_config_file(user_drizzle_ifs, drizzle_options), vm);
1441
1431
ifstream user_client_ifs(user_config_dir_client.c_str());
1442
po::store(dpo::parse_config_file(user_client_ifs, client_options), vm);
1432
po::store(parse_config_file(user_client_ifs, client_options), vm);
1444
1434
ifstream system_drizzle_ifs(system_config_dir_drizzle.c_str());
1445
store(dpo::parse_config_file(system_drizzle_ifs, drizzle_options), vm);
1435
store(parse_config_file(system_drizzle_ifs, drizzle_options), vm);
1447
1437
ifstream system_client_ifs(system_config_dir_client.c_str());
1448
po::store(dpo::parse_config_file(system_client_ifs, client_options), vm);
1438
po::store(parse_config_file(system_client_ifs, client_options), vm);
1451
1441
po::notify(vm);
1453
#ifdef DRIZZLE_ADMIN_TOOL
1454
default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1455
getenv("DRIZZLE_PS1") :
1458
1443
default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1459
1444
getenv("DRIZZLE_PS1") :
1462
1446
if (default_prompt == NULL)
1464
1448
fprintf(stderr, _("Memory allocation error while constructing initial "
1868
1840
sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u",
1869
1841
drizzle_con_thread_id(&con));
1871
if (drizzle_query_str(kill_drizzle.get(), &res, kill_buffer, &ret) != NULL)
1843
if (drizzle_query_str(&kill_drizzle, &res, kill_buffer, &ret) != NULL)
1872
1844
drizzle_result_free(&res);
1874
drizzle_con_free(kill_drizzle.get());
1846
drizzle_con_free(&kill_drizzle);
1875
1847
tee_fprintf(stdout, _("Query aborted by Ctrl+C\n"));
1877
1849
interrupted_query= 1;
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
3887
com_warnings(string *, const char *)
4045
3973
drizzle_free(&drizzle);
4047
3975
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
3976
if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(),
4056
3977
opt_drizzle_port, (char *)user.c_str(),
4057
3978
(char *)password.c_str(), (char *)database.c_str(),
3979
use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
4060
3981
(void) put_error(&con, NULL);
4061
3982
(void) fflush(stdout);