Commit 52960624 authored by Bjorn Munch's avatar Bjorn Munch

Bug #12793118 MYSQLTEST: --ERROR AND --DISABLE_ABORT_ON_ERROR DO NOT WORK FOR SQL IN COMMANDS

  Call handle_error() instead of die() when evaluating these
  Must remember "current command" with link to errors to ignore
  Added test cases to mysqltest.test 
parent 52d9e13f
......@@ -451,6 +451,7 @@ TYPELIB command_typelib= {array_elements(command_names),"",
command_names, 0};
DYNAMIC_STRING ds_res;
struct st_command *curr_command= 0;
char builtin_echo[FN_REFLEN];
......@@ -2212,9 +2213,16 @@ void var_query_set(VAR *var, const char *query, const char** query_end)
init_dynamic_string(&ds_query, 0, (end - query) + 32, 256);
do_eval(&ds_query, query, end, FALSE);
if (mysql_real_query(mysql, ds_query.str, ds_query.length))
die("Error running query '%s': %d %s", ds_query.str,
mysql_errno(mysql), mysql_error(mysql));
if (mysql_real_query(mysql, ds_query.str, ds_query.length))
{
handle_error (curr_command, mysql_errno(mysql), mysql_error(mysql),
mysql_sqlstate(mysql), &ds_res);
/* If error was acceptable, return empty string */
dynstr_free(&ds_query);
eval_expr(var, "", 0);
DBUG_VOID_RETURN;
}
if (!(res= mysql_store_result(mysql)))
die("Query '%s' didn't return a result set", ds_query.str);
dynstr_free(&ds_query);
......@@ -2315,8 +2323,15 @@ void var_set_query_get_value(struct st_command *command, VAR *var)
/* Run the query */
if (mysql_real_query(mysql, ds_query.str, ds_query.length))
die("Error running query '%s': %d %s", ds_query.str,
mysql_errno(mysql), mysql_error(mysql));
{
handle_error (curr_command, mysql_errno(mysql), mysql_error(mysql),
mysql_sqlstate(mysql), &ds_res);
/* If error was acceptable, return empty string */
dynstr_free(&ds_query);
eval_expr(var, "", 0);
DBUG_VOID_RETURN;
}
if (!(res= mysql_store_result(mysql)))
die("Query '%s' didn't return a result set", ds_query.str);
......@@ -8147,6 +8162,8 @@ int main(int argc, char **argv)
{
command->last_argument= command->first_argument;
processed = 1;
/* Need to remember this for handle_error() */
curr_command= command;
switch (command->type) {
case Q_CONNECT:
do_connect(command);
......
......@@ -135,6 +135,10 @@ select 1146 as "after_!errno_masked_error" ;
after_!errno_masked_error
1146
mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146: 'Table 'test.t1' doesn't exist', instead of 1000...
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'garbage' at line 1
is empty
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'nonsense' at line 1
is empty
garbage ;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'garbage' at line 1
select 1064 as "after_--enable_abort_on_error" ;
......@@ -143,6 +147,9 @@ after_--enable_abort_on_error
select 3 from t1 ;
ERROR 42S02: Table 'test.t1' doesn't exist
mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146: 'Table 'test.t1' doesn't exist', instead of 1064...
is empty
is empty
"Yes it's empty"
hello
hello
;;;;;;;;
......@@ -315,7 +322,7 @@ insert into t1 values ('$dollar');
$dollar
`select 42`
drop table t1;
mysqltest: At line 1: Error running query 'failing query': 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'failing query' at line 1
mysqltest: At line 1: query 'let $var2= `failing query`' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'failing query' at line 1
mysqltest: At line 1: Missing required argument 'filename' to command 'source'
mysqltest: At line 1: Could not open './non_existingFile' for reading, errno: 2
mysqltest: In included file "MYSQLTEST_VARDIR/tmp/recursive.sql":
......@@ -813,7 +820,7 @@ mysqltest: At line 1: Could not find column 'column_not_exists' in the result of
mysqltest: At line 1: Query 'SET @A = 1' didn't return a result set
mysqltest: At line 1: Could not find column '1 AS B' in the result of 'SELECT 1 AS A'
value= No such row
mysqltest: At line 1: Error running query 'SHOW COLNS FROM t1': 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COLNS FROM t1' at line 1
mysqltest: At line 1: query 'let $value= query_get_value(SHOW COLNS FROM t1, Field, 1)' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COLNS FROM t1' at line 1
Field Type Null Key Default Extra
a int(11) YES -><- NULL
......
......@@ -334,6 +334,14 @@ eval select $mysql_errno as "after_!errno_masked_error" ;
exit(2);
EOF
# ----------------------------------------------------------------------------
# Check backtick and query_get_value, result should be empty
# ----------------------------------------------------------------------------
let $empty= `garbage`;
echo $empty is empty;
let $empty= query_get_value(nonsense, blabla, 1);
echo $empty is empty;
# ----------------------------------------------------------------------------
# Switch the abort on error on and check the effect on $mysql_errno
# ----------------------------------------------------------------------------
......@@ -364,6 +372,23 @@ select 3 from t1 ;
--exec echo "disable_abort_on_error; enable_abort_on_error; error 1064; select 3 from t1; select 3 from t1;" | $MYSQL_TEST 2>&1
# ----------------------------------------------------------------------------
# Test --error with backtick operator or query_get_value
# ----------------------------------------------------------------------------
--error 0,ER_NO_SUCH_TABLE
let $empty= `SELECT foo from bar`;
echo $empty is empty;
--error 0,ER_BAD_FIELD_ERROR
let $empty= query_get_value(SELECT bar as foo, baz, 1);
echo $empty is empty;
--error 0,ER_NO_SUCH_TABLE
if (!`SELECT foo from bar`) {
echo "Yes it's empty";
}
# ----------------------------------------------------------------------------
# Test comments
# ----------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment