63
63
#include <stdarg.h>
64
64
#include <boost/unordered_map.hpp>
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>
73
74
#ifndef DRIZZLE_RETURN_SERVER_GONE
1461
1463
char temp_file_path[FN_REFLEN];
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");
3375
3387
abort_not_supported_test("Test requires charset '%s'", charset_name);
3378
static void fill_global_error_names()
3380
drizzle_result_st res;
3381
drizzle_return_t ret;
3383
drizzle_con_st *con= &cur_con->con;
3385
global_error_names.clear();
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)
3392
if (ret == DRIZZLE_RETURN_ERROR_CODE)
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);
3400
die("Error running query '%s': %d %s", ds_query.c_str(), ret,
3401
drizzle_con_error(con));
3404
if (drizzle_result_column_count(&res) == 0 ||
3405
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3407
drizzle_result_free(&res);
3408
die("Query '%s' didn't return a result set", ds_query.c_str());
3411
while ((row= drizzle_row_next(&res)) && row[0])
3414
Concatenate all fields in the first row with tab in between
3415
and assign that string to the $variable
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]);
3423
global_error_names.insert(ErrorCodes::value_type(error_name,
3424
boost::lexical_cast<uint32_t>(error_code)));
3426
catch (boost::bad_lexical_cast &ex)
3428
drizzle_result_free(&res);
3429
die("Invalid error_code from Drizzle: %s", ex.what());
3434
drizzle_result_free(&res);
3437
3390
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3439
3392
size_t err_name_len= error_end - error_name;
3440
3393
string error_name_s(error_name, err_name_len);
3442
ErrorCodes::iterator it= global_error_names.find(error_name_s);
3443
if (it != global_error_names.end())
3445
return (*it).second;
3448
die("Unknown SQL error name '%s'", error_name_s.c_str());
3395
uint32_t code= global_error_names.getErrorCode(error_name_s);
3398
die("Unknown SQL error name '%s'", error_name_s.c_str());
3452
3403
static void do_get_errcodes(struct st_command *command)
3515
3466
die("The error name definition must start with an uppercase E");
3519
/* Error name string */
3521
to->code.errnum= get_errcode_from_name(p, end);
3472
/* Check that the string passed to str2int only contain digits */
3473
while (*p && p != end)
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);
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);
3487
to->code.errnum= (uint32_t) val;
3522
3488
to->type= ERR_ERRNO;
3526
die ("You must either use the SQLSTATE or built in drizzle error label, numbers are not accepted");
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;
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;
5732
5694
safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5733
5695
opt_db, opt_port);
5735
fill_global_error_names();
5737
5697
/* Use all time until exit if no explicit 'start_timer' */
5738
5698
timer_start= timer_now();