113
113
static bool abort_on_error= true;
114
114
static bool server_initialized= false;
115
115
static bool is_windows= false;
116
static bool use_drizzle_protocol= false;
116
static bool opt_mysql= false;
117
117
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
119
119
std::string opt_basedir,
1462
1459
char temp_file_path[FN_REFLEN];
1464
if ((fd= internal::create_temp_file(temp_file_path, TMPDIR,
1461
if ((fd= internal::create_temp_file(temp_file_path, NULL,
1465
1462
"tmp", MYF(MY_WME))) < 0)
1466
1463
die("Failed to create temporary file for ds");
3386
3383
abort_not_supported_test("Test requires charset '%s'", charset_name);
3389
static void fill_global_error_names()
3391
drizzle_result_st res;
3392
drizzle_return_t ret;
3394
drizzle_con_st *con= &cur_con->con;
3396
global_error_names.clear();
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)
3403
if (ret == DRIZZLE_RETURN_ERROR_CODE)
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);
3411
die("Error running query '%s': %d %s", ds_query.c_str(), ret,
3412
drizzle_con_error(con));
3415
if (drizzle_result_column_count(&res) == 0 ||
3416
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3418
drizzle_result_free(&res);
3419
die("Query '%s' didn't return a result set", ds_query.c_str());
3422
while ((row= drizzle_row_next(&res)) && row[0])
3425
Concatenate all fields in the first row with tab in between
3426
and assign that string to the $variable
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]);
3434
global_error_names.insert(ErrorCodes::value_type(error_name,
3435
boost::lexical_cast<uint32_t>(error_code)));
3437
catch (boost::bad_lexical_cast &ex)
3439
drizzle_result_free(&res);
3440
die("Invalid error_code from Drizzle: %s", ex.what());
3445
drizzle_result_free(&res);
3448
3386
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3450
3388
size_t err_name_len= error_end - error_name;
3451
3389
string error_name_s(error_name, err_name_len);
3453
ErrorCodes::iterator it= global_error_names.find(error_name_s);
3454
if (it != global_error_names.end())
3456
return (*it).second;
3459
die("Unknown SQL error name '%s'", error_name_s.c_str());
3391
uint32_t code= global_error_names.getErrorCode(error_name_s);
3394
die("Unknown SQL error name '%s'", error_name_s.c_str());
3463
3399
static void do_get_errcodes(struct st_command *command)
3975
3911
if (!strncmp(con_options, "SSL", 3))
3913
else if (!strncmp(con_options, "COMPRESS", 8))
3978
3916
die("Illegal option to connect: %.*s",
3979
3917
(int) (end - con_options), con_options);
3999
3937
die("Failed on drizzle_create()");
4000
3938
if (!drizzle_con_create(con_slot->drizzle, &con_slot->con))
4001
3939
die("Failed on drizzle_con_create()");
4002
drizzle_con_add_options(&con_slot->con, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
3941
drizzle_con_add_options(&con_slot->con, DRIZZLE_CON_MYSQL);
4004
3943
/* Use default db name */
4005
3944
if (ds_database.length() == 0)
5497
5436
"Directory for log files")
5498
5437
("max-connect-retries", po::value<uint32_t>(&opt_max_connect_retries)->default_value(500)->notifier(&check_retries),
5499
5438
"Max number of connection attempts when connecting to server")
5500
("quiet,s", po::value<bool>(&silent)->default_value(false)->zero_tokens(),
5439
("quiet,s", po::value<bool>(&silent)->default_value(0)->zero_tokens(),
5501
5440
"Suppress all normal output.")
5502
5441
("record,r", "Record output of test_file into result file.")
5503
5442
("result-file,R", po::value<string>(&result_file_name)->default_value(""),
5514
5453
("host,h", po::value<string>(&opt_host)->default_value("localhost"),
5515
5454
"Connect to host.")
5455
("mysql,m", po::value<bool>(&opt_mysql)->default_value(true)->zero_tokens(),
5456
N_("Use MySQL Protocol."))
5516
5457
("password,P", po::value<string>(&password)->default_value("PASSWORD_SENTINEL"),
5517
5458
"Password to use when connecting to server.")
5518
5459
("port,p", po::value<uint32_t>(&opt_port)->default_value(0),
5519
5460
"Port number to use for connection or 0 for default")
5520
("protocol", po::value<string>(&opt_protocol),
5521
"The protocol of connection (mysql or drizzle).")
5461
("protocol", po::value<string>(),
5462
"The protocol of connection (tcp,socket,pipe,memory).")
5522
5463
("user,u", po::value<string>(&opt_user)->default_value(""),
5523
5464
"User for login.")
5538
5479
std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
5540
if (user_config_dir.compare(0, 2, "~/") == 0)
5543
homedir= getenv("HOME");
5544
if (homedir != NULL)
5545
user_config_dir.replace(0, 1, homedir);
5548
5481
po::variables_map vm;
5550
// Disable allow_guessing
5551
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
5553
5483
po::store(po::command_line_parser(argc, argv).options(long_options).
5554
style(style).positional(p).extra_parser(parse_password_arg).run(),
5484
positional(p).extra_parser(parse_password_arg).run(), vm);
5557
5486
if (! vm["no-defaults"].as<bool>())
5657
5586
unlink(timer_file); /* Ignore error, may not exist */
5660
if (vm.count("protocol"))
5662
std::transform(opt_protocol.begin(), opt_protocol.end(),
5663
opt_protocol.begin(), ::tolower);
5665
if (not opt_protocol.compare("mysql"))
5666
use_drizzle_protocol=false;
5667
else if (not opt_protocol.compare("drizzle"))
5668
use_drizzle_protocol=true;
5671
cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
5676
5589
if (vm.count("port"))
5678
5591
/* If the port number is > 65535 it is not a valid port
5747
5660
die("Failed in drizzle_create()");
5748
5661
if (!( drizzle_con_create(cur_con->drizzle, &cur_con->con)))
5749
5662
die("Failed in drizzle_con_create()");
5750
drizzle_con_add_options(&cur_con->con, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
5664
drizzle_con_add_options(&cur_con->con, DRIZZLE_CON_MYSQL);
5752
5666
if (!(cur_con->name = strdup("default")))
5753
5667
die("Out of memory");
5754
5668
safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5755
5669
opt_db, opt_port);
5757
fill_global_error_names();
5759
5671
/* Use all time until exit if no explicit 'start_timer' */
5760
5672
timer_start= timer_now();
6716
6628
/* Repeatedly replace the string with the matched regex */
6717
6629
string subject(in_string);
6718
6630
size_t replace_length= strlen(replace);
6719
size_t length_of_replacement= strlen(replace);
6720
6631
size_t current_position= 0;
6633
while(0 >= (rc= pcre_exec(re, NULL, subject.c_str() + current_position, subject.length() - current_position,
6725
rc= pcre_exec(re, NULL, subject.c_str(), subject.length(),
6726
current_position, 0, ovector, 3);
6732
6636
current_position= static_cast<size_t>(ovector[0]);
6733
6637
replace_length= static_cast<size_t>(ovector[1] - ovector[0]);
6734
subject.replace(current_position, replace_length, replace, length_of_replacement);
6735
current_position= current_position + length_of_replacement;
6638
subject.replace(current_position, replace_length, replace, replace_length);
6738
6641
char *new_buf = (char *) malloc(subject.length() + 1);