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
1461
char temp_file_path[FN_REFLEN];
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");
3375
3385
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
3388
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3439
3390
size_t err_name_len= error_end - error_name;
3440
3391
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());
3393
uint32_t code= global_error_names.getErrorCode(error_name_s);
3396
die("Unknown SQL error name '%s'", error_name_s.c_str());
3452
3401
static void do_get_errcodes(struct st_command *command)
3515
3464
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);
3470
/* Check that the string passed to str2int only contain digits */
3471
while (*p && p != end)
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);
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);
3485
to->code.errnum= (uint32_t) val;
3522
3486
to->type= ERR_ERRNO;
3526
die ("You must either use the SQLSTATE or built in drizzle error label, numbers are not accepted");
3953
3913
if (!strncmp(con_options, "SSL", 3))
3915
else if (!strncmp(con_options, "COMPRESS", 8))
3956
3918
die("Illegal option to connect: %.*s",
3957
3919
(int) (end - con_options), con_options);
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;
5475
5437
"Directory for log files")
5476
5438
("max-connect-retries", po::value<uint32_t>(&opt_max_connect_retries)->default_value(500)->notifier(&check_retries),
5477
5439
"Max number of connection attempts when connecting to server")
5478
("quiet,s", po::value<bool>(&silent)->default_value(false)->zero_tokens(),
5440
("quiet,s", po::value<bool>(&silent)->default_value(0)->zero_tokens(),
5479
5441
"Suppress all normal output.")
5480
5442
("record,r", "Record output of test_file into result file.")
5481
5443
("result-file,R", po::value<string>(&result_file_name)->default_value(""),
5516
5478
std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
5518
if (user_config_dir.compare(0, 2, "~/") == 0)
5521
homedir= getenv("HOME");
5522
if (homedir != NULL)
5523
user_config_dir.replace(0, 1, homedir);
5526
5480
po::variables_map vm;
5528
// Disable allow_guessing
5529
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
5531
5482
po::store(po::command_line_parser(argc, argv).options(long_options).
5532
style(style).positional(p).extra_parser(parse_password_arg).run(),
5483
positional(p).extra_parser(parse_password_arg).run(), vm);
5535
5485
if (! vm["no-defaults"].as<bool>())
5732
5682
safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5733
5683
opt_db, opt_port);
5735
fill_global_error_names();
5737
5685
/* Use all time until exit if no explicit 'start_timer' */
5738
5686
timer_start= timer_now();
6694
6642
/* Repeatedly replace the string with the matched regex */
6695
6643
string subject(in_string);
6696
6644
size_t replace_length= strlen(replace);
6697
size_t length_of_replacement= strlen(replace);
6698
6645
size_t current_position= 0;
6647
while(0 >= (rc= pcre_exec(re, NULL, subject.c_str() + current_position, subject.length() - current_position,
6703
rc= pcre_exec(re, NULL, subject.c_str(), subject.length(),
6704
current_position, 0, ovector, 3);
6710
6650
current_position= static_cast<size_t>(ovector[0]);
6711
6651
replace_length= static_cast<size_t>(ovector[1] - ovector[0]);
6712
subject.replace(current_position, replace_length, replace, length_of_replacement);
6713
current_position= current_position + length_of_replacement;
6652
subject.replace(current_position, replace_length, replace, replace_length);
6716
6655
char *new_buf = (char *) malloc(subject.length() + 1);