Skip to content

Commit e72a373

Browse files
authored
Merge pull request #11 from singlestore-labs/enable_multi_statements
Add connection option to enable multi statements
2 parents ac6e607 + b81e3a1 commit e72a373

5 files changed

Lines changed: 26 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ docs/src/_build/doctrees
7676
docs/src/generated
7777

7878
dask-worker-space
79+
80+
## Test configuration
81+
singlestoredb/mysql/tests/databases.json

singlestoredb/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@
9090
environ='SINGLESTOREDB_LOCAL_INFILE',
9191
)
9292

93+
register_option(
94+
'multi_statements', 'bool', check_bool, False,
95+
'Should it be possible use multiple statements in one query?',
96+
environ='SINGLESTOREDB_MULTI_STATEMENTS',
97+
)
98+
9399
register_option(
94100
'ssl_key', 'str', check_str, None,
95101
'File containing SSL key',

singlestoredb/connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,7 @@ def connect(
12761276
results_format: Optional[str] = None,
12771277
program_name: Optional[str] = None,
12781278
conn_attrs: Optional[Dict[str, str]] = None,
1279+
multi_statements: Optional[bool] = None,
12791280
) -> Connection:
12801281
"""
12811282
Return a SingleStoreDB connection.

singlestoredb/mysql/connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def __init__( # noqa: C901
292292
db=None, # deprecated
293293
driver=None, # internal use
294294
conn_attrs=None,
295+
multi_statements=None,
295296
):
296297
BaseConnection.__init__(**dict(locals()))
297298

@@ -316,6 +317,8 @@ def __init__( # noqa: C901
316317
self._local_infile = bool(local_infile)
317318
if self._local_infile:
318319
client_flag |= CLIENT.LOCAL_FILES
320+
if multi_statements:
321+
client_flag |= CLIENT.MULTI_STATEMENTS
319322

320323
if read_default_group and not read_default_file:
321324
if sys.platform.startswith('win'):

singlestoredb/tests/test_connection.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,19 @@ def test_results_format(self):
13571357
out = cur.fetchall()
13581358
assert type(out[0]) is dict, type(out)
13591359

1360+
def test_multi_statements(self):
1361+
if self.conn.driver not in ['http', 'https']:
1362+
with s2.connect(database=type(self).dbname, multi_statements=True) as conn:
1363+
with conn.cursor() as cur:
1364+
cur.execute('SELECT 1; SELECT 2;')
1365+
self.assertEqual([(1,)], list(cur))
1366+
1367+
r = cur.nextset()
1368+
self.assertTrue(r)
1369+
1370+
self.assertEqual([(2,)], list(cur))
1371+
self.assertIsNone(cur.nextset())
1372+
13601373
def test_show_accessors(self):
13611374
out = self.conn.show.columns('data')
13621375
assert out.columns == [

0 commit comments

Comments
 (0)