Skip to content

Commit

Permalink
Strip comments to ensure more stable parameter pre-binding (fixes #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Jan 14, 2024
1 parent f637946 commit 10ab41d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion database/macrostrat/database/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _get_queries(sql, interpret_as_file=None):
if isinstance(sql, Path):
sql = sql.read_text()

return split(sql)
return split(format(sql, strip_comments=True))


def _is_prebind_param(param):
Expand Down
10 changes: 10 additions & 0 deletions database/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ def test_run_query_2(db):
assert r1[0].name == "Test"


def test_ambiguous_comment_bind(db):
sql = """
/* This is a comment {with_fake_param} */
SELECT name FROM sample WHERE name = {name}
"""
res = db.run_query(sql, dict(name=Literal("Test")))
data = res.scalar()
assert data == "Test"


def test_close_connection(conn):
"""
Basic test demonstrating the underlying capability to kill a long-running query
Expand Down

0 comments on commit 10ab41d

Please sign in to comment.