mirror of
https://github.com/mariadb-corporation/mariadb-connector-python.git
synced 2025-08-07 11:39:43 +00:00
Fix for CONPY-246:
Rollback transaction if connection pool was created with pool_reset_connection=False.
This commit is contained in:
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
import mariadb
|
import mariadb
|
||||||
import _thread
|
import _thread
|
||||||
|
from mariadb.constants import STATUS
|
||||||
|
|
||||||
MAX_POOL_SIZE = 64
|
MAX_POOL_SIZE = 64
|
||||||
POOL_IDLE_TIMEOUT = 1800
|
|
||||||
|
|
||||||
|
|
||||||
class ConnectionPool(object):
|
class ConnectionPool(object):
|
||||||
@ -193,9 +193,12 @@ class ConnectionPool(object):
|
|||||||
by connection object.
|
by connection object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with self._lock_pool:
|
|
||||||
if self._pool_args["reset_connection"]:
|
if self._pool_args["reset_connection"]:
|
||||||
connection.reset()
|
connection.reset()
|
||||||
|
elif connection.server_status & STATUS.IN_TRANS:
|
||||||
|
connection.rollback()
|
||||||
|
|
||||||
|
with self._lock_pool:
|
||||||
|
|
||||||
for i in range(0, len(self._connections_used)):
|
for i in range(0, len(self._connections_used)):
|
||||||
if self._connections_used[i] == connection:
|
if self._connections_used[i] == connection:
|
||||||
|
@ -36,6 +36,30 @@ class TestPooling(unittest.TestCase):
|
|||||||
except mariadb.ProgrammingError:
|
except mariadb.ProgrammingError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_conpy246(self):
|
||||||
|
# test if a pooled connection will be roll backed
|
||||||
|
|
||||||
|
default_conf = conf()
|
||||||
|
|
||||||
|
pool = mariadb.ConnectionPool(pool_name="CONPY246",
|
||||||
|
pool_size=1,
|
||||||
|
pool_reset_connection=False,
|
||||||
|
**default_conf)
|
||||||
|
conn = pool.get_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("CREATE OR REPLACE TABLE conpy246(a int)")
|
||||||
|
cursor.execute("INSERT INTO conpy246 VALUES (1)")
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
conn = pool.get_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SELECT * FROM conpy246")
|
||||||
|
self.assertEqual(cursor.rowcount, 0)
|
||||||
|
cursor.execute("DROP TABLE conpy246")
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
pool.close()
|
||||||
|
|
||||||
def test_conpy245(self):
|
def test_conpy245(self):
|
||||||
# we can't test performance here, but we can check if LRU works.
|
# we can't test performance here, but we can check if LRU works.
|
||||||
# All connections must have been used the same number of times.
|
# All connections must have been used the same number of times.
|
||||||
|
Reference in New Issue
Block a user