~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Brian Aker
  • Date: 2011-01-17 04:15:23 UTC
  • mto: (2088.1.3 merge)
  • mto: This revision was merged to the branch mainline in revision 2089.
  • Revision ID: brian@gir-3-20110117041523-o9ex94kfz1a6iqyw
Modify TableIdentifier to fit with the rest of the identifiers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
368
368
  com_nopager(string *str, const char*), com_pager(string *str, const char*);
369
369
 
370
370
static int read_and_execute(bool interactive);
371
 
static int sql_connect(const string &host, const string &database, const string &user, const string &password,
372
 
                       uint32_t silent);
 
371
static int sql_connect(const string &host, const string &database, const string &user, const string &password);
373
372
static const char *server_version_string(drizzle_con_st *con);
374
373
static int put_info(const char *str,INFO_TYPE info,uint32_t error,
375
374
                    const char *sql_state);
1281
1280
# if defined(HAVE_LOCALE_H)
1282
1281
  setlocale(LC_ALL, "");
1283
1282
# endif
1284
 
  bindtextdomain("drizzle", LOCALEDIR);
1285
 
  textdomain("drizzle");
 
1283
  bindtextdomain("drizzle7", LOCALEDIR);
 
1284
  textdomain("drizzle7");
1286
1285
#endif
1287
1286
 
1288
 
  po::options_description commandline_options(N_("Options used only in command line"));
 
1287
  po::options_description commandline_options(_("Options used only in command line"));
1289
1288
  commandline_options.add_options()
1290
 
  ("help,?",N_("Displays this help and exit."))
1291
 
  ("batch,B",N_("Don't use history file. Disable interactive behavior. (Enables --silent)"))
 
1289
  ("help,?",_("Displays this help and exit."))
 
1290
  ("batch,B",_("Don't use history file. Disable interactive behavior. (Enables --silent)"))
1292
1291
  ("column-type-info", po::value<bool>(&column_types_flag)->default_value(false)->zero_tokens(),
1293
 
  N_("Display column type information."))
 
1292
  _("Display column type information."))
1294
1293
  ("comments,c", po::value<bool>(&preserve_comments)->default_value(false)->zero_tokens(),
1295
 
  N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"))
 
1294
  _("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"))
1296
1295
  ("vertical,E", po::value<bool>(&vertical)->default_value(false)->zero_tokens(),
1297
 
  N_("Print the output of a query (rows) vertically."))
 
1296
  _("Print the output of a query (rows) vertically."))
1298
1297
  ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
1299
 
  N_("Continue even if we get an sql error."))
 
1298
  _("Continue even if we get an sql error."))
1300
1299
  ("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."))
 
1300
  _("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."))
1302
1301
  ("no-beep,b", po::value<bool>(&opt_nobeep)->default_value(false)->zero_tokens(),
1303
 
  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."))
 
1302
  _("Turn off beep on error."))
 
1303
  ("disable-line-numbers", _("Do not write line numbers for errors."))
 
1304
  ("disable-column-names", _("Do not write column names in results."))
1306
1305
  ("skip-column-names,N", 
1307
 
  N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."))
 
1306
  _("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."))
1308
1307
  ("set-variable,O", po::value<string>(),
1309
 
  N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."))
 
1308
  _("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."))
1310
1309
  ("table,t", po::value<bool>(&output_tables)->default_value(false)->zero_tokens(),
1311
 
  N_("Output in table format.")) 
 
1310
  _("Output in table format.")) 
1312
1311
  ("safe-updates,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
1313
 
  N_("Only allow UPDATE and DELETE that uses keys."))
 
1312
  _("Only allow UPDATE and DELETE that uses keys."))
1314
1313
  ("i-am-a-dummy,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
1315
 
  N_("Synonym for option --safe-updates, -U."))
 
1314
  _("Synonym for option --safe-updates, -U."))
1316
1315
  ("verbose,v", po::value<string>(&opt_verbose)->default_value(""),
1317
 
  N_("-v vvv implies that verbose= 3, Used to specify verbose"))
1318
 
  ("version,V", N_("Output version information and exit."))
 
1316
  _("-v vvv implies that verbose= 3, Used to specify verbose"))
 
1317
  ("version,V", _("Output version information and exit."))
1319
1318
  ("secure-auth", po::value<bool>(&opt_secure_auth)->default_value(false)->zero_tokens(),
1320
 
  N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"))
 
1319
  _("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"))
1321
1320
  ("show-warnings", po::value<bool>(&show_warnings)->default_value(false)->zero_tokens(),
1322
 
  N_("Show warnings after every statement."))
 
1321
  _("Show warnings after every statement."))
1323
1322
  ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(0),
1324
 
  N_("Number of lines before each import progress report."))
 
