Skip to content

Commit 4ed2fb2

Browse files
committed
BUG#35549008 Classic session does not report errors in stored procedures
Classic sessions were not validating result errors when fetching multiple results, i.e. in calls to stored procedures, this prevented the errors from being properly reported Change-Id: I1fa57ebef1d60b5fa302c0f96dbf90292088f8eb
1 parent 6302f17 commit 4ed2fb2

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

mysqlshdk/libs/db/mysql/session.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,14 @@ static void free_result(T *result) {
700700
bool Session_impl::next_resultset() {
701701
if (_prev_result) _prev_result.reset();
702702

703-
return mysql_next_result(_mysql) == 0;
703+
int rc = mysql_next_result(_mysql);
704+
705+
if (rc > 0) {
706+
throw Error(mysql_error(_mysql), mysql_errno(_mysql),
707+
mysql_sqlstate(_mysql));
708+
}
709+
710+
return rc == 0;
704711
}
705712

706713
void Session_impl::prepare_fetch(Result *target) {

unittest/scripts/auto/js_devapi/scripts/stored_procedure_calls_norecord.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,23 @@ session.runSql("call multiupdates();");
2727

2828
session.runSql("drop schema bug29451154");
2929

30+
//@<> Test stored procedure error is properly reported
31+
shell.connect(__uripwd);
32+
session.createSchema("bug35549008");
33+
session.runSql("CREATE PROCEDURE bug35549008.my_sp_with_error() BEGIN SELECT 1; SELECT * FROM UNEXISTING; SELECT 2; END;")
34+
35+
// Tests Classic Protocol
36+
shell.connect(__mysqluripwd + "/bug35549008");
37+
session.runSql("call my_sp_with_error()")
38+
EXPECT_OUTPUT_CONTAINS("ERROR: 1146: ClassicResult.dump: Table 'bug35549008.UNEXISTING' doesn't exist");
39+
WIPE_OUTPUT()
40+
41+
// Tests X Protocol
42+
shell.connect(__uripwd + "/bug35549008");
43+
session.runSql("call my_sp_with_error()")
44+
EXPECT_OUTPUT_CONTAINS("ERROR: 1146: SqlResult.dump: Table 'bug35549008.UNEXISTING' doesn't exist");
45+
WIPE_OUTPUT()
46+
47+
session.runSql("drop schema bug35549008");
48+
3049
session.close();

0 commit comments

Comments
 (0)