Merge pull request #306 from boglin/multi_init_cmd

Multi-statement init_command causes subsequent query to fail
This commit is contained in:
INADA Naoki
2015-02-15 18:31:56 +09:00
2 changed files with 11 additions and 0 deletions

View File

@@ -841,6 +841,7 @@ class Connection(object):
if self.init_command is not None: if self.init_command is not None:
c = self.cursor() c = self.cursor()
c.execute(self.init_command) c.execute(self.init_command)
c.close()
self.commit() self.commit()
if self.autocommit_mode is not None: if self.autocommit_mode is not None:

View File

@@ -69,3 +69,13 @@ class TestConnection(base.PyMySQLTestCase):
# error occures while reading, not writing because of socket buffer. # error occures while reading, not writing because of socket buffer.
#self.assertEquals(cm.exception.args[0], 2006) #self.assertEquals(cm.exception.args[0], 2006)
self.assertIn(cm.exception.args[0], (2006, 2013)) self.assertIn(cm.exception.args[0], (2006, 2013))
def test_init_command(self):
conn = pymysql.connect(
init_command='SELECT "bar"; SELECT "baz"',
**self.databases[0]
)
c = conn.cursor()
c.execute('select "foobar";')
self.assertEqual(('foobar',), c.fetchone())
conn.close()