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
4634
static void print_version(void)
4644
4636
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4645
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
4637
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
4648
4640
static void usage(void)
4650
4642
print_version();
4651
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
4643
printf("DRIZZLE AB, by Sasha, Matt, Monty & Jani\n");
4652
4644
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
4653
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");
4654
4646
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4655
4647
my_print_help(my_long_options);
4656
4648
printf(" --no-defaults Don't read default options from any options file.\n");
4677
4669
if (!embedded_server_arg_count)
4679
4671
embedded_server_arg_count=1;
4680
embedded_server_args[0]= (char*) ""; /* Progname */
4672
embedded_server_args[0]= (char*) ""; /* Progname */
4682
4674
if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME))))
4683
4675
die("Failed to open file '%s'", buff);
4685
4677
while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4686
(str=fgets(argument,sizeof(argument), file)))
4678
(str=fgets(argument,sizeof(argument), file)))
4688
*(strend(str)-1)=0; /* Remove end newline */
4680
*(strend(str)-1)=0; /* Remove end newline */
4689
4681
if (!(embedded_server_args[embedded_server_arg_count]=
4690
(char*) my_strdup(str,MYF(MY_WME))))
4682
(char*) my_strdup(str,MYF(MY_WME))))
4692
4684
my_fclose(file,MYF(0));
4693
4685
die("Out of memory");
4929
4921
Values may be converted with 'replace_column'
4932
static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
4924
static void append_result(DYNAMIC_STRING *ds, DRIZZLE_RES *res)
4935
uint32_t num_fields= mysql_num_fields(res);
4936
MYSQL_FIELD *fields= mysql_fetch_fields(res);
4927
uint32_t num_fields= drizzle_num_fields(res);
4928
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
4937
4929
uint32_t *lengths;
4939
while ((row = mysql_fetch_row(res)))
4931
while ((row = drizzle_fetch_row(res)))
4942
lengths = mysql_fetch_lengths(res);
4934
lengths = drizzle_fetch_lengths(res);
4943
4935
for (i = 0; i < num_fields; i++)
4944
4936
append_field(ds, i, &fields[i],
4945
4937
(const char*)row[i], lengths[i], !row[i]);
5059
5051
through PS API we should not issue SHOW WARNINGS until
5060
5052
we have not read all results...
5062
assert(!mysql_more_results(mysql));
5064
if (mysql_real_query(mysql, "SHOW WARNINGS", 13))
5065
die("Error running query \"SHOW WARNINGS\": %s", mysql_error(mysql));
5067
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)))
5068
5060
die("Warning count is %u but didn't get any warnings",
5071
5063
append_result(ds, warn_res);
5072
mysql_free_result(warn_res);
5064
drizzle_free_result(warn_res);
5079
Run query using MySQL C API
5071
Run query using DRIZZLE C API
5082
5074
run_query_normal()
5084
command current command pointer
5085
flags flags indicating if we should SEND and/or REAP
5086
query query string to execute
5087
query_len length query string to execute
5088
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
5091
5083
static void run_query_normal(struct st_connection *cn,
5126
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
5127
5119
answer to the query sent earlier
5129
if ((counter==0) && mysql_read_query_result(mysql))
5121
if ((counter==0) && drizzle_read_query_result(drizzle))
5131
handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5132
mysql_sqlstate(mysql), ds);
5123
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5124
drizzle_sqlstate(drizzle), ds);
5153
MYSQL_FIELD *fields= mysql_fetch_fields(res);
5154
uint num_fields= mysql_num_fields(res);
5145
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
5146
uint num_fields= drizzle_num_fields(res);
5156
if (display_metadata)
5148
if (display_metadata)
5157
5149
append_metadata(ds, fields, num_fields);
5159
if (!display_result_vertically)
5160
append_table_headings(ds, fields, num_fields);
5151
if (!display_result_vertically)
5152
append_table_headings(ds, fields, num_fields);
5162
append_result(ds, res);
5154
append_result(ds, res);
5166
Need to call mysql_affected_rows() before the "new"
5158
Need to call drizzle_affected_rows() before the "new"
5167
5159
query to find the warnings
5169
5161
if (!disable_info)
5170
affected_rows= mysql_affected_rows(mysql);
5162
affected_rows= drizzle_affected_rows(drizzle);
5173
5165
Add all warnings to the result. We can't do this if we are in
5174
5166
the middle of processing results from multi-statement, because
5175
5167
this will break protocol.
5177
if (!disable_warnings && !mysql_more_results(mysql))
5169
if (!disable_warnings && !drizzle_more_results(drizzle))
5179
if (append_warnings(ds_warnings, mysql) || ds_warnings->length)
5181
dynstr_append_mem(ds, "Warnings:\n", 10);
5182
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);
5186
5178
if (!disable_info)
5187
append_info(ds, affected_rows, mysql_info(mysql));
5179
append_info(ds, affected_rows, drizzle_info(drizzle));
5192
mysql_free_result(res);
5184
drizzle_free_result(res);
5196
} while (!(err= mysql_next_result(mysql)));
5188
} while (!(err= drizzle_next_result(drizzle)));
5199
/* We got an error from mysql_next_result, maybe expected */
5200
handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5201
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);
5204
5196
assert(err == -1); /* Successful and there are no more results */
5662
5650
cur_file->lineno= 1;
5664
5652
cur_con= connections;
5665
if (!( mysql_init(&cur_con->mysql)))
5666
die("Failed in mysql_init()");
5653
if (!( drizzle_create(&cur_con->drizzle)))
5654
die("Failed in drizzle_create()");
5667
5655
if (opt_compress)
5668
mysql_options(&cur_con->mysql,MYSQL_OPT_COMPRESS,NullS);
5669
mysql_options(&cur_con->mysql, MYSQL_OPT_LOCAL_INFILE, 0);
5670
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,
5671
5659
charset_info->csname);
5672
int opt_protocol= MYSQL_PROTOCOL_TCP;
5673
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);
5674
5662
if (opt_charsets_dir)
5675
mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_DIR,
5663
drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_DIR,
5676
5664
opt_charsets_dir);
5678
5666
if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5679
5667
die("Out of memory");
5681
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,
5682
5670
opt_db, opt_port);
5684
5672
/* Use all time until exit if no explicit 'start_timer' */
5685
5673
timer_start= timer_now();
5688
Initialize $mysql_errno with -1, so we can
5676
Initialize $drizzle_errno with -1, so we can
5689
5677
- distinguish it from valid values ( >= 0 ) and
5690
5678
- detect if there was never a command sent to the server
5692
5680
var_set_errno(-1);
5694
/* Update $mysql_get_server_version to that of current connection */
5695
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);
5697
5685
if (opt_include)
5808
5796
/* Check for special property for this query */
5809
5797
display_result_vertically|= (command->type == Q_QUERY_VERTICAL);
5813
strmake(command->require_file, save_file, sizeof(save_file) - 1);
5816
run_query(cur_con, command, flags);
5801
strmake(command->require_file, save_file, sizeof(save_file) - 1);
5804
run_query(cur_con, command, flags);
5818
5806
command->last_argument= command->end;
5820
5808
/* Restore settings */
5821
display_result_vertically= old_display_result_vertically;
5809
display_result_vertically= old_display_result_vertically;
5826
5814
if (!*command->first_argument)
5836
5824
/* Remove "send" if this is first iteration */
5837
if (command->query == command->query_buf)
5838
command->query= command->first_argument;
5825
if (command->query == command->query_buf)
5826
command->query= command->first_argument;
5841
run_query() can execute a query partially, depending on the flags.
5842
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
5843
5831
the query and read the result some time later when reap instruction
5844
is given on this connection.
5832
is given on this connection.
5846
run_query(cur_con, command, QUERY_SEND_FLAG);
5834
run_query(cur_con, command, QUERY_SEND_FLAG);
5848
5836
command->last_argument= command->end;
5850
5838
case Q_REQUIRE:
5851
do_get_file_name(command, save_file, sizeof(save_file));
5839
do_get_file_name(command, save_file, sizeof(save_file));
5854
5842
do_get_errcodes(command);
5856
5844
case Q_REPLACE:
5857
do_get_replace(command);
5845
do_get_replace(command);
5859
5847
case Q_REPLACE_REGEX:
5860
5848
do_get_replace_regex(command);
5862
5850
case Q_REPLACE_COLUMN:
5863
do_get_replace_column(command);
5851
do_get_replace_column(command);
5865
5853
case Q_SAVE_MASTER_POS: do_save_master_pos(); break;
5866
5854
case Q_SYNC_WITH_MASTER: do_sync_with_master(command); break;
5867
5855
case Q_SYNC_SLAVE_WITH_MASTER:
5869
do_save_master_pos();
5870
if (*command->first_argument)
5871
select_connection(command);
5873
select_connection_name("slave");
5874
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);
5877
case Q_COMMENT: /* Ignore row */
5865
case Q_COMMENT: /* Ignore row */
5878
5866
command->last_argument= command->end;
5881
(void) mysql_ping(&cur_con->mysql);
5869
(void) drizzle_ping(&cur_con->drizzle);
5887
5875
case Q_START_TIMER:
5888
/* Overwrite possible earlier start of timer */
5889
timer_start= timer_now();
5876
/* Overwrite possible earlier start of timer */
5877
timer_start= timer_now();
5891
5879
case Q_END_TIMER:
5892
/* End timer before ending mysqltest */
5880
/* End timer before ending drizzletest */
5895
5883
case Q_CHARACTER_SET:
5896
do_set_charset(command);
5884
do_set_charset(command);
5898
5886
case Q_DISABLE_RECONNECT:
5899
set_reconnect(&cur_con->mysql, 0);
5887
set_reconnect(&cur_con->drizzle, 0);
5901
5889
case Q_ENABLE_RECONNECT:
5902
set_reconnect(&cur_con->mysql, 1);
5890
set_reconnect(&cur_con->drizzle, 1);
5904
5892
case Q_DISABLE_PARSING:
5905
5893
if (parsing_disabled == 0)
6152
6140
/* Definitions for replace result */
6154
typedef struct st_pointer_array { /* when using array-strings */
6155
TYPELIB typelib; /* Pointer to strings */
6156
uchar *str; /* Strings is here */
6157
int7 *flag; /* Flag about each var. */
6158
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;
6159
6147
} POINTER_ARRAY;
6161
6149
struct st_replace;
6162
6150
struct st_replace *init_replace(char * *from, char * *to, uint count,
6163
char * word_end_chars);
6151
char * word_end_chars);
6164
6152
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
6165
6153
void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
6166
6154
const char *from, int len);
6206
6194
for (i= 1,pos= word_end_chars ; i < 256 ; i++)
6207
6195
if (my_isspace(charset_info,i))
6209
*pos=0; /* End pointer */
6197
*pos=0; /* End pointer */
6210
6198
if (!(glob_replace= init_replace((char**) from_array.typelib.type_names,
6211
(char**) to_array.typelib.type_names,
6212
(uint) from_array.typelib.count,
6199
(char**) to_array.typelib.type_names,
6200
(uint) from_array.typelib.count,
6214
6202
die("Can't initialize replace from '%s'", command->query);
6215
6203
free_pointer_array(&from_array);
6216
6204
free_pointer_array(&to_array);
6597
6585
#define LAST_CHAR_CODE 259
6599
6587
typedef struct st_rep_set {
6600
uint *bits; /* Pointer to used sets */
6601
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6602
uint found_len; /* Best match to date */
6605
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 */
6608
6596
typedef struct st_rep_sets {
6609
uint count; /* Number of sets */
6610
uint extra; /* Extra sets in buffer */
6611
uint invisible; /* Sets not chown */
6613
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;
6617
6605
typedef struct st_found_set {
6737
6725
internal_set_bit(word_states,states);
6738
6726
if (!from[i][2] && start_states->table_offset == (uint) ~0)
6740
start_states->table_offset=i;
6741
start_states->found_offset=0;
6728
start_states->table_offset=i;
6729
start_states->found_offset=0;
6746
6734
internal_set_bit(word_states,states);
6747
6735
if (from[i][0] == '\\' && (from[i][1] == 'b' && from[i][2]))
6748
internal_set_bit(start_states,states+1);
6736
internal_set_bit(start_states,states+1);
6750
internal_set_bit(start_states,states);
6738
internal_set_bit(start_states,states);
6752
6740
for (pos=from[i], len=0; *pos ; pos++)
6754
6742
if (*pos == '\\' && *(pos+1))
6759
follow_ptr->chr = SPACE_CHAR;
6762
follow_ptr->chr = START_OF_LINE;
6765
follow_ptr->chr = END_OF_LINE;
6768
follow_ptr->chr = '\r';
6771
follow_ptr->chr = '\t';
6774
follow_ptr->chr = '\v';
6777
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;
6782
follow_ptr->chr= (uchar) *pos;
6770
follow_ptr->chr= (uchar) *pos;
6783
6771
follow_ptr->table_offset=i;
6784
6772
follow_ptr->len= ++len;
6819
6807
used_chars[follow[i].chr]=1;
6820
6808
if ((follow[i].chr == SPACE_CHAR && !follow[i+1].chr &&
6821
follow[i].len > 1) || follow[i].chr == END_OF_LINE)
6809
follow[i].len > 1) || follow[i].chr == END_OF_LINE)
6825
6813
/* Mark word_chars used if \b is in state */
6826
6814
if (used_chars[SPACE_CHAR])
6827
6815
for (pos= word_end_chars ; *pos ; pos++)
6828
used_chars[(int) (uchar) *pos] = 1;
6816
used_chars[(int) (uchar) *pos] = 1;
6830
6818
/* Handle other used characters */
6831
6819
for (chr= 0 ; chr < 256 ; chr++)
6833
6821
if (! used_chars[chr])
6834
set->next[chr]= chr ? default_state : -1;
6822
set->next[chr]= chr ? default_state : -1;
6837
new_set=make_new_set(&sets);
6838
set=sets.set+set_nr; /* if realloc */
6839
new_set->table_offset=set->table_offset;
6840
new_set->found_len=set->found_len;
6841
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;
6844
for (i= (uint) ~0 ; (i=get_next_bit(sets.set+used_sets,i)) ; )
6846
if (!follow[i].chr || follow[i].chr == chr ||
6847
(follow[i].chr == SPACE_CHAR &&
6848
(is_word_end[chr] ||
6849
(!chr && follow[i].len > 1 && ! follow[i+1].chr))) ||
6850
(follow[i].chr == END_OF_LINE && ! chr))
6852
if ((! chr || (follow[i].chr && !follow[i+1].chr)) &&
6853
follow[i].len > found_end)
6854
found_end=follow[i].len;
6855
if (chr && follow[i].chr)
6856
internal_set_bit(new_set,i+1); /* To next set */
6858
internal_set_bit(new_set,i);
6863
new_set->found_len=0; /* Set for testing if first */
6865
for (i= (uint) ~0; (i=get_next_bit(new_set,i)) ;)
6867
if ((follow[i].chr == SPACE_CHAR ||
6868
follow[i].chr == END_OF_LINE) && ! chr)
6872
if (follow[bit_nr-1].len < found_end ||
6873
(new_set->found_len &&
6874
(chr == 0 || !follow[bit_nr].chr)))
6875
internal_clear_bit(new_set,i);
6878
if (chr == 0 || !follow[bit_nr].chr)
6880
new_set->table_offset=follow[bit_nr].table_offset;
6881
if (chr || (follow[i].chr == SPACE_CHAR ||
6882
follow[i].chr == END_OF_LINE))
6883
new_set->found_offset=found_end; /* New match */
6884
new_set->found_len=found_end;
6891
set->next[chr] = find_found(found_set,
6892
new_set->table_offset,
6893
new_set->found_offset);
6894
free_last_set(&sets);
6897
set->next[chr] = find_set(&sets,new_set);
6900
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);
6924
6912
pos=from[found_set[i-1].table_offset];
6925
6913
rep_str[i].found= !bcmp((const uchar*) pos,
6926
(const uchar*) "\\^", 3) ? 2 : 1;
6914
(const uchar*) "\\^", 3) ? 2 : 1;
6927
6915
rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
6928
6916
rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
6929
6917
rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
6932
6920
for (i=0 ; i < sets.count ; i++)
6934
6922
for (j=0 ; j < 256 ; j++)
6935
if (sets.set[i].next[j] >= 0)
6936
replace[i].next[j]=replace+sets.set[i].next[j];
6938
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));
6941
6929
my_free(follow,MYF(0));
7150
7138
if (! pa->typelib.count)
7152
7140
if (!(pa->typelib.type_names=(const char **)
7153
my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
7154
(sizeof(char *)+sizeof(*pa->flag))*
7155
(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))))
7157
7145
if (!(pa->str= (uchar*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD),
7160
7148
my_free((char*) pa->typelib.type_names,MYF(0));
7163
7151
pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(uchar*)+
7165
7153
pa->flag= (int7*) (pa->typelib.type_names+pa->max_count);
7167
7155
pa->max_length=PS_MALLOC-MALLOC_OVERHEAD;