diff --git a/.travis.yml b/.travis.yml index bfc434d4..d742f09a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,7 +38,7 @@ matrix: - ${HOME}/mysql - env: - TOX_ENV=py34 - - DB=5.7.8-rc + - DB=5.7.10 addons: apt: packages: diff --git a/pymysql/connections.py b/pymysql/connections.py index 94c0796b..1cccd9dc 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -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): diff --git a/pymysql/tests/test_connection.py b/pymysql/tests/test_connection.py index 203f8276..df834256 100644 --- a/pymysql/tests/test_connection.py +++ b/pymysql/tests/test_connection.py @@ -1,7 +1,7 @@ import datetime import decimal -import time import sys +import time import unittest2 import pymysql from pymysql.tests import base @@ -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")