Skip to content

Commit 40b4268

Browse files
smtakedaankit-bhatnagar167
authored andcommitted
SNOW-64158: Incorporate kwargs style group of key-value pairs in connection's execute_string function
1 parent 6984eae commit 40b4268

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

connection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ def cursor(self, cursor_class=SnowflakeCursor):
525525

526526
def execute_string(self, sql_text,
527527
remove_comments=False,
528-
return_cursors=True):
528+
return_cursors=True,
529+
**kwargs):
529530
"""
530531
Executes a SQL text including multiple statements.
531532
This is a non-standard convenient method.
@@ -541,7 +542,7 @@ def execute_string(self, sql_text,
541542
cur = self.cursor()
542543
if return_cursors:
543544
ret.append(cur)
544-
cur.execute(sql, _is_put_get=is_put_or_get)
545+
cur.execute(sql, _is_put_get=is_put_or_get, **kwargs)
545546
return ret
546547

547548
def execute_stream(self, stream,

test/test_execute_multi_statements.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66

77
import codecs
88
import os
9+
from six import PY2
910
from io import StringIO, BytesIO
1011

12+
if PY2:
13+
from mock import patch
14+
else:
15+
from unittest.mock import patch
1116
import pytest
1217

1318
from snowflake.connector import ProgrammingError
@@ -70,6 +75,25 @@ def test_execute_string(conn_cnx, db_parameters):
7075
tbl2=db_parameters['name'] + '2'), return_cursors=False)
7176

7277

78+
def test_execute_string_kwargs(conn_cnx, db_parameters):
79+
with conn_cnx() as cnx:
80+
with patch('snowflake.connector.cursor.SnowflakeCursor.execute', autospec=True) as mock_execute:
81+
cnx.execute_string("""
82+
CREATE OR REPLACE TABLE {tbl1} (c1 int, c2 string);
83+
CREATE OR REPLACE TABLE {tbl2} (c1 int, c2 string);
84+
INSERT INTO {tbl1} VALUES(1,'test123');
85+
INSERT INTO {tbl1} VALUES(2,'test234');
86+
INSERT INTO {tbl1} VALUES(3,'test345');
87+
INSERT INTO {tbl2} VALUES(101,'test123');
88+
INSERT INTO {tbl2} VALUES(102,'test234');
89+
INSERT INTO {tbl2} VALUES(103,'test345');
90+
""".format(
91+
tbl1=db_parameters['name'] + '1',
92+
tbl2=db_parameters['name'] + '2'), return_cursors=False, _no_results=True)
93+
for call in mock_execute.call_args_list:
94+
assert call[1].get('_no_results', False)
95+
96+
7397
def test_execute_string_with_error(conn_cnx):
7498
with conn_cnx() as cnx:
7599
with pytest.raises(ProgrammingError):

0 commit comments

Comments
 (0)