~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: lbieber
  • Date: 2010-10-06 16:34:16 UTC
  • mfrom: (1816.1.3 build)
  • Revision ID: lbieber@orisndriz08-20101006163416-ea0sl59qgpglk21y
Merge Monty - Change the requirement from either libinnodb to libhaildb. Also, tied it to version 2.2
Merge Andrew - fix bug 650935: remove --compress from all clients
Merge Andrew - fix bug 653471: Add -A to drizzle client
Merge Travis - 621861 = To change C structs to C++ classes in Drizzle

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
 
#include "drizzled/type/time.h"
 
70
#include "drizzled/drizzle_time.h"
69
71
#include "drizzled/charset.h"
70
 
#include "drizzled/typelib.h"
71
72
#include <drizzled/configmake.h>
72
73
 
73
74
#ifndef DRIZZLE_RETURN_SERVER_GONE
89
90
#define QUERY_SEND_FLAG  1
90
91
#define QUERY_REAP_FLAG  2
91
92
 
92
 
typedef boost::unordered_map<std::string, uint32_t> ErrorCodes;
93
93
ErrorCodes global_error_names;
94
94
 
95
95
enum {
783
783
    const struct command_arg *arg= &args[i];
784
784
    arg->ds->clear();
785
785
 
786
 
    bool known_arg_type= true;
787
786
    switch (arg->type) {
788
787
      /* A string */
789
788
    case ARG_STRING:
818
817
      break;
819
818
 
820
819
    default:
821
 
      known_arg_type= false;
 
820
      assert("Unknown argument type");
822
821
      break;
823
822
    }
824
 
    assert(known_arg_type);
825
823
 
826
824
    /* Check required arg */
827
825
    if (arg->ds->length() == 0 && arg->required)
844
842
 
845
843
static void handle_command_error(struct st_command *command, uint32_t error)
846
844
{
 
845
 
847
846
  if (error != 0)
848
847
  {
849
848
    uint32_t i;
870
869
        command->first_word_len, command->query,
871
870
        command->expected_errors.err[0].code.errnum);
872
871
  }
 
872
  return;
873
873
}
874
874
 
875
875
 
1460
1460
  int fd;
1461
1461
  char temp_file_path[FN_REFLEN];
1462
1462
 
1463
 
  if ((fd= internal::create_temp_file(temp_file_path, TMPDIR,
 
1463
  if ((fd= internal::create_temp_file(temp_file_path, NULL,
1464
1464
                            "tmp", MYF(MY_WME))) < 0)
1465
1465
    die("Failed to create temporary file for ds");
1466
1466
 
2479
2479
 
2480
2480
  error= internal::my_delete(ds_filename.c_str(), MYF(0)) != 0;
2481
2481
  handle_command_error(command, error);
 
2482
  return;
2482
2483
}
2483
2484
 
2484
2485
 
2513
2514
  error= (internal::my_copy(ds_from_file.c_str(), ds_to_file.c_str(),
2514
2515
                  MYF(MY_DONT_OVERWRITE_FILE)) != 0);
2515
2516
  handle_command_error(command, error);
 
2517
  return;
2516
2518
}
2517
2519
 
2518
2520
 
2550
2552
    die("You must write a 4 digit octal number for mode");
2551
2553
 
2552
2554
  handle_command_error(command, chmod(ds_file.c_str(), mode));
 
2555
  return;
2553
2556
}
2554
2557
 
2555
2558
 
2579
2582
 
2580
2583
  error= (access(ds_filename.c_str(), F_OK) != 0);
2581
2584
  handle_command_error(command, error);
 
2585
  return;
2582
2586
}
2583
2587
 
2584
2588
 
2607
2611
 
2608
2612
  error= mkdir(ds_dirname.c_str(), (0777 & internal::my_umask_dir)) != 0;
2609
2613
  handle_command_error(command, error);
 
2614
  return;
2610
2615
}
2611
2616
 
