Skip to content
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
13 changes: 11 additions & 2 deletions MySQLdb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class object, used to create cursors (keyword only)
:param int client_flag:
flags to use or 0 (see MySQL docs or constants/CLIENTS.py)

:param bool multi_statements:
If True, enable multi statements for clients >= 4.1.
Defaults to True.

:param str ssl_mode:
specify the security settings for connection to the server;
see the MySQL documentation for more details
Expand Down Expand Up @@ -169,11 +173,16 @@ class object, used to create cursors (keyword only)
self._binary_prefix = kwargs2.pop("binary_prefix", False)

client_flag = kwargs.get("client_flag", 0)

client_version = tuple(
[numeric_part(n) for n in _mysql.get_client_info().split(".")[:2]]
)
if client_version >= (4, 1):
client_flag |= CLIENT.MULTI_STATEMENTS

multi_statements = kwargs2.pop("multi_statements", True)
if multi_statements:
if client_version >= (4, 1):
client_flag |= CLIENT.MULTI_STATEMENTS

if client_version >= (5, 0):
client_flag |= CLIENT.MULTI_RESULTS

Expand Down
26 changes: 26 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from MySQLdb._exceptions import ProgrammingError

from configdb import connection_factory


def test_multi_statements_default_true():
conn = connection_factory()
cursor = conn.cursor()

cursor.execute("select 17; select 2")
rows = cursor.fetchall()
assert rows == ((17,),)


def test_multi_statements_false():
conn = connection_factory(multi_statements=False)
cursor = conn.cursor()

with pytest.raises(ProgrammingError):
cursor.execute("select 17; select 2")

cursor.execute("select 17")
rows = cursor.fetchall()
assert rows == ((17,),)