1323
  _("Number of lines before each import progress report."))
1325
1324
  ("ping", po::value<bool>(&opt_ping)->default_value(false)->zero_tokens(),
1326
 
  N_("Ping the server to check if it's alive."))
 
1325
  _("Ping the server to check if it's alive."))
1327
1326
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1328
 
  N_("Configuration file defaults are not used if no-defaults is set"))
 
1327
  _("Configuration file defaults are not used if no-defaults is set"))
1329
1328
  ;
1330
1329
 
1331
 
  po::options_description drizzle_options(N_("Options specific to the drizzle client"));
 
1330
  po::options_description drizzle_options(_("Options specific to the drizzle client"));
1332
1331
  drizzle_options.add_options()
1333
1332
  ("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."))
 
1333
  _("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
1334
  ("auto-vertical-output", po::value<bool>(&auto_vertical_output)->default_value(false)->zero_tokens(),
1336
 
  N_("Automatically switch to vertical output mode if the result is wider than the terminal width."))
 
1335
  _("Automatically switch to vertical output mode if the result is wider than the terminal width."))
1337
1336
  ("database,D", po::value<string>(&current_db)->default_value(""),
1338
 
  N_("Database to use."))
 
1337
  _("Database to use."))
1339
1338
  ("default-character-set",po::value<string>(),
1340
 
  N_("(not used)"))
 
1339
  _("(not used)"))
1341
1340
  ("delimiter", po::value<string>(&delimiter_str)->default_value(";"),
1342
 
  N_("Delimiter to be used."))
 
1341
  _("Delimiter to be used."))
1343
1342
  ("execute,e", po::value<string>(),
1344
 
  N_("Execute command and quit. (Disables --force and history file)"))
 
1343
  _("Execute command and quit. (Disables --force and history file)"))
1345
1344
  ("local-infile", po::value<bool>(&opt_local_infile)->default_value(false)->zero_tokens(),
1346
 
  N_("Enable LOAD DATA LOCAL INFILE."))
 
1345
  _("Enable LOAD DATA LOCAL INFILE."))
1347
1346
  ("unbuffered,n", po::value<bool>(&unbuffered)->default_value(false)->zero_tokens(),
1348
 
  N_("Flush buffer after each query."))
 
1347
  _("Flush buffer after each query."))
1349
1348
  ("sigint-ignore", po::value<bool>(&opt_sigint_ignore)->default_value(false)->zero_tokens(),
1350
 
  N_("Ignore SIGINT (CTRL-C)"))
 
1349
  _("Ignore SIGINT (CTRL-C)"))
1351
1350
  ("one-database,o", po::value<bool>(&one_database)->default_value(false)->zero_tokens(),
1352
 
  N_("Only update the default database. This is useful for skipping updates to other database in the update log."))
 
1351
  _("Only update the default database. This is useful for skipping updates to other database in the update log."))
1353
1352
  ("pager", po::value<string>(),
1354
 
  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."))
 
1353
  _("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."))
1355
1354
  ("disable-pager", po::value<bool>(&opt_nopager)->default_value(false)->zero_tokens(),
1356
 
  N_("Disable pager and print to stdout. See interactive help (\\h) also."))
 
1355
  _("Disable pager and print to stdout. See interactive help (\\h) also."))
1357
1356
  ("prompt", po::value<string>(&current_prompt)->default_value(""),  
1358
 
  N_("Set the drizzle prompt to this value."))
 
1357
  _("Set the drizzle prompt to this value."))
1359
1358
  ("quick,q", po::value<bool>(&quick)->default_value(false)->zero_tokens(),
1360
 
  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."))
 
1359
  _("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
1360
  ("raw,r", po::value<bool>(&opt_raw_data)->default_value(false)->zero_tokens(),
1362
 
  N_("Write fields without conversion. Used with --batch.")) 
1363
 
  ("disable-reconnect", N_("Do not reconnect if the connection is lost."))
 
1361
  _("Write fields without conversion. Used with --batch.")) 
 
1362
  ("disable-reconnect", _("Do not reconnect if the connection is lost."))
1364
1363
  ("shutdown", po::value<bool>()->zero_tokens(),
1365
 
  N_("Shutdown the server"))
1366
 
  ("silent,s", N_("Be more silent. Print results with a tab as separator, each row on new line."))
 
1364
  _("Shutdown the server"))
 
1365
  ("silent,s", _("Be more silent. Print results with a tab as separator, each row on new line."))
1367
1366
  ("tee", po::value<string>(),
1368
 
  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."))
 
1367
  _("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
1368
  ("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(), 
1370
 
  N_("Disable outfile. See interactive help (\\h) also."))
 
1369
  _("Disable outfile. See interactive help (\\h) also."))
1371
1370
  ("connect-timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
1372
 
  N_("Number of seconds before connection timeout."))
 
1371
  _("Number of seconds before connection timeout."))
