~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Stewart Smith
  • Date: 2010-11-03 03:30:44 UTC
  • mto: (1902.1.1 build) (1910.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1903.
  • Revision ID: stewart@flamingspork.com-20101103033044-10ctxt43f0yhm4v2
fix docs warning: underline/overline too short for update.rst

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
#include <cassert>
62
62
#include <stdarg.h>
63
63
#include <math.h>
64
 
#include <memory>
65
64
#include "client/linebuffer.h"
66
65
#include <signal.h>
67
66
#include <sys/ioctl.h>
159
158
#define vidattr(A) {}      // Can't get this to work
160
159
#endif
161
160
#include <boost/program_options.hpp>
162
 
#include <boost/scoped_ptr.hpp>
163
161
#include "drizzled/program_options/config_file.h"
164
162
 
165
163
using namespace std;
360
358
  com_help(string *str,const char*), com_clear(string *str,const char*),
361
359
  com_connect(string *str,const char*), com_status(string *str,const char*),
362
360
  com_use(string *str,const char*), com_source(string *str, const char*),
363
 
  com_shutdown(string *str,const char*),
364
361
  com_rehash(string *str, const char*), com_tee(string *str, const char*),
365
362
  com_notee(string *str, const char*),
366
363
  com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
492
489
    N_("Set outfile [to_outfile]. Append everything into given outfile.") ),
493
490
  Commands( "use",    'u', com_use,    1,
494
491
    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
492
  Commands( "warnings", 'W', com_warnings,  0,
498
493
    N_("Show warnings after every statement.") ),
499
494
  Commands( "nowarning", 'w', com_nowarnings, 0,
1368
1363
  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
1364
  ("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(), 
1370
1365
  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),
 
1366
  ("connect_timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
1372
1367
  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),
 
1368
  ("max_input_line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
1374
1369
  N_("Max length of input line"))
1375
 
  ("select-limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
 
1370
  ("select_limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
1376
1371
  N_("Automatic limit for SELECT when using --safe-updates"))
1377
 
  ("max-join-size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
 
1372
  ("max_join_size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
1378
1373
  N_("Automatic limit for rows in a join when using --safe-updates"))
1379
1374
  ;
1380
1375
 
1386
1381
  N_("Password to use when connecting to server. If password is not given it's asked from the tty."))
1387
1382
  ("port,p", po::value<uint32_t>()->default_value(0),
1388
1383
  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>(&current_user)->default_value("root"),
1391
 
#else
1392
1384
  ("user,u", po::value<string>(&current_user)->default_value(""),
1393
 
#endif
1394
1385
  N_("User for login if not current user."))
1395
1386
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
1396
1387
  N_("The protocol of connection (mysql or drizzle)."))
1406
1397
  system_config_dir_client.append("/drizzle/client.cnf");
1407
1398
 
1408
1399
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
1409
 
 
1410
 
  if (user_config_dir.compare(0, 2, "~/") == 0)
1411
 
  {
1412
 
    char *homedir;
1413
 
    homedir= getenv("HOME");
1414
 
    if (homedir != NULL)
1415
 
      user_config_dir.replace(0, 1, homedir);
1416
 
  }
1417
 
 
 
1400
  
1418
1401
  po::variables_map vm;
1419
1402
 
1420
1403
  po::positional_options_description p;
1450
1433
 
1451
1434
  po::notify(vm);
1452
1435
 
1453
 
#ifdef DRIZZLE_ADMIN_TOOL
1454
 
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1455
 
                         getenv("DRIZZLE_PS1") :
1456
 
                         "drizzleadmin> ");
1457
 
#else
1458
1436
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1459
1437
                         getenv("DRIZZLE_PS1") :
1460
1438
                         "drizzle> ");
1461
 
#endif
1462
1439
  if (default_prompt == NULL)
1463
1440
  {
1464
1441
    fprintf(stderr, _("Memory allocation error while constructing initial "
1848
1825
void handle_sigint(int sig)
1849
1826
{
1850
1827
  char kill_buffer[40];
1851
 
  boost::scoped_ptr<drizzle_con_st> kill_drizzle(new drizzle_con_st);
 
1828
  drizzle_con_st kill_drizzle;
1852
1829
  drizzle_result_st res;
1853
1830
  drizzle_return_t ret;
1854
1831
 
1857
1834
    goto err;
1858
1835
  }
1859
1836
 
1860
 
  if (drizzle_con_add_tcp(&drizzle, kill_drizzle.get(), current_host.c_str(),
 
1837
  if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host.c_str(),
1861
1838
    opt_drizzle_port, current_user.c_str(), opt_password.c_str(), NULL,
1862
1839
    use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
1863
1840
  {
1868
1845
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u",
1869
1846
          drizzle_con_thread_id(&con));
1870
1847
 
1871
 
  if (drizzle_query_str(kill_drizzle.get(), &res, kill_buffer, &ret) != NULL)
 
1848
  if (drizzle_query_str(&kill_drizzle, &res, kill_buffer, &ret) != NULL)
1872
1849
    drizzle_result_free(&res);
1873
1850
 
1874
 
  drizzle_con_free(kill_drizzle.get());
 
1851
  drizzle_con_free(&kill_drizzle);
1875
1852
  tee_fprintf(stdout, _("Query aborted by Ctrl+C\n"));
1876
1853
 
1877
1854
  interrupted_query= 1;
2342
2319
  {
2343
2320
    *out++='\n';
2344
2321
    uint32_t length=(uint32_t) (out-line);
2345
 
    if ((buffer->length() + length) > opt_max_input_line)
2346
 
    {
2347
 
      status.setExitStatus(1);
2348
 
      put_info(_("Not found a delimiter within max_input_line of input"), INFO_ERROR, 0, 0);
2349
 
      return 1;
2350
 
    }
2351
2322
    if ((!*ml_comment || preserve_comments))
2352
2323
      buffer->append(line, length);
2353
2324
  }
2623
2594
  {
2624
2595
    string query;
2625
2596
 
2626
 
    query.append("show fields in `");
 
2597
    query.append("show fields in '");
2627
2598
    query.append(table_row[0]);
2628
 
    query.append("`");
 
2599
    query.append("'");
2629
2600
    
2630
2601
    if (drizzle_query(&con, &fields, query.c_str(), query.length(),
2631
2602
                      &ret) != NULL)
3917
3888
  return 0;
3918
3889
}
3919
3890
 
3920
 
static int com_shutdown(string *, const char *)
3921
 
{
3922
 
  drizzle_result_st result;
3923
 
  drizzle_return_t ret;
3924
 
 
3925
 
  if (verbose)
3926
 
  {
3927
 
    printf(_("shutting down drizzled"));
3928
 
    if (opt_drizzle_port > 0)
3929
 
      printf(_(" on port %d"), opt_drizzle_port);
3930
 
    printf("... ");
3931
 
  }
3932
 
 
3933
 
  if (drizzle_shutdown(&con, &result, DRIZZLE_SHUTDOWN_DEFAULT,
3934
 
                       &ret) == NULL || ret != DRIZZLE_RETURN_OK)
3935
 
  {
3936
 
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
3937
 
    {
3938
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
3939
 
              drizzle_result_error(&result));
3940
 
      drizzle_result_free(&result);
3941
 
    }
3942
 
    else
3943
 
    {
3944
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
3945
 
              drizzle_con_error(&con));
3946
 
    }
3947
 
    return false;
3948
 
  }
3949
 
 
3950
 
  drizzle_result_free(&result);
3951
 
 
3952
 
  if (verbose)
3953
 
    printf(_("done\n"));
3954
 
 
3955
 
  return false;
3956
 
}
3957
 
 
3958
3891
static int
3959
3892
com_warnings(string *, const char *)
3960
3893
{
4045
3978
    drizzle_free(&drizzle);
4046
3979
  }
4047
3980
  drizzle_create(&drizzle);
4048
 
 
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));
4051
 
#else
4052
 
  drizzle_con_options_t options= (drizzle_con_options_t) (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
4053
 
#endif
4054
 
 
4055
3981
  if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(),
4056
3982
    opt_drizzle_port, (char *)user.c_str(),
4057
3983
    (char *)password.c_str(), (char *)database.c_str(),
4058
 
    options) == NULL)
 
3984
    use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
4059
3985
  {
4060
3986
    (void) put_error(&con, NULL);
4061
3987
    (void) fflush(stdout);