Skip to content

Raise ProgrammingError when previous multi result not fetched. #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ matrix:
- ${HOME}/mysql
- env:
- TOX_ENV=py34
- DB=5.7.8-rc
- DB=5.7.10
addons:
apt:
packages:
Expand Down
4 changes: 4 additions & 0 deletions pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ def __exit__(self, exc, value, traceback):

# The following methods are INTERNAL USE ONLY (called from Cursor)
def query(self, sql, unbuffered=False):
if self._result is not None and self._result.has_next:
raise err.ProgrammingError(
"Previous results have not been fetched. "
"You may not close previous cursor.")
# if DEBUG:
# print("DEBUG: sending query:", sql)
if isinstance(sql, text_type) and not (JYTHON or IRONPYTHON):
Expand Down
10 changes: 9 additions & 1 deletion pymysql/tests/test_connection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import decimal
import time
import sys
import time
import unittest2
import pymysql
from pymysql.tests import base
Expand Down Expand Up @@ -202,3 +202,11 @@ def test_escape_list_item(self):
mapping = con.encoders.copy()
mapping[Foo] = escape_foo
self.assertEqual(con.escape([Foo()], mapping), "(bar)")

def test_previous_cursor_not_closed(self):
con = self.connections[0]
cur1 = con.cursor()
cur1.execute("SELECT 1; SELECT 2")
cur2 = con.cursor()
with self.assertRaises(pymysql.ProgrammingError):
cur2.execute("SELECT 3")