2612
2617
/*
2634
2639
 
2635
2640
  error= rmdir(ds_dirname.c_str()) != 0;
2636
2641
  handle_command_error(command, error);
 
2642
  return;
2637
2643
}
2638
2644
 
2639
2645
 
2872
2878
  }
2873
2879
 
2874
2880
  handle_command_error(command, error);
 
2881
  return;
2875
2882
}
2876
2883
 
2877
2884
 
2921
2928
 
2922
2929
  if (drizzle_quit(&con->con,&result, &ret))
2923
2930
    drizzle_result_free(&result);
 
2931
 
 
2932
  return;
2924
2933
}
2925
2934
 
2926
2935
 
3017
3026
  internal::my_delete(temp_file_path, MYF(0));
3018
3027
 
3019
3028
  handle_command_error(command, WEXITSTATUS(error));
 
3029
  return;
3020
3030
}
3021
3031
 
3022
3032
 
3306
3316
  bool error= false;
3307
3317
  char *p= command->first_argument;
3308
3318
  char *sleep_start, *sleep_end= command->end;
3309
 
  double sleep_val= 0;
 
3319
  double sleep_val;
3310
3320
 
3311
3321
  while (my_isspace(charset_info, *p))
3312
3322
    p++;
3375
3385
    abort_not_supported_test("Test requires charset '%s'", charset_name);
3376
3386
}
3377
3387
 
3378
 
static void fill_global_error_names()
3379
 
{
3380
 
  drizzle_result_st res;
3381
 
  drizzle_return_t ret;
3382
 
  drizzle_row_t row;
3383
 
  drizzle_con_st *con= &cur_con->con;
3384
 
 
3385
 
  global_error_names.clear();
3386
 
 
3387
 
  const std::string ds_query("select error_name, error_code "
3388
 
                             "from data_dictionary.errors");
3389
 
  if (drizzle_query_str(con, &res, ds_query.c_str(), &ret) == NULL ||
3390
 
      ret != DRIZZLE_RETURN_OK)
3391
 
  {
3392
 
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
3393
 
    {
3394
 
      die("Error running query '%s': %d %s", ds_query.c_str(),
3395
 
          drizzle_result_error_code(&res), drizzle_result_error(&res));
3396
 
      drizzle_result_free(&res);
3397
 
    }
3398
 
    else
3399
 
    {
3400
 
      die("Error running query '%s': %d %s", ds_query.c_str(), ret,
3401
 
          drizzle_con_error(con));
3402
 
    }
3403
 
  }
3404
 
  if (drizzle_result_column_count(&res) == 0 ||
3405
 
      drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3406
 
  {
3407
 
    drizzle_result_free(&res);
3408
 
    die("Query '%s' didn't return a result set", ds_query.c_str());
3409
 
  }
3410
 
 
3411
 
  while ((row= drizzle_row_next(&res)) && row[0])
3412
 
  {
3413
 
    /*
3414
 
      Concatenate all fields in the first row with tab in between
3415
 
      and assign that string to the $variable
3416
 
    */
3417
 
    size_t *lengths= drizzle_row_field_sizes(&res);
3418
 
    const std::string error_name(row[0], lengths[0]);
3419
 
    const std::string error_code(row[1], lengths[1]);
3420
 
 
3421
 
    try
3422
 
    {
3423
 
      global_error_names.insert(ErrorCodes::value_type(error_name,
3424
 
                                                       boost::lexical_cast<uint32_t>(error_code)));
3425
 
    }
3426
 
    catch (boost::bad_lexical_cast &ex)
3427
 
    {
3428
 
      drizzle_result_free(&res);
3429
 
      die("Invalid error_code from Drizzle: %s", ex.what());
3430
 
    }
3431
 
 
3432
 
  }
3433
 
 
3434
 
  drizzle_result_free(&res);
