74
74
static my_bool debug_info_flag= 0, debug_check_flag= 0;
75
75
static my_bool tty_password= 0;
76
76
static my_bool opt_mark_progress= 0;
77
static my_bool ps_protocol= 0, ps_protocol_enabled= 0;
78
static my_bool sp_protocol= 0, sp_protocol_enabled= 0;
79
static my_bool view_protocol= 0, view_protocol_enabled= 0;
80
77
static my_bool cursor_protocol= 0, cursor_protocol_enabled= 0;
81
78
static my_bool parsing_disabled= 0;
82
79
static my_bool display_result_vertically= FALSE,
4939
4928
{"compress", 'C', "Use the compressed server/client protocol.",
4940
4929
(uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
4942
{"cursor-protocol", OPT_CURSOR_PROTOCOL, "Use cursors for prepared statements.",
4943
(uchar**) &cursor_protocol, (uchar**) &cursor_protocol, 0,
4944
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4945
4931
{"database", 'D', "Database to use.", (uchar**) &opt_db, (uchar**) &opt_db, 0,
4946
4932
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4947
4933
#ifdef DBUG_OFF
4981
4967
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
4982
4968
(uchar**) &opt_port,
4983
4969
(uchar**) &opt_port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4984
{"protocol", OPT_MYSQL_PROTOCOL,
4985
"The protocol of connection (tcp,socket,pipe,memory).",
4986
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4987
{"ps-protocol", OPT_PS_PROTOCOL, "Use prepared statements protocol for communication",
4988
(uchar**) &ps_protocol, (uchar**) &ps_protocol, 0,
4989
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4990
4970
{"quiet", 's', "Suppress all normal output.", (uchar**) &silent,
4991
4971
(uchar**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4992
4972
{"record", 'r', "Record output of test_file into result file.",
5003
4983
{"sleep", 'T', "Sleep always this many seconds on sleep commands.",
5004
4984
(uchar**) &opt_sleep, (uchar**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, -1, 0,
5006
{"socket", 'S', "Socket file to use for connection.",
5007
(uchar**) &unix_sock, (uchar**) &unix_sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
5009
{"sp-protocol", OPT_SP_PROTOCOL, "Use stored procedures for select",
5010
(uchar**) &sp_protocol, (uchar**) &sp_protocol, 0,
5011
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
5012
4986
{"tail-lines", OPT_TAIL_LINES,
5013
4987
"Number of lines of the resul to include in a failure report",
5014
4988
(uchar**) &opt_tail_lines, (uchar**) &opt_tail_lines, 0,
5025
4999
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
5026
5000
{"version", 'V', "Output version information and exit.",
5027
5001
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
5028
{"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select",
5029
(uchar**) &view_protocol, (uchar**) &view_protocol, 0,
5030
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
5031
5002
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
6156
6126
dynstr_append_mem(ds, "\n", 1);
6159
if (view_protocol_enabled &&
6161
match_re(&view_re, query))
6164
Create the query as a view.
6165
Use replace since view can exist from a failed mysqltest run
6167
DYNAMIC_STRING query_str;
6168
init_dynamic_string(&query_str,
6169
"CREATE OR REPLACE VIEW mysqltest_tmp_v AS ",
6171
dynstr_append_mem(&query_str, query, query_len);
6172
if (util_query(mysql, query_str.str))
6175
Failed to create the view, this is not fatal
6176
just run the query the normal way
6178
DBUG_PRINT("view_create_error",
6179
("Failed to create view '%s': %d: %s", query_str.str,
6180
mysql_errno(mysql), mysql_error(mysql)));
6182
/* Log error to create view */
6183
verbose_msg("Failed to create view '%s' %d: %s", query_str.str,
6184
mysql_errno(mysql), mysql_error(mysql));
6189
Yes, it was possible to create this query as a view
6192
query= (char*)"SELECT * FROM mysqltest_tmp_v";
6193
query_len = strlen(query);
6196
Collect warnings from create of the view that should otherwise
6197
have been produced when the SELECT was executed
6199
append_warnings(&ds_warnings, cur_con->util_mysql);
6202
dynstr_free(&query_str);
6206
if (sp_protocol_enabled &&
6208
match_re(&sp_re, query))
6211
Create the query as a stored procedure
6212
Drop first since sp can exist from a failed mysqltest run
6214
DYNAMIC_STRING query_str;
6215
init_dynamic_string(&query_str,
6216
"DROP PROCEDURE IF EXISTS mysqltest_tmp_sp;",
6218
util_query(mysql, query_str.str);
6219
dynstr_set(&query_str, "CREATE PROCEDURE mysqltest_tmp_sp()\n");
6220
dynstr_append_mem(&query_str, query, query_len);
6221
if (util_query(mysql, query_str.str))
6224
Failed to create the stored procedure for this query,
6225
this is not fatal just run the query the normal way
6227
DBUG_PRINT("sp_create_error",
6228
("Failed to create sp '%s': %d: %s", query_str.str,
6229
mysql_errno(mysql), mysql_error(mysql)));
6231
/* Log error to create sp */
6232
verbose_msg("Failed to create sp '%s' %d: %s", query_str.str,
6233
mysql_errno(mysql), mysql_error(mysql));
6240
query= (char*)"CALL mysqltest_tmp_sp()";
6241
query_len = strlen(query);
6243
dynstr_free(&query_str);
6246
6129
if (display_result_sorted)
6259
Find out how to run this query
6261
6142
Always run with normal C API if it's not a complete
6264
If it is a '?' in the query it may be a SQL level prepared
6265
statement already and we can't do it twice
6267
if (ps_protocol_enabled &&
6269
match_re(&ps_re, query))
6270
run_query_stmt(mysql, command, query, query_len, ds, &ds_warnings);
6272
run_query_normal(cn, command, flags, query, query_len,
6145
run_query_normal(cn, command, flags, query, query_len,
6275
6148
if (display_result_sorted)
6280
6153
dynstr_free(&ds_sorted);
6285
if (util_query(mysql, "DROP PROCEDURE mysqltest_tmp_sp "))
6286
die("Failed to drop sp: %d: %s", mysql_errno(mysql), mysql_error(mysql));
6291
if (util_query(mysql, "DROP VIEW mysqltest_tmp_v "))
6292
die("Failed to drop view: %d: %s",
6293
mysql_errno(mysql), mysql_error(mysql));
6296
6156
if (command->require_file[0])
6298
6158
/* A result file was specified for _this_ query
6343
Filter for queries that can be run using the
6344
MySQL Prepared Statements C API
6346
const char *ps_re_str =
6348
"[[:space:]]*REPLACE[[:space:]]|"
6349
"[[:space:]]*INSERT[[:space:]]|"
6350
"[[:space:]]*UPDATE[[:space:]]|"
6351
"[[:space:]]*DELETE[[:space:]]|"
6352
"[[:space:]]*SELECT[[:space:]]|"
6353
"[[:space:]]*CREATE[[:space:]]+TABLE[[:space:]]|"
6354
"[[:space:]]*DO[[:space:]]|"
6355
"[[:space:]]*SET[[:space:]]+OPTION[[:space:]]|"
6356
"[[:space:]]*DELETE[[:space:]]+MULTI[[:space:]]|"
6357
"[[:space:]]*UPDATE[[:space:]]+MULTI[[:space:]]|"
6358
"[[:space:]]*INSERT[[:space:]]+SELECT[[:space:]])";
6361
Filter for queries that can be run using the
6364
const char *sp_re_str =ps_re_str;
6367
Filter for queries that can be run as views
6369
const char *view_re_str =
6371
"[[:space:]]*SELECT[[:space:]])";
6373
init_re_comp(&ps_re, ps_re_str);
6374
init_re_comp(&sp_re, sp_re_str);
6375
init_re_comp(&view_re, view_re_str);
6379
6200
int match_re(my_regex_t *re, char *str)
6381
6202
int err= my_regexec(re, str, (size_t)0, NULL, 0);
6586
6404
init_dynamic_string(&ds_warning_messages, "", 0, 2048);
6587
6405
parse_args(argc, argv);
6589
var_set_int("$PS_PROTOCOL", ps_protocol);
6590
var_set_int("$SP_PROTOCOL", sp_protocol);
6591
var_set_int("$VIEW_PROTOCOL", view_protocol);
6592
var_set_int("$CURSOR_PROTOCOL", cursor_protocol);
6594
6407
DBUG_PRINT("info",("result_file: '%s'",
6595
6408
result_file_name ? result_file_name : ""));
6596
6409
if (mysql_server_init(embedded_server_arg_count,
6604
6417
cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
6605
6418
cur_file->lineno= 1;
6608
ps_protocol_enabled= ps_protocol;
6609
sp_protocol_enabled= sp_protocol;
6610
view_protocol_enabled= view_protocol;
6611
cursor_protocol_enabled= cursor_protocol;
6612
/* Cursor protcol implies ps protocol */
6613
if (cursor_protocol_enabled)
6614
ps_protocol_enabled= 1;
6616
6420
cur_con= connections;
6617
6421
if (!( mysql_init(&cur_con->mysql)))
6618
6422
die("Failed in mysql_init()");