summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2017-12-22 08:22:10 +0400
committerAlexander Barkov <bar@mariadb.org>2017-12-22 08:23:33 +0400
commita76a2522ec4f8c069827e038997387a8b8eb3a3a (patch)
tree945540cb61152d4ee1e26a799aa504ed842f25e1
parent9c28fd7a3337a4d6773f3b53e70af9a3b0dbb919 (diff)
downloadmariadb-git-a76a2522ec4f8c069827e038997387a8b8eb3a3a.tar.gz
MDEV-14426 Assertion in Diagnostics_area::set_error_status when using a bad datetime with PS and SP
-rw-r--r--mysql-test/r/ps.result29
-rw-r--r--mysql-test/t/ps.test34
-rw-r--r--sql/sql_prepare.cc12
3 files changed, 75 insertions, 0 deletions
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index 6857ebc68af..5ddc52579bc 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -5074,3 +5074,32 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
DROP PROCEDURE p1;
+#
+# MDEV-14426 Assertion in Diagnostics_area::set_error_status when using a bad datetime with PS and SP
+#
+CREATE PROCEDURE p1(OUT a VARCHAR(20))
+BEGIN
+SET a=10;
+END;
+$$
+BEGIN NOT ATOMIC
+DECLARE a DATETIME;
+CALL p1(a);
+END;
+$$
+ERROR 22007: Incorrect datetime value: '10' for column 'a' at row 1
+BEGIN NOT ATOMIC
+DECLARE a DATETIME;
+EXECUTE IMMEDIATE 'CALL p1(?)' USING a;
+END;
+$$
+ERROR 22007: Incorrect datetime value: '10' for column 'a' at row 1
+BEGIN NOT ATOMIC
+DECLARE a DATETIME;
+PREPARE stmt FROM 'CALL p1(?)';
+EXECUTE stmt USING a;
+DEALLOCATE PREPARE stmt;
+END;
+$$
+ERROR 22007: Incorrect datetime value: '10' for column 'a' at row 1
+DROP PROCEDURE p1;
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index a7683b5aae6..f147f4b7e1e 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -4529,3 +4529,37 @@ CREATE TABLE t1 AS SELECT @a AS a, @b AS b;
SHOW CREATE TABLE t1;
DROP TABLE t1;
DROP PROCEDURE p1;
+
+
+--echo #
+--echo # MDEV-14426 Assertion in Diagnostics_area::set_error_status when using a bad datetime with PS and SP
+--echo #
+
+DELIMITER $$;
+CREATE PROCEDURE p1(OUT a VARCHAR(20))
+BEGIN
+ SET a=10;
+END;
+$$
+--error ER_TRUNCATED_WRONG_VALUE
+BEGIN NOT ATOMIC
+ DECLARE a DATETIME;
+ CALL p1(a);
+END;
+$$
+--error ER_TRUNCATED_WRONG_VALUE
+BEGIN NOT ATOMIC
+ DECLARE a DATETIME;
+ EXECUTE IMMEDIATE 'CALL p1(?)' USING a;
+END;
+$$
+--error ER_TRUNCATED_WRONG_VALUE
+BEGIN NOT ATOMIC
+ DECLARE a DATETIME;
+ PREPARE stmt FROM 'CALL p1(?)';
+ EXECUTE stmt USING a;
+ DEALLOCATE PREPARE stmt;
+END;
+$$
+DELIMITER ;$$
+DROP PROCEDURE p1;
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 19c714cfc01..ae6f0e8f63d 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -4786,7 +4786,19 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
if (error == 0 && this->lex->sql_command == SQLCOM_CALL)
{
if (is_sql_prepare())
+ {
+ /*
+ Here we have the diagnostics area status already set to DA_OK.
+ sent_out_parameters() can raise errors when assigning OUT parameters:
+ DECLARE a DATETIME;
+ EXECUTE IMMEDIATE 'CALL p1(?)' USING a;
+ when the procedure p1 assigns a DATETIME-incompatible value (e.g. 10)
+ to the out parameter. Allow to overwrite status (to DA_ERROR).
+ */
+ thd->get_stmt_da()->set_overwrite_status(true);
thd->protocol_text.send_out_parameters(&this->lex->param_list);
+ thd->get_stmt_da()->set_overwrite_status(false);
+ }
else
thd->protocol->send_out_parameters(&this->lex->param_list);
}