187
176
struct st_connection
190
179
/* Used when creating views and sp, to avoid implicit commit */
180
DRIZZLE *util_drizzle;
194
183
struct st_connection connections[128];
195
184
struct st_connection* cur_con= NULL, *next_con, *connections_end;
198
List of commands in mysqltest
187
List of commands in drizzletest
199
188
Must match the "command_names" array
200
189
Add new commands before Q_UNKNOWN!
202
191
enum enum_commands {
203
192
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,
193
Q_CONNECT, Q_SLEEP, Q_REAL_SLEEP,
195
Q_SOURCE, Q_DISCONNECT,
197
Q_WHILE, Q_END_BLOCK,
199
Q_REQUIRE, Q_SAVE_MASTER_POS,
211
200
Q_SYNC_WITH_MASTER,
212
201
Q_SYNC_SLAVE_WITH_MASTER,
215
Q_DIRTY_CLOSE, Q_REPLACE, Q_REPLACE_COLUMN,
204
Q_DIRTY_CLOSE, Q_REPLACE, Q_REPLACE_COLUMN,
218
207
Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG,
219
208
Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG,
369
358
TYPELIB command_typelib= {array_elements(command_names),"",
372
361
DYNAMIC_STRING ds_res, ds_progress, ds_warning_messages;
374
363
char builtin_echo[FN_REFLEN];
376
365
void die(const char *fmt, ...)
377
ATTRIBUTE_FORMAT(printf, 1, 2);
366
__attribute__((format(printf, 1, 2)));
378
367
void abort_not_supported_test(const char *fmt, ...)
379
ATTRIBUTE_FORMAT(printf, 1, 2);
368
__attribute__((format(printf, 1, 2)));
380
369
void verbose_msg(const char *fmt, ...)
381
ATTRIBUTE_FORMAT(printf, 1, 2);
370
__attribute__((format(printf, 1, 2)));
382
371
void warning_msg(const char *fmt, ...)
383
ATTRIBUTE_FORMAT(printf, 1, 2);
372
__attribute__((format(printf, 1, 2)));
384
373
void log_msg(const char *fmt, ...)
385
ATTRIBUTE_FORMAT(printf, 1, 2);
374
__attribute__((format(printf, 1, 2)));
387
376
VAR* var_from_env(const char *, const char *);
388
377
VAR* var_init(VAR* v, const char *name, int name_len, const char *val,
522
dynstr_append_mem(query_eval, p, 1);
511
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);
515
if (!(v= var_get(p, &p, 0, 0)))
516
die("Bad variable in eval");
517
dynstr_append_mem(query_eval, v->str_val, v->str_val_len);
536
dynstr_append_mem(query_eval, p, 1);
525
dynstr_append_mem(query_eval, p, 1);
538
527
else if (next_c == '\\' || next_c == '$' || next_c == '"')
540
529
/* Set escaped only if next char is \, " or $ */
543
532
if (pass_through_escape_chars)
570
mysql - connection to use
559
drizzle - connection to use
571
560
query - query to run
575
static void show_query(MYSQL* mysql, const char* query)
564
static void show_query(DRIZZLE *drizzle, const char* query)
583
if (mysql_query(mysql, query))
572
if (drizzle_query(drizzle, query))
585
574
log_msg("Error running query '%s': %d %s",
586
query, mysql_errno(mysql), mysql_error(mysql));
575
query, drizzle_errno(drizzle), drizzle_error(drizzle));
590
if ((res= mysql_store_result(mysql)) == NULL)
579
if ((res= drizzle_store_result(drizzle)) == NULL)
592
581
/* No result set returned */
599
588
unsigned int row_num= 0;
600
unsigned int num_fields= mysql_num_fields(res);
601
MYSQL_FIELD *fields= mysql_fetch_fields(res);
589
unsigned int num_fields= drizzle_num_fields(res);
590
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
603
592
fprintf(stderr, "=== %s ===\n", query);
604
while ((row= mysql_fetch_row(res)))
593
while ((row= drizzle_fetch_row(res)))
606
uint32_t *lengths= mysql_fetch_lengths(res);
595
uint32_t *lengths= drizzle_fetch_lengths(res);
609
598
fprintf(stderr, "---- %d. ----\n", row_num);
635
624
show_warnings_before_error
636
mysql - connection to use
625
drizzle - connection to use
640
static void show_warnings_before_error(MYSQL* mysql)
629
static void show_warnings_before_error(DRIZZLE *drizzle)
643
632
const char* query= "SHOW WARNINGS";
649
if (mysql_query(mysql, query))
638
if (drizzle_query(drizzle, query))
651
640
log_msg("Error running query '%s': %d %s",
652
query, mysql_errno(mysql), mysql_error(mysql));
641
query, drizzle_errno(drizzle), drizzle_error(drizzle));
656
if ((res= mysql_store_result(mysql)) == NULL)
645
if ((res= drizzle_store_result(drizzle)) == NULL)
658
647
/* No result set returned */
662
if (mysql_num_rows(res) <= 1)
651
if (drizzle_num_rows(res) <= 1)
664
653
/* Don't display the last row, it's "last error" */
669
658
unsigned int row_num= 0;
670
unsigned int num_fields= mysql_num_fields(res);
659
unsigned int num_fields= drizzle_num_fields(res);
672
661
fprintf(stderr, "\nWarnings from just before the error:\n");
673
while ((row= mysql_fetch_row(res)))
662
while ((row= drizzle_fetch_row(res)))
676
uint32_t *lengths= mysql_fetch_lengths(res);
665
uint32_t *lengths= drizzle_fetch_lengths(res);
678
if (++row_num >= mysql_num_rows(res))
667
if (++row_num >= drizzle_num_rows(res))
680
669
/* Don't display the last row, it's "last error" */
1839
1828
init_dynamic_string(&ds_query, 0, (end - query) + 32, 256);
1840
1829
do_eval(&ds_query, query, end, false);
1842
if (mysql_real_query(mysql, ds_query.str, ds_query.length))
1831
if (drizzle_real_query(drizzle, ds_query.str, ds_query.length))
1843
1832
die("Error running query '%s': %d %s", ds_query.str,
1844
mysql_errno(mysql), mysql_error(mysql));
1845
if (!(res= mysql_store_result(mysql)))
1833
drizzle_errno(drizzle), drizzle_error(drizzle));
1834
if (!(res= drizzle_store_result(drizzle)))
1846
1835
die("Query '%s' didn't return a result set", ds_query.str);
1847
1836
dynstr_free(&ds_query);
1849
if ((row= mysql_fetch_row(res)) && row[0])
1838
if ((row= drizzle_fetch_row(res)) && row[0])
1852
1841
Concatenate all fields in the first row with tab in between
1934
1923
die("Mismatched \"'s around query '%s'", ds_query.str);
1936
1925
/* Run the query */
1937
if (mysql_real_query(mysql, ds_query.str, ds_query.length))
1926
if (drizzle_real_query(drizzle, ds_query.str, ds_query.length))
1938
1927
die("Error running query '%s': %d %s", ds_query.str,
1939
mysql_errno(mysql), mysql_error(mysql));
1940
if (!(res= mysql_store_result(mysql)))
1928
drizzle_errno(drizzle), drizzle_error(drizzle));
1929
if (!(res= drizzle_store_result(drizzle)))
1941
1930
die("Query '%s' didn't return a result set", ds_query.str);
1944
1933
/* Find column number from the given column name */
1946
uint num_fields= mysql_num_fields(res);
1947
MYSQL_FIELD *fields= mysql_fetch_fields(res);
1935
uint num_fields= drizzle_num_fields(res);
1936
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
1949
1938
for (i= 0; i < num_fields; i++)
3069
3058
do_wait_for_slave_to_stop(struct st_command *c __attribute__((unused)))
3071
3060
static int SLAVE_POLL_INTERVAL= 300000;
3072
MYSQL* mysql = &cur_con->mysql;
3061
DRIZZLE *drizzle= &cur_con->drizzle;
3075
MYSQL_RES *res= NULL;
3064
DRIZZLE_RES *res= NULL;
3079
if (mysql_query(mysql,"show status like 'Slave_running'") ||
3080
!(res=mysql_store_result(mysql)))
3068
if (drizzle_query(drizzle,"show status like 'Slave_running'") ||
3069
!(res=drizzle_store_result(drizzle)))
3081
3070
die("Query failed while probing slave for stop: %s",
3082
mysql_error(mysql));
3083
if (!(row=mysql_fetch_row(res)) || !row[1])
3071
drizzle_error(drizzle));
3072
if (!(row=drizzle_fetch_row(res)) || !row[1])
3085
mysql_free_result(res);
3074
drizzle_free_result(res);
3086
3075
die("Strange result from query while probing slave for stop");
3088
3077
done = !strcmp(row[1],"OFF");
3089
mysql_free_result(res);
3078
drizzle_free_result(res);
3092
3081
my_sleep(SLAVE_POLL_INTERVAL);
3107
3096
die("Calling 'sync_with_master' without calling 'save_master_pos'");
3109
3098
sprintf(query_buf, "select master_pos_wait('%s', %ld)", master_pos.file,
3110
master_pos.pos + offset);
3099
master_pos.pos + offset);
3112
3101
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));
3103
if (drizzle_query(drizzle, query_buf))
3104
die("failed in '%s': %d: %s", query_buf, drizzle_errno(drizzle),
3105
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)))
3107
if (!(res= drizzle_store_result(drizzle)))
3108
die("drizzle_store_result() returned NULL for '%s'", query_buf);
3109
if (!(row= drizzle_fetch_row(res)))
3122
mysql_free_result(res);
3111
drizzle_free_result(res);
3123
3112
die("empty result in %s", query_buf);
3166
3155
when ndb binlog is on, this call will wait until last updated epoch
3167
(locally in the mysqld) has been received into the binlog
3156
(locally in the drizzled) has been received into the binlog
3169
3158
static int do_save_master_pos(void)
3173
MYSQL *mysql = &cur_con->mysql;
3162
DRIZZLE *drizzle= &cur_con->drizzle;
3174
3163
const char *query;
3177
if (mysql_query(mysql, query= "show master status"))
3166
if (drizzle_query(drizzle, query= "show master status"))
3178
3167
die("failed in 'show master status': %d %s",
3179
mysql_errno(mysql), mysql_error(mysql));
3168
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)))
3170
if (!(res = drizzle_store_result(drizzle)))
3171
die("drizzle_store_result() retuned NULL for '%s'", query);
3172
if (!(row = drizzle_fetch_row(res)))
3184
3173
die("empty result in show master status");
3185
3174
strnmov(master_pos.file, row[0], sizeof(master_pos.file)-1);
3186
3175
master_pos.pos = strtoul(row[1], (char**) 0, 10);
3187
mysql_free_result(res);
3176
drizzle_free_result(res);
3694
3669
on protocol/connection type
3697
if ((mysql_errno(mysql) == CR_CONN_HOST_ERROR ||
3698
mysql_errno(mysql) == CR_CONNECTION_ERROR) &&
3672
if ((drizzle_errno(drizzle) == CR_CONN_HOST_ERROR ||
3673
drizzle_errno(drizzle) == CR_CONNECTION_ERROR) &&
3699
3674
failed_attempts < opt_max_connect_retries)
3701
3676
verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts,
3702
opt_max_connect_retries, mysql_errno(mysql),
3703
mysql_error(mysql));
3677
opt_max_connect_retries, drizzle_errno(drizzle),
3678
drizzle_error(drizzle));
3704
3679
my_sleep(connection_retry_sleep);
3708
3683
if (failed_attempts > 0)
3709
3684
die("Could not open connection '%s' after %d attempts: %d %s", name,
3710
failed_attempts, mysql_errno(mysql), mysql_error(mysql));
3685
failed_attempts, drizzle_errno(drizzle), drizzle_error(drizzle));
3712
3687
die("Could not open connection '%s': %d %s", name,
3713
mysql_errno(mysql), mysql_error(mysql));
3688
drizzle_errno(drizzle), drizzle_error(drizzle));
3715
3690
failed_attempts++;
3775
3750
dynstr_append_mem(ds, delimiter, delimiter_length);
3776
3751
dynstr_append_mem(ds, "\n", 1);
3778
if (!mysql_real_connect(con, host, user, pass, db, port, 0,
3753
if (!drizzle_connect(con, host, user, pass, db, port, 0,
3779
3754
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);
3756
var_set_errno(drizzle_errno(con));
3757
handle_error(command, drizzle_errno(con), drizzle_error(con),
3758
drizzle_sqlstate(con), ds);
3784
3759
return 0; /* Not connected */
3913
3888
#ifdef EMBEDDED_LIBRARY
3914
3889
con_slot->query_done= 1;
3916
if (!mysql_init(&con_slot->mysql))
3917
die("Failed on mysql_init()");
3891
if (!drizzle_create(&con_slot->drizzle))
3892
die("Failed on drizzle_create()");
3918
3893
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,
3894
drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_COMPRESS, NullS);
3895
drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
3896
drizzle_options(&con_slot->drizzle, DRIZZLE_SET_CHARSET_NAME,
3922
3897
charset_info->csname);
3923
int opt_protocol= MYSQL_PROTOCOL_TCP;
3924
mysql_options(&con_slot->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
3898
int opt_protocol= DRIZZLE_PROTOCOL_TCP;
3899
drizzle_options(&con_slot->drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
3925
3900
if (opt_charsets_dir)
3926
mysql_options(&con_slot->mysql, MYSQL_SET_CHARSET_DIR,
3901
drizzle_options(&con_slot->drizzle, DRIZZLE_SET_CHARSET_DIR,
3927
3902
opt_charsets_dir);
3929
3904
/* Use default db name */
4294
4269
/* completed before we pass buf_end */
4295
4270
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)
4277
for (i= 1; i < charlen; i++)
4279
if (feof(cur_file->file))
4281
c= my_getc(cur_file->file);
4284
if (! my_ismbchar(charset_info, mb_start, p))
4286
/* It was not a multiline char, push back the characters */
4287
/* We leave first 'c', i.e. pretend it was a normal char */
4288
while (p > mb_start)
4322
4297
die("The input buffer is too small for this query.x\n" \
4642
#include <help_start.h>
4644
4617
static void print_version(void)
4646
4619
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4647
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
4620
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
4650
4623
static void usage(void)
4652
4625
print_version();
4653
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
4626
printf("DRIZZLE AB, by Sasha, Matt, Monty & Jani\n");
4654
4627
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");
4628
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4656
4629
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4657
4630
my_print_help(my_long_options);
4658
4631
printf(" --no-defaults Don't read default options from any options file.\n");
4659
4632
my_print_variables(my_long_options);
4662
#include <help_end.h>
4666
4636
Read arguments for embedded server and put them into
4667
4637
embedded_server_args[]
4682
4652
if (!embedded_server_arg_count)
4684
4654
embedded_server_arg_count=1;
4685
embedded_server_args[0]= (char*) ""; /* Progname */
4655
embedded_server_args[0]= (char*) ""; /* Progname */
4687
4657
if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME))))
4688
4658
die("Failed to open file '%s'", buff);
4690
4660
while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4691
(str=fgets(argument,sizeof(argument), file)))
4661
(str=fgets(argument,sizeof(argument), file)))
4693
*(strend(str)-1)=0; /* Remove end newline */
4663
*(strend(str)-1)=0; /* Remove end newline */
4694
4664
if (!(embedded_server_args[embedded_server_arg_count]=
4695
(char*) my_strdup(str,MYF(MY_WME))))
4665
(char*) my_strdup(str,MYF(MY_WME))))
4697
4667
my_fclose(file,MYF(0));
4698
4668
die("Out of memory");
4934
4904
Values may be converted with 'replace_column'
4937
static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
4907
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);
4910
uint32_t num_fields= drizzle_num_fields(res);
4911
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
4942
4912
uint32_t *lengths;
4944
while ((row = mysql_fetch_row(res)))
4914
while ((row = drizzle_fetch_row(res)))
4947
lengths = mysql_fetch_lengths(res);
4917
lengths = drizzle_fetch_lengths(res);
4948
4918
for (i = 0; i < num_fields; i++)
4949
4919
append_field(ds, i, &fields[i],
4950
4920
(const char*)row[i], lengths[i], !row[i]);
5064
5034
through PS API we should not issue SHOW WARNINGS until
5065
5035
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)))
5037
assert(!drizzle_more_results(drizzle));
5039
if (drizzle_real_query(drizzle, "SHOW WARNINGS", 13))
5040
die("Error running query \"SHOW WARNINGS\": %s", drizzle_error(drizzle));
5042
if (!(warn_res= drizzle_store_result(drizzle)))
5073
5043
die("Warning count is %u but didn't get any warnings",
5076
5046
append_result(ds, warn_res);
5077
mysql_free_result(warn_res);
5047
drizzle_free_result(warn_res);
5084
Run query using MySQL C API
5054
Run query using DRIZZLE C API
5087
5057
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
5058
drizzle DRIZZLE handle
5059
command current command pointer
5060
flags flags indicating if we should SEND and/or REAP
5061
query query string to execute
5062
query_len length query string to execute
5063
ds output buffer where to store result form query
5096
5066
static void run_query_normal(struct st_connection *cn,
5158
MYSQL_FIELD *fields= mysql_fetch_fields(res);
5159
uint num_fields= mysql_num_fields(res);
5128
DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
5129
uint num_fields= drizzle_num_fields(res);
5161
if (display_metadata)
5131
if (display_metadata)
5162
5132
append_metadata(ds, fields, num_fields);
5164
if (!display_result_vertically)
5165
append_table_headings(ds, fields, num_fields);
5134
if (!display_result_vertically)
5135
append_table_headings(ds, fields, num_fields);
5167
append_result(ds, res);
5137
append_result(ds, res);
5171
Need to call mysql_affected_rows() before the "new"
5141
Need to call drizzle_affected_rows() before the "new"
5172
5142
query to find the warnings
5174
5144
if (!disable_info)
5175
affected_rows= mysql_affected_rows(mysql);
5145
affected_rows= drizzle_affected_rows(drizzle);
5178
5148
Add all warnings to the result. We can't do this if we are in
5179
5149
the middle of processing results from multi-statement, because
5180
5150
this will break protocol.
5182
if (!disable_warnings && !mysql_more_results(mysql))
5152
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);
5154
if (append_warnings(ds_warnings, drizzle) || ds_warnings->length)
5156
dynstr_append_mem(ds, "Warnings:\n", 10);
5157
dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
5191
5161
if (!disable_info)
5192
append_info(ds, affected_rows, mysql_info(mysql));
5162
append_info(ds, affected_rows, drizzle_info(drizzle));
5197
mysql_free_result(res);
5167
drizzle_free_result(res);
5201
} while (!(err= mysql_next_result(mysql)));
5171
} 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);
5174
/* We got an error from drizzle_next_result, maybe expected */
5175
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5176
drizzle_sqlstate(drizzle), ds);
5209
5179
assert(err == -1); /* Successful and there are no more results */
5667
5633
cur_file->lineno= 1;
5669
5635
cur_con= connections;
5670
if (!( mysql_init(&cur_con->mysql)))
5671
die("Failed in mysql_init()");
5636
if (!( drizzle_create(&cur_con->drizzle)))
5637
die("Failed in drizzle_create()");
5672
5638
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,
5639
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NullS);
5640
drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5641
drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_NAME,
5676
5642
charset_info->csname);
5677
int opt_protocol= MYSQL_PROTOCOL_TCP;
5678
mysql_options(&cur_con->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
5643
int opt_protocol= DRIZZLE_PROTOCOL_TCP;
5644
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
5679
5645
if (opt_charsets_dir)
5680
mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_DIR,
5646
drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_DIR,
5681
5647
opt_charsets_dir);
5683
5649
if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5684
5650
die("Out of memory");
5686
safe_connect(&cur_con->mysql, cur_con->name, opt_host, opt_user, opt_pass,
5652
safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5687
5653
opt_db, opt_port);
5689
5655
/* Use all time until exit if no explicit 'start_timer' */
5690
5656
timer_start= timer_now();
5693
Initialize $mysql_errno with -1, so we can
5659
Initialize $drizzle_errno with -1, so we can
5694
5660
- distinguish it from valid values ( >= 0 ) and
5695
5661
- detect if there was never a command sent to the server
5697
5663
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);
5665
/* Update $drizzle_get_server_version to that of current connection */
5666
var_set_drizzle_get_server_version(&cur_con->drizzle);
5702
5668
if (opt_include)
5841
5807
/* Remove "send" if this is first iteration */
5842
if (command->query == command->query_buf)
5843
command->query= command->first_argument;
5808
if (command->query == command->query_buf)
5809
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
5812
run_query() can execute a query partially, depending on the flags.
5813
QUERY_SEND_FLAG flag without QUERY_REAP_FLAG tells it to just send
5848
5814
the query and read the result some time later when reap instruction
5849
is given on this connection.
5815
is given on this connection.
5851
run_query(cur_con, command, QUERY_SEND_FLAG);
5817
run_query(cur_con, command, QUERY_SEND_FLAG);
5853
5819
command->last_argument= command->end;
5855
5821
case Q_REQUIRE:
5856
do_get_file_name(command, save_file, sizeof(save_file));
5822
do_get_file_name(command, save_file, sizeof(save_file));
5859
5825
do_get_errcodes(command);
5861
5827
case Q_REPLACE:
5862
do_get_replace(command);
5828
do_get_replace(command);
5864
5830
case Q_REPLACE_REGEX:
5865
5831
do_get_replace_regex(command);
5867
5833
case Q_REPLACE_COLUMN:
5868
do_get_replace_column(command);
5834
do_get_replace_column(command);
5870
5836
case Q_SAVE_MASTER_POS: do_save_master_pos(); break;
5871
5837
case Q_SYNC_WITH_MASTER: do_sync_with_master(command); break;
5872
5838
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);
5840
do_save_master_pos();
5841
if (*command->first_argument)
5842
select_connection(command);
5844
select_connection_name("slave");
5845
do_sync_with_master2(0);
5882
case Q_COMMENT: /* Ignore row */
5848
case Q_COMMENT: /* Ignore row */
5883
5849
command->last_argument= command->end;
5886
(void) mysql_ping(&cur_con->mysql);
5852
(void) drizzle_ping(&cur_con->drizzle);
5892
5858
case Q_START_TIMER:
5893
/* Overwrite possible earlier start of timer */
5894
timer_start= timer_now();
5859
/* Overwrite possible earlier start of timer */
5860
timer_start= timer_now();
5896
5862
case Q_END_TIMER:
5897
/* End timer before ending mysqltest */
5863
/* End timer before ending drizzletest */
5900
5866
case Q_CHARACTER_SET:
5901
do_set_charset(command);
5867
do_set_charset(command);
5903
5869
case Q_DISABLE_RECONNECT:
5904
set_reconnect(&cur_con->mysql, 0);
5870
set_reconnect(&cur_con->drizzle, 0);
5906
5872
case Q_ENABLE_RECONNECT:
5907
set_reconnect(&cur_con->mysql, 1);
5873
set_reconnect(&cur_con->drizzle, 1);
5909
5875
case Q_DISABLE_PARSING:
5910
5876
if (parsing_disabled == 0)
6157
6123
/* 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;
6125
typedef struct st_pointer_array { /* when using array-strings */
6126
TYPELIB typelib; /* Pointer to strings */
6127
uchar *str; /* Strings is here */
6128
int7 *flag; /* Flag about each var. */
6129
uint array_allocs,max_count,length,max_length;
6164
6130
} POINTER_ARRAY;
6166
6132
struct st_replace;
6167
6133
struct st_replace *init_replace(char * *from, char * *to, uint count,
6168
char * word_end_chars);
6134
char * word_end_chars);
6169
6135
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
6170
6136
void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
6171
6137
const char *from, int len);
6602
6568
#define LAST_CHAR_CODE 259
6604
6570
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 */
6571
uint *bits; /* Pointer to used sets */
6572
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6573
uint found_len; /* Best match to date */
6576
uint size_of_bits; /* For convinience */
6613
6579
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;
6580
uint count; /* Number of sets */
6581
uint extra; /* Extra sets in buffer */
6582
uint invisible; /* Sets not chown */
6584
REP_SET *set,*set_buffer;
6622
6588
typedef struct st_found_set {
6742
6708
internal_set_bit(word_states,states);
6743
6709
if (!from[i][2] && start_states->table_offset == (uint) ~0)
6745
start_states->table_offset=i;
6746
start_states->found_offset=0;
6711
start_states->table_offset=i;
6712
start_states->found_offset=0;
6751
6717
internal_set_bit(word_states,states);
6752
6718
if (from[i][0] == '\\' && (from[i][1] == 'b' && from[i][2]))
6753
internal_set_bit(start_states,states+1);
6719
internal_set_bit(start_states,states+1);
6755
internal_set_bit(start_states,states);
6721
internal_set_bit(start_states,states);
6757
6723
for (pos=from[i], len=0; *pos ; pos++)
6759
6725
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;
6730
follow_ptr->chr = SPACE_CHAR;
6733
follow_ptr->chr = START_OF_LINE;
6736
follow_ptr->chr = END_OF_LINE;
6739
follow_ptr->chr = '\r';
6742
follow_ptr->chr = '\t';
6745
follow_ptr->chr = '\v';
6748
follow_ptr->chr = (uchar) *pos;
6787
follow_ptr->chr= (uchar) *pos;
6753
follow_ptr->chr= (uchar) *pos;
6788
6754
follow_ptr->table_offset=i;
6789
6755
follow_ptr->len= ++len;
6809
6775
if (!follow[i].chr)
6811
if (! default_state)
6812
default_state= find_found(found_set,set->table_offset,
6813
set->found_offset+1);
6777
if (! default_state)
6778
default_state= find_found(found_set,set->table_offset,
6779
set->found_offset+1);
6816
copy_bits(sets.set+used_sets,set); /* Save set for changes */
6782
copy_bits(sets.set+used_sets,set); /* Save set for changes */
6817
6783
if (!default_state)
6818
or_bits(sets.set+used_sets,sets.set); /* Can restart from start */
6784
or_bits(sets.set+used_sets,sets.set); /* Can restart from start */
6820
6786
/* Find all chars that follows current sets */
6821
bzero((char*) used_chars,sizeof(used_chars));
6787
memset((char*) used_chars, 0, sizeof(used_chars));
6822
6788
for (i= (uint) ~0; (i=get_next_bit(sets.set+used_sets,i)) ;)
6824
6790
used_chars[follow[i].chr]=1;
6825
6791
if ((follow[i].chr == SPACE_CHAR && !follow[i+1].chr &&
6826
follow[i].len > 1) || follow[i].chr == END_OF_LINE)
6792
follow[i].len > 1) || follow[i].chr == END_OF_LINE)
6830
6796
/* Mark word_chars used if \b is in state */
6831
6797
if (used_chars[SPACE_CHAR])
6832
6798
for (pos= word_end_chars ; *pos ; pos++)
6833
used_chars[(int) (uchar) *pos] = 1;
6799
used_chars[(int) (uchar) *pos] = 1;
6835
6801
/* Handle other used characters */
6836
6802
for (chr= 0 ; chr < 256 ; chr++)
6838
6804
if (! used_chars[chr])
6839
set->next[chr]= chr ? default_state : -1;
6805
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;
6808
new_set=make_new_set(&sets);
6809
set=sets.set+set_nr; /* if realloc */
6810
new_set->table_offset=set->table_offset;
6811
new_set->found_len=set->found_len;
6812
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);
6815
for (i= (uint) ~0 ; (i=get_next_bit(sets.set+used_sets,i)) ; )
6817
if (!follow[i].chr || follow[i].chr == chr ||
6818
(follow[i].chr == SPACE_CHAR &&
6819
(is_word_end[chr] ||
6820
(!chr && follow[i].len > 1 && ! follow[i+1].chr))) ||
6821
(follow[i].chr == END_OF_LINE && ! chr))
6823
if ((! chr || (follow[i].chr && !follow[i+1].chr)) &&
6824
follow[i].len > found_end)
6825
found_end=follow[i].len;
6826
if (chr && follow[i].chr)
6827
internal_set_bit(new_set,i+1); /* To next set */
6829
internal_set_bit(new_set,i);
6834
new_set->found_len=0; /* Set for testing if first */
6836
for (i= (uint) ~0; (i=get_next_bit(new_set,i)) ;)
6838
if ((follow[i].chr == SPACE_CHAR ||
6839
follow[i].chr == END_OF_LINE) && ! chr)
6843
if (follow[bit_nr-1].len < found_end ||
6844
(new_set->found_len &&
6845
(chr == 0 || !follow[bit_nr].chr)))
6846
internal_clear_bit(new_set,i);
6849
if (chr == 0 || !follow[bit_nr].chr)
6851
new_set->table_offset=follow[bit_nr].table_offset;
6852
if (chr || (follow[i].chr == SPACE_CHAR ||
6853
follow[i].chr == END_OF_LINE))
6854
new_set->found_offset=found_end; /* New match */
6855
new_set->found_len=found_end;
6862
set->next[chr] = find_found(found_set,
6863
new_set->table_offset,
6864
new_set->found_offset);
6865
free_last_set(&sets);
6868
set->next[chr] = find_set(&sets,new_set);
6871
set->next[chr] = find_set(&sets,new_set);
6927
6893
for (i=1 ; i <= found_sets ; i++)
6929
6895
pos=from[found_set[i-1].table_offset];
6930
rep_str[i].found= !bcmp((const uchar*) pos,
6931
(const uchar*) "\\^", 3) ? 2 : 1;
6896
rep_str[i].found= !memcmp((const uchar*) pos,
6897
(const uchar*) "\\^", 3) ? 2 : 1;
6932
6898
rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
6933
6899
rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
6934
6900
rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
6937
6903
for (i=0 ; i < sets.count ; i++)
6939
6905
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));
6906
if (sets.set[i].next[j] >= 0)
6907
replace[i].next[j]=replace+sets.set[i].next[j];
6909
replace[i].next[j]=(REPLACE*) (rep_str+(-sets.set[i].next[j]-1));
6946
6912
my_free(follow,MYF(0));
7114
7080
for (i=0 ; (uint) i < found_sets ; i++)
7115
7081
if (found_set[i].table_offset == table_offset &&
7116
found_set[i].found_offset == found_offset)
7082
found_set[i].found_offset == found_offset)
7118
7084
found_set[i].table_offset=table_offset;
7119
7085
found_set[i].found_offset=found_offset;
7121
return -i-2; /* return new postion */
7087
return -i-2; /* return new postion */
7124
7090
/* Return 1 if regexp starts with \b or ends with \b*/
7126
7092
uint start_at_word(char * pos)
7128
return (((!bcmp((const uchar*) pos, (const uchar*) "\\b",2) && pos[2]) ||
7129
!bcmp((const uchar*) pos, (const uchar*) "\\^", 2)) ? 1 : 0);
7094
return (((!memcmp((const uchar*) pos, (const uchar*) "\\b",2) && pos[2]) ||
7095
!memcmp((const uchar*) pos, (const uchar*) "\\^", 2)) ? 1 : 0);
7132
7098
uint end_of_word(char * pos)
7134
7100
char * end=strend(pos);
7135
return ((end > pos+2 && !bcmp((const uchar*) end-2,
7136
(const uchar*) "\\b", 2)) ||
7137
(end >= pos+2 && !bcmp((const uchar*) end-2,
7101
return ((end > pos+2 && !memcmp((const uchar*) end-2,
7102
(const uchar*) "\\b", 2)) ||
7103
(end >= pos+2 && !memcmp((const uchar*) end-2,
7138
7104
(const uchar*) "\\$",2))) ? 1 : 0;