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" \
4644
4636
static void print_version(void)
4646
4638
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4647
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
4639
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
4650
4642
static void usage(void)
4652
4644
print_version();
4653
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
4645
printf("DRIZZLE AB, by Sasha, Matt, Monty & Jani\n");
4654
4646
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");
4647
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4656
4648
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4657
4649
my_print_help(my_long_options);
4658
4650
printf(" --no-defaults Don't read default options from any options file.\n");
4682
4674
if (!embedded_server_arg_count)
4684
4676
embedded_server_arg_count=1;
4685
embedded_server_args[0]= (char*) ""; /* Progname */
4677
embedded_server_args[0]= (char*) ""; /* Progname */
4687
4679
if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME))))
4688
4680
die("Failed to open file '%s'", buff);
4690
4682
while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4691
(str=fgets(argument,sizeof(argument), file)))
4683
(str=fgets(argument,sizeof(argument), file)))
4693
*(strend(str)-1)=0; /* Remove end newline */
4685
*(strend(str)-1)=0; /* Remove end newline */
4694
4686
if (!(embedded_server_args[embedded_server_arg_count]=
4695
(char*) my_strdup(str,MYF(MY_WME))))
4687
(char*) my_strdup(str,MYF(MY_WME))))
4697
4689
my_fclose(file,MYF(0));
4698
4690
die("Out of memory");
4934
4926
Values may be converted with 'replace_column'
4937
static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
4929
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);
4932
uint32_t num_fields= drizzle_num_fields(res);
4933
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
4942
4934
uint32_t *lengths;
4944
while ((row = mysql_fetch_row(res)))
4936
while ((row = drizzle_fetch_row(res)))
4947
lengths = mysql_fetch_lengths(res);
4939
lengths = drizzle_fetch_lengths(res);
4948
4940
for (i = 0; i < num_fields; i++)
4949
4941
append_field(ds, i, &fields[i],
4950
4942
(const char*)row[i], lengths[i], !row[i]);
5064
5056
through PS API we should not issue SHOW WARNINGS until
5065
5057
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)))
5059
assert(!drizzle_more_results(drizzle));
5061
if (drizzle_real_query(drizzle, "SHOW WARNINGS", 13))
5062
die("Error running query \"SHOW WARNINGS\": %s", drizzle_error(drizzle));
5064
if (!(warn_res= drizzle_store_result(drizzle)))
5073
5065
die("Warning count is %u but didn't get any warnings",
5076
5068
append_result(ds, warn_res);
5077
mysql_free_result(warn_res);
5069
drizzle_free_result(warn_res);
5084
Run query using MySQL C API
5076
Run query using DRIZZLE C API
5087
5079
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
5080
drizzle DRIZZLE handle
5081
command current command pointer
5082
flags flags indicating if we should SEND and/or REAP
5083
query query string to execute
5084
query_len length query string to execute
5085
ds output buffer where to store result form query
5096
5088
static void run_query_normal(struct st_connection *cn,
5131
When on first result set, call mysql_read_query_result to retrieve
5123
When on first result set, call drizzle_read_query_result to retrieve
5132
5124
answer to the query sent earlier
5134
if ((counter==0) && mysql_read_query_result(mysql))
5126
if ((counter==0) && drizzle_read_query_result(drizzle))
5136
handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5137
mysql_sqlstate(mysql), ds);
5128
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5129
drizzle_sqlstate(drizzle), ds);
5158
MYSQL_FIELD *fields= mysql_fetch_fields(res);
5159
uint num_fields= mysql_num_fields(res);
5150
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
5151
uint num_fields= drizzle_num_fields(res);
5161
if (display_metadata)
5153
if (display_metadata)
5162
5154
append_metadata(ds, fields, num_fields);
5164
if (!display_result_vertically)
5165
append_table_headings(ds, fields, num_fields);
5156
if (!display_result_vertically)
5157
append_table_headings(ds, fields, num_fields);
5167
append_result(ds, res);
5159
append_result(ds, res);
5171
Need to call mysql_affected_rows() before the "new"
5163
Need to call drizzle_affected_rows() before the "new"
5172
5164
query to find the warnings
5174
5166
if (!disable_info)
5175
affected_rows= mysql_affected_rows(mysql);
5167
affected_rows= drizzle_affected_rows(drizzle);
5178
5170
Add all warnings to the result. We can't do this if we are in
5179
5171
the middle of processing results from multi-statement, because
5180
5172
this will break protocol.
5182
if (!disable_warnings && !mysql_more_results(mysql))
5174
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);
5176
if (append_warnings(ds_warnings, drizzle) || ds_warnings->length)
5178
dynstr_append_mem(ds, "Warnings:\n", 10);
5179
dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
5191
5183
if (!disable_info)
5192
append_info(ds, affected_rows, mysql_info(mysql));
5184
append_info(ds, affected_rows, drizzle_info(drizzle));
5197
mysql_free_result(res);
5189
drizzle_free_result(res);
5201
} while (!(err= mysql_next_result(mysql)));
5193
} 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);
5196
/* We got an error from drizzle_next_result, maybe expected */
5197
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5198
drizzle_sqlstate(drizzle), ds);
5209
5201
assert(err == -1); /* Successful and there are no more results */
5667
5655
cur_file->lineno= 1;
5669
5657
cur_con= connections;
5670
if (!( mysql_init(&cur_con->mysql)))
5671
die("Failed in mysql_init()");
5658
if (!( drizzle_create(&cur_con->drizzle)))
5659
die("Failed in drizzle_create()");
5672
5660
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,
5661
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NullS);
5662
drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5663
drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_NAME,
5676
5664
charset_info->csname);
5677
int opt_protocol= MYSQL_PROTOCOL_TCP;
5678
mysql_options(&cur_con->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
5665
int opt_protocol= DRIZZLE_PROTOCOL_TCP;
5666
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
5679
5667
if (opt_charsets_dir)
5680
mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_DIR,
5668
drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_DIR,
5681
5669
opt_charsets_dir);
5683
5671
if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5684
5672
die("Out of memory");
5686
safe_connect(&cur_con->mysql, cur_con->name, opt_host, opt_user, opt_pass,
5674
safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5687
5675
opt_db, opt_port);
5689
5677
/* Use all time until exit if no explicit 'start_timer' */
5690
5678
timer_start= timer_now();
5693
Initialize $mysql_errno with -1, so we can
5681
Initialize $drizzle_errno with -1, so we can
5694
5682
- distinguish it from valid values ( >= 0 ) and
5695
5683
- detect if there was never a command sent to the server
5697
5685
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);
5687
/* Update $drizzle_get_server_version to that of current connection */
5688
var_set_drizzle_get_server_version(&cur_con->drizzle);
5702
5690
if (opt_include)
5813
5801
/* Check for special property for this query */
5814
5802
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);
5806
strmake(command->require_file, save_file, sizeof(save_file) - 1);
5809
run_query(cur_con, command, flags);
5823
5811
command->last_argument= command->end;
5825
5813
/* Restore settings */
5826
display_result_vertically= old_display_result_vertically;
5814
display_result_vertically= old_display_result_vertically;
5831
5819
if (!*command->first_argument)
5841
5829
/* Remove "send" if this is first iteration */
5842
if (command->query == command->query_buf)
5843
command->query= command->first_argument;
5830
if (command->query == command->query_buf)
5831
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
5834
run_query() can execute a query partially, depending on the flags.
5835
QUERY_SEND_FLAG flag without QUERY_REAP_FLAG tells it to just send
5848
5836
the query and read the result some time later when reap instruction
5849
is given on this connection.
5837
is given on this connection.
5851
run_query(cur_con, command, QUERY_SEND_FLAG);
5839
run_query(cur_con, command, QUERY_SEND_FLAG);
5853
5841
command->last_argument= command->end;
5855
5843
case Q_REQUIRE:
5856
do_get_file_name(command, save_file, sizeof(save_file));
5844
do_get_file_name(command, save_file, sizeof(save_file));
5859
5847
do_get_errcodes(command);
5861
5849
case Q_REPLACE:
5862
do_get_replace(command);
5850
do_get_replace(command);
5864
5852
case Q_REPLACE_REGEX:
5865
5853
do_get_replace_regex(command);
5867
5855
case Q_REPLACE_COLUMN:
5868
do_get_replace_column(command);
5856
do_get_replace_column(command);
5870
5858
case Q_SAVE_MASTER_POS: do_save_master_pos(); break;
5871
5859
case Q_SYNC_WITH_MASTER: do_sync_with_master(command); break;
5872
5860
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);
5862
do_save_master_pos();
5863
if (*command->first_argument)
5864
select_connection(command);
5866
select_connection_name("slave");
5867
do_sync_with_master2(0);
5882
case Q_COMMENT: /* Ignore row */
5870
case Q_COMMENT: /* Ignore row */
5883
5871
command->last_argument= command->end;
5886
(void) mysql_ping(&cur_con->mysql);
5874
(void) drizzle_ping(&cur_con->drizzle);
5892
5880
case Q_START_TIMER:
5893
/* Overwrite possible earlier start of timer */
5894
timer_start= timer_now();
5881
/* Overwrite possible earlier start of timer */
5882
timer_start= timer_now();
5896
5884
case Q_END_TIMER:
5897
/* End timer before ending mysqltest */
5885
/* End timer before ending drizzletest */
5900
5888
case Q_CHARACTER_SET:
5901
do_set_charset(command);
5889
do_set_charset(command);
5903
5891
case Q_DISABLE_RECONNECT:
5904
set_reconnect(&cur_con->mysql, 0);
5892
set_reconnect(&cur_con->drizzle, 0);
5906
5894
case Q_ENABLE_RECONNECT:
5907
set_reconnect(&cur_con->mysql, 1);
5895
set_reconnect(&cur_con->drizzle, 1);
5909
5897
case Q_DISABLE_PARSING:
5910
5898
if (parsing_disabled == 0)
6157
6145
/* 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;
6147
typedef struct st_pointer_array { /* when using array-strings */
6148
TYPELIB typelib; /* Pointer to strings */
6149
uchar *str; /* Strings is here */
6150
int7 *flag; /* Flag about each var. */
6151
uint array_allocs,max_count,length,max_length;
6164
6152
} POINTER_ARRAY;
6166
6154
struct st_replace;
6167
6155
struct st_replace *init_replace(char * *from, char * *to, uint count,
6168
char * word_end_chars);
6156
char * word_end_chars);
6169
6157
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
6170
6158
void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
6171
6159
const char *from, int len);
6211
6199
for (i= 1,pos= word_end_chars ; i < 256 ; i++)
6212
6200
if (my_isspace(charset_info,i))
6214
*pos=0; /* End pointer */
6202
*pos=0; /* End pointer */
6215
6203
if (!(glob_replace= init_replace((char**) from_array.typelib.type_names,
6216
(char**) to_array.typelib.type_names,
6217
(uint) from_array.typelib.count,
6204
(char**) to_array.typelib.type_names,
6205
(uint) from_array.typelib.count,
6219
6207
die("Can't initialize replace from '%s'", command->query);
6220
6208
free_pointer_array(&from_array);
6221
6209
free_pointer_array(&to_array);
6602
6590
#define LAST_CHAR_CODE 259
6604
6592
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 */
6593
uint *bits; /* Pointer to used sets */
6594
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6595
uint found_len; /* Best match to date */
6598
uint size_of_bits; /* For convinience */
6613
6601
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;
6602
uint count; /* Number of sets */
6603
uint extra; /* Extra sets in buffer */
6604
uint invisible; /* Sets not chown */
6606
REP_SET *set,*set_buffer;
6622
6610
typedef struct st_found_set {
6742
6730
internal_set_bit(word_states,states);
6743
6731
if (!from[i][2] && start_states->table_offset == (uint) ~0)
6745
start_states->table_offset=i;
6746
start_states->found_offset=0;
6733
start_states->table_offset=i;
6734
start_states->found_offset=0;
6751
6739
internal_set_bit(word_states,states);
6752
6740
if (from[i][0] == '\\' && (from[i][1] == 'b' && from[i][2]))
6753
internal_set_bit(start_states,states+1);
6741
internal_set_bit(start_states,states+1);
6755
internal_set_bit(start_states,states);
6743
internal_set_bit(start_states,states);
6757
6745
for (pos=from[i], len=0; *pos ; pos++)
6759
6747
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;
6752
follow_ptr->chr = SPACE_CHAR;
6755
follow_ptr->chr = START_OF_LINE;
6758
follow_ptr->chr = END_OF_LINE;
6761
follow_ptr->chr = '\r';
6764
follow_ptr->chr = '\t';
6767
follow_ptr->chr = '\v';
6770
follow_ptr->chr = (uchar) *pos;
6787
follow_ptr->chr= (uchar) *pos;
6775
follow_ptr->chr= (uchar) *pos;
6788
6776
follow_ptr->table_offset=i;
6789
6777
follow_ptr->len= ++len;
6824
6812
used_chars[follow[i].chr]=1;
6825
6813
if ((follow[i].chr == SPACE_CHAR && !follow[i+1].chr &&
6826
follow[i].len > 1) || follow[i].chr == END_OF_LINE)
6814
follow[i].len > 1) || follow[i].chr == END_OF_LINE)
6830
6818
/* Mark word_chars used if \b is in state */
6831
6819
if (used_chars[SPACE_CHAR])
6832
6820
for (pos= word_end_chars ; *pos ; pos++)
6833
used_chars[(int) (uchar) *pos] = 1;
6821
used_chars[(int) (uchar) *pos] = 1;
6835
6823
/* Handle other used characters */
6836
6824
for (chr= 0 ; chr < 256 ; chr++)
6838
6826
if (! used_chars[chr])
6839
set->next[chr]= chr ? default_state : -1;
6827
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;
6830
new_set=make_new_set(&sets);
6831
set=sets.set+set_nr; /* if realloc */
6832
new_set->table_offset=set->table_offset;
6833
new_set->found_len=set->found_len;
6834
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);
6837
for (i= (uint) ~0 ; (i=get_next_bit(sets.set+used_sets,i)) ; )
6839
if (!follow[i].chr || follow[i].chr == chr ||
6840
(follow[i].chr == SPACE_CHAR &&
6841
(is_word_end[chr] ||
6842
(!chr && follow[i].len > 1 && ! follow[i+1].chr))) ||
6843
(follow[i].chr == END_OF_LINE && ! chr))
6845
if ((! chr || (follow[i].chr && !follow[i+1].chr)) &&
6846
follow[i].len > found_end)
6847
found_end=follow[i].len;
6848
if (chr && follow[i].chr)
6849
internal_set_bit(new_set,i+1); /* To next set */
6851
internal_set_bit(new_set,i);
6856
new_set->found_len=0; /* Set for testing if first */
6858
for (i= (uint) ~0; (i=get_next_bit(new_set,i)) ;)
6860
if ((follow[i].chr == SPACE_CHAR ||
6861
follow[i].chr == END_OF_LINE) && ! chr)
6865
if (follow[bit_nr-1].len < found_end ||
6866
(new_set->found_len &&
6867
(chr == 0 || !follow[bit_nr].chr)))
6868
internal_clear_bit(new_set,i);
6871
if (chr == 0 || !follow[bit_nr].chr)
6873
new_set->table_offset=follow[bit_nr].table_offset;
6874
if (chr || (follow[i].chr == SPACE_CHAR ||
6875
follow[i].chr == END_OF_LINE))
6876
new_set->found_offset=found_end; /* New match */
6877
new_set->found_len=found_end;
6884
set->next[chr] = find_found(found_set,
6885
new_set->table_offset,
6886
new_set->found_offset);
6887
free_last_set(&sets);
6890
set->next[chr] = find_set(&sets,new_set);
6893
set->next[chr] = find_set(&sets,new_set);
6929
6917
pos=from[found_set[i-1].table_offset];
6930
6918
rep_str[i].found= !bcmp((const uchar*) pos,
6931
(const uchar*) "\\^", 3) ? 2 : 1;
6919
(const uchar*) "\\^", 3) ? 2 : 1;
6932
6920
rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
6933
6921
rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
6934
6922
rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
6937
6925
for (i=0 ; i < sets.count ; i++)
6939
6927
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));
6928
if (sets.set[i].next[j] >= 0)
6929
replace[i].next[j]=replace+sets.set[i].next[j];
6931
replace[i].next[j]=(REPLACE*) (rep_str+(-sets.set[i].next[j]-1));
6946
6934
my_free(follow,MYF(0));
7155
7143
if (! pa->typelib.count)
7157
7145
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))))
7146
my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
7147
(sizeof(char *)+sizeof(*pa->flag))*
7148
(sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
7162
7150
if (!(pa->str= (uchar*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD),
7165
7153
my_free((char*) pa->typelib.type_names,MYF(0));
7168
7156
pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(uchar*)+
7170
7158
pa->flag= (int7*) (pa->typelib.type_names+pa->max_count);
7172
7160
pa->max_length=PS_MALLOC-MALLOC_OVERHEAD;