~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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
 
 
68
66
/* Added this for string translation. */
69
67
#include "drizzled/gettext.h"
70
 
#include "drizzled/drizzle_time.h"
 
68
#include "drizzled/type/time.h"
71
69
#include "drizzled/charset.h"
 
70
#include "drizzled/typelib.h"
72
71
#include <drizzled/configmake.h>
73
72
 
74
73
#ifndef DRIZZLE_RETURN_SERVER_GONE
90
89
#define QUERY_SEND_FLAG  1
91
90
#define QUERY_REAP_FLAG  2
92
91
 
 
92
typedef boost::unordered_map<std::string, uint32_t> ErrorCodes;
93
93
ErrorCodes global_error_names;
94
94
 
95
95
enum {
844
844
 
845
845
static void handle_command_error(struct st_command *command, uint32_t error)
846
846
{
847
 
 
848
847
  if (error != 0)
849
848
  {
850
849
    uint32_t i;
871
870
        command->first_word_len, command->query,
872
871
        command->expected_errors.err[0].code.errnum);
873
872
  }
874
 
  return;
875
873
}
876
874
 
877
875
 
1462
1460
  int fd;
1463
1461
  char temp_file_path[FN_REFLEN];
1464
1462
 
1465
 
  if ((fd= internal::create_temp_file(temp_file_path, NULL,
 
1463
  if ((fd= internal::create_temp_file(temp_file_path, TMPDIR,
1466
1464
                            "tmp", MYF(MY_WME))) < 0)
1467
1465
    die("Failed to create temporary file for ds");
1468
1466
 
2481
2479
 
2482
2480
  error= internal::my_delete(ds_filename.c_str(), MYF(0)) != 0;
2483
2481
  handle_command_error(command, error);
2484
 
  return;
2485
2482
}
2486
2483
 
2487
2484
 
2516
2513
  error= (internal::my_copy(ds_from_file.c_str(), ds_to_file.c_str(),
2517
2514
                  MYF(MY_DONT_OVERWRITE_FILE)) != 0);
2518
2515
  handle_command_error(command, error);
2519
 
  return;
2520
2516
}
2521
2517
 
2522
2518
 
2554
2550
    die("You must write a 4 digit octal number for mode");
2555
2551
 
2556
2552
  handle_command_error(command, chmod(ds_file.c_str(), mode));
2557
 
  return;
2558
2553
}
2559
2554
 
2560
2555
 
2584
2579
 
2585
2580
  error= (access(ds_filename.c_str(), F_OK) != 0);
2586
2581
  handle_command_error(command, error);
2587
 
  return;
2588
2582
}
2589
2583
 
2590
2584
 
2613
2607
 
2614
2608
  error= mkdir(ds_dirname.c_str(), (0777 & internal::my_umask_dir)) != 0;
2615
2609
  handle_command_error(command, error);
2616
 
  return;
2617
2610
}
2618
2611
 
2619
2612
/*
2641
2634
 
2642
2635
  error= rmdir(ds_dirname.c_str()) != 0;
2643
2636
  handle_command_error(command, error);
2644
 
  return;
2645
2637
}
2646
2638
 
2647
2639
 
2880
2872
  }
2881
2873
 
2882
2874
  handle_command_error(command, error);
2883
 
  return;
2884
2875
}
2885
2876
 
2886
2877
 
2930
2921
 
2931
2922
  if (drizzle_quit(&con->con,&result, &ret))
2932
2923
    drizzle_result_free(&result);
2933
 
 
2934
 
  return;
2935
2924
}
2936
2925
 
2937
2926
 
3028
3017
  internal::my_delete(temp_file_path, MYF(0));
3029
3018
 
3030
3019
  handle_command_error(command, WEXITSTATUS(error));
3031
 
  return;
3032
3020
}
3033
3021
 
3034
3022
 
3387
3375
    abort_not_supported_test("Test requires charset '%s'", charset_name);
3388
3376
}
3389
3377
 
 
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
 
3390
3437
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3391
3438
{
3392
3439
  size_t err_name_len= error_end - error_name;
3393
3440
  string error_name_s(error_name, err_name_len);
3394
3441
 
3395
 
  uint32_t code= global_error_names.getErrorCode(error_name_s);
3396
 
 
3397
 
  if (!code)
3398
 
    die("Unknown SQL error name '%s'", error_name_s.c_str());
3399
 
 
3400
 
  return(code);
 
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;
3401
3450
}
3402
3451
 
3403
3452
static void do_get_errcodes(struct st_command *command)
3465
3514
    {
3466
3515
      die("The error name definition must start with an uppercase E");
3467
3516
    }
 
3517
    else if (*p == 'H')
 
3518
    {
 
3519
      /* Error name string */
 
3520
 
 
3521
      to->code.errnum= get_errcode_from_name(p, end);
 
3522
      to->type= ERR_ERRNO;
 
3523
    }
3468
3524
    else
3469
3525
    {
3470
 
      long val;
3471
 
      char *start= p;
3472
 
      /* Check that the string passed to str2int only contain digits */
3473
 
      while (*p && p != end)
3474
 
      {
3475
 
        if (!my_isdigit(charset_info, *p))
3476
 
          die("Invalid argument to error: '%s' - "              \
3477
 
              "the errno may only consist of digits[0-9]",
3478
 
              command->first_argument);
3479
 
        p++;
3480
 
      }
3481
 
 
3482
 
      /* Convert the sting to int */
3483
 
      istringstream buff(start);
3484
 
      if ((buff >> val).fail())
3485
 
        die("Invalid argument to error: '%s'", command->first_argument);
3486
 
 
3487
 
      to->code.errnum= (uint32_t) val;
3488
 
      to->type= ERR_ERRNO;
 
3526
      die ("You must either use the SQLSTATE or built in drizzle error label, numbers are not accepted");
3489
3527
    }
3490
3528
    to++;
3491
3529
    count++;
4438
4476
        end++;
4439
4477
      save= *end;
4440
4478
      *end= 0;
4441
 
      type= find_type(start, &command_typelib, 1+2);
 
4479
      type= command_typelib.find_type(start, 1+2);
4442
4480
      if (type)
4443
4481
        warning_msg("Embedded drizzletest command '--%s' detected in "
4444
4482
                    "query '%s' was this intentional? ",
5261
5299
 
5262
5300
  save= command->query[command->first_word_len];
5263
5301
  command->query[command->first_word_len]= 0;
5264
 
  type= find_type(command->query, &command_typelib, 1+2);
 
5302
  type= command_typelib.find_type(command->query, 1+2);
5265
5303
  command->query[command->first_word_len]= save;
5266
5304
  if (type > 0)
5267
5305
  {
5305
5343
        */
5306
5344
        save= command->query[command->first_word_len-1];
5307
5345
        command->query[command->first_word_len-1]= 0;
5308
 
        if (find_type(command->query, &command_typelib, 1+2) > 0)
 
5346
        if (command_typelib.find_type(command->query, 1+2) > 0)
5309
5347
          die("Extra delimiter \";\" found");
5310
5348
        command->query[command->first_word_len-1]= save;
5311
5349
 
5694
5732
  safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5695
5733
               opt_db, opt_port);
5696
5734
 
 
5735
  fill_global_error_names();
 
5736
 
5697
5737
  /* Use all time until exit if no explicit 'start_timer' */
5698
5738
  timer_start= timer_now();
5699
5739