39
39
#define MTEST_VERSION "3.3"
41
#include "client_priv.h"
49
#include "client_priv.h"
50
50
#include <mysys/hash.h>
51
51
#include <stdarg.h>
53
53
#include "errname.h"
55
/* Added this for string translation. */
56
#include <drizzled/gettext.h>
55
58
using namespace std;
57
60
#define MAX_VAR_NAME_LENGTH 256
58
61
#define MAX_COLUMNS 256
59
62
#define MAX_EMBEDDED_SERVER_ARGS 64
60
63
#define MAX_DELIMITER_LENGTH 16
62
64
/* Flags controlling send and reap */
63
65
#define QUERY_SEND_FLAG 1
64
66
#define QUERY_REAP_FLAG 2
67
69
OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
68
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES
70
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES,
71
74
static int record= 0, opt_sleep= -1;
72
static char *opt_db= 0, *opt_pass= 0;
73
const char *opt_user= 0, *opt_host= 0, *unix_sock= 0, *opt_basedir= "./";
75
static char *opt_db= NULL, *opt_pass= NULL;
76
const char *opt_user= NULL, *opt_host= NULL, *unix_sock= NULL,
74
78
const char *opt_logdir= "";
75
const char *opt_include= 0, *opt_charsets_dir;
76
static int opt_port= 0;
79
const char *opt_include= NULL, *opt_charsets_dir;
80
const char *opt_testdir= NULL;
81
static uint32_t opt_port= 0;
77
82
static int opt_max_connect_retries;
78
static bool opt_compress= 0, silent= 0, verbose= 0;
79
static bool debug_info_flag= 0, debug_check_flag= 0;
80
static bool tty_password= 0;
81
static bool opt_mark_progress= 0;
82
static bool parsing_disabled= 0;
83
static bool opt_compress= false, silent= false, verbose= false;
84
static bool debug_info_flag= false, debug_check_flag= false;
85
static bool tty_password= false;
86
static bool opt_mark_progress= false;
87
static bool parsing_disabled= false;
83
88
static bool display_result_vertically= false,
84
89
display_metadata= false, display_result_sorted= false;
85
static bool disable_query_log= 0, disable_result_log= 0;
86
static bool disable_warnings= 0;
87
static bool disable_info= 1;
88
static bool abort_on_error= 1;
89
static bool server_initialized= 0;
90
static bool is_windows= 0;
90
static bool disable_query_log= false, disable_result_log= false;
91
static bool disable_warnings= false;
92
static bool disable_info= true;
93
static bool abort_on_error= true;
94
static bool server_initialized= false;
95
static bool is_windows= false;
91
96
static char **default_argv;
92
97
static const char *load_default_groups[]= { "drizzletest", "client", 0 };
93
98
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
95
static uint start_lineno= 0; /* Start line of current command */
96
static uint my_end_arg= 0;
100
static uint32_t start_lineno= 0; /* Start line of current command */
101
static uint32_t my_end_arg= 0;
98
103
/* Number of lines of the result to include in failure report */
99
static uint opt_tail_lines= 0;
104
static uint32_t opt_tail_lines= 0;
101
106
static char delimiter[MAX_DELIMITER_LENGTH]= ";";
102
static uint delimiter_length= 1;
107
static uint32_t delimiter_length= 1;
104
109
static char TMPDIR[FN_REFLEN];
388
393
VAR* var_from_env(const char *, const char *);
389
394
VAR* var_init(VAR* v, const char *name, int name_len, const char *val,
391
void var_free(void* v);
396
extern "C" void var_free(void* v);
392
397
VAR* var_get(const char *var_name, const char** var_name_end,
393
398
bool raw, bool ignore_not_existing);
394
399
void eval_expr(VAR* v, const char *p, const char** p_end);
395
bool match_delimiter(int c, const char *delim, uint length);
400
bool match_delimiter(int c, const char *delim, uint32_t length);
396
401
void dump_result_to_reject_file(char *buf, int size);
397
402
void dump_result_to_log_file(const char *buf, int size);
398
403
void dump_warning_messages(void);
631
if (drizzle_query(drizzle, query))
636
if (drizzleclient_query(drizzle, query))
633
638
log_msg("Error running query '%s': %d %s",
634
query, drizzle_errno(drizzle), drizzle_error(drizzle));
639
query, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
638
if ((res= drizzle_store_result(drizzle)) == NULL)
643
if ((res= drizzleclient_store_result(drizzle)) == NULL)
640
645
/* No result set returned */
644
if (drizzle_num_rows(res) <= 1)
649
if (drizzleclient_num_rows(res) <= 1)
646
651
/* Don't display the last row, it's "last error" */
1283
1287
int error= RESULT_OK;
1286
1290
char buff[512], buff2[512];
1291
const char *fname= filename2;
1288
if ((fd2= my_open(filename2, O_RDONLY, MYF(0))) < 0)
1294
if ((fd2= my_open(fname, O_RDONLY, MYF(0))) < 0)
1290
1296
my_close(fd, MYF(0));
1291
die("Failed to open second file: '%s'", filename2);
1297
if (opt_testdir != NULL)
1299
tmpfile= opt_testdir;
1300
if (tmpfile[tmpfile.length()] != '/')
1301
tmpfile.append("/");
1302
tmpfile.append(filename2);
1303
fname= tmpfile.c_str();
1305
if ((fd2= my_open(fname, O_RDONLY, MYF(0))) < 0)
1307
my_close(fd, MYF(0));
1309
die("Failed to open second file: '%s'", fname);
1293
1312
while((len= my_read(fd, (unsigned char*)&buff,
1294
1313
sizeof(buff), MYF(0))) > 0)
1374
1393
char temp_file_path[FN_REFLEN];
1376
1395
if ((fd= create_temp_file(temp_file_path, NULL,
1377
"tmp", O_CREAT | O_SHARE | O_RDWR,
1396
"tmp", O_CREAT | O_RDWR,
1378
1397
MYF(MY_WME))) < 0)
1379
1398
die("Failed to create temporary file for ds");
1381
1400
/* Write ds to temporary file and set file pos to beginning*/
1382
1401
if (my_write(fd, (unsigned char *) ds->c_str(), ds->length(),
1383
1402
MYF(MY_FNABP | MY_WME)) ||
1384
my_seek(fd, 0, SEEK_SET, MYF(0)) == MY_FILEPOS_ERROR)
1403
lseek(fd, 0, SEEK_SET) == MY_FILEPOS_ERROR)
1386
1405
my_close(fd, MYF(0));
1387
1406
/* Remove the temporary file */
1738
1758
Store an integer (typically the returncode of the last SQL)
1739
statement in the drizzletest builtin variable $drizzle_errno
1759
statement in the drizzletest builtin variable $drizzleclient_errno
1742
1762
static void var_set_errno(int sql_errno)
1744
var_set_int("$drizzle_errno", sql_errno);
1764
var_set_int("$drizzleclient_errno", sql_errno);
1749
Update $drizzle_get_server_version variable with version
1769
Update $drizzleclient_get_server_version variable with version
1750
1770
of the currently connected server
1753
static void var_set_drizzle_get_server_version(DRIZZLE *drizzle)
1773
static void var_set_drizzleclient_get_server_version(DRIZZLE *drizzle)
1755
var_set_int("$drizzle_get_server_version", drizzle_get_server_version(drizzle));
1775
var_set_int("$drizzleclient_get_server_version", drizzleclient_get_server_version(drizzle));
1798
1818
/* Eval the query, thus replacing all environment variables */
1799
1819
do_eval(&ds_query, query, end, false);
1801
if (drizzle_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1821
if (drizzleclient_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1802
1822
die("Error running query '%s': %d %s", ds_query.c_str(),
1803
drizzle_errno(drizzle), drizzle_error(drizzle));
1804
if (!(res= drizzle_store_result(drizzle)))
1823
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
1824
if (!(res= drizzleclient_store_result(drizzle)))
1805
1825
die("Query '%s' didn't return a result set", ds_query.c_str());
1807
if ((row= drizzle_fetch_row(res)) && row[0])
1827
if ((row= drizzleclient_fetch_row(res)) && row[0])
1810
1830
Concatenate all fields in the first row with tab in between
1889
1909
char * unstripped_query= strdup(ds_query.c_str());
1890
1910
if (strip_surrounding(unstripped_query, '"', '"'))
1891
1911
die("Mismatched \"'s around query '%s'", ds_query.c_str());
1892
ds_query= unstripped_query;
1913
ds_query.append(unstripped_query);
1894
1915
/* Run the query */
1895
if (drizzle_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1916
if (drizzleclient_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1896
1917
die("Error running query '%s': %d %s", ds_query.c_str(),
1897
drizzle_errno(drizzle), drizzle_error(drizzle));
1898
if (!(res= drizzle_store_result(drizzle)))
1918
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
1919
if (!(res= drizzleclient_store_result(drizzle)))
1899
1920
die("Query '%s' didn't return a result set", ds_query.c_str());
1902
1923
/* Find column number from the given column name */
1904
uint num_fields= drizzle_num_fields(res);
1905
const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
1925
uint32_t num_fields= drizzleclient_num_fields(res);
1926
const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
1907
1928
for (i= 0; i < num_fields; i++)
2817
static void do_change_user(struct st_command *command)
2848
static void do_change_user(struct st_command *)
2819
DRIZZLE *drizzle= &cur_con->drizzle;
2820
/* static keyword to make the NetWare compiler happy. */
2821
string ds_user, ds_passwd, ds_db;
2822
const struct command_arg change_user_args[] = {
2823
{ "user", ARG_STRING, false, &ds_user, "User to connect as" },
2824
{ "password", ARG_STRING, false, &ds_passwd, "Password used when connecting" },
2825
{ "database", ARG_STRING, false, &ds_db, "Database to select after connect" },
2830
check_command_args(command, command->first_argument,
2832
sizeof(change_user_args)/sizeof(struct command_arg),
2835
if (!ds_user.length())
2836
ds_user= drizzle->user;
2838
if (!ds_passwd.length())
2839
ds_passwd= drizzle->passwd;
2841
if (!ds_db.length())
2844
if (drizzle_change_user(drizzle, ds_user.c_str(),
2845
ds_passwd.c_str(), ds_db.c_str()))
2846
die("change user failed: %s", drizzle_error(drizzle));
2975
2975
DRIZZLE_ROW row;
2978
if (drizzle_query(drizzle,"show status like 'Slave_running'") ||
2979
!(res=drizzle_store_result(drizzle)))
2978
if (drizzleclient_query(drizzle,"show status like 'Slave_running'") ||
2979
!(res=drizzleclient_store_result(drizzle)))
2980
2980
die("Query failed while probing slave for stop: %s",
2981
drizzle_error(drizzle));
2982
if (!(row=drizzle_fetch_row(res)) || !row[1])
2981
drizzleclient_error(drizzle));
2982
if (!(row=drizzleclient_fetch_row(res)) || !row[1])
2984
drizzle_free_result(res);
2984
drizzleclient_free_result(res);
2985
2985
die("Strange result from query while probing slave for stop");
2987
2987
done = !strcmp(row[1],"OFF");
2988
drizzle_free_result(res);
2988
drizzleclient_free_result(res);
2991
my_sleep(SLAVE_POLL_INTERVAL);
2991
usleep(SLAVE_POLL_INTERVAL);
3011
3011
wait_for_position:
3013
if (drizzle_query(drizzle, query_buf))
3014
die("failed in '%s': %d: %s", query_buf, drizzle_errno(drizzle),
3015
drizzle_error(drizzle));
3013
if (drizzleclient_query(drizzle, query_buf))
3014
die("failed in '%s': %d: %s", query_buf, drizzleclient_errno(drizzle),
3015
drizzleclient_error(drizzle));
3017
if (!(res= drizzle_store_result(drizzle)))
3018
die("drizzle_store_result() returned NULL for '%s'", query_buf);
3019
if (!(row= drizzle_fetch_row(res)))
3017
if (!(res= drizzleclient_store_result(drizzle)))
3018
die("drizzleclient_store_result() returned NULL for '%s'", query_buf);
3019
if (!(row= drizzleclient_fetch_row(res)))
3021
drizzle_free_result(res);
3021
drizzleclient_free_result(res);
3022
3022
die("empty result in %s", query_buf);
3073
3073
const char *query;
3076
if (drizzle_query(drizzle, query= "show master status"))
3076
if (drizzleclient_query(drizzle, query= "show master status"))
3077
3077
die("failed in 'show master status': %d %s",
3078
drizzle_errno(drizzle), drizzle_error(drizzle));
3078
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3080
if (!(res = drizzle_store_result(drizzle)))
3081
die("drizzle_store_result() retuned NULL for '%s'", query);
3082
if (!(row = drizzle_fetch_row(res)))
3080
if (!(res = drizzleclient_store_result(drizzle)))
3081
die("drizzleclient_store_result() retuned NULL for '%s'", query);
3082
if (!(row = drizzleclient_fetch_row(res)))
3083
3083
die("empty result in show master status");
3084
my_stpncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3084
strncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3085
3085
master_pos.pos = strtoul(row[1], (char**) 0, 10);
3086
drizzle_free_result(res);
3086
drizzleclient_free_result(res);
3575
3575
on protocol/connection type
3578
if ((drizzle_errno(drizzle) == CR_CONN_HOST_ERROR ||
3579
drizzle_errno(drizzle) == CR_CONNECTION_ERROR) &&
3578
if ((drizzleclient_errno(drizzle) == CR_CONN_HOST_ERROR ||
3579
drizzleclient_errno(drizzle) == CR_CONNECTION_ERROR) &&
3580
3580
failed_attempts < opt_max_connect_retries)
3582
3582
verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts,
3583
opt_max_connect_retries, drizzle_errno(drizzle),
3584
drizzle_error(drizzle));
3585
my_sleep(connection_retry_sleep);
3583
opt_max_connect_retries, drizzleclient_errno(drizzle),
3584
drizzleclient_error(drizzle));
3585
usleep(connection_retry_sleep);
3589
3589
if (failed_attempts > 0)
3590
3590
die("Could not open connection '%s' after %d attempts: %d %s", name,
3591
failed_attempts, drizzle_errno(drizzle), drizzle_error(drizzle));
3591
failed_attempts, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3593
3593
die("Could not open connection '%s': %d %s", name,
3594
drizzle_errno(drizzle), drizzle_error(drizzle));
3594
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3596
3596
failed_attempts++;
3653
3653
ds_res.append(delimiter);
3654
3654
ds_res.append("\n");
3656
if (!drizzle_connect(con, host, user, pass, db, port, 0,
3656
if (!drizzleclient_connect(con, host, user, pass, db, port, 0,
3657
3657
CLIENT_MULTI_STATEMENTS))
3659
var_set_errno(drizzle_errno(con));
3660
handle_error(command, drizzle_errno(con), drizzle_error(con),
3661
drizzle_sqlstate(con), &ds_res);
3659
var_set_errno(drizzleclient_errno(con));
3660
handle_error(command, drizzleclient_errno(con), drizzleclient_error(con),
3661
drizzleclient_sqlstate(con), &ds_res);
3662
3662
return 0; /* Not connected */
3785
3786
(int) (sizeof(connections)/sizeof(struct st_connection)));
3788
if (!drizzle_create(&con_slot->drizzle))
3789
die("Failed on drizzle_create()");
3789
if (!drizzleclient_create(&con_slot->drizzle))
3790
die("Failed on drizzleclient_create()");
3790
3791
if (opt_compress || con_compress)
3791
drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_COMPRESS, NULL);
3792
drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
3792
drizzleclient_options(&con_slot->drizzle, DRIZZLE_OPT_COMPRESS, NULL);
3794
3795
/* Use default db name */
3795
3796
if (ds_database.length() == 0)
3796
ds_database= opt_db;
3797
ds_database.append(opt_db);
3798
3799
/* Special database to allow one to connect without a database name */
3799
3800
if (ds_database.length() && !strcmp(ds_database.c_str(),"*NO-ONE*"))
3801
ds_database.clear();
3802
3803
if (connect_n_handle_errors(command, &con_slot->drizzle,
3803
3804
ds_host.c_str(),ds_user.c_str(),
4440
4441
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4441
4442
{"include", 'i', "Include SQL before each test case.", (char**) &opt_include,
4442
4443
(char**) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4444
{"testdir", OPT_TESTDIR, "Path to use to search for test files",
4445
(char**) &opt_testdir,
4446
(char**) &opt_testdir, 0,GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4443
4447
{"logdir", OPT_LOG_DIR, "Directory for log files", (char**) &opt_logdir,
4444
4448
(char**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4445
4449
{"mark-progress", OPT_MARK_PROGRESS,
4450
4454
"Max number of connection attempts when connecting to server",
4451
4455
(char**) &opt_max_connect_retries, (char**) &opt_max_connect_retries, 0,
4452
4456
GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0},
4453
{"password", 'p', "Password to use when connecting to server.",
4457
{"password", 'P', "Password to use when connecting to server.",
4454
4458
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
4455
{"port", 'P', "Port number to use for connection or 0 for default to, in "
4456
"order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
4459
{"port", 'p', "Port number to use for connection or 0 for default to, in "
4460
"order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
4457
4461
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
4459
(char**) &opt_port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4462
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4460
4463
{"quiet", 's', "Suppress all normal output.", (char**) &silent,
4461
4464
(char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4462
4465
{"record", 'r', "Record output of test_file into result file.",
4570
4575
char buff[FN_REFLEN];
4571
4576
if (!test_if_hard_path(argument))
4573
strxmov(buff, opt_basedir, argument, NULL);
4578
sprintf(buff,"%s%s",opt_basedir,argument);
4574
4579
argument= buff;
4576
4581
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4577
4582
assert(cur_file == file_stack && cur_file->file == 0);
4578
if (!(cur_file->file=
4579
my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0))))
4583
if (!(cur_file->file= fopen(buff, "r")))
4580
4584
die("Could not open '%s' for reading: errno = %d", buff, errno);
4581
cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
4585
if (!(cur_file->file_name= strdup(buff)))
4586
die("Out of memory");
4582
4587
cur_file->lineno= 1;
4604
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
4605
/* if there is an alpha character this is not a valid port */
4606
if (strlen(endchar) != 0)
4608
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
4611
/* If the port number is > 65535 it is not a valid port
4612
This also helps with potential data loss casting unsigned long to a
4614
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
4616
fprintf(stderr, _("Value supplied for port is not valid.\n"));
4621
opt_port= (uint32_t) temp_drizzle_port;
4602
opt_pass= my_strdup(argument, MYF(MY_FAE));
4603
while (*argument) *argument++= 'x'; /* Destroy argument */
4629
opt_pass = strdup(argument);
4630
if (opt_pass == NULL)
4631
die("Out of memory");
4634
/* Overwriting password with 'x' */
4604
4637
tty_password= 0;
4607
4640
tty_password= 1;
4610
my_stpncpy(TMPDIR, argument, sizeof(TMPDIR));
4643
strncpy(TMPDIR, argument, sizeof(TMPDIR));
4613
4646
if (!embedded_server_arg_count)
4786
4819
static void append_result(string *ds, DRIZZLE_RES *res)
4788
4821
DRIZZLE_ROW row;
4789
uint32_t num_fields= drizzle_num_fields(res);
4790
const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
4822
uint32_t num_fields= drizzleclient_num_fields(res);
4823
const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
4791
4824
uint32_t *lengths;
4793
while ((row = drizzle_fetch_row(res)))
4826
while ((row = drizzleclient_fetch_row(res)))
4796
lengths = drizzle_fetch_lengths(res);
4829
lengths = drizzleclient_fetch_lengths(res);
4797
4830
for (i = 0; i < num_fields; i++)
4798
4831
append_field(ds, i, &fields[i],
4799
4832
(const char*)row[i], lengths[i], !row[i]);
4914
4947
through PS API we should not issue SHOW WARNINGS until
4915
4948
we have not read all results...
4917
assert(!drizzle_more_results(drizzle));
4919
if (drizzle_real_query(drizzle, "SHOW WARNINGS", 13))
4920
die("Error running query \"SHOW WARNINGS\": %s", drizzle_error(drizzle));
4922
if (!(warn_res= drizzle_store_result(drizzle)))
4950
assert(!drizzleclient_more_results(drizzle));
4952
if (drizzleclient_real_query(drizzle, "SHOW WARNINGS", 13))
4953
die("Error running query \"SHOW WARNINGS\": %s", drizzleclient_error(drizzle));
4955
if (!(warn_res= drizzleclient_store_result(drizzle)))
4923
4956
die("Warning count is %u but didn't get any warnings",
4972
When on first result set, call drizzle_read_query_result to retrieve
5005
When on first result set, call drizzleclient_read_query_result to retrieve
4973
5006
answer to the query sent earlier
4975
if ((counter==0) && drizzle_read_query_result(drizzle))
5008
if ((counter==0) && drizzleclient_read_query_result(drizzle))
4977
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4978
drizzle_sqlstate(drizzle), ds);
5010
handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
5011
drizzleclient_sqlstate(drizzle), ds);
5032
5065
if (!disable_info)
5033
append_info(ds, affected_rows, drizzle_info(drizzle));
5066
append_info(ds, affected_rows, drizzleclient_info(drizzle));
5038
drizzle_free_result(res);
5071
drizzleclient_free_result(res);
5042
} while (!(err= drizzle_next_result(drizzle)));
5075
} while (!(err= drizzleclient_next_result(drizzle)));
5045
/* We got an error from drizzle_next_result, maybe expected */
5046
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5047
drizzle_sqlstate(drizzle), ds);
5078
/* We got an error from drizzleclient_next_result, maybe expected */
5079
handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
5080
drizzleclient_sqlstate(drizzle), ds);
5050
5083
assert(err == -1); /* Successful and there are no more results */
5482
5514
if (cur_file == file_stack && cur_file->file == 0)
5484
5516
cur_file->file= stdin;
5485
cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
5517
cur_file->file_name= strdup("<stdin>");
5518
if (cur_file->file_name == NULL)
5519
die("Out of memory");
5486
5520
cur_file->lineno= 1;
5488
5522
cur_con= connections;
5489
if (!( drizzle_create(&cur_con->drizzle)))
5490
die("Failed in drizzle_create()");
5523
if (!( drizzleclient_create(&cur_con->drizzle)))
5524
die("Failed in drizzleclient_create()");
5491
5525
if (opt_compress)
5492
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5493
drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5526
drizzleclient_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5495
if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5528
if (!(cur_con->name = strdup("default")))
5496
5529
die("Out of memory");
5498
5531
safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5974
6009
TYPELIB typelib; /* Pointer to strings */
5975
6010
unsigned char *str; /* Strings is here */
5976
6011
uint8_t *flag; /* Flag about each var. */
5977
uint array_allocs,max_count,length,max_length;
6012
uint32_t array_allocs,max_count,length,max_length;
5978
6013
} POINTER_ARRAY;
5980
6015
struct st_replace;
5981
struct st_replace *init_replace(char * *from, char * *to, uint count,
6016
struct st_replace *init_replace(char * *from, char * *to, uint32_t count,
5982
6017
char * word_end_chars);
5983
6018
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
5984
6019
void replace_strings_append(struct st_replace *rep, string* ds,
6384
6407
char *replace, char *in_string, int icase)
6386
6409
string string_to_match(in_string);
6387
pcrecpp::RE_Options opt;
6390
opt.set_caseless(true);
6392
if (!pcrecpp::RE(pattern, opt).Replace(replace,&string_to_match)){
6410
const char *error= NULL;
6413
pcre *re= pcre_compile(pattern,
6414
icase ? PCRE_CASELESS : 0,
6415
&error, &erroffset, NULL);
6419
int rc= pcre_exec(re, NULL, in_string, (int)strlen(in_string),
6396
const char * new_str= string_to_match.c_str();
6397
*buf_len_p= strlen(new_str);
6427
char *substring_to_replace= in_string + ovector[0];
6428
int substring_length= ovector[1] - ovector[0];
6429
*buf_len_p= strlen(in_string) - substring_length + strlen(replace);
6398
6430
char * new_buf = (char *)malloc(*buf_len_p+1);
6399
6431
if (new_buf == NULL)
6403
strcpy(new_buf, new_str);
6437
memset(new_buf, 0, *buf_len_p+1);
6438
strncpy(new_buf, in_string, substring_to_replace-in_string);
6439
strncpy(new_buf+(substring_to_replace-in_string), replace, strlen(replace));
6440
strncpy(new_buf+(substring_to_replace-in_string)+strlen(replace),
6441
substring_to_replace + substring_length,
6444
- (substring_to_replace-in_string));
6410
6452
#ifndef WORD_BIT
6411
#define WORD_BIT (8*sizeof(uint))
6453
#define WORD_BIT (8*sizeof(uint32_t))
6414
6456
#define SET_MALLOC_HUNC 64
6415
6457
#define LAST_CHAR_CODE 259
6417
6459
typedef struct st_rep_set {
6418
uint *bits; /* Pointer to used sets */
6460
uint32_t *bits; /* Pointer to used sets */
6419
6461
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6420
uint found_len; /* Best match to date */
6462
uint32_t found_len; /* Best match to date */
6421
6463
int found_offset;
6423
uint size_of_bits; /* For convinience */
6464
uint32_t table_offset;
6465
uint32_t size_of_bits; /* For convinience */
6426
6468
typedef struct st_rep_sets {
6427
uint count; /* Number of sets */
6428
uint extra; /* Extra sets in buffer */
6429
uint invisible; /* Sets not chown */
6469
uint32_t count; /* Number of sets */
6470
uint32_t extra; /* Extra sets in buffer */
6471
uint32_t invisible; /* Sets not chown */
6472
uint32_t size_of_bits;
6431
6473
REP_SET *set,*set_buffer;
6474
uint32_t *bit_buffer;
6435
6477
typedef struct st_found_set {
6478
uint32_t table_offset;
6437
6479
int found_offset;
6440
6482
typedef struct st_follow {
6484
uint32_t table_offset;
6447
int init_sets(REP_SETS *sets,uint states);
6489
int init_sets(REP_SETS *sets,uint32_t states);
6448
6490
REP_SET *make_new_set(REP_SETS *sets);
6449
6491
void make_sets_invisible(REP_SETS *sets);
6450
6492
void free_last_set(REP_SETS *sets);
6451
6493
void free_sets(REP_SETS *sets);
6452
void internal_set_bit(REP_SET *set, uint bit);
6453
void internal_clear_bit(REP_SET *set, uint bit);
6494
void internal_set_bit(REP_SET *set, uint32_t bit);
6495
void internal_clear_bit(REP_SET *set, uint32_t bit);
6454
6496
void or_bits(REP_SET *to,REP_SET *from);
6455
6497
void copy_bits(REP_SET *to,REP_SET *from);
6456
6498
int cmp_bits(REP_SET *set1,REP_SET *set2);
6457
int get_next_bit(REP_SET *set,uint lastpos);
6499
int get_next_bit(REP_SET *set,uint32_t lastpos);
6458
6500
int find_set(REP_SETS *sets,REP_SET *find);
6459
int find_found(FOUND_SET *found_set,uint table_offset,
6501
int find_found(FOUND_SET *found_set,uint32_t table_offset,
6460
6502
int found_offset);
6461
uint start_at_word(char * pos);
6462
uint end_of_word(char * pos);
6464
static uint found_sets=0;
6467
static uint replace_len(char * str)
6503
uint32_t start_at_word(char * pos);
6504
uint32_t end_of_word(char * pos);
6506
static uint32_t found_sets=0;
6509
static uint32_t replace_len(char * str)
6472
6514
if (str[0] == '\\' && str[1])
6480
6522
/* Init a replace structure for further calls */
6482
REPLACE *init_replace(char * *from, char * *to,uint count,
6524
REPLACE *init_replace(char * *from, char * *to,uint32_t count,
6483
6525
char * word_end_chars)
6485
6527
static const int SPACE_CHAR= 256;
6486
6528
static const int START_OF_LINE= 257;
6487
6529
static const int END_OF_LINE= 258;
6489
uint i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr;
6531
uint32_t i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr;
6490
6532
int used_sets,chr,default_state;
6491
6533
char used_chars[LAST_CHAR_CODE],is_word_end[256];
6492
6534
char * pos, *to_pos, **to_array;
6723
6765
/* Alloc replace structure for the replace-state-machine */
6725
if ((replace=(REPLACE*) my_malloc(sizeof(REPLACE)*(sets.count)+
6726
sizeof(REPLACE_STRING)*(found_sets+1)+
6727
sizeof(char *)*count+result_len,
6728
MYF(MY_WME | MY_ZEROFILL))))
6767
if ((replace=(REPLACE*) malloc(sizeof(REPLACE)*(sets.count)+
6768
sizeof(REPLACE_STRING)*(found_sets+1)+
6769
sizeof(char *)*count+result_len)))
6771
memset(replace, 0, sizeof(REPLACE)*(sets.count)+
6772
sizeof(REPLACE_STRING)*(found_sets+1)+
6773
sizeof(char *)*count+result_len);
6730
6774
rep_str=(REPLACE_STRING*) (replace+sets.count);
6731
6775
to_array= (char **) (rep_str+found_sets+1);
6732
6776
to_pos=(char *) (to_array+count);
6733
6777
for (i=0 ; i < count ; i++)
6735
6779
to_array[i]=to_pos;
6736
to_pos=my_stpcpy(to_pos,to[i])+1;
6780
to_pos=strcpy(to_pos,to[i])+strlen(to[i])+1;
6738
6782
rep_str[0].found=1;
6739
6783
rep_str[0].replace_string=0;
6862
6903
void copy_bits(REP_SET *to,REP_SET *from)
6864
6905
memcpy(to->bits,from->bits,
6865
(size_t) (sizeof(uint) * to->size_of_bits));
6906
(size_t) (sizeof(uint32_t) * to->size_of_bits));
6868
6909
int cmp_bits(REP_SET *set1,REP_SET *set2)
6870
return memcmp(set1->bits,set2->bits, sizeof(uint) * set1->size_of_bits);
6911
return memcmp(set1->bits,set2->bits, sizeof(uint32_t) * set1->size_of_bits);
6874
6915
/* Get next set bit from set. */
6876
int get_next_bit(REP_SET *set,uint lastpos)
6917
int get_next_bit(REP_SET *set,uint32_t lastpos)
6878
uint pos,*start,*end,bits;
6919
uint32_t pos,*start,*end,bits;
6880
6921
start=set->bits+ ((lastpos+1) / WORD_BIT);
6881
6922
end=set->bits + set->size_of_bits;