3435
 
}
3436
 
 
3437
3388
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3438
3389
{
3439
3390
  size_t err_name_len= error_end - error_name;
3440
3391
  string error_name_s(error_name, err_name_len);
3441
3392
 
3442
 
  ErrorCodes::iterator it= global_error_names.find(error_name_s);
3443
 
  if (it != global_error_names.end())
3444
 
  {
3445
 
    return (*it).second;
3446
 
  }
3447
 
 
3448
 
  die("Unknown SQL error name '%s'", error_name_s.c_str());
3449
 
  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);
3450
3399
}
3451
3400
 
3452
3401
static void do_get_errcodes(struct st_command *command)
3514
3463
    {
3515
3464
      die("The error name definition must start with an uppercase E");
3516
3465
    }
3517
 
    else if (*p == 'H')
 
3466
    else
3518
3467
    {
3519
 
      /* Error name string */
3520
 
 
3521
 
      to->code.errnum= get_errcode_from_name(p, end);
 
3468
      long val;
 
3469
      char *start= p;
 
3470
      /* Check that the string passed to str2int only contain digits */
 
3471
      while (*p && p != end)
 
3472
      {
 
3473
        if (!my_isdigit(charset_info, *p))
 
3474
          die("Invalid argument to error: '%s' - "              \
 
3475
              "the errno may only consist of digits[0-9]",
 
3476
              command->first_argument);
 
3477
        p++;
 
3478
      }
 
3479
 
 
3480
      /* Convert the sting to int */
 
3481
      istringstream buff(start);
 
3482
      if ((buff >> val).fail())
 
3483
        die("Invalid argument to error: '%s'", command->first_argument);
 
3484
 
 
3485
      to->code.errnum= (uint32_t) val;
3522
3486
      to->type= ERR_ERRNO;
3523
3487
    }
3524
 
    else
3525
 
    {
3526
 
      die ("You must either use the SQLSTATE or built in drizzle error label, numbers are not accepted");
3527
 
    }
3528
3488
    to++;
3529
3489
    count++;
3530
3490
 
4476
4436
        end++;
4477
4437
      save= *end;
4478
4438
      *end= 0;
4479
 
      type= command_typelib.find_type(start, 1+2);
 
4439
      type= find_type(start, &command_typelib, 1+2);
4480
4440
      if (type)
4481
4441
        warning_msg("Embedded drizzletest command '--%s' detected in "
4482
4442
                    "query '%s' was this intentional? ",
5299
5259
 
5300
5260
  save= command->query[command->first_word_len];
5301
5261
  command->query[command->first_word_len]= 0;
5302
 
  type= command_typelib.find_type(command->query, 1+2);
 
5262
  type= find_type(command->query, &command_typelib, 1+2);
5303
5263
  command->query[command->first_word_len]= save;
5304
5264
  if (type > 0)
5305
5265
  {
5343
5303
        */
5344
5304
        save= command->query[command->first_word_len-1];
5345
5305
        command->query[command->first_word_len-1]= 0;
5346
 
        if (command_typelib.find_type(command->query, 1+2) > 0)
 
5306
        if (find_type(command->query, &command_typelib, 1+2) > 0)
5347
5307
          die("Extra delimiter \";\" found");
5348
5308
        command->query[command->first_word_len-1]= save;
5349
5309
 
5515
5475
 
5516
5476
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
5517
5477
 
5518
 
  if (user_config_dir.compare(0, 2, "~/") == 0)
5519
 
  {
5520
 
    char *homedir;
5521
 
    homedir= getenv("HOME");
5522
 
    if (homedir != NULL)
5523
 
      user_config_dir.replace(0, 1, homedir);
5524
 
  }
5525
 
 
5526
5478
  po::variables_map vm;
5527
5479
 
5528
5480
  // Disable allow_guessing
5732
5684
  safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5733
5685
               opt_db, opt_port);
5734
5686
 
5735
 
  fill_global_error_names();
5736
 
 
5737
5687
  /* Use all time until exit if no explicit 'start_timer' */
5738
5688
  timer_start= timer_now();
5739
5689