187
179
struct st_connection
190
182
/* Used when creating views and sp, to avoid implicit commit */
183
DRIZZLE *util_drizzle;
194
186
struct st_connection connections[128];
195
187
struct st_connection* cur_con= NULL, *next_con, *connections_end;
198
List of commands in mysqltest
190
List of commands in drizzletest
199
191
Must match the "command_names" array
200
192
Add new commands before Q_UNKNOWN!
202
194
enum enum_commands {
203
195
Q_CONNECTION=1, Q_QUERY,
204
Q_CONNECT, Q_SLEEP, Q_REAL_SLEEP,
206
Q_SOURCE, Q_DISCONNECT,
208
Q_WHILE, Q_END_BLOCK,
210
Q_REQUIRE, Q_SAVE_MASTER_POS,
196
Q_CONNECT, Q_SLEEP, Q_REAL_SLEEP,
198
Q_SOURCE, Q_DISCONNECT,
200
Q_WHILE, Q_END_BLOCK,
202
Q_REQUIRE, Q_SAVE_MASTER_POS,
211
203
Q_SYNC_WITH_MASTER,
212
204
Q_SYNC_SLAVE_WITH_MASTER,
215
Q_DIRTY_CLOSE, Q_REPLACE, Q_REPLACE_COLUMN,
207
Q_DIRTY_CLOSE, Q_REPLACE, Q_REPLACE_COLUMN,
218
210
Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG,
219
211
Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG,
446
438
send_one_query executes query in separate thread, which is
447
439
necessary in embedded library to run 'send' in proper way.
448
440
This implementation doesn't handle errors returned
449
by mysql_send_query. It's technically possible, though
441
by drizzle_send_query. It's technically possible, though
450
442
I don't see where it is needed.
452
444
pthread_handler_t send_one_query(void *arg)
454
446
struct st_connection *cn= (struct st_connection*)arg;
457
VOID(mysql_send_query(&cn->mysql, cn->cur_query, cn->cur_query_len));
448
drizzle_thread_init();
449
VOID(drizzle_send_query(&cn->drizzle, cn->cur_query, cn->cur_query_len));
451
drizzle_thread_end();
460
452
pthread_mutex_lock(&cn->mutex);
461
453
cn->query_done= 1;
462
454
VOID(pthread_cond_signal(&cn->cond));
522
dynstr_append_mem(query_eval, p, 1);
514
dynstr_append_mem(query_eval, p, 1);
526
if (!(v= var_get(p, &p, 0, 0)))
527
die("Bad variable in eval");
528
dynstr_append_mem(query_eval, v->str_val, v->str_val_len);
518
if (!(v= var_get(p, &p, 0, 0)))
519
die("Bad variable in eval");
520
dynstr_append_mem(query_eval, v->str_val, v->str_val_len);
536
dynstr_append_mem(query_eval, p, 1);
528
dynstr_append_mem(query_eval, p, 1);
538
530
else if (next_c == '\\' || next_c == '$' || next_c == '"')
540
532
/* Set escaped only if next char is \, " or $ */
543
535
if (pass_through_escape_chars)
570
mysql - connection to use
562
drizzle - connection to use
571
563
query - query to run
575
static void show_query(MYSQL* mysql, const char* query)
567
static void show_query(DRIZZLE *drizzle, const char* query)
583
if (mysql_query(mysql, query))
575
if (drizzle_query(drizzle, query))
585
577
log_msg("Error running query '%s': %d %s",
586
query, mysql_errno(mysql), mysql_error(mysql));
578
query, drizzle_errno(drizzle), drizzle_error(drizzle));
590
if ((res= mysql_store_result(mysql)) == NULL)
582
if ((res= drizzle_store_result(drizzle)) == NULL)
592
584
/* No result set returned */
599
591
unsigned int row_num= 0;
600
unsigned int num_fields= mysql_num_fields(res);
601
MYSQL_FIELD *fields= mysql_fetch_fields(res);
592
unsigned int num_fields= drizzle_num_fields(res);
593
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
603
595
fprintf(stderr, "=== %s ===\n", query);
604
while ((row= mysql_fetch_row(res)))
596
while ((row= drizzle_fetch_row(res)))
606
uint32_t *lengths= mysql_fetch_lengths(res);
598
uint32_t *lengths= drizzle_fetch_lengths(res);
609
601
fprintf(stderr, "---- %d. ----\n", row_num);
635
627
show_warnings_before_error
636
mysql - connection to use
628
drizzle - connection to use
640
static void show_warnings_before_error(MYSQL* mysql)
632
static void show_warnings_before_error(DRIZZLE *drizzle)
643
635
const char* query= "SHOW WARNINGS";
649
if (mysql_query(mysql, query))
641
if (drizzle_query(drizzle, query))
651
643
log_msg("Error running query '%s': %d %s",
652
query, mysql_errno(mysql), mysql_error(mysql));
644
query, drizzle_errno(drizzle), drizzle_error(drizzle));
656
if ((res= mysql_store_result(mysql)) == NULL)
648
if ((res= drizzle_store_result(drizzle)) == NULL)
658
650
/* No result set returned */
662
if (mysql_num_rows(res) <= 1)
654
if (drizzle_num_rows(res) <= 1)
664
656
/* Don't display the last row, it's "last error" */
669
661
unsigned int row_num= 0;
670
unsigned int num_fields= mysql_num_fields(res);
662
unsigned int num_fields= drizzle_num_fields(res);
672
664
fprintf(stderr, "\nWarnings from just before the error:\n");
673
while ((row= mysql_fetch_row(res)))
665
while ((row= drizzle_fetch_row(res)))
676
uint32_t *lengths= mysql_fetch_lengths(res);
668
uint32_t *lengths= drizzle_fetch_lengths(res);
678
if (++row_num >= mysql_num_rows(res))
670
if (++row_num >= drizzle_num_rows(res))
680
672
/* Don't display the last row, it's "last error" */
1778
1770
Store an integer (typically the returncode of the last SQL)
1779
statement in the mysqltest builtin variable $mysql_errno
1771
statement in the drizzletest builtin variable $drizzle_errno
1782
1774
static void var_set_errno(int sql_errno)
1784
var_set_int("$mysql_errno", sql_errno);
1776
var_set_int("$drizzle_errno", sql_errno);
1789
Update $mysql_get_server_version variable with version
1781
Update $drizzle_get_server_version variable with version
1790
1782
of the currently connected server
1793
static void var_set_mysql_get_server_version(MYSQL* mysql)
1785
static void var_set_drizzle_get_server_version(DRIZZLE *drizzle)
1795
var_set_int("$mysql_get_server_version", mysql_get_server_version(mysql));
1787
var_set_int("$drizzle_get_server_version", drizzle_get_server_version(drizzle));
1839
1831
init_dynamic_string(&ds_query, 0, (end - query) + 32, 256);
1840
1832
do_eval(&ds_query, query, end, false);
1842
if (mysql_real_query(mysql, ds_query.str, ds_query.length))
1834
if (drizzle_real_query(drizzle, ds_query.str, ds_query.length))
1843
1835
die("Error running query '%s': %d %s", ds_query.str,
1844
mysql_errno(mysql), mysql_error(mysql));
1845
if (!(res= mysql_store_result(mysql)))
1836
drizzle_errno(drizzle), drizzle_error(drizzle));
1837
if (!(res= drizzle_store_result(drizzle)))
1846
1838
die("Query '%s' didn't return a result set", ds_query.str);
1847
1839
dynstr_free(&ds_query);
1849
if ((row= mysql_fetch_row(res)) && row[0])
1841
if ((row= drizzle_fetch_row(res)) && row[0])
1852
1844
Concatenate all fields in the first row with tab in between
1934
1926
die("Mismatched \"'s around query '%s'", ds_query.str);
1936
1928
/* Run the query */
1937
if (mysql_real_query(mysql, ds_query.str, ds_query.length))
1929
if (drizzle_real_query(drizzle, ds_query.str, ds_query.length))
1938
1930
die("Error running query '%s': %d %s", ds_query.str,
1939
mysql_errno(mysql), mysql_error(mysql));
1940
if (!(res= mysql_store_result(mysql)))
1931
drizzle_errno(drizzle), drizzle_error(drizzle));
1932
if (!(res= drizzle_store_result(drizzle)))
1941
1933
die("Query '%s' didn't return a result set", ds_query.str);
1944
1936
/* Find column number from the given column name */
1946
uint num_fields= mysql_num_fields(res);
1947
MYSQL_FIELD *fields= mysql_fetch_fields(res);
1938
uint num_fields= drizzle_num_fields(res);
1939
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
1949
1941
for (i= 0; i < num_fields; i++)
2929
2921
if (!ds_user.length)
2930
dynstr_set(&ds_user, mysql->user);
2922
dynstr_set(&ds_user, drizzle->user);
2932
2924
if (!ds_passwd.length)
2933
dynstr_set(&ds_passwd, mysql->passwd);
2925
dynstr_set(&ds_passwd, drizzle->passwd);
2935
2927
if (!ds_db.length)
2936
dynstr_set(&ds_db, mysql->db);
2928
dynstr_set(&ds_db, drizzle->db);
2938
if (mysql_change_user(mysql, ds_user.str, ds_passwd.str, ds_db.str))
2939
die("change user failed: %s", mysql_error(mysql));
2930
if (drizzle_change_user(drizzle, ds_user.str, ds_passwd.str, ds_db.str))
2931
die("change user failed: %s", drizzle_error(drizzle));
2941
2933
dynstr_free(&ds_user);
2942
2934
dynstr_free(&ds_passwd);
3069
3061
do_wait_for_slave_to_stop(struct st_command *c __attribute__((unused)))
3071
3063
static int SLAVE_POLL_INTERVAL= 300000;
3072
MYSQL* mysql = &cur_con->mysql;
3064
DRIZZLE *drizzle= &cur_con->drizzle;
3075
MYSQL_RES *res= NULL;
3067
DRIZZLE_RES *res= NULL;
3079
if (mysql_query(mysql,"show status like 'Slave_running'") ||
3080
!(res=mysql_store_result(mysql)))
3071
if (drizzle_query(drizzle,"show status like 'Slave_running'") ||
3072
!(res=drizzle_store_result(drizzle)))
3081
3073
die("Query failed while probing slave for stop: %s",
3082
mysql_error(mysql));
3083
if (!(row=mysql_fetch_row(res)) || !row[1])
3074
drizzle_error(drizzle));
3075
if (!(row=drizzle_fetch_row(res)) || !row[1])
3085
mysql_free_result(res);
3077
drizzle_free_result(res);
3086
3078
die("Strange result from query while probing slave for stop");
3088
3080
done = !strcmp(row[1],"OFF");
3089
mysql_free_result(res);
3081
drizzle_free_result(res);
3092
3084
my_sleep(SLAVE_POLL_INTERVAL);
3107
3099
die("Calling 'sync_with_master' without calling 'save_master_pos'");
3109
3101
sprintf(query_buf, "select master_pos_wait('%s', %ld)", master_pos.file,
3110
master_pos.pos + offset);
3102
master_pos.pos + offset);
3112
3104
wait_for_position:
3114
if (mysql_query(mysql, query_buf))
3115
die("failed in '%s': %d: %s", query_buf, mysql_errno(mysql),
3116
mysql_error(mysql));
3106
if (drizzle_query(drizzle, query_buf))
3107
die("failed in '%s': %d: %s", query_buf, drizzle_errno(drizzle),
3108
drizzle_error(drizzle));
3118
if (!(res= mysql_store_result(mysql)))
3119
die("mysql_store_result() returned NULL for '%s'", query_buf);
3120
if (!(row= mysql_fetch_row(res)))
3110
if (!(res= drizzle_store_result(drizzle)))
3111
die("drizzle_store_result() returned NULL for '%s'", query_buf);
3112
if (!(row= drizzle_fetch_row(res)))
3122
mysql_free_result(res);
3114
drizzle_free_result(res);
3123
3115
die("empty result in %s", query_buf);
3166
3158
when ndb binlog is on, this call will wait until last updated epoch
3167
(locally in the mysqld) has been received into the binlog
3159
(locally in the drizzled) has been received into the binlog
3169
3161
static int do_save_master_pos(void)
3173
MYSQL *mysql = &cur_con->mysql;
3165
DRIZZLE *drizzle= &cur_con->drizzle;
3174
3166
const char *query;
3177
if (mysql_query(mysql, query= "show master status"))
3169
if (drizzle_query(drizzle, query= "show master status"))
3178
3170
die("failed in 'show master status': %d %s",
3179
mysql_errno(mysql), mysql_error(mysql));
3171
drizzle_errno(drizzle), drizzle_error(drizzle));
3181
if (!(res = mysql_store_result(mysql)))
3182
die("mysql_store_result() retuned NULL for '%s'", query);
3183
if (!(row = mysql_fetch_row(res)))
3173
if (!(res = drizzle_store_result(drizzle)))
3174
die("drizzle_store_result() retuned NULL for '%s'", query);
3175
if (!(row = drizzle_fetch_row(res)))
3184
3176
die("empty result in show master status");
3185
3177
strnmov(master_pos.file, row[0], sizeof(master_pos.file)-1);
3186
3178
master_pos.pos = strtoul(row[1], (char**) 0, 10);
3187
mysql_free_result(res);
3179
drizzle_free_result(res);
3505
3497
if (*from == '"' || *from == '\'')
3508
sep=' '; /* Separated with space */
3500
sep=' '; /* Separated with space */
3510
3502
for ( ; (c=*from) ; from++)
3512
3504
if (c == '\\' && from[1])
3513
{ /* Escaped character */
3505
{ /* Escaped character */
3514
3506
/* We can't translate \0 -> ASCII 0 as replace can't handle ASCII 0 */
3515
3507
switch (*++from) {
3528
case 'Z': /* ^Z must be escaped on Win32 */
3520
case 'Z': /* ^Z must be escaped on Win32 */
3536
3528
else if (c == sep)
3538
3530
if (c == ' ' || c != *++from)
3539
break; /* Found end of string */
3540
*to++=c; /* Copy duplicated separator */
3531
break; /* Found end of string */
3532
*to++=c; /* Copy duplicated separator */
3694
3686
on protocol/connection type
3697
if ((mysql_errno(mysql) == CR_CONN_HOST_ERROR ||
3698
mysql_errno(mysql) == CR_CONNECTION_ERROR) &&
3689
if ((drizzle_errno(drizzle) == CR_CONN_HOST_ERROR ||
3690
drizzle_errno(drizzle) == CR_CONNECTION_ERROR) &&
3699
3691
failed_attempts < opt_max_connect_retries)
3701
3693
verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts,
3702
opt_max_connect_retries, mysql_errno(mysql),
3703
mysql_error(mysql));
3694
opt_max_connect_retries, drizzle_errno(drizzle),
3695
drizzle_error(drizzle));
3704
3696
my_sleep(connection_retry_sleep);
3708
3700
if (failed_attempts > 0)
3709
3701
die("Could not open connection '%s' after %d attempts: %d %s", name,
3710
failed_attempts, mysql_errno(mysql), mysql_error(mysql));
3702
failed_attempts, drizzle_errno(drizzle), drizzle_error(drizzle));
3712
3704
die("Could not open connection '%s': %d %s", name,
3713
mysql_errno(mysql), mysql_error(mysql));
3705
drizzle_errno(drizzle), drizzle_error(drizzle));
3715
3707
failed_attempts++;
3775
3767
dynstr_append_mem(ds, delimiter, delimiter_length);
3776
3768
dynstr_append_mem(ds, "\n", 1);
3778
if (!mysql_real_connect(con, host, user, pass, db, port, 0,
3770
if (!drizzle_connect(con, host, user, pass, db, port, 0,
3779
3771
CLIENT_MULTI_STATEMENTS))
3781
var_set_errno(mysql_errno(con));
3782
handle_error(command, mysql_errno(con), mysql_error(con),
3783
mysql_sqlstate(con), ds);
3773
var_set_errno(drizzle_errno(con));
3774
handle_error(command, drizzle_errno(con), drizzle_error(con),
3775
drizzle_sqlstate(con), ds);
3784
3776
return 0; /* Not connected */
3913
3905
#ifdef EMBEDDED_LIBRARY
3914
3906
con_slot->query_done= 1;
3916
if (!mysql_init(&con_slot->mysql))
3917
die("Failed on mysql_init()");
3908
if (!drizzle_create(&con_slot->drizzle))
3909
die("Failed on drizzle_create()");
3918
3910
if (opt_compress || con_compress)
3919
mysql_options(&con_slot->mysql, MYSQL_OPT_COMPRESS, NullS);
3920
mysql_options(&con_slot->mysql, MYSQL_OPT_LOCAL_INFILE, 0);
3921
mysql_options(&con_slot->mysql, MYSQL_SET_CHARSET_NAME,
3911
drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_COMPRESS, NullS);
3912
drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
3913
drizzle_options(&con_slot->drizzle, DRIZZLE_SET_CHARSET_NAME,
3922
3914
charset_info->csname);
3923
int opt_protocol= MYSQL_PROTOCOL_TCP;
3924
mysql_options(&con_slot->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
3915
int opt_protocol= DRIZZLE_PROTOCOL_TCP;
3916
drizzle_options(&con_slot->drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
3925
3917
if (opt_charsets_dir)
3926
mysql_options(&con_slot->mysql, MYSQL_SET_CHARSET_DIR,
3918
drizzle_options(&con_slot->drizzle, DRIZZLE_SET_CHARSET_DIR,
3927
3919
opt_charsets_dir);
3929
3921
/* Use default db name */
4294
4286
/* completed before we pass buf_end */
4295
4287
if ((charlen > 1) && (p + charlen) <= buf_end)
4302
for (i= 1; i < charlen; i++)
4304
if (feof(cur_file->file))
4306
c= my_getc(cur_file->file);
4309
if (! my_ismbchar(charset_info, mb_start, p))
4311
/* It was not a multiline char, push back the characters */
4312
/* We leave first 'c', i.e. pretend it was a normal char */
4313
while (p > mb_start)
4294
for (i= 1; i < charlen; i++)
4296
if (feof(cur_file->file))
4298
c= my_getc(cur_file->file);
4301
if (! my_ismbchar(charset_info, mb_start, p))
4303
/* It was not a multiline char, push back the characters */
4304
/* We leave first 'c', i.e. pretend it was a normal char */
4305
while (p > mb_start)
4322
4314
die("The input buffer is too small for this query.x\n" \
4642
#include <help_start.h>
4644
4634
static void print_version(void)
4646
4636
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4647
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
4637
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
4650
4640
static void usage(void)
4652
4642
print_version();
4653
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
4643
printf("DRIZZLE AB, by Sasha, Matt, Monty & Jani\n");
4654
4644
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
4655
printf("Runs a test against the mysql server and compares output with a results file.\n\n");
4645
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4656
4646
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4657
4647
my_print_help(my_long_options);
4658
4648
printf(" --no-defaults Don't read default options from any options file.\n");
4659
4649
my_print_variables(my_long_options);
4662
#include <help_end.h>
4666
4653
Read arguments for embedded server and put them into
4667
4654
embedded_server_args[]
4682
4669
if (!embedded_server_arg_count)
4684
4671
embedded_server_arg_count=1;
4685
embedded_server_args[0]= (char*) ""; /* Progname */
4672
embedded_server_args[0]= (char*) ""; /* Progname */
4687
4674
if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME))))
4688
4675
die("Failed to open file '%s'", buff);
4690
4677
while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4691
(str=fgets(argument,sizeof(argument), file)))
4678
(str=fgets(argument,sizeof(argument), file)))
4693
*(strend(str)-1)=0; /* Remove end newline */
4680
*(strend(str)-1)=0; /* Remove end newline */
4694
4681
if (!(embedded_server_args[embedded_server_arg_count]=
4695
(char*) my_strdup(str,MYF(MY_WME))))
4682
(char*) my_strdup(str,MYF(MY_WME))))
4697
4684
my_fclose(file,MYF(0));
4698
4685
die("Out of memory");
4934
4921
Values may be converted with 'replace_column'
4937
static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
4924
static void append_result(DYNAMIC_STRING *ds, DRIZZLE_RES *res)
4940
uint32_t num_fields= mysql_num_fields(res);
4941
MYSQL_FIELD *fields= mysql_fetch_fields(res);
4927
uint32_t num_fields= drizzle_num_fields(res);
4928
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
4942
4929
uint32_t *lengths;
4944
while ((row = mysql_fetch_row(res)))
4931
while ((row = drizzle_fetch_row(res)))
4947
lengths = mysql_fetch_lengths(res);
4934
lengths = drizzle_fetch_lengths(res);
4948
4935
for (i = 0; i < num_fields; i++)
4949
4936
append_field(ds, i, &fields[i],
4950
4937
(const char*)row[i], lengths[i], !row[i]);
5064
5051
through PS API we should not issue SHOW WARNINGS until
5065
5052
we have not read all results...
5067
assert(!mysql_more_results(mysql));
5069
if (mysql_real_query(mysql, "SHOW WARNINGS", 13))
5070
die("Error running query \"SHOW WARNINGS\": %s", mysql_error(mysql));
5072
if (!(warn_res= mysql_store_result(mysql)))
5054
assert(!drizzle_more_results(drizzle));
5056
if (drizzle_real_query(drizzle, "SHOW WARNINGS", 13))
5057
die("Error running query \"SHOW WARNINGS\": %s", drizzle_error(drizzle));
5059
if (!(warn_res= drizzle_store_result(drizzle)))
5073
5060
die("Warning count is %u but didn't get any warnings",
5076
5063
append_result(ds, warn_res);
5077
mysql_free_result(warn_res);
5064
drizzle_free_result(warn_res);
5084
Run query using MySQL C API
5071
Run query using DRIZZLE C API
5087
5074
run_query_normal()
5089
command current command pointer
5090
flags flags indicating if we should SEND and/or REAP
5091
query query string to execute
5092
query_len length query string to execute
5093
ds output buffer where to store result form query
5075
drizzle DRIZZLE handle
5076
command current command pointer
5077
flags flags indicating if we should SEND and/or REAP
5078
query query string to execute
5079
query_len length query string to execute
5080
ds output buffer where to store result form query
5096
5083
static void run_query_normal(struct st_connection *cn,
5131
When on first result set, call mysql_read_query_result to retrieve
5118
When on first result set, call drizzle_read_query_result to retrieve
5132
5119
answer to the query sent earlier
5134
if ((counter==0) && mysql_read_query_result(mysql))
5121
if ((counter==0) && drizzle_read_query_result(drizzle))
5136
handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5137
mysql_sqlstate(mysql), ds);
5123
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5124
drizzle_sqlstate(drizzle), ds);
5158
MYSQL_FIELD *fields= mysql_fetch_fields(res);
5159
uint num_fields= mysql_num_fields(res);
5145
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
5146
uint num_fields= drizzle_num_fields(res);
5161
if (display_metadata)
5148
if (display_metadata)
5162
5149
append_metadata(ds, fields, num_fields);
5164
if (!display_result_vertically)
5165
append_table_headings(ds, fields, num_fields);
5151
if (!display_result_vertically)
5152
append_table_headings(ds, fields, num_fields);
5167
append_result(ds, res);
5154
append_result(ds, res);
5171
Need to call mysql_affected_rows() before the "new"
5158
Need to call drizzle_affected_rows() before the "new"
5172
5159
query to find the warnings
5174
5161
if (!disable_info)
5175
affected_rows= mysql_affected_rows(mysql);
5162
affected_rows= drizzle_affected_rows(drizzle);
5178
5165
Add all warnings to the result. We can't do this if we are in
5179
5166
the middle of processing results from multi-statement, because
5180
5167
this will break protocol.
5182
if (!disable_warnings && !mysql_more_results(mysql))
5169
if (!disable_warnings && !drizzle_more_results(drizzle))
5184
if (append_warnings(ds_warnings, mysql) || ds_warnings->length)
5186
dynstr_append_mem(ds, "Warnings:\n", 10);
5187
dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
5171
if (append_warnings(ds_warnings, drizzle) || ds_warnings->length)
5173
dynstr_append_mem(ds, "Warnings:\n", 10);
5174
dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
5191
5178
if (!disable_info)
5192
append_info(ds, affected_rows, mysql_info(mysql));
5179
append_info(ds, affected_rows, drizzle_info(drizzle));
5197
mysql_free_result(res);
5184
drizzle_free_result(res);
5201
} while (!(err= mysql_next_result(mysql)));
5188
} while (!(err= drizzle_next_result(drizzle)));
5204
/* We got an error from mysql_next_result, maybe expected */
5205
handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5206
mysql_sqlstate(mysql), ds);
5191
/* We got an error from drizzle_next_result, maybe expected */
5192
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5193
drizzle_sqlstate(drizzle), ds);
5209
5196
assert(err == -1); /* Successful and there are no more results */
5667
5650
cur_file->lineno= 1;
5669
5652
cur_con= connections;
5670
if (!( mysql_init(&cur_con->mysql)))
5671
die("Failed in mysql_init()");
5653
if (!( drizzle_create(&cur_con->drizzle)))
5654
die("Failed in drizzle_create()");
5672
5655
if (opt_compress)
5673
mysql_options(&cur_con->mysql,MYSQL_OPT_COMPRESS,NullS);
5674
mysql_options(&cur_con->mysql, MYSQL_OPT_LOCAL_INFILE, 0);
5675
mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_NAME,
5656
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NullS);
5657
drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5658
drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_NAME,
5676
5659
charset_info->csname);
5677
int opt_protocol= MYSQL_PROTOCOL_TCP;
5678
mysql_options(&cur_con->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
5660
int opt_protocol= DRIZZLE_PROTOCOL_TCP;
5661
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
5679
5662
if (opt_charsets_dir)
5680
mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_DIR,
5663
drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_DIR,
5681
5664
opt_charsets_dir);
5683
5666
if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5684
5667
die("Out of memory");
5686
safe_connect(&cur_con->mysql, cur_con->name, opt_host, opt_user, opt_pass,
5669
safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5687
5670
opt_db, opt_port);
5689
5672
/* Use all time until exit if no explicit 'start_timer' */
5690
5673
timer_start= timer_now();
5693
Initialize $mysql_errno with -1, so we can
5676
Initialize $drizzle_errno with -1, so we can
5694
5677
- distinguish it from valid values ( >= 0 ) and
5695
5678
- detect if there was never a command sent to the server
5697
5680
var_set_errno(-1);
5699
/* Update $mysql_get_server_version to that of current connection */
5700
var_set_mysql_get_server_version(&cur_con->mysql);
5682
/* Update $drizzle_get_server_version to that of current connection */
5683
var_set_drizzle_get_server_version(&cur_con->drizzle);
5702
5685
if (opt_include)
5813
5796
/* Check for special property for this query */
5814
5797
display_result_vertically|= (command->type == Q_QUERY_VERTICAL);
5818
strmake(command->require_file, save_file, sizeof(save_file) - 1);
5821
run_query(cur_con, command, flags);
5801
strmake(command->require_file, save_file, sizeof(save_file) - 1);
5804
run_query(cur_con, command, flags);
5823
5806
command->last_argument= command->end;
5825
5808
/* Restore settings */
5826
display_result_vertically= old_display_result_vertically;
5809
display_result_vertically= old_display_result_vertically;
5831
5814
if (!*command->first_argument)
5841
5824
/* Remove "send" if this is first iteration */
5842
if (command->query == command->query_buf)
5843
command->query= command->first_argument;
5825
if (command->query == command->query_buf)
5826
command->query= command->first_argument;
5846
run_query() can execute a query partially, depending on the flags.
5847
QUERY_SEND_FLAG flag without QUERY_REAP_FLAG tells it to just send
5829
run_query() can execute a query partially, depending on the flags.
5830
QUERY_SEND_FLAG flag without QUERY_REAP_FLAG tells it to just send
5848
5831
the query and read the result some time later when reap instruction
5849
is given on this connection.
5832
is given on this connection.
5851
run_query(cur_con, command, QUERY_SEND_FLAG);
5834
run_query(cur_con, command, QUERY_SEND_FLAG);
5853
5836
command->last_argument= command->end;
5855
5838
case Q_REQUIRE:
5856
do_get_file_name(command, save_file, sizeof(save_file));
5839
do_get_file_name(command, save_file, sizeof(save_file));
5859
5842
do_get_errcodes(command);
5861
5844
case Q_REPLACE:
5862
do_get_replace(command);
5845
do_get_replace(command);
5864
5847
case Q_REPLACE_REGEX:
5865
5848
do_get_replace_regex(command);
5867
5850
case Q_REPLACE_COLUMN:
5868
do_get_replace_column(command);
5851
do_get_replace_column(command);
5870
5853
case Q_SAVE_MASTER_POS: do_save_master_pos(); break;
5871
5854
case Q_SYNC_WITH_MASTER: do_sync_with_master(command); break;
5872
5855
case Q_SYNC_SLAVE_WITH_MASTER:
5874
do_save_master_pos();
5875
if (*command->first_argument)
5876
select_connection(command);
5878
select_connection_name("slave");
5879
do_sync_with_master2(0);
5857
do_save_master_pos();
5858
if (*command->first_argument)
5859
select_connection(command);
5861
select_connection_name("slave");
5862
do_sync_with_master2(0);
5882
case Q_COMMENT: /* Ignore row */
5865
case Q_COMMENT: /* Ignore row */
5883
5866
command->last_argument= command->end;
5886
(void) mysql_ping(&cur_con->mysql);
5869
(void) drizzle_ping(&cur_con->drizzle);
5892
5875
case Q_START_TIMER:
5893
/* Overwrite possible earlier start of timer */
5894
timer_start= timer_now();
5876
/* Overwrite possible earlier start of timer */
5877
timer_start= timer_now();
5896
5879
case Q_END_TIMER:
5897
/* End timer before ending mysqltest */
5880
/* End timer before ending drizzletest */
5900
5883
case Q_CHARACTER_SET:
5901
do_set_charset(command);
5884
do_set_charset(command);
5903
5886
case Q_DISABLE_RECONNECT:
5904
set_reconnect(&cur_con->mysql, 0);
5887
set_reconnect(&cur_con->drizzle, 0);
5906
5889
case Q_ENABLE_RECONNECT:
5907
set_reconnect(&cur_con->mysql, 1);
5890
set_reconnect(&cur_con->drizzle, 1);
5909
5892
case Q_DISABLE_PARSING:
5910
5893
if (parsing_disabled == 0)
6157
6140
/* Definitions for replace result */
6159
typedef struct st_pointer_array { /* when using array-strings */
6160
TYPELIB typelib; /* Pointer to strings */
6161
uchar *str; /* Strings is here */
6162
int7 *flag; /* Flag about each var. */
6163
uint array_allocs,max_count,length,max_length;
6142
typedef struct st_pointer_array { /* when using array-strings */
6143
TYPELIB typelib; /* Pointer to strings */
6144
uchar *str; /* Strings is here */
6145
int7 *flag; /* Flag about each var. */
6146
uint array_allocs,max_count,length,max_length;
6164
6147
} POINTER_ARRAY;
6166
6149
struct st_replace;
6167
6150
struct st_replace *init_replace(char * *from, char * *to, uint count,
6168
char * word_end_chars);
6151
char * word_end_chars);
6169
6152
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
6170
6153
void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
6171
6154
const char *from, int len);
6211
6194
for (i= 1,pos= word_end_chars ; i < 256 ; i++)
6212
6195
if (my_isspace(charset_info,i))
6214
*pos=0; /* End pointer */
6197
*pos=0; /* End pointer */
6215
6198
if (!(glob_replace= init_replace((char**) from_array.typelib.type_names,
6216
(char**) to_array.typelib.type_names,
6217
(uint) from_array.typelib.count,
6199
(char**) to_array.typelib.type_names,
6200
(uint) from_array.typelib.count,
6219
6202
die("Can't initialize replace from '%s'", command->query);
6220
6203
free_pointer_array(&from_array);
6221
6204
free_pointer_array(&to_array);
6602
6585
#define LAST_CHAR_CODE 259
6604
6587
typedef struct st_rep_set {
6605
uint *bits; /* Pointer to used sets */
6606
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6607
uint found_len; /* Best match to date */
6610
uint size_of_bits; /* For convinience */
6588
uint *bits; /* Pointer to used sets */
6589
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6590
uint found_len; /* Best match to date */
6593
uint size_of_bits; /* For convinience */
6613
6596
typedef struct st_rep_sets {
6614
uint count; /* Number of sets */
6615
uint extra; /* Extra sets in buffer */
6616
uint invisible; /* Sets not chown */
6618
REP_SET *set,*set_buffer;
6597
uint count; /* Number of sets */
6598
uint extra; /* Extra sets in buffer */
6599
uint invisible; /* Sets not chown */
6601
REP_SET *set,*set_buffer;
6622
6605
typedef struct st_found_set {
6742
6725
internal_set_bit(word_states,states);
6743
6726
if (!from[i][2] && start_states->table_offset == (uint) ~0)
6745
start_states->table_offset=i;
6746
start_states->found_offset=0;
6728
start_states->table_offset=i;
6729
start_states->found_offset=0;
6751
6734
internal_set_bit(word_states,states);
6752
6735
if (from[i][0] == '\\' && (from[i][1] == 'b' && from[i][2]))
6753
internal_set_bit(start_states,states+1);
6736
internal_set_bit(start_states,states+1);
6755
internal_set_bit(start_states,states);
6738
internal_set_bit(start_states,states);
6757
6740
for (pos=from[i], len=0; *pos ; pos++)
6759
6742
if (*pos == '\\' && *(pos+1))
6764
follow_ptr->chr = SPACE_CHAR;
6767
follow_ptr->chr = START_OF_LINE;
6770
follow_ptr->chr = END_OF_LINE;
6773
follow_ptr->chr = '\r';
6776
follow_ptr->chr = '\t';
6779
follow_ptr->chr = '\v';
6782
follow_ptr->chr = (uchar) *pos;
6747
follow_ptr->chr = SPACE_CHAR;
6750
follow_ptr->chr = START_OF_LINE;
6753
follow_ptr->chr = END_OF_LINE;
6756
follow_ptr->chr = '\r';
6759
follow_ptr->chr = '\t';
6762
follow_ptr->chr = '\v';
6765
follow_ptr->chr = (uchar) *pos;
6787
follow_ptr->chr= (uchar) *pos;
6770
follow_ptr->chr= (uchar) *pos;
6788
6771
follow_ptr->table_offset=i;
6789
6772
follow_ptr->len= ++len;
6824
6807
used_chars[follow[i].chr]=1;
6825
6808
if ((follow[i].chr == SPACE_CHAR && !follow[i+1].chr &&
6826
follow[i].len > 1) || follow[i].chr == END_OF_LINE)
6809
follow[i].len > 1) || follow[i].chr == END_OF_LINE)
6830
6813
/* Mark word_chars used if \b is in state */
6831
6814
if (used_chars[SPACE_CHAR])
6832
6815
for (pos= word_end_chars ; *pos ; pos++)
6833
used_chars[(int) (uchar) *pos] = 1;
6816
used_chars[(int) (uchar) *pos] = 1;
6835
6818
/* Handle other used characters */
6836
6819
for (chr= 0 ; chr < 256 ; chr++)
6838
6821
if (! used_chars[chr])
6839
set->next[chr]= chr ? default_state : -1;
6822
set->next[chr]= chr ? default_state : -1;
6842
new_set=make_new_set(&sets);
6843
set=sets.set+set_nr; /* if realloc */
6844
new_set->table_offset=set->table_offset;
6845
new_set->found_len=set->found_len;
6846
new_set->found_offset=set->found_offset+1;
6825
new_set=make_new_set(&sets);
6826
set=sets.set+set_nr; /* if realloc */
6827
new_set->table_offset=set->table_offset;
6828
new_set->found_len=set->found_len;
6829
new_set->found_offset=set->found_offset+1;
6849
for (i= (uint) ~0 ; (i=get_next_bit(sets.set+used_sets,i)) ; )
6851
if (!follow[i].chr || follow[i].chr == chr ||
6852
(follow[i].chr == SPACE_CHAR &&
6853
(is_word_end[chr] ||
6854
(!chr && follow[i].len > 1 && ! follow[i+1].chr))) ||
6855
(follow[i].chr == END_OF_LINE && ! chr))
6857
if ((! chr || (follow[i].chr && !follow[i+1].chr)) &&
6858
follow[i].len > found_end)
6859
found_end=follow[i].len;
6860
if (chr && follow[i].chr)
6861
internal_set_bit(new_set,i+1); /* To next set */
6863
internal_set_bit(new_set,i);
6868
new_set->found_len=0; /* Set for testing if first */
6870
for (i= (uint) ~0; (i=get_next_bit(new_set,i)) ;)
6872
if ((follow[i].chr == SPACE_CHAR ||
6873
follow[i].chr == END_OF_LINE) && ! chr)
6877
if (follow[bit_nr-1].len < found_end ||
6878
(new_set->found_len &&
6879
(chr == 0 || !follow[bit_nr].chr)))
6880
internal_clear_bit(new_set,i);
6883
if (chr == 0 || !follow[bit_nr].chr)
6885
new_set->table_offset=follow[bit_nr].table_offset;
6886
if (chr || (follow[i].chr == SPACE_CHAR ||
6887
follow[i].chr == END_OF_LINE))
6888
new_set->found_offset=found_end; /* New match */
6889
new_set->found_len=found_end;
6896
set->next[chr] = find_found(found_set,
6897
new_set->table_offset,
6898
new_set->found_offset);
6899
free_last_set(&sets);
6902
set->next[chr] = find_set(&sets,new_set);
6905
set->next[chr] = find_set(&sets,new_set);
6832
for (i= (uint) ~0 ; (i=get_next_bit(sets.set+used_sets,i)) ; )
6834
if (!follow[i].chr || follow[i].chr == chr ||
6835
(follow[i].chr == SPACE_CHAR &&
6836
(is_word_end[chr] ||
6837
(!chr && follow[i].len > 1 && ! follow[i+1].chr))) ||
6838
(follow[i].chr == END_OF_LINE && ! chr))
6840
if ((! chr || (follow[i].chr && !follow[i+1].chr)) &&
6841
follow[i].len > found_end)
6842
found_end=follow[i].len;
6843
if (chr && follow[i].chr)
6844
internal_set_bit(new_set,i+1); /* To next set */
6846
internal_set_bit(new_set,i);
6851
new_set->found_len=0; /* Set for testing if first */
6853
for (i= (uint) ~0; (i=get_next_bit(new_set,i)) ;)
6855
if ((follow[i].chr == SPACE_CHAR ||
6856
follow[i].chr == END_OF_LINE) && ! chr)
6860
if (follow[bit_nr-1].len < found_end ||
6861
(new_set->found_len &&
6862
(chr == 0 || !follow[bit_nr].chr)))
6863
internal_clear_bit(new_set,i);
6866
if (chr == 0 || !follow[bit_nr].chr)
6868
new_set->table_offset=follow[bit_nr].table_offset;
6869
if (chr || (follow[i].chr == SPACE_CHAR ||
6870
follow[i].chr == END_OF_LINE))
6871
new_set->found_offset=found_end; /* New match */
6872
new_set->found_len=found_end;
6879
set->next[chr] = find_found(found_set,
6880
new_set->table_offset,
6881
new_set->found_offset);
6882
free_last_set(&sets);
6885
set->next[chr] = find_set(&sets,new_set);
6888
set->next[chr] = find_set(&sets,new_set);
6929
6912
pos=from[found_set[i-1].table_offset];
6930
6913
rep_str[i].found= !bcmp((const uchar*) pos,
6931
(const uchar*) "\\^", 3) ? 2 : 1;
6914
(const uchar*) "\\^", 3) ? 2 : 1;
6932
6915
rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
6933
6916
rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
6934
6917
rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
6937
6920
for (i=0 ; i < sets.count ; i++)
6939
6922
for (j=0 ; j < 256 ; j++)
6940
if (sets.set[i].next[j] >= 0)
6941
replace[i].next[j]=replace+sets.set[i].next[j];
6943
replace[i].next[j]=(REPLACE*) (rep_str+(-sets.set[i].next[j]-1));
6923
if (sets.set[i].next[j] >= 0)
6924
replace[i].next[j]=replace+sets.set[i].next[j];
6926
replace[i].next[j]=(REPLACE*) (rep_str+(-sets.set[i].next[j]-1));
6946
6929
my_free(follow,MYF(0));
7155
7138
if (! pa->typelib.count)
7157
7140
if (!(pa->typelib.type_names=(const char **)
7158
my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
7159
(sizeof(char *)+sizeof(*pa->flag))*
7160
(sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
7141
my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
7142
(sizeof(char *)+sizeof(*pa->flag))*
7143
(sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
7162
7145
if (!(pa->str= (uchar*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD),
7165
7148
my_free((char*) pa->typelib.type_names,MYF(0));
7168
7151
pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(uchar*)+
7170
7153
pa->flag= (int7*) (pa->typelib.type_names+pa->max_count);
7172
7155
pa->max_length=PS_MALLOC-MALLOC_OVERHEAD;