~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Brian Aker
  • Date: 2010-09-20 00:00:20 UTC
  • Revision ID: brian@tangent.org-20100920000020-s6x30brpajr83pkr
Update session/memory to use boost specific.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
#include <stdarg.h>
64
64
#include <boost/unordered_map.hpp>
65
65
 
 
66
#include "errname.h"
 
67
 
66
68
/* Added this for string translation. */
67
69
#include "drizzled/gettext.h"
68
70
#include "drizzled/drizzle_time.h"
88
90
#define QUERY_SEND_FLAG  1
89
91
#define QUERY_REAP_FLAG  2
90
92
 
91
 
typedef boost::unordered_map<std::string, uint32_t> ErrorCodes;
92
93
ErrorCodes global_error_names;
93
94
 
94
95
enum {
782
783
    const struct command_arg *arg= &args[i];
783
784
    arg->ds->clear();
784
785
 
785
 
    bool known_arg_type= true;
786
786
    switch (arg->type) {
787
787
      /* A string */
788
788
    case ARG_STRING:
817
817
      break;
818
818
 
819
819
    default:
820
 
      known_arg_type= false;
 
820
      assert("Unknown argument type");
821
821
      break;
822
822
    }
823
 
    assert(known_arg_type);
824
823
 
825
824
    /* Check required arg */
826
825
    if (arg->ds->length() == 0 && arg->required)
1461
1460
  int fd;
1462
1461
  char temp_file_path[FN_REFLEN];
1463
1462
 
1464
 
  if ((fd= internal::create_temp_file(temp_file_path, TMPDIR,
 
1463
  if ((fd= internal::create_temp_file(temp_file_path, NULL,
1465
1464
                            "tmp", MYF(MY_WME))) < 0)
1466
1465
    die("Failed to create temporary file for ds");
1467
1466
 
3317
3316
  bool error= false;
3318
3317
  char *p= command->first_argument;
3319
3318
  char *sleep_start, *sleep_end= command->end;
3320
 
  double sleep_val= 0;
 
3319
  double sleep_val;
3321
3320
 
3322
3321
  while (my_isspace(charset_info, *p))
3323
3322
    p++;
3386
3385
    abort_not_supported_test("Test requires charset '%s'", charset_name);
3387
3386
}
3388
3387
 
3389
 
static void fill_global_error_names()
3390
 
{
3391
 
  drizzle_result_st res;
3392
 
  drizzle_return_t ret;
3393
 
  drizzle_row_t row;
3394
 
  drizzle_con_st *con= &cur_con->con;
3395
 
 
3396
 
  global_error_names.clear();
3397
 
 
3398
 
  const std::string ds_query("select error_name, error_code "
3399
 
                             "from data_dictionary.errors");
3400
 
  if (drizzle_query_str(con, &res, ds_query.c_str(), &ret) == NULL ||
3401
 
      ret != DRIZZLE_RETURN_OK)
3402
 
  {
3403
 
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
3404
 
    {
3405
 
      die("Error running query '%s': %d %s", ds_query.c_str(),
3406
 
          drizzle_result_error_code(&res), drizzle_result_error(&res));
3407
 
      drizzle_result_free(&res);
3408
 
    }
3409
 
    else
3410
 
    {
3411
 
      die("Error running query '%s': %d %s", ds_query.c_str(), ret,
3412
 
          drizzle_con_error(con));
3413
 
    }
3414
 
  }
3415
 
  if (drizzle_result_column_count(&res) == 0 ||
3416
 
      drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3417
 
  {
3418
 
    drizzle_result_free(&res);
3419
 
    die("Query '%s' didn't return a result set", ds_query.c_str());
3420
 
  }
3421
 
 
3422
 
  while ((row= drizzle_row_next(&res)) && row[0])
3423
 
  {
3424
 
    /*
3425
 
      Concatenate all fields in the first row with tab in between
3426
 
      and assign that string to the $variable
3427
 
    */
3428
 
    size_t *lengths= drizzle_row_field_sizes(&res);
3429
 
    const std::string error_name(row[0], lengths[0]);
3430
 
    const std::string error_code(row[1], lengths[1]);
3431
 
 
3432
 
    try
3433
 
    {
3434
 
      global_error_names.insert(ErrorCodes::value_type(error_name,
3435
 
                                                       boost::lexical_cast<uint32_t>(error_code)));
3436
 
    }
3437
 
    catch (boost::bad_lexical_cast &ex)
3438
 
    {
3439
 
      drizzle_result_free(&res);
3440
 
      die("Invalid error_code from Drizzle: %s", ex.what());
3441
 
    }
3442
 
 
3443
 
  }
3444
 
 
3445
 
  drizzle_result_free(&res);
3446
 
}
3447
 
 
3448
3388
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3449
3389
{
3450
3390
  size_t err_name_len= error_end - error_name;
3451
3391
  string error_name_s(error_name, err_name_len);
3452
3392
 
3453
 
  ErrorCodes::iterator it= global_error_names.find(error_name_s);
3454
 
  if (it != global_error_names.end())
3455
 
  {
3456
 
    return (*it).second;
3457
 
  }
3458
 
 
3459
 
  die("Unknown SQL error name '%s'", error_name_s.c_str());
3460
 
  return 0;
 
3393
  uint32_t code= global_error_names.getErrorCode(error_name_s);
 
3394
 
 
3395
  if (!code)
 
3396
    die("Unknown SQL error name '%s'", error_name_s.c_str());
 
3397
 
 
3398
  return(code);
3461
3399
}
3462
3400
 
3463
3401
static void do_get_errcodes(struct st_command *command)
3908
3846
{
3909
3847
  uint32_t con_port= opt_port;
3910
3848
  const char *con_options;
3911
 
  bool con_ssl= 0;
 
3849
  bool con_ssl= 0, con_compress= 0;
3912
3850
  struct st_connection* con_slot;
3913
3851
 
3914
3852
  string ds_connection_name;
3974
3912
      end++;
3975
3913
    if (!strncmp(con_options, "SSL", 3))
3976
3914
      con_ssl= 1;
 
3915
    else if (!strncmp(con_options, "COMPRESS", 8))
 
3916
      con_compress= 1;
3977
3917
    else
3978
3918
      die("Illegal option to connect: %.*s",
3979
3919
          (int) (end - con_options), con_options);
5537
5477
 
5538
5478
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
5539
5479
 
5540
 
  if (user_config_dir.compare(0, 2, "~/") == 0)
5541
 
  {
5542
 
    char *homedir;
5543
 
    homedir= getenv("HOME");
5544
 
    if (homedir != NULL)
5545
 
      user_config_dir.replace(0, 1, homedir);
5546
 
  }
5547
 
 
5548
5480
  po::variables_map vm;
5549
5481
 
5550
 
  // Disable allow_guessing
5551
 
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
5552
 
 
5553
5482
  po::store(po::command_line_parser(argc, argv).options(long_options).
5554
 
            style(style).positional(p).extra_parser(parse_password_arg).run(),
5555
 
            vm);
 
5483
            positional(p).extra_parser(parse_password_arg).run(), vm);
5556
5484
 
5557
5485
  if (! vm["no-defaults"].as<bool>())
5558
5486
  {
5754
5682
  safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5755
5683
               opt_db, opt_port);
5756
5684
 
5757
 
  fill_global_error_names();
5758
 
 
5759
5685
  /* Use all time until exit if no explicit 'start_timer' */
5760
5686
  timer_start= timer_now();
5761
5687