~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Lee Bieber
  • Date: 2010-11-14 23:15:42 UTC
  • mfrom: (1929.1.42 warning-stack-frame)
  • Revision ID: kalebral@gmail.com-20101114231542-fnnu6ydd2p17n582
Merge Monty - fix bug 672372: some functions use > 32k stack

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