1373
1372
  ("max-input-line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
1374
 
  N_("Max length of input line"))
 
1373
  _("Max length of input line"))
1375
1374
  ("select-limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
1376
 
  N_("Automatic limit for SELECT when using --safe-updates"))
 
1375
  _("Automatic limit for SELECT when using --safe-updates"))
1377
1376
  ("max-join-size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
1378
 
  N_("Automatic limit for rows in a join when using --safe-updates"))
 
1377
  _("Automatic limit for rows in a join when using --safe-updates"))
1379
1378
  ;
1380
1379
 
1381
 
  po::options_description client_options(N_("Options specific to the client"));
 
1380
  po::options_description client_options(_("Options specific to the client"));
1382
1381
  client_options.add_options()
1383
1382
  ("host,h", po::value<string>(&current_host)->default_value("localhost"),
1384
 
  N_("Connect to host"))
 
1383
  _("Connect to host"))
1385
1384
  ("password,P", po::value<string>(&current_password)->default_value(PASSWORD_SENTINEL),
1386
 
  N_("Password to use when connecting to server. If password is not given it's asked from the tty."))
 
1385
  _("Password to use when connecting to server. If password is not given it's asked from the tty."))
1387
1386
  ("port,p", po::value<uint32_t>()->default_value(0),
1388
 
  N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default"))
 
1387
  _("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default"))
1389
1388
#ifdef DRIZZLE_ADMIN_TOOL
1390
1389
  ("user,u", po::value<string>(&current_user)->default_value("root"),
1391
1390
#else
1392
1391
  ("user,u", po::value<string>(&current_user)->default_value(""),
1393
1392
#endif
1394
 
  N_("User for login if not current user."))
 
1393
  _("User for login if not current user."))
1395
1394
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
1396
 
  N_("The protocol of connection (mysql or drizzle)."))
 
1395
  _("The protocol of connection (mysql or drizzle)."))
1397
1396
  ;
1398
1397
 
1399
 
  po::options_description long_options(N_("Allowed Options"));
 
1398
  po::options_description long_options(_("Allowed Options"));
1400
1399
  long_options.add(commandline_options).add(drizzle_options).add(client_options);
1401
1400
 
1402
1401
  std::string system_config_dir_drizzle(SYSCONFDIR); 
1490
1489
  if (! isatty(0) || ! isatty(1))
1491
1490
  {
1492
1491
    status.setBatch(1); opt_silent=1;
1493
 
    ignore_errors=0;
1494
1492
  }
1495
1493
  else
1496
1494
    status.setAddToHistory(1);
1667
1665
  }
1668
1666
  if (vm.count("silent"))
1669
1667
  {
1670
 
    opt_silent++;
 
1668
    opt_silent= 2;
1671
1669
  }
1672
1670
  
1673
1671
  if (vm.count("help") || vm.count("version"))
1695
1693
  }
1696
1694
 
1697
1695
  memset(&drizzle, 0, sizeof(drizzle));
1698
 
  if (sql_connect(current_host, current_db, current_user, opt_password,opt_silent))
 
1696
  if (sql_connect(current_host, current_db, current_user, opt_password))
1699
1697
  {
1700
1698
    quick= 1;          // Avoid history
1701
1699
    status.setExitStatus(1);
3695
3693
  }
3696
3694
  else
3697
3695
    opt_rehash= 0;
3698
 
  error=sql_connect(current_host, current_db, current_user, opt_password,0);
 
3696
  error=sql_connect(current_host, current_db, current_user, opt_password);
3699
3697
  opt_rehash= save_rehash;
3700
3698
 
3701
3699
  if (connected)
4004
4002
 
4005
4003
 
4006
4004
static int
4007
 
sql_connect(const string &host, const string &database, const string &user, const string &password,
4008
 
                 uint32_t silent)
 
4005
sql_connect(const string &host, const string &database, const string &user, const string &password)
4009
4006
{
4010
4007
  drizzle_return_t ret;
4011
4008
  if (connected)
4054
4051
*/
4055
4052
  if ((ret= drizzle_con_connect(&con)) != DRIZZLE_RETURN_OK)
4056
4053
  {
4057
 
    if (!silent || (ret != DRIZZLE_RETURN_GETADDRINFO &&
4058
 
                    ret != DRIZZLE_RETURN_COULD_NOT_CONNECT))
 
4054
 
 
4055
    if (opt_silent < 2)
4059
4056
    {
4060
4057
      (void) put_error(&con, NULL);
4061
4058
      (void) fflush(stdout);