~stewart/drizzle/docs-improvements-1

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

merged with up to date trunk

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"
72
70
#include <drizzled/configmake.h>
73
71
 
90
88
#define QUERY_SEND_FLAG  1
91
89
#define QUERY_REAP_FLAG  2
92
90
 
 
91
typedef boost::unordered_map<std::string, uint32_t> ErrorCodes;
93
92
ErrorCodes global_error_names;
94
93
 
95
94
enum {
1462
1461
  int fd;
1463
1462
  char temp_file_path[FN_REFLEN];
1464
1463
 
1465
 
  if ((fd= internal::create_temp_file(temp_file_path, NULL,
 
1464
  if ((fd= internal::create_temp_file(temp_file_path, TMPDIR,
1466
1465
                            "tmp", MYF(MY_WME))) < 0)
1467
1466
    die("Failed to create temporary file for ds");
1468
1467
 
3387
3386
    abort_not_supported_test("Test requires charset '%s'", charset_name);
3388
3387
}
3389
3388
 
 
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
 
3390
3448
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3391
3449
{
3392
3450
  size_t err_name_len= error_end - error_name;
3393
3451
  string error_name_s(error_name, err_name_len);
3394
3452
 
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);
 
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;
3401
3461
}
3402
3462
 
3403
3463
static void do_get_errcodes(struct st_command *command)
5694
5754
  safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5695
5755
               opt_db, opt_port);
5696
5756
 
 
5757
  fill_global_error_names();
 
5758
 
5697
5759
  /* Use all time until exit if no explicit 'start_timer' */
5698
5760
  timer_start= timer_now();
5699
5761