Skip to content

Commit

Permalink
fix: execute_string ignores comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tekumara committed Jun 29, 2024
1 parent e7f3f97 commit e6513f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fakesnow/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def execute_string(
cursors = [
self.cursor(cursor_class).execute(e.sql(dialect="snowflake"))
for e in sqlglot.parse(sql_text, read="snowflake")
if e
if e and not isinstance(e, exp.Semicolon) # ignore comments
]
return cursors if return_cursors else []

Expand Down
11 changes: 7 additions & 4 deletions tests/test_fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,14 @@ def test_executemany(cur: snowflake.connector.cursor.SnowflakeCursor):


def test_execute_string(conn: snowflake.connector.SnowflakeConnection):
[_, cur2] = conn.execute_string(
""" create table customers (ID int, FIRST_NAME varchar, LAST_NAME varchar);
select count(*) customers """
*_, cur = conn.execute_string(
"""
create table customers (ID int, FIRST_NAME varchar, LAST_NAME varchar);
-- test comments are ignored
select count(*) customers
"""
)
assert cur2.fetchall() == [(1,)]
assert cur.fetchall() == [(1,)]


def test_fetchall(conn: snowflake.connector.SnowflakeConnection):
Expand Down

0 comments on commit e6513f7

Please sign in to comment.