39
39
#define MTEST_VERSION "3.3"
41
42
#include "client_priv.h"
50
#ifdef HAVE_SYS_WAIT_H
55
#include <sys/types.h>
51
#include <mysys/hash.h>
60
52
#include <stdarg.h>
62
54
#include "errname.h"
64
/* Added this for string translation. */
65
#include "drizzled/gettext.h"
66
#include "drizzled/hash.h"
67
#include "drizzled/drizzle_time.h"
68
#include "drizzled/charset.h"
70
#ifndef DRIZZLE_RETURN_SERVER_GONE
71
#define DRIZZLE_RETURN_HANDSHAKE_FAILED DRIZZLE_RETURN_ERROR_CODE
74
56
using namespace std;
75
using namespace drizzled;
78
unsigned char *get_var_key(const unsigned char* var, size_t *len, bool);
80
int get_one_option(int optid, const struct option *, char *argument);
82
58
#define MAX_VAR_NAME_LENGTH 256
83
59
#define MAX_COLUMNS 256
60
#define MAX_EMBEDDED_SERVER_ARGS 64
84
61
#define MAX_DELIMITER_LENGTH 16
85
62
/* Flags controlling send and reap */
86
63
#define QUERY_SEND_FLAG 1
87
64
#define QUERY_REAP_FLAG 2
89
ErrorCodes global_error_names;
92
67
OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
93
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES,
68
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES
97
71
static int record= 0, opt_sleep= -1;
98
static char *opt_db= NULL, *opt_pass= NULL;
99
const char *opt_user= NULL, *opt_host= NULL, *unix_sock= NULL,
72
static char *opt_db= 0, *opt_pass= 0;
73
const char *opt_user= 0, *opt_host= 0, *unix_sock= 0, *opt_basedir= "./";
101
74
const char *opt_logdir= "";
102
const char *opt_include= NULL, *opt_charsets_dir;
103
const char *opt_testdir= NULL;
104
static uint32_t opt_port= 0;
75
const char *opt_include= 0, *opt_charsets_dir;
76
static int opt_port= 0;
105
77
static int opt_max_connect_retries;
106
static bool silent= false, verbose= false;
107
static bool tty_password= false;
108
static bool opt_mark_progress= false;
109
static bool parsing_disabled= false;
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;
110
83
static bool display_result_vertically= false,
111
84
display_metadata= false, display_result_sorted= false;
112
static bool disable_query_log= false, disable_result_log= false;
113
static bool disable_warnings= false;
114
static bool disable_info= true;
115
static bool abort_on_error= true;
116
static bool server_initialized= false;
117
static bool is_windows= false;
118
static bool opt_mysql= 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;
119
91
static char **default_argv;
120
92
static const char *load_default_groups[]= { "drizzletest", "client", 0 };
121
93
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
123
static uint32_t start_lineno= 0; /* Start line of current command */
95
static uint start_lineno= 0; /* Start line of current command */
96
static uint my_end_arg= 0;
125
98
/* Number of lines of the result to include in failure report */
126
static uint32_t opt_tail_lines= 0;
99
static uint opt_tail_lines= 0;
128
101
static char delimiter[MAX_DELIMITER_LENGTH]= ";";
129
static uint32_t delimiter_length= 1;
102
static uint delimiter_length= 1;
131
104
static char TMPDIR[FN_REFLEN];
430
388
VAR* var_from_env(const char *, const char *);
431
389
VAR* var_init(VAR* v, const char *name, int name_len, const char *val,
433
void var_free(pair<string, VAR*> v);
391
void var_free(void* v);
434
392
VAR* var_get(const char *var_name, const char** var_name_end,
435
393
bool raw, bool ignore_not_existing);
436
394
void eval_expr(VAR* v, const char *p, const char** p_end);
437
bool match_delimiter(int c, const char *delim, uint32_t length);
395
bool match_delimiter(int c, const char *delim, uint length);
438
396
void dump_result_to_reject_file(char *buf, int size);
439
397
void dump_result_to_log_file(const char *buf, int size);
440
398
void dump_warning_messages(void);
597
static void show_query(drizzle_con_st *con, const char* query)
557
static void show_query(DRIZZLE *drizzle, const char* query)
599
drizzle_result_st res;
600
drizzle_return_t ret;
605
if (drizzle_query_str(con, &res, query, &ret) == NULL ||
606
ret != DRIZZLE_RETURN_OK)
565
if (drizzle_query(drizzle, query))
608
if (ret == DRIZZLE_RETURN_ERROR_CODE)
610
log_msg("Error running query '%s': %d %s",
611
query, drizzle_result_error_code(&res),
612
drizzle_result_error(&res));
613
drizzle_result_free(&res);
617
log_msg("Error running query '%s': %d %s",
618
query, ret, drizzle_con_error(con));
567
log_msg("Error running query '%s': %d %s",
568
query, drizzle_errno(drizzle), drizzle_error(drizzle));
623
if (drizzle_result_column_count(&res) == 0 ||
624
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
572
if ((res= drizzle_store_result(drizzle)) == NULL)
626
574
/* No result set returned */
627
drizzle_result_free(&res);
634
581
unsigned int row_num= 0;
635
unsigned int num_fields= drizzle_result_column_count(&res);
636
drizzle_column_st *column;
582
unsigned int num_fields= drizzle_num_fields(res);
583
const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
638
585
fprintf(stderr, "=== %s ===\n", query);
639
while ((row= drizzle_row_next(&res)))
586
while ((row= drizzle_fetch_row(res)))
641
size_t *lengths= drizzle_row_field_sizes(&res);
588
uint32_t *lengths= drizzle_fetch_lengths(res);
644
591
fprintf(stderr, "---- %d. ----\n", row_num);
645
drizzle_column_seek(&res, 0);
646
592
for(i= 0; i < num_fields; i++)
648
column= drizzle_column_next(&res);
649
594
fprintf(stderr, "%s\t%.*s\n",
650
drizzle_column_name(column),
651
596
(int)lengths[i], row[i] ? row[i] : "NULL");
677
static void show_warnings_before_error(drizzle_con_st *con)
622
static void show_warnings_before_error(DRIZZLE *drizzle)
679
drizzle_result_st res;
680
drizzle_return_t ret;
681
625
const char* query= "SHOW WARNINGS";
686
if (drizzle_query_str(con, &res, query, &ret) == NULL ||
687
ret != DRIZZLE_RETURN_OK)
631
if (drizzle_query(drizzle, query))
689
if (ret == DRIZZLE_RETURN_ERROR_CODE)
691
log_msg("Error running query '%s': %d %s",
692
query, drizzle_result_error_code(&res),
693
drizzle_result_error(&res));
694
drizzle_result_free(&res);
698
log_msg("Error running query '%s': %d %s",
699
query, ret, drizzle_con_error(con));
633
log_msg("Error running query '%s': %d %s",
634
query, drizzle_errno(drizzle), drizzle_error(drizzle));
704
if (drizzle_result_column_count(&res) == 0 ||
705
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
638
if ((res= drizzle_store_result(drizzle)) == NULL)
707
640
/* No result set returned */
708
drizzle_result_free(&res);
712
if (drizzle_result_row_count(&res) <= 1)
644
if (drizzle_num_rows(res) <= 1)
714
646
/* Don't display the last row, it's "last error" */
719
651
unsigned int row_num= 0;
720
unsigned int num_fields= drizzle_result_column_count(&res);
652
unsigned int num_fields= drizzle_num_fields(res);
722
654
fprintf(stderr, "\nWarnings from just before the error:\n");
723
while ((row= drizzle_row_next(&res)))
655
while ((row= drizzle_fetch_row(res)))
726
size_t *lengths= drizzle_row_field_sizes(&res);
658
uint32_t *lengths= drizzle_fetch_lengths(res);
728
if (++row_num >= drizzle_result_row_count(&res))
660
if (++row_num >= drizzle_num_rows(res))
730
662
/* Don't display the last row, it's "last error" */
1345
static int compare_files2(int fd, const char* filename2)
1281
static int compare_files2(File fd, const char* filename2)
1347
1283
int error= RESULT_OK;
1350
1286
char buff[512], buff2[512];
1351
const char *fname= filename2;
1354
if ((fd2= internal::my_open(fname, O_RDONLY, MYF(0))) < 0)
1288
if ((fd2= my_open(filename2, O_RDONLY, MYF(0))) < 0)
1356
internal::my_close(fd, MYF(0));
1357
if (opt_testdir != NULL)
1359
tmpfile= opt_testdir;
1360
if (tmpfile[tmpfile.length()] != '/')
1361
tmpfile.append("/");
1362
tmpfile.append(filename2);
1363
fname= tmpfile.c_str();
1365
if ((fd2= internal::my_open(fname, O_RDONLY, MYF(0))) < 0)
1367
internal::my_close(fd, MYF(0));
1369
die("Failed to open second file: '%s'", fname);
1290
my_close(fd, MYF(0));
1291
die("Failed to open second file: '%s'", filename2);
1372
while((len= internal::my_read(fd, (unsigned char*)&buff,
1293
while((len= my_read(fd, (unsigned char*)&buff,
1373
1294
sizeof(buff), MYF(0))) > 0)
1375
if ((len2= internal::my_read(fd2, (unsigned char*)&buff2,
1296
if ((len2= my_read(fd2, (unsigned char*)&buff2,
1376
1297
sizeof(buff2), MYF(0))) < len)
1378
1299
/* File 2 was smaller */
1449
1370
static int string_cmp(string* ds, const char *fname)
1453
1374
char temp_file_path[FN_REFLEN];
1455
if ((fd= internal::create_temp_file(temp_file_path, NULL,
1456
"tmp", MYF(MY_WME))) < 0)
1376
if ((fd= create_temp_file(temp_file_path, NULL,
1377
"tmp", O_CREAT | O_RDWR,
1457
1379
die("Failed to create temporary file for ds");
1459
1381
/* Write ds to temporary file and set file pos to beginning*/
1460
if (internal::my_write(fd, (unsigned char *) ds->c_str(), ds->length(),
1382
if (my_write(fd, (unsigned char *) ds->c_str(), ds->length(),
1461
1383
MYF(MY_FNABP | MY_WME)) ||
1462
lseek(fd, 0, SEEK_SET) == MY_FILEPOS_ERROR)
1384
my_seek(fd, 0, SEEK_SET, MYF(0)) == MY_FILEPOS_ERROR)
1464
internal::my_close(fd, MYF(0));
1386
my_close(fd, MYF(0));
1465
1387
/* Remove the temporary file */
1466
internal::my_delete(temp_file_path, MYF(0));
1388
my_delete(temp_file_path, MYF(0));
1467
1389
die("Failed to write file '%s'", temp_file_path);
1470
1392
error= compare_files2(fd, fname);
1472
internal::my_close(fd, MYF(0));
1394
my_close(fd, MYF(0));
1473
1395
/* Remove the temporary file */
1474
internal::my_delete(temp_file_path, MYF(0));
1396
my_delete(temp_file_path, MYF(0));
1514
1436
char reject_file[FN_REFLEN];
1515
1437
size_t reject_length;
1516
internal::dirname_part(reject_file, result_file_name, &reject_length);
1438
dirname_part(reject_file, result_file_name, &reject_length);
1518
1440
if (access(reject_file, W_OK) == 0)
1520
1442
/* Result file directory is writable, save reject file there */
1521
internal::fn_format(reject_file, result_file_name, NULL,
1443
fn_format(reject_file, result_file_name, NULL,
1522
1444
".reject", MY_REPLACE_EXT);
1526
1448
/* Put reject file in opt_logdir */
1527
internal::fn_format(reject_file, result_file_name, opt_logdir,
1449
fn_format(reject_file, result_file_name, opt_logdir,
1528
1450
".reject", MY_REPLACE_DIR | MY_REPLACE_EXT);
1530
1452
str_to_file(reject_file, ds->c_str(), ds->length());
1878
1798
/* Eval the query, thus replacing all environment variables */
1879
1799
do_eval(&ds_query, query, end, false);
1881
if (drizzle_query(con, &res, ds_query.c_str(), ds_query.length(),
1883
ret != DRIZZLE_RETURN_OK)
1885
if (ret == DRIZZLE_RETURN_ERROR_CODE)
1887
die("Error running query '%s': %d %s", ds_query.c_str(),
1888
drizzle_result_error_code(&res), drizzle_result_error(&res));
1889
drizzle_result_free(&res);
1893
die("Error running query '%s': %d %s", ds_query.c_str(), ret,
1894
drizzle_con_error(con));
1897
if (drizzle_result_column_count(&res) == 0 ||
1898
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
1801
if (drizzle_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1802
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)))
1899
1805
die("Query '%s' didn't return a result set", ds_query.c_str());
1901
if ((row= drizzle_row_next(&res)) && row[0])
1807
if ((row= drizzle_fetch_row(res)) && row[0])
1904
1810
Concatenate all fields in the first row with tab in between
1987
1889
char * unstripped_query= strdup(ds_query.c_str());
1988
1890
if (strip_surrounding(unstripped_query, '"', '"'))
1989
1891
die("Mismatched \"'s around query '%s'", ds_query.c_str());
1991
ds_query.append(unstripped_query);
1892
ds_query= unstripped_query;
1993
1894
/* Run the query */
1994
if (drizzle_query(con, &res, ds_query.c_str(), ds_query.length(),
1996
ret != DRIZZLE_RETURN_OK)
1998
if (ret == DRIZZLE_RETURN_ERROR_CODE)
2000
die("Error running query '%s': %d %s", ds_query.c_str(),
2001
drizzle_result_error_code(&res), drizzle_result_error(&res));
2002
drizzle_result_free(&res);
2006
die("Error running query '%s': %d %s", ds_query.c_str(), ret,
2007
drizzle_con_error(con));
2010
if (drizzle_result_column_count(&res) == 0 ||
2011
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
1895
if (drizzle_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1896
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)))
2012
1899
die("Query '%s' didn't return a result set", ds_query.c_str());
2015
1902
/* Find column number from the given column name */
2017
uint32_t num_fields= drizzle_result_column_count(&res);
2018
drizzle_column_st *column;
1904
uint num_fields= drizzle_num_fields(res);
1905
const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
2020
1907
for (i= 0; i < num_fields; i++)
2022
column= drizzle_column_next(&res);
2023
if (strcmp(drizzle_column_name(column), ds_col.c_str()) == 0 &&
2024
strlen(drizzle_column_name(column)) == ds_col.length())
1909
if (strcmp(fields[i].name, ds_col.c_str()) == 0 &&
1910
strlen(fields[i].name) == ds_col.length())
2146
2032
char buff[FN_REFLEN];
2148
if (!internal::test_if_hard_path(name))
2034
if (!test_if_hard_path(name))
2150
snprintf(buff, sizeof(buff), "%s%s",opt_basedir,name);
2036
strxmov(buff, opt_basedir, name, NULL);
2153
internal::fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
2039
fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
2155
2041
if (cur_file == file_stack_end)
2156
2042
die("Source directives are nesting too deep");
2158
if (!(cur_file->file= fopen(buff, "r")))
2044
if (!(cur_file->file = my_fopen(buff, O_RDONLY, MYF(0))))
2161
2047
die("Could not open '%s' for reading", buff);
2163
if (!(cur_file->file_name= strdup(buff)))
2164
die("Out of memory");
2049
cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
2165
2050
cur_file->lineno=1;
2944
static void do_change_user(struct st_command *)
2817
static void do_change_user(struct st_command *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));
3063
do_wait_for_slave_to_stop(struct st_command *)
2968
do_wait_for_slave_to_stop(struct st_command *c __attribute__((unused)))
3065
2970
static int SLAVE_POLL_INTERVAL= 300000;
3066
drizzle_con_st *con= &cur_con->con;
2971
DRIZZLE *drizzle= &cur_con->drizzle;
3069
drizzle_result_st res;
3070
drizzle_return_t ret;
2974
DRIZZLE_RES *res= NULL;
3074
if (drizzle_query_str(con,&res,"show status like 'Slave_running'",
3075
&ret) == NULL || ret != DRIZZLE_RETURN_OK)
3077
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3079
die("Query failed while probing slave for stop: %s",
3080
drizzle_result_error(&res));
3081
drizzle_result_free(&res);
3085
die("Query failed while probing slave for stop: %s",
3086
drizzle_con_error(con));
3090
if (drizzle_result_column_count(&res) == 0 ||
3091
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
2978
if (drizzle_query(drizzle,"show status like 'Slave_running'") ||
2979
!(res=drizzle_store_result(drizzle)))
3093
2980
die("Query failed while probing slave for stop: %s",
3094
drizzle_con_error(con));
3097
if (!(row=drizzle_row_next(&res)) || !row[1])
2981
drizzle_error(drizzle));
2982
if (!(row=drizzle_fetch_row(res)) || !row[1])
3099
drizzle_result_free(&res);
2984
drizzle_free_result(res);
3100
2985
die("Strange result from query while probing slave for stop");
3102
2987
done = !strcmp(row[1],"OFF");
3103
drizzle_result_free(&res);
2988
drizzle_free_result(res);
3106
usleep(SLAVE_POLL_INTERVAL);
2991
my_sleep(SLAVE_POLL_INTERVAL);
3112
2997
static void do_sync_with_master2(long offset)
3114
drizzle_result_st res;
3115
drizzle_return_t ret;
3117
drizzle_con_st *con= &cur_con->con;
3001
DRIZZLE *drizzle= &cur_con->drizzle;
3118
3002
char query_buf[FN_REFLEN+128];
3121
3005
if (!master_pos.file[0])
3122
3006
die("Calling 'sync_with_master' without calling 'save_master_pos'");
3124
snprintf(query_buf, sizeof(query_buf), "select master_pos_wait('%s', %ld)", master_pos.file,
3008
sprintf(query_buf, "select master_pos_wait('%s', %ld)", master_pos.file,
3125
3009
master_pos.pos + offset);
3127
3011
wait_for_position:
3129
if (drizzle_query_str(con, &res, query_buf, &ret) == NULL ||
3130
ret != DRIZZLE_RETURN_OK)
3132
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3134
die("failed in '%s': %d: %s", query_buf, drizzle_result_error_code(&res),
3135
drizzle_result_error(&res));
3136
drizzle_result_free(&res);
3139
die("failed in '%s': %d: %s", query_buf, ret, drizzle_con_error(con));
3142
if (drizzle_result_column_count(&res) == 0 ||
3143
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3144
die("drizzle_result_buffer() returned NULL for '%s'", query_buf);
3146
if (!(row= drizzle_row_next(&res)))
3148
drizzle_result_free(&res);
3013
if (drizzle_query(drizzle, query_buf))
3014
die("failed in '%s': %d: %s", query_buf, drizzle_errno(drizzle),
3015
drizzle_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)))
3021
drizzle_free_result(res);
3149
3022
die("empty result in %s", query_buf);
3195
3068
static int do_save_master_pos(void)
3197
drizzle_result_st res;
3198
drizzle_return_t ret;
3200
drizzle_con_st *con= &cur_con->con;
3072
DRIZZLE *drizzle= &cur_con->drizzle;
3201
3073
const char *query;
3204
if (drizzle_query_str(con, &res, query= "show master status", &ret) == NULL ||
3205
ret != DRIZZLE_RETURN_OK)
3207
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3209
die("failed in '%s': %d: %s", query, drizzle_result_error_code(&res),
3210
drizzle_result_error(&res));
3211
drizzle_result_free(&res);
3214
die("failed in '%s': %d: %s", query, ret, drizzle_con_error(con));
3076
if (drizzle_query(drizzle, query= "show master status"))
3077
die("failed in 'show master status': %d %s",
3078
drizzle_errno(drizzle), drizzle_error(drizzle));
3217
if (drizzle_result_column_count(&res) == 0 ||
3218
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3219
die("drizzleclient_store_result() retuned NULL for '%s'", query);
3220
if (!(row = drizzle_row_next(&res)))
3080
if (!(res = drizzle_store_result(drizzle)))
3081
die("drizzle_store_result() retuned NULL for '%s'", query);
3082
if (!(row = drizzle_fetch_row(res)))
3221
3083
die("empty result in show master status");
3222
strncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3084
my_stpncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3223
3085
master_pos.pos = strtoul(row[1], (char**) 0, 10);
3224
drizzle_result_free(&res);
3086
drizzle_free_result(res);
3374
3229
command->last_argument= p;
3375
charset_info= get_charset_by_csname(charset_name, MY_CS_PRIMARY);
3230
charset_info= get_charset_by_csname(charset_name,MY_CS_PRIMARY,MYF(MY_WME));
3376
3231
if (!charset_info)
3377
3232
abort_not_supported_test("Test requires charset '%s'", charset_name);
3380
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3235
static uint get_errcode_from_name(char *error_name, char *error_end)
3382
size_t err_name_len= error_end - error_name;
3383
string error_name_s(error_name, err_name_len);
3385
uint32_t code= global_error_names.getErrorCode(error_name_s);
3388
die("Unknown SQL error name '%s'", error_name_s.c_str());
3237
/* SQL error as string */
3238
st_error *e= global_error_names;
3240
/* Loop through the array of known error names */
3241
for (; e->name; e++)
3244
If we get a match, we need to check the length of the name we
3245
matched against in case it was longer than what we are checking
3246
(as in ER_WRONG_VALUE vs. ER_WRONG_VALUE_COUNT).
3248
if (!strncmp(error_name, e->name, (int) (error_end - error_name)) &&
3249
(uint) strlen(e->name) == (uint) (error_end - error_name))
3255
die("Unknown SQL error name '%s'", error_name);
3393
3259
static void do_get_errcodes(struct st_command *command)
3395
3261
struct st_match_err *to= saved_expected_errors.err;
3396
3262
char *p= command->first_argument;
3687
static void safe_connect(drizzle_con_st *con, const char *name,
3688
const char *host, const char *user, const char *pass,
3689
const char *db, int port)
3559
static void safe_connect(DRIZZLE *drizzle, const char *name, const char *host,
3560
const char *user, const char *pass, const char *db,
3691
3563
int failed_attempts= 0;
3692
3564
static uint32_t connection_retry_sleep= 100000; /* Microseconds */
3693
drizzle_return_t ret;
3695
drizzle_con_set_tcp(con, host, port);
3696
drizzle_con_set_auth(con, user, pass);
3697
drizzle_con_set_db(con, db);
3698
while((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
3567
while(!drizzle_connect(drizzle, host, user, pass, db, port, NULL,
3568
CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS))
3705
3575
on protocol/connection type
3708
if ((ret == DRIZZLE_RETURN_GETADDRINFO ||
3709
ret == DRIZZLE_RETURN_COULD_NOT_CONNECT) &&
3578
if ((drizzle_errno(drizzle) == CR_CONN_HOST_ERROR ||
3579
drizzle_errno(drizzle) == CR_CONNECTION_ERROR) &&
3710
3580
failed_attempts < opt_max_connect_retries)
3712
3582
verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts,
3713
opt_max_connect_retries, ret, drizzle_con_error(con));
3714
usleep(connection_retry_sleep);
3583
opt_max_connect_retries, drizzle_errno(drizzle),
3584
drizzle_error(drizzle));
3585
my_sleep(connection_retry_sleep);
3718
3589
if (failed_attempts > 0)
3719
3590
die("Could not open connection '%s' after %d attempts: %d %s", name,
3720
failed_attempts, ret, drizzle_con_error(con));
3591
failed_attempts, drizzle_errno(drizzle), drizzle_error(drizzle));
3722
die("Could not open connection '%s': %d %s", name, ret,
3723
drizzle_con_error(con));
3593
die("Could not open connection '%s': %d %s", name,
3594
drizzle_errno(drizzle), drizzle_error(drizzle));
3725
3596
failed_attempts++;
3783
3653
ds_res.append(delimiter);
3784
3654
ds_res.append("\n");
3786
drizzle_con_set_tcp(con, host, port);
3787
drizzle_con_set_auth(con, user, pass);
3788
drizzle_con_set_db(con, db);
3789
if ((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
3656
if (!drizzle_connect(con, host, user, pass, db, port, 0,
3657
CLIENT_MULTI_STATEMENTS))
3791
if (ret == DRIZZLE_RETURN_HANDSHAKE_FAILED)
3793
var_set_errno(drizzle_con_error_code(con));
3794
handle_error(command, drizzle_con_error_code(con), drizzle_con_error(con),
3795
drizzle_con_sqlstate(con), &ds_res);
3800
handle_error(command, ret, drizzle_con_error(con), "", &ds_res);
3659
var_set_errno(drizzle_errno(con));
3660
handle_error(command, drizzle_errno(con), drizzle_error(con),
3661
drizzle_sqlstate(con), &ds_res);
3803
3662
return 0; /* Not connected */
3927
3785
(int) (sizeof(connections)/sizeof(struct st_connection)));
3930
if ((con_slot->drizzle= drizzle_create(NULL)) == NULL)
3788
if (!drizzle_create(&con_slot->drizzle))
3931
3789
die("Failed on drizzle_create()");
3932
if (!drizzle_con_create(con_slot->drizzle, &con_slot->con))
3933
die("Failed on drizzle_con_create()");
3935
drizzle_con_add_options(&con_slot->con, DRIZZLE_CON_MYSQL);
3790
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);
3937
3794
/* Use default db name */
3938
3795
if (ds_database.length() == 0)
3939
ds_database.append(opt_db);
3796
ds_database= opt_db;
3941
3798
/* Special database to allow one to connect without a database name */
3942
3799
if (ds_database.length() && !strcmp(ds_database.c_str(),"*NO-ONE*"))
3943
ds_database.clear();
3945
if (connect_n_handle_errors(command, &con_slot->con,
3802
if (connect_n_handle_errors(command, &con_slot->drizzle,
3946
3803
ds_host.c_str(),ds_user.c_str(),
3947
3804
ds_password.c_str(), ds_database.c_str(),
3948
3805
con_port, ds_sock.c_str()))
4587
4425
{"character-sets-dir", OPT_CHARSETS_DIR,
4588
4426
"Directory where character sets are.", (char**) &opt_charsets_dir,
4589
4427
(char**) &opt_charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4428
{"compress", 'C', "Use the compressed server/client protocol.",
4429
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
4590
4431
{"database", 'D', "Database to use.", (char**) &opt_db, (char**) &opt_db, 0,
4591
4432
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4433
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
4434
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
4435
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4436
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
4437
(char**) &debug_info_flag, (char**) &debug_info_flag,
4438
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4592
4439
{"host", 'h', "Connect to host.", (char**) &opt_host, (char**) &opt_host, 0,
4593
4440
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4594
4441
{"include", 'i', "Include SQL before each test case.", (char**) &opt_include,
4595
4442
(char**) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4596
{"testdir", OPT_TESTDIR, "Path to use to search for test files",
4597
(char**) &opt_testdir,
4598
(char**) &opt_testdir, 0,GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4599
4443
{"logdir", OPT_LOG_DIR, "Directory for log files", (char**) &opt_logdir,
4600
4444
(char**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4601
4445
{"mark-progress", OPT_MARK_PROGRESS,
4606
4450
"Max number of connection attempts when connecting to server",
4607
4451
(char**) &opt_max_connect_retries, (char**) &opt_max_connect_retries, 0,
4608
4452
GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0},
4609
{"mysql", 'm', N_("Use MySQL Protocol."),
4610
(char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
4612
{"password", 'P', "Password to use when connecting to server.",
4453
{"password", 'p', "Password to use when connecting to server.",
4613
4454
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
4614
{"port", 'p', "Port number to use for connection or 0 for default to, in "
4455
{"port", 'P', "Port number to use for connection or 0 for default to, in "
4615
4456
"order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
4616
4457
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
4617
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4459
(char**) &opt_port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4618
4460
{"quiet", 's', "Suppress all normal output.", (char**) &silent,
4619
4461
(char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4620
4462
{"record", 'r', "Record output of test_file into result file.",
4622
4464
{"result-file", 'R', "Read/Store result from/in this file.",
4623
4465
(char**) &result_file_name, (char**) &result_file_name, 0,
4624
4466
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4467
{"server-arg", 'A', "Send option value to embedded server as a parameter.",
4468
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4469
{"server-file", 'F', "Read embedded server arguments from file.",
4470
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4625
4471
{"silent", 's', "Suppress all normal output. Synonym for --quiet.",
4626
4472
(char**) &silent, (char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4627
4473
{"sleep", 'T', "Sleep always this many seconds on sleep commands.",
4650
4496
static void print_version(void)
4652
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
4653
drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
4498
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4499
drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
4656
4502
static void usage(void)
4658
4504
print_version();
4659
4505
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
4660
printf("Drizzle version modified by Brian, Jay, Monty Taylor, PatG and Stewart\n");
4661
4506
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
4662
4507
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4663
printf("Usage: %s [OPTIONS] [database] < test_file\n", internal::my_progname);
4508
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4664
4509
my_print_help(my_long_options);
4665
4510
printf(" --no-defaults Don't read default options from any options file.\n");
4666
4511
my_print_variables(my_long_options);
4669
int get_one_option(int optid, const struct option *, char *argument)
4671
char *endchar= NULL;
4672
uint64_t temp_drizzle_port= 0;
4515
Read arguments for embedded server and put them into
4516
embedded_server_args[]
4519
static void read_embedded_server_arguments(const char *name)
4521
char argument[1024],buff[FN_REFLEN], *str=0;
4524
if (!test_if_hard_path(name))
4526
strxmov(buff, opt_basedir, name, NULL);
4529
fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
4531
if (!embedded_server_arg_count)
4533
embedded_server_arg_count=1;
4534
embedded_server_args[0]= (char*) ""; /* Progname */
4536
if (!(file=my_fopen(buff, O_RDONLY, MYF(MY_WME))))
4537
die("Failed to open file '%s'", buff);
4539
while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4540
(str=fgets(argument,sizeof(argument), file)))
4542
*(strchr(str, '\0')-1)=0; /* Remove end newline */
4543
if (!(embedded_server_args[embedded_server_arg_count]=
4544
(char*) my_strdup(str,MYF(MY_WME))))
4546
my_fclose(file,MYF(0));
4547
die("Out of memory");
4550
embedded_server_arg_count++;
4552
my_fclose(file,MYF(0));
4554
die("Too many arguments in option file: %s",name);
4561
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
4674
4564
switch(optid) {
4680
4570
char buff[FN_REFLEN];
4681
if (!internal::test_if_hard_path(argument))
4571
if (!test_if_hard_path(argument))
4683
snprintf(buff, sizeof(buff), "%s%s",opt_basedir,argument);
4573
strxmov(buff, opt_basedir, argument, NULL);
4684
4574
argument= buff;
4686
internal::fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4576
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4687
4577
assert(cur_file == file_stack && cur_file->file == 0);
4688
if (!(cur_file->file= fopen(buff, "r")))
4690
fprintf(stderr, _("Could not open '%s' for reading: errno = %d"), buff, errno);
4691
return EXIT_ARGUMENT_INVALID;
4693
if (!(cur_file->file_name= strdup(buff)))
4695
fprintf(stderr, _("Out of memory"));
4696
return EXIT_OUT_OF_MEMORY;
4578
if (!(cur_file->file=
4579
my_fopen(buff, O_RDONLY, MYF(0))))
4580
die("Could not open '%s' for reading: errno = %d", buff, errno);
4581
cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
4698
4582
cur_file->lineno= 1;
4703
4587
static char buff[FN_REFLEN];
4704
if (!internal::test_if_hard_path(argument))
4588
if (!test_if_hard_path(argument))
4706
snprintf(buff, sizeof(buff), "%s%s",opt_basedir,argument);
4590
strxmov(buff, opt_basedir, argument, NULL);
4707
4591
argument= buff;
4709
internal::fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4593
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4710
4594
timer_file= buff;
4711
4595
unlink(timer_file); /* Ignore error, may not exist */
4715
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
4716
/* if there is an alpha character this is not a valid port */
4717
if (strlen(endchar) != 0)
4719
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
4720
return EXIT_ARGUMENT_INVALID;
4722
/* If the port number is > 65535 it is not a valid port
4723
This also helps with potential data loss casting unsigned long to a
4725
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
4727
fprintf(stderr, _("Value supplied for port is not valid.\n"));
4728
return EXIT_ARGUMENT_INVALID;
4732
opt_port= (uint32_t) temp_drizzle_port;
4740
opt_pass = strdup(argument);
4741
if (opt_pass == NULL)
4743
fprintf(stderr, _("Out of memory"));
4744
return EXIT_OUT_OF_MEMORY;
4748
/* Overwriting password with 'x' */
4602
opt_pass= my_strdup(argument, MYF(MY_FAE));
4603
while (*argument) *argument++= 'x'; /* Destroy argument */
4751
4604
tty_password= 0;
4754
4607
tty_password= 1;
4757
strncpy(TMPDIR, argument, sizeof(TMPDIR));
4610
my_stpncpy(TMPDIR, argument, sizeof(TMPDIR));
4613
if (!embedded_server_arg_count)
4615
embedded_server_arg_count=1;
4616
embedded_server_args[0]= (char*) "";
4618
if (embedded_server_arg_count == MAX_EMBEDDED_SERVER_ARGS-1 ||
4619
!(embedded_server_args[embedded_server_arg_count++]=
4620
my_strdup(argument, MYF(MY_FAE))))
4622
die("Can't use server argument");
4626
read_embedded_server_arguments(argument);
4760
4629
print_version();
4805
4678
char buff[FN_REFLEN];
4806
4679
int flags= O_WRONLY | O_CREAT;
4807
if (!internal::test_if_hard_path(fname))
4680
if (!test_if_hard_path(fname))
4809
snprintf(buff, sizeof(buff), "%s%s",opt_basedir,fname);
4682
strxmov(buff, opt_basedir, fname, NULL);
4812
internal::fn_format(buff, fname, "", "", MY_UNPACK_FILENAME);
4685
fn_format(buff, fname, "", "", MY_UNPACK_FILENAME);
4815
4688
flags|= O_TRUNC;
4816
if ((fd= internal::my_open(buff, flags,
4689
if ((fd= my_open(buff, flags,
4817
4690
MYF(MY_WME | MY_FFNF))) < 0)
4818
4691
die("Could not open '%s' for writing: errno = %d", buff, errno);
4819
if (append && lseek(fd, 0, SEEK_END) == MY_FILEPOS_ERROR)
4692
if (append && my_seek(fd, 0, SEEK_END, MYF(0)) == MY_FILEPOS_ERROR)
4820
4693
die("Could not find end of file '%s': errno = %d", buff, errno);
4821
if (internal::my_write(fd, (unsigned char*)str, size, MYF(MY_WME|MY_FNABP)))
4694
if (my_write(fd, (unsigned char*)str, size, MYF(MY_WME|MY_FNABP)))
4822
4695
die("write failed");
4823
internal::my_close(fd, MYF(0));
4696
my_close(fd, MYF(0));
4910
4783
Values may be converted with 'replace_column'
4913
static void append_result(string *ds, drizzle_result_st *res)
4786
static void append_result(string *ds, DRIZZLE_RES *res)
4916
uint32_t num_fields= drizzle_result_column_count(res);
4917
drizzle_column_st *column;
4789
uint32_t num_fields= drizzle_num_fields(res);
4790
const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
4920
while ((row = drizzle_row_next(res)))
4793
while ((row = drizzle_fetch_row(res)))
4923
lengths = drizzle_row_field_sizes(res);
4924
drizzle_column_seek(res, 0);
4796
lengths = drizzle_fetch_lengths(res);
4925
4797
for (i = 0; i < num_fields; i++)
4927
column= drizzle_column_next(res);
4928
append_field(ds, i, column,
4798
append_field(ds, i, &fields[i],
4929
4799
(const char*)row[i], lengths[i], !row[i]);
4931
4800
if (!display_result_vertically)
4932
4801
ds->append("\n");
4939
4808
Append metadata for fields to output
4942
static void append_metadata(string *ds, drizzle_result_st *res)
4811
static void append_metadata(string *ds,
4812
const DRIZZLE_FIELD *field,
4944
drizzle_column_st *column;
4815
const DRIZZLE_FIELD *field_end;
4945
4816
ds->append("Catalog\tDatabase\tTable\tTable_alias\tColumn\t"
4946
4817
"Column_alias\tType\tLength\tMax length\tIs_null\t"
4947
4818
"Flags\tDecimals\tCharsetnr\n");
4949
drizzle_column_seek(res, 0);
4950
while ((column= drizzle_column_next(res)))
4820
for (field_end= field+num_fields ;
4952
ds->append(drizzle_column_catalog(column),
4953
strlen(drizzle_column_catalog(column)));
4954
ds->append("\t", 1);
4955
ds->append(drizzle_column_db(column), strlen(drizzle_column_db(column)));
4956
ds->append("\t", 1);
4957
ds->append(drizzle_column_orig_table(column),
4958
strlen(drizzle_column_orig_table(column)));
4959
ds->append("\t", 1);
4960
ds->append(drizzle_column_table(column),
4961
strlen(drizzle_column_table(column)));
4962
ds->append("\t", 1);
4963
ds->append(drizzle_column_orig_name(column),
4964
strlen(drizzle_column_orig_name(column)));
4965
ds->append("\t", 1);
4966
ds->append(drizzle_column_name(column),
4967
strlen(drizzle_column_name(column)));
4968
ds->append("\t", 1);
4969
replace_append_uint(ds, drizzle_column_type_drizzle(column));
4970
ds->append("\t", 1);
4971
replace_append_uint(ds, drizzle_column_size(column));
4972
ds->append("\t", 1);
4973
replace_append_uint(ds, drizzle_column_max_size(column));
4974
ds->append("\t", 1);
4975
ds->append((char*) ((drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_NOT_NULL) ? "N" : "Y"), 1);
4976
ds->append("\t", 1);
4977
replace_append_uint(ds, drizzle_column_flags(column));
4978
ds->append("\t", 1);
4979
replace_append_uint(ds, drizzle_column_decimals(column));
4980
ds->append("\t", 1);
4981
replace_append_uint(ds, drizzle_column_charset(column));
4824
ds->append(field->catalog,
4825
field->catalog_length);
4826
ds->append("\t", 1);
4827
ds->append(field->db, field->db_length);
4828
ds->append("\t", 1);
4829
ds->append(field->org_table,
4830
field->org_table_length);
4831
ds->append("\t", 1);
4832
ds->append(field->table,
4833
field->table_length);
4834
ds->append("\t", 1);
4835
ds->append(field->org_name,
4836
field->org_name_length);
4837
ds->append("\t", 1);
4838
ds->append(field->name, field->name_length);
4839
ds->append("\t", 1);
4840
replace_append_uint(ds, field->type);
4841
ds->append("\t", 1);
4842
replace_append_uint(ds, field->length);
4843
ds->append("\t", 1);
4844
replace_append_uint(ds, field->max_length);
4845
ds->append("\t", 1);
4846
ds->append((char*) ((field->flags & NOT_NULL_FLAG) ?
4848
ds->append("\t", 1);
4849
replace_append_uint(ds, field->flags);
4850
ds->append("\t", 1);
4851
replace_append_uint(ds, field->decimals);
4852
ds->append("\t", 1);
4853
replace_append_uint(ds, field->charsetnr);
4982
4854
ds->append("\n", 1);
5029
4900
Number of warnings appended to ds
5032
static int append_warnings(string *ds, drizzle_con_st *con,
5033
drizzle_result_st *res)
4903
static int append_warnings(string *ds, DRIZZLE *drizzle)
5036
drizzle_result_st warn_res;
5037
drizzle_return_t ret;
5040
if (!(count= drizzle_result_warning_count(res)))
4906
DRIZZLE_RES *warn_res;
4909
if (!(count= drizzle_warning_count(drizzle)))
5043
if (drizzle_query_str(con, &warn_res, "SHOW WARNINGS", &ret) == NULL ||
5044
ret != DRIZZLE_RETURN_OK)
5046
if (ret == DRIZZLE_RETURN_ERROR_CODE)
5047
die("Error running query \"SHOW WARNINGS\": %s", drizzle_result_error(&warn_res));
5049
die("Error running query \"SHOW WARNINGS\": %s", drizzle_con_error(con));
5052
if (drizzle_result_column_count(&warn_res) == 0 ||
5053
drizzle_result_buffer(&warn_res) != DRIZZLE_RETURN_OK)
5054
die("Warning count is %u but didn't get any warnings", count);
5056
append_result(ds, &warn_res);
5057
drizzle_result_free(&warn_res);
4913
If one day we will support execution of multi-statements
4914
through PS API we should not issue SHOW WARNINGS until
4915
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)))
4923
die("Warning count is %u but didn't get any warnings",
4926
append_result(ds, warn_res);
5078
4947
int flags, char *query, int query_len,
5079
4948
string *ds, string *ds_warnings)
5081
drizzle_result_st res;
5082
drizzle_return_t ret;
5083
drizzle_con_st *con= &cn->con;
5086
drizzle_con_add_options(con, DRIZZLE_CON_NO_RESULT_READ);
4950
DRIZZLE_RES *res= 0;
4951
DRIZZLE *drizzle= &cn->drizzle;
4952
int err= 0, counter= 0;
5088
4954
if (flags & QUERY_SEND_FLAG)
5091
4957
* Send the query
5094
(void) drizzle_query(con, &res, query, query_len, &ret);
5095
if (ret != DRIZZLE_RETURN_OK)
4959
if (do_send_query(cn, query, query_len, flags))
5097
if (ret == DRIZZLE_RETURN_ERROR_CODE ||
5098
ret == DRIZZLE_RETURN_HANDSHAKE_FAILED)
5100
err= drizzle_result_error_code(&res);
5101
handle_error(command, err, drizzle_result_error(&res),
5102
drizzle_result_sqlstate(&res), ds);
5103
if (ret == DRIZZLE_RETURN_ERROR_CODE)
5104
drizzle_result_free(&res);
5108
handle_error(command, ret, drizzle_con_error(con), "", ds);
4961
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4962
drizzle_sqlstate(drizzle), ds);
5114
4966
if (!(flags & QUERY_REAP_FLAG))
5119
* Read the result packet
5121
if (drizzle_result_read(con, &res, &ret) == NULL ||
5122
ret != DRIZZLE_RETURN_OK)
4972
When on first result set, call drizzle_read_query_result to retrieve
4973
answer to the query sent earlier
4975
if ((counter==0) && drizzle_read_query_result(drizzle))
5124
if (ret == DRIZZLE_RETURN_ERROR_CODE)
5126
handle_error(command, drizzle_result_error_code(&res),
5127
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
5131
handle_error(command, ret, drizzle_con_error(con), "", ds);
5132
drizzle_result_free(&res);
4977
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4978
drizzle_sqlstate(drizzle), ds);
5138
4984
Store the result of the query if it will return any fields
5140
if (drizzle_result_column_count(&res) &&
5141
(ret= drizzle_result_buffer(&res)) != DRIZZLE_RETURN_OK)
4986
if (drizzle_field_count(drizzle) && ((res= drizzle_store_result(drizzle)) == 0))
5143
if (ret == DRIZZLE_RETURN_ERROR_CODE)
5145
handle_error(command, drizzle_result_error_code(&res),
5146
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
5150
handle_error(command, ret, drizzle_con_error(con), "", ds);
5151
drizzle_result_free(&res);
4988
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4989
drizzle_sqlstate(drizzle), ds);
5158
4995
uint64_t affected_rows= 0; /* Ok to be undef if 'disable_info' is set */
5160
if (drizzle_result_column_count(&res))
4999
const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
5000
uint num_fields= drizzle_num_fields(res);
5162
5002
if (display_metadata)
5163
append_metadata(ds, &res);
5003
append_metadata(ds, fields, num_fields);
5165
5005
if (!display_result_vertically)
5166
append_table_headings(ds, &res);
5006
append_table_headings(ds, fields, num_fields);
5168
append_result(ds, &res);
5008
append_result(ds, res);
5172
Need to call drizzle_result_affected_rows() before the "new"
5012
Need to call drizzle_affected_rows() before the "new"
5173
5013
query to find the warnings
5175
5015
if (!disable_info)
5176
affected_rows= drizzle_result_affected_rows(&res);
5016
affected_rows= drizzle_affected_rows(drizzle);
5179
5019
Add all warnings to the result. We can't do this if we are in
5180
5020
the middle of processing results from multi-statement, because
5181
5021
this will break protocol.
5183
if (!disable_warnings)
5023
if (!disable_warnings && !drizzle_more_results(drizzle))
5185
drizzle_con_remove_options(con, DRIZZLE_CON_NO_RESULT_READ);
5186
if (append_warnings(ds_warnings, con, &res) || ds_warnings->length())
5025
if (append_warnings(ds_warnings, drizzle) || ds_warnings->length())
5188
5027
ds->append("Warnings:\n", 10);
5189
5028
ds->append(ds_warnings->c_str(), ds_warnings->length());
5542
static void mark_progress(struct st_command*, int line)
5394
static void mark_progress(struct st_command* command __attribute__((unused)),
5544
5398
uint64_t timer= timer_now();
5545
5399
if (!progress_start)
5546
5400
progress_start= timer;
5547
5401
timer-= progress_start;
5550
5403
/* Milliseconds since start */
5551
buf << timer << "\t";
5404
end= int64_t2str(timer, buf, 10);
5405
ds_progress.append(buf, (int)(end-buf));
5406
ds_progress.append("\t", 1);
5553
5408
/* Parser line number */
5554
buf << line << "\t";
5409
end= int10_to_str(line, buf, 10);
5410
ds_progress.append(buf, (int)(end-buf));
5411
ds_progress.append("\t", 1);
5557
buf << cur_file->file_name << ":";
5414
ds_progress.append(cur_file->file_name);
5415
ds_progress.append(":", 1);
5559
5417
/* Line in file */
5560
buf << cur_file->lineno << endl;
5562
ds_progress.append(buf.str());
5418
end= int10_to_str(cur_file->lineno, buf, 10);
5419
ds_progress.append(buf, (int)(end-buf));
5422
ds_progress.append("\n", 1);
5617
5482
if (cur_file == file_stack && cur_file->file == 0)
5619
5484
cur_file->file= stdin;
5620
cur_file->file_name= strdup("<stdin>");
5621
if (cur_file->file_name == NULL)
5622
die("Out of memory");
5485
cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
5623
5486
cur_file->lineno= 1;
5625
5488
cur_con= connections;
5626
if ((cur_con->drizzle= drizzle_create(NULL)) == NULL)
5489
if (!( drizzle_create(&cur_con->drizzle)))
5627
5490
die("Failed in drizzle_create()");
5628
if (!( drizzle_con_create(cur_con->drizzle, &cur_con->con)))
5629
die("Failed in drizzle_con_create()");
5631
drizzle_con_add_options(&cur_con->con, DRIZZLE_CON_MYSQL);
5492
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5493
drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5633
if (!(cur_con->name = strdup("default")))
5495
if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5634
5496
die("Out of memory");
5636
safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5498
safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5637
5499
opt_db, opt_port);
5639
5501
/* Use all time until exit if no explicit 'start_timer' */
5640
5502
timer_start= timer_now();
5643
Initialize $drizzleclient_errno with -1, so we can
5505
Initialize $drizzle_errno with -1, so we can
5644
5506
- distinguish it from valid values ( >= 0 ) and
5645
5507
- detect if there was never a command sent to the server
5647
5509
var_set_errno(-1);
5649
/* Update $drizzleclient_get_server_version to that of current connection */
5650
var_set_drizzleclient_get_server_version(&cur_con->con);
5511
/* Update $drizzle_get_server_version to that of current connection */
5512
var_set_drizzle_get_server_version(&cur_con->drizzle);
5652
5514
if (opt_include)
6132
5974
TYPELIB typelib; /* Pointer to strings */
6133
5975
unsigned char *str; /* Strings is here */
6134
5976
uint8_t *flag; /* Flag about each var. */
6135
uint32_t array_allocs,max_count,length,max_length;
5977
uint array_allocs,max_count,length,max_length;
6136
5978
} POINTER_ARRAY;
6138
5980
struct st_replace;
6139
struct st_replace *init_replace(char * *from, char * *to, uint32_t count,
5981
struct st_replace *init_replace(char * *from, char * *to, uint count,
6140
5982
char * word_end_chars);
6141
5983
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
6142
5984
void replace_strings_append(struct st_replace *rep, string* ds,
6143
5985
const char *from, int len);
6144
5986
void free_pointer_array(POINTER_ARRAY *pa);
6146
struct st_replace *glob_replace= NULL;
5988
struct st_replace *glob_replace;
6149
5991
Get arguments for replace. The syntax is:
6539
6369
icase - flag, if set to 1 the match is case insensitive
6541
6371
int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
6542
char *replace, char *in_string, int icase, int global)
6372
char *replace, char *in_string, int icase)
6544
const char *error= NULL;
6547
pcre *re= pcre_compile(pattern,
6548
icase ? PCRE_CASELESS | PCRE_MULTILINE : PCRE_MULTILINE,
6549
&error, &erroffset, NULL);
6556
int rc= pcre_exec(re, NULL, in_string, (int)strlen(in_string),
6564
char *substring_to_replace= in_string + ovector[0];
6565
int substring_length= ovector[1] - ovector[0];
6566
*buf_len_p= strlen(in_string) - substring_length + strlen(replace);
6567
char * new_buf = (char *)malloc(*buf_len_p+1);
6568
if (new_buf == NULL)
6574
memset(new_buf, 0, *buf_len_p+1);
6575
strncpy(new_buf, in_string, substring_to_replace-in_string);
6576
strncpy(new_buf+(substring_to_replace-in_string), replace, strlen(replace));
6577
strncpy(new_buf+(substring_to_replace-in_string)+strlen(replace),
6578
substring_to_replace + substring_length,
6581
- (substring_to_replace-in_string));
6589
/* Repeatedly replace the string with the matched regex */
6590
string subject(in_string);
6591
size_t replace_length= strlen(replace);
6592
size_t current_position= 0;
6594
while(0 >= (rc= pcre_exec(re, NULL, subject.c_str() + current_position, subject.length() - current_position,
6597
current_position= static_cast<size_t>(ovector[0]);
6598
replace_length= static_cast<size_t>(ovector[1] - ovector[0]);
6599
subject.replace(current_position, replace_length, replace, replace_length);
6602
char *new_buf = (char *) malloc(subject.length() + 1);
6603
if (new_buf == NULL)
6608
memset(new_buf, 0, subject.length() + 1);
6609
strncpy(new_buf, subject.c_str(), subject.length());
6610
*buf_len_p= subject.length() + 1;
6374
string string_to_match(in_string);
6375
pcrecpp::RE_Options opt;
6378
opt.set_caseless(true);
6380
if (!pcrecpp::RE(pattern, opt).Replace(replace,&string_to_match)){
6384
const char * new_str= string_to_match.c_str();
6385
*buf_len_p= strlen(new_str);
6386
char * new_buf = (char *)malloc(*buf_len_p+1);
6387
if (new_buf == NULL)
6391
strcpy(new_buf, new_str);
6619
6398
#ifndef WORD_BIT
6620
#define WORD_BIT (8*sizeof(uint32_t))
6399
#define WORD_BIT (8*sizeof(uint))
6623
6402
#define SET_MALLOC_HUNC 64
6624
6403
#define LAST_CHAR_CODE 259
6626
6405
typedef struct st_rep_set {
6627
uint32_t *bits; /* Pointer to used sets */
6406
uint *bits; /* Pointer to used sets */
6628
6407
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6629
uint32_t found_len; /* Best match to date */
6408
uint found_len; /* Best match to date */
6630
6409
int found_offset;
6631
uint32_t table_offset;
6632
uint32_t size_of_bits; /* For convinience */
6411
uint size_of_bits; /* For convinience */
6635
6414
typedef struct st_rep_sets {
6636
uint32_t count; /* Number of sets */
6637
uint32_t extra; /* Extra sets in buffer */
6638
uint32_t invisible; /* Sets not chown */
6639
uint32_t size_of_bits;
6415
uint count; /* Number of sets */
6416
uint extra; /* Extra sets in buffer */
6417
uint invisible; /* Sets not chown */
6640
6419
REP_SET *set,*set_buffer;
6641
uint32_t *bit_buffer;
6644
6423
typedef struct st_found_set {
6645
uint32_t table_offset;
6646
6425
int found_offset;
6649
6428
typedef struct st_follow {
6651
uint32_t table_offset;
6656
int init_sets(REP_SETS *sets,uint32_t states);
6435
int init_sets(REP_SETS *sets,uint states);
6657
6436
REP_SET *make_new_set(REP_SETS *sets);
6658
6437
void make_sets_invisible(REP_SETS *sets);
6659
6438
void free_last_set(REP_SETS *sets);
6660
6439
void free_sets(REP_SETS *sets);
6661
void internal_set_bit(REP_SET *set, uint32_t bit);
6662
void internal_clear_bit(REP_SET *set, uint32_t bit);
6440
void internal_set_bit(REP_SET *set, uint bit);
6441
void internal_clear_bit(REP_SET *set, uint bit);
6663
6442
void or_bits(REP_SET *to,REP_SET *from);
6664
6443
void copy_bits(REP_SET *to,REP_SET *from);
6665
6444
int cmp_bits(REP_SET *set1,REP_SET *set2);
6666
int get_next_bit(REP_SET *set,uint32_t lastpos);
6445
int get_next_bit(REP_SET *set,uint lastpos);
6667
6446
int find_set(REP_SETS *sets,REP_SET *find);
6668
int find_found(FOUND_SET *found_set,uint32_t table_offset,
6447
int find_found(FOUND_SET *found_set,uint table_offset,
6669
6448
int found_offset);
6670
uint32_t start_at_word(char * pos);
6671
uint32_t end_of_word(char * pos);
6673
static uint32_t found_sets=0;
6676
static uint32_t replace_len(char * str)
6449
uint start_at_word(char * pos);
6450
uint end_of_word(char * pos);
6452
static uint found_sets=0;
6455
static uint replace_len(char * str)
6681
6460
if (str[0] == '\\' && str[1])
6689
6468
/* Init a replace structure for further calls */
6691
REPLACE *init_replace(char * *from, char * *to,uint32_t count,
6470
REPLACE *init_replace(char * *from, char * *to,uint count,
6692
6471
char * word_end_chars)
6694
6473
static const int SPACE_CHAR= 256;
6695
6474
static const int START_OF_LINE= 257;
6696
6475
static const int END_OF_LINE= 258;
6698
uint32_t i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr;
6477
uint i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr;
6699
6478
int used_sets,chr,default_state;
6700
6479
char used_chars[LAST_CHAR_CODE],is_word_end[256];
6701
6480
char * pos, *to_pos, **to_array;
6932
6711
/* Alloc replace structure for the replace-state-machine */
6934
if ((replace=(REPLACE*) malloc(sizeof(REPLACE)*(sets.count)+
6935
sizeof(REPLACE_STRING)*(found_sets+1)+
6936
sizeof(char *)*count+result_len)))
6713
if ((replace=(REPLACE*) my_malloc(sizeof(REPLACE)*(sets.count)+
6714
sizeof(REPLACE_STRING)*(found_sets+1)+
6715
sizeof(char *)*count+result_len,
6716
MYF(MY_WME | MY_ZEROFILL))))
6938
memset(replace, 0, sizeof(REPLACE)*(sets.count)+
6939
sizeof(REPLACE_STRING)*(found_sets+1)+
6940
sizeof(char *)*count+result_len);
6941
6718
rep_str=(REPLACE_STRING*) (replace+sets.count);
6942
6719
to_array= (char **) (rep_str+found_sets+1);
6943
6720
to_pos=(char *) (to_array+count);
6944
6721
for (i=0 ; i < count ; i++)
6946
6723
to_array[i]=to_pos;
6947
to_pos=strcpy(to_pos,to[i])+strlen(to[i])+1;
6724
to_pos=my_stpcpy(to_pos,to[i])+1;
6949
6726
rep_str[0].found=1;
6950
6727
rep_str[0].replace_string=0;
7070
6850
void copy_bits(REP_SET *to,REP_SET *from)
7072
6852
memcpy(to->bits,from->bits,
7073
(size_t) (sizeof(uint32_t) * to->size_of_bits));
6853
(size_t) (sizeof(uint) * to->size_of_bits));
7076
6856
int cmp_bits(REP_SET *set1,REP_SET *set2)
7078
return memcmp(set1->bits,set2->bits, sizeof(uint32_t) * set1->size_of_bits);
6858
return memcmp(set1->bits,set2->bits, sizeof(uint) * set1->size_of_bits);
7082
6862
/* Get next set bit from set. */
7084
int get_next_bit(REP_SET *set,uint32_t lastpos)
6864
int get_next_bit(REP_SET *set,uint lastpos)
7086
uint32_t pos,*start,*end,bits;
6866
uint pos,*start,*end,bits;
7088
6868
start=set->bits+ ((lastpos+1) / WORD_BIT);
7089
6869
end=set->bits + set->size_of_bits;