Skip to content

Commit 3889e86

Browse files
committed
BUG19777815: Add support for warnings with MySQLCursor.callproc()
MySQLCursor.fetchwarnings() was not returning any warnings even when warnings were generated by calling a stored procedure using MySQLCursor.callproc() method. We add support to fetch warnings generated by a stored procedure. A unit test has been added for BUG#19777815.
1 parent f452732 commit 3889e86

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

lib/mysql/connector/cursor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,14 @@ def callproc(self, procname, args=()):
697697
call = "CALL {0}({1})".format(procname, ','.join(argnames))
698698

699699
for result in self._connection.cmd_query_iter(call):
700+
# pylint: disable=W0212
701+
tmp = MySQLCursorBuffered(self._connection._get_self())
702+
tmp._handle_result(result)
703+
if tmp._warnings is not None:
704+
self._warnings = tmp._warnings
705+
# pylint: enable=W0212
700706
if 'columns' in result:
701-
# pylint: disable=W0212
702-
tmp = MySQLCursorBuffered(self._connection._get_self())
703-
tmp._handle_result(result)
704707
results.append(tmp)
705-
# pylint: enable=W0212
706708

707709
if argnames:
708710
select = "SELECT {0}".format(','.join(argtypes))

tests/test_bugs.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,3 +3050,54 @@ def tearDown(self):
30503050
self.cur.execute("DROP TABLE IF EXISTS {0}".format(self.tbl))
30513051
self.cur.close()
30523052
self.cnx.close()
3053+
3054+
3055+
3056+
class BugOra19777815(tests.MySQLConnectorTests):
3057+
"""BUG#19777815: CALLPROC() DOES NOT SUPPORT WARNINGS
3058+
"""
3059+
def setUp(self):
3060+
config = tests.get_mysql_config()
3061+
config['get_warnings'] = True
3062+
self.cnx = connection.MySQLConnection(**config)
3063+
cur = self.cnx.cursor()
3064+
self.sp1 = 'BUG19777815'
3065+
self.sp2 = 'BUG19777815_with_result'
3066+
create1 = (
3067+
"CREATE PROCEDURE {0}() BEGIN SIGNAL SQLSTATE '01000' "
3068+
"SET MESSAGE_TEXT = 'TEST WARNING'; END;".format(self.sp1)
3069+
)
3070+
create2 = (
3071+
"CREATE PROCEDURE {0}() BEGIN SELECT 1; SIGNAL SQLSTATE '01000' "
3072+
"SET MESSAGE_TEXT = 'TEST WARNING'; END;".format(self.sp2)
3073+
)
3074+
3075+
cur.execute("DROP PROCEDURE IF EXISTS {0}".format(self.sp1))
3076+
cur.execute("DROP PROCEDURE IF EXISTS {0}".format(self.sp2))
3077+
cur.execute(create1)
3078+
cur.execute(create2)
3079+
cur.close()
3080+
3081+
def tearDown(self):
3082+
cur = self.cnx.cursor()
3083+
cur.execute("DROP PROCEDURE IF EXISTS {0}".format(self.sp1))
3084+
cur.execute("DROP PROCEDURE IF EXISTS {0}".format(self.sp2))
3085+
cur.close()
3086+
self.cnx.close()
3087+
3088+
def test_warning(self):
3089+
cur = self.cnx.cursor()
3090+
cur.callproc(self.sp1)
3091+
exp = [(u'Warning', 1642, u'TEST WARNING')]
3092+
self.assertEqual(exp, cur.fetchwarnings())
3093+
cur.close()
3094+
3095+
def test_warning_with_rows(self):
3096+
cur = self.cnx.cursor()
3097+
cur.callproc(self.sp2)
3098+
3099+
exp = [(1,)]
3100+
self.assertEqual(exp, cur.stored_results().next().fetchall())
3101+
exp = [(u'Warning', 1642, u'TEST WARNING')]
3102+
self.assertEqual(exp, cur.fetchwarnings())
3103+
cur.close()

0 commit comments

Comments
 (0)