~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Monty Taylor
  • Date: 2010-08-20 20:54:13 UTC
  • mto: (1728.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1729.
  • Revision ID: mordred@inaugust.com-20100820205413-2zebseruww4uq3dg
Removed a HASH in xa_resource_manager. It's not actually used, but I left it
in case someone did actually want to implement RECOVER some day.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 * 
4
 
 *  Copyright (C) 2010 Vijay Samuel
 
3
 *
5
4
 *  Copyright (C) 2008 MySQL
6
5
 *
7
6
 *  This program is free software; you can redistribute it and/or modify
63
62
#include <stdarg.h>
64
63
#include <boost/unordered_map.hpp>
65
64
 
 
65
#include "errname.h"
 
66
 
66
67
/* Added this for string translation. */
67
68
#include "drizzled/gettext.h"
68
69
#include "drizzled/drizzle_time.h"
88
89
#define QUERY_SEND_FLAG  1
89
90
#define QUERY_REAP_FLAG  2
90
91
 
91
 
typedef boost::unordered_map<std::string, uint32_t> ErrorCodes;
92
92
ErrorCodes global_error_names;
93
93
 
94
94
enum {
113
113
static bool abort_on_error= true;
114
114
static bool server_initialized= false;
115
115
static bool is_windows= false;
116
 
static bool use_drizzle_protocol= false;
 
116
static bool opt_mysql= false;
117
117
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
118
118
 
119
119
std::string opt_basedir,
126
126
  password,
127
127
  opt_password,
128
128
  result_file_name,
129
 
  opt_user,
130
 
  opt_protocol;
 
129
  opt_user;
131
130
 
132
131
static uint32_t start_lineno= 0; /* Start line of current command */
133
132
 
782
781
    const struct command_arg *arg= &args[i];
783
782
    arg->ds->clear();
784
783
 
785
 
    bool known_arg_type= true;
786
784
    switch (arg->type) {
787
785
      /* A string */
788
786
    case ARG_STRING:
817
815
      break;
818
816
 
819
817
    default:
820
 
      known_arg_type= false;
 
818
      assert("Unknown argument type");
821
819
      break;
822
820
    }
823
 
    assert(known_arg_type);
824
821
 
825
822
    /* Check required arg */
826
823
    if (arg->ds->length() == 0 && arg->required)
1461
1458
  int fd;
1462
1459
  char temp_file_path[FN_REFLEN];
1463
1460
 
1464
 
  if ((fd= internal::create_temp_file(temp_file_path, TMPDIR,
 
1461
  if ((fd= internal::create_temp_file(temp_file_path, NULL,
1465
1462
                            "tmp", MYF(MY_WME))) < 0)
1466
1463
    die("Failed to create temporary file for ds");
1467
1464
 
3317
3314
  bool error= false;
3318
3315
  char *p= command->first_argument;
3319
3316
  char *sleep_start, *sleep_end= command->end;
3320
 
  double sleep_val= 0;
 
3317
  double sleep_val;
3321
3318
 
3322
3319
  while (my_isspace(charset_info, *p))
3323
3320
    p++;
3386
3383
    abort_not_supported_test("Test requires charset '%s'", charset_name);
3387
3384
}
3388
3385
 
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
3386
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3449
3387
{
3450
3388
  size_t err_name_len= error_end - error_name;
3451
3389
  string error_name_s(error_name, err_name_len);
3452
3390
 
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;
 
3391
  uint32_t code= global_error_names.getErrorCode(error_name_s);
 
3392
 
 
3393
  if (!code)
 
3394
    die("Unknown SQL error name '%s'", error_name_s.c_str());
 
3395
 
 
3396
  return(code);
3461
3397
}
3462
3398
 
3463
3399
static void do_get_errcodes(struct st_command *command)
3908
3844
{
3909
3845
  uint32_t con_port= opt_port;
3910
3846
  const char *con_options;
3911
 
  bool con_ssl= 0;
 
3847
  bool con_ssl= 0, con_compress= 0;
3912
3848
  struct st_connection* con_slot;
3913
3849
 
3914
3850
  string ds_connection_name;
3974
3910
      end++;
3975
3911
    if (!strncmp(con_options, "SSL", 3))
3976
3912
      con_ssl= 1;
 
3913
    else if (!strncmp(con_options, "COMPRESS", 8))
 
3914
      con_compress= 1;
3977
3915
    else
3978
3916
      die("Illegal option to connect: %.*s",
3979
3917
          (int) (end - con_options), con_options);
3999
3937
    die("Failed on drizzle_create()");
4000
3938
  if (!drizzle_con_create(con_slot->drizzle, &con_slot->con))
4001
3939
    die("Failed on drizzle_con_create()");
4002
 
  drizzle_con_add_options(&con_slot->con, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
 
3940
  if (opt_mysql)
 
3941
    drizzle_con_add_options(&con_slot->con, DRIZZLE_CON_MYSQL);
4003
3942
 
4004
3943
  /* Use default db name */
4005
3944
  if (ds_database.length() == 0)
5497
5436
  "Directory for log files")
5498
5437
  ("max-connect-retries", po::value<uint32_t>(&opt_max_connect_retries)->default_value(500)->notifier(&check_retries),
5499
5438
  "Max number of connection attempts when connecting to server")
5500
 
  ("quiet,s", po::value<bool>(&silent)->default_value(false)->zero_tokens(),
 
5439
  ("quiet,s", po::value<bool>(&silent)->default_value(0)->zero_tokens(),
5501
5440
  "Suppress all normal output.")
5502
5441
  ("record,r", "Record output of test_file into result file.")
5503
5442
  ("result-file,R", po::value<string>(&result_file_name)->default_value(""),
5513
5452
 
5514
5453
  ("host,h", po::value<string>(&opt_host)->default_value("localhost"),
5515
5454
  "Connect to host.")
 
5455
  ("mysql,m", po::value<bool>(&opt_mysql)->default_value(true)->zero_tokens(),
 
5456
  N_("Use MySQL Protocol."))
5516
5457
  ("password,P", po::value<string>(&password)->default_value("PASSWORD_SENTINEL"),
5517
5458
  "Password to use when connecting to server.")
5518
5459
  ("port,p", po::value<uint32_t>(&opt_port)->default_value(0),
5519
5460
  "Port number to use for connection or 0 for default")
5520
 
  ("protocol", po::value<string>(&opt_protocol),
5521
 
  "The protocol of connection (mysql or drizzle).")
 
5461
  ("protocol", po::value<string>(),
 
5462
  "The protocol of connection (tcp,socket,pipe,memory).")
5522
5463
  ("user,u", po::value<string>(&opt_user)->default_value(""),
5523
5464
  "User for login.")
5524
5465
  ;
5537
5478
 
5538
5479
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
5539
5480
 
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
5481
  po::variables_map vm;
5549
5482
 
5550
 
  // Disable allow_guessing
5551
 
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
5552
 
 
5553
5483
  po::store(po::command_line_parser(argc, argv).options(long_options).
5554
 
            style(style).positional(p).extra_parser(parse_password_arg).run(),
5555
 
            vm);
 
5484
            positional(p).extra_parser(parse_password_arg).run(), vm);
5556
5485
 
5557
5486
  if (! vm["no-defaults"].as<bool>())
5558
5487
  {
5657
5586
    unlink(timer_file);       /* Ignore error, may not exist */
5658
5587
  }
5659
5588
 
5660
 
  if (vm.count("protocol"))
5661
 
  {
5662
 
    std::transform(opt_protocol.begin(), opt_protocol.end(),
5663
 
      opt_protocol.begin(), ::tolower);
5664
 
 
5665
 
    if (not opt_protocol.compare("mysql"))
5666
 
      use_drizzle_protocol=false;
5667
 
    else if (not opt_protocol.compare("drizzle"))
5668
 
      use_drizzle_protocol=true;
5669
 
    else
5670
 
    {
5671
 
      cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
5672
 
      exit(-1);
5673
 
    }
5674
 
  }
5675
 
 
5676
5589
  if (vm.count("port"))
5677
5590
  {
5678
5591
    /* If the port number is > 65535 it is not a valid port
5747
5660
    die("Failed in drizzle_create()");
5748
5661
  if (!( drizzle_con_create(cur_con->drizzle, &cur_con->con)))
5749
5662
    die("Failed in drizzle_con_create()");
5750
 
  drizzle_con_add_options(&cur_con->con, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
 
5663
  if (opt_mysql)
 
5664
    drizzle_con_add_options(&cur_con->con, DRIZZLE_CON_MYSQL);
5751
5665
 
5752
5666
  if (!(cur_con->name = strdup("default")))
5753
5667
    die("Out of memory");
5754
5668
  safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5755
5669
               opt_db, opt_port);
5756
5670
 
5757
 
  fill_global_error_names();
5758
 
 
5759
5671
  /* Use all time until exit if no explicit 'start_timer' */
5760
5672
  timer_start= timer_now();
5761
5673
 
6716
6628
    /* Repeatedly replace the string with the matched regex */
6717
6629
    string subject(in_string);
6718
6630
    size_t replace_length= strlen(replace);
6719
 
    size_t length_of_replacement= strlen(replace);
6720
6631
    size_t current_position= 0;
6721
6632
    int rc= 0;
6722
 
 
6723
 
    while (true) 
 
6633
    while(0 >= (rc= pcre_exec(re, NULL, subject.c_str() + current_position, subject.length() - current_position,
 
6634
                      0, 0, ovector, 3)))
6724
6635
    {
6725
 
      rc= pcre_exec(re, NULL, subject.c_str(), subject.length(), 
6726
 
                    current_position, 0, ovector, 3);
6727
 
      if (rc < 0)
6728
 
      {
6729
 
        break;
6730
 
      }
6731
 
 
6732
6636
      current_position= static_cast<size_t>(ovector[0]);
6733
6637
      replace_length= static_cast<size_t>(ovector[1] - ovector[0]);
6734
 
      subject.replace(current_position, replace_length, replace, length_of_replacement);
6735
 
      current_position= current_position + length_of_replacement;
 
6638
      subject.replace(current_position, replace_length, replace, replace_length);
6736
6639
    }
6737
6640
 
6738
6641
    char *new_buf = (char *) malloc(subject.length() + 1);