~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: patrick crews
  • Date: 2011-03-15 12:12:09 UTC
  • mfrom: (1099.4.216 drizzle)
  • Revision ID: gleebix@gmail.com-20110315121209-8g2tkf31w0rx9ter
Tags: 2011.03.12
Updated translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 **/
36
36
 
37
37
#include <config.h>
38
 
#include <libdrizzle/drizzle_client.h>
 
38
#include <libdrizzle/libdrizzle.h>
39
39
 
40
40
#include "server_detect.h"
41
41
#include "get_password.h"
164
164
/* Buffer to hold 'version' and 'version_comment' */
165
165
const int MAX_SERVER_VERSION_LENGTH= 128;
166
166
 
 
167
/* Options used during connect */
 
168
drizzle_con_options_t global_con_options= DRIZZLE_CON_NONE;
 
169
 
167
170
#define PROMPT_CHAR '\\'
168
171
 
169
172
class Status
291
294
  auto_vertical_output= false,
292
295
  show_warnings= false, executing_query= false, interrupted_query= false,
293
296
  use_drizzle_protocol= false, opt_local_infile;
 
297
static uint32_t opt_kill= 0;
294
298
static uint32_t show_progress_size= 0;
295
299
static bool column_types_flag;
296
300
static bool preserve_comments= false;
297
301
static uint32_t opt_max_input_line;
298
302
static uint32_t opt_drizzle_port= 0;
299
303
static int  opt_silent, verbose= 0;
300
 
static drizzle_capabilities_t connect_flag= DRIZZLE_CAPABILITIES_NONE;
301
304
static char *histfile;
302
305
static char *histfile_tmp;
303
306
static string *glob_buffer;
1223
1226
  return true;
1224
1227
}
1225
1228
 
 
1229
static bool kill_query(uint32_t query_id)
 
1230
{
 
1231
  drizzle_result_st result;
 
1232
  drizzle_return_t ret;
 
1233
 
 
1234
  if (verbose)
 
1235
  {
 
1236
    printf(_("killing query %u"), query_id);
 
1237
    printf("... ");
 
1238
  }
 
1239
 
 
1240
  if (drizzle_kill(&con, &result, query_id,
 
1241
                   &ret) == NULL || ret != DRIZZLE_RETURN_OK)
 
1242
  {
 
1243
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
1244
    {
 
1245
      fprintf(stderr, _("kill failed; error: '%s'"),
 
1246
              drizzle_result_error(&result));
 
1247
      drizzle_result_free(&result);
 
1248
    }
 
1249
    else
 
1250
    {
 
1251
      fprintf(stderr, _("kill failed; error: '%s'"),
 
1252
              drizzle_con_error(&con));
 
1253
    }
 
1254
    return false;
 
1255
  }
 
1256
 
 
1257
  drizzle_result_free(&result);
 
1258
 
 
1259
  if (verbose)
 
1260
    printf(_("done\n"));
 
1261
 
 
1262
  return true;
 
1263
}
 
1264
 
1226
1265
/**
1227
1266
  Ping the server that we are currently connected to.
1228
1267
 
1292
1331
      *error= 1;
1293
1332
    executed= true;
1294
1333
  }
 
1334
 
 
1335
  if (opt_kill)
 
1336
  {
 
1337
    if (kill_query(opt_kill) == false)
 
1338
    {
 
1339
      *error= 1;
 
1340
    }
 
1341
    executed= true;
 
1342
  }
 
1343
 
1295
1344
  return executed;
1296
1345
}
1297
1346
 
1409
1458
  ("shutdown", po::value<bool>()->zero_tokens(),
1410
1459
  _("Shutdown the server"))
1411
1460
  ("silent,s", _("Be more silent. Print results with a tab as separator, each row on new line."))
 
1461
  ("kill", po::value<uint32_t>(&opt_kill)->default_value(0),
 
1462
  _("Kill a running query."))
1412
1463
  ("tee", po::value<string>(),
1413
1464
  _("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."))
1414
1465
  ("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(), 
1422
1473
  ("max-join-size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
1423
1474
  _("Automatic limit for rows in a join when using --safe-updates"))
1424
1475
  ;
1425
 
 
 
1476
#ifndef DRIZZLE_ADMIN_TOOL
 
1477
  const char* unix_user= getlogin();
 
1478
#endif
1426
1479
  po::options_description client_options(_("Options specific to the client"));
1427
1480
  client_options.add_options()
1428
1481
  ("host,h", po::value<string>(&current_host)->default_value("localhost"),
1434
1487
#ifdef DRIZZLE_ADMIN_TOOL
1435
1488
  ("user,u", po::value<string>(&current_user)->default_value("root"),
1436
1489
#else
1437
 
  ("user,u", po::value<string>(&current_user)->default_value(""),
 
1490
  ("user,u", po::value<string>(&current_user)->default_value((unix_user ? unix_user : "")),
1438
1491
#endif
1439
1492
  _("User for login if not current user."))
1440
1493
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
1441
 
  _("The protocol of connection (mysql or drizzle)."))
 
1494
  _("The protocol of connection (mysql, mysql-plugin-auth, or drizzle)."))
1442
1495
  ;
1443
1496
 
1444
1497
  po::options_description long_options(_("Allowed Options"));
1654
1707
      opt_protocol.begin(), ::tolower);
1655
1708
 
1656
1709
    if (not opt_protocol.compare("mysql"))
1657
 
      use_drizzle_protocol=false;
 
1710
    {
 
1711
 
 
1712
      global_con_options= (drizzle_con_options_t)(DRIZZLE_CON_MYSQL|DRIZZLE_CON_INTERACTIVE);
 
1713
      use_drizzle_protocol= false;
 
1714
    }
 
1715
    else if (not opt_protocol.compare("mysql-plugin-auth"))
 
1716
    {
 
1717
      global_con_options= (drizzle_con_options_t)(DRIZZLE_CON_MYSQL|DRIZZLE_CON_INTERACTIVE|DRIZZLE_CON_AUTH_PLUGIN);
 
1718
      use_drizzle_protocol= false;
 
1719
    }
1658
1720
    else if (not opt_protocol.compare("drizzle"))
1659
 
      use_drizzle_protocol=true;
 
1721
    {
 
1722
      global_con_options= (drizzle_con_options_t)(DRIZZLE_CON_EXPERIMENTAL);
 
1723
      use_drizzle_protocol= true;
 
1724
    }
1660
1725
    else
1661
1726
    {
1662
1727
      cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
1900
1965
  drizzle_return_t ret;
1901
1966
 
1902
1967
  /* terminate if no query being executed, or we already tried interrupting */
1903
 
  if (!executing_query || interrupted_query) {
 
1968
  if (!executing_query || interrupted_query)
 
1969
  {
1904
1970
    goto err;
1905
1971
  }
1906
1972
 
1973
2039
    default_pager_set= 0;
1974
2040
    opt_outfile= 0;
1975
2041
    opt_reconnect= 0;
1976
 
    connect_flag= DRIZZLE_CAPABILITIES_NONE; /* Not in interactive mode */
1977
2042
  }
1978
2043
 
1979
2044
  if (tty_password)
4175
4240
  drizzle_create(&drizzle);
4176
4241
 
4177
4242
#ifdef DRIZZLE_ADMIN_TOOL
4178
 
  drizzle_con_options_t options= (drizzle_con_options_t) (DRIZZLE_CON_ADMIN | (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL));
4179
 
#else
4180
 
  drizzle_con_options_t options= (drizzle_con_options_t) (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
 
4243
  global_con_options= (drizzle_con_options_t) (DRIZZLE_CON_ADMIN | global_con_options);
4181
4244
#endif
4182
4245
 
4183
4246
  if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(),
4184
 
    opt_drizzle_port, (char *)user.c_str(),
4185
 
    (char *)password.c_str(), (char *)database.c_str(),
4186
 
    options) == NULL)
 
4247
                          opt_drizzle_port, (char *)user.c_str(),
 
4248
                          (char *)password.c_str(), (char *)database.c_str(),
 
4249
                          global_con_options) == NULL)
4187
4250
  {
4188
4251
    (void) put_error(&con, NULL);
4189
4252
    (void) fflush(stdout);
4190
4253
    return 1;
4191
4254
  }
4192
4255
 
4193
 
/* XXX add this back in
4194
 
  if (opt_connect_timeout)
4195
 
  {
4196
 
    uint32_t timeout=opt_connect_timeout;
4197
 
    drizzleclient_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT,
4198
 
                  (char*) &timeout);
4199
 
  }
4200
 
*/
4201
 
 
4202
 
/* XXX Do we need this?
4203
 
  if (safe_updates)
4204
 
  {
4205
 
    char init_command[100];
4206
 
    sprintf(init_command,
4207
 
            "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
4208
 
            ",MAX_JOIN_SIZE=%"PRIu32,
4209
 
            select_limit, max_join_size);
4210
 
    drizzleclient_options(&drizzle, DRIZZLE_INIT_COMMAND, init_command);
4211
 
  }
4212
 
*/
4213
4256
  if ((ret= drizzle_con_connect(&con)) != DRIZZLE_RETURN_OK)
4214
4257
  {
4215
4258
 
4221
4264
    }
4222
4265
    return -1;          // Retryable
4223
4266
  }
4224
 
  connected=1;
 
4267
  connected= 1;
4225
4268
 
4226
4269
  ServerDetect server_detect(&con);
4227
4270
  server_type= server_detect.getServerType();