Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(SQLAlchemy): queries w/o parameters #317

Merged
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
2 changes: 1 addition & 1 deletion pydruid/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def rows_from_chunks(chunks):

def apply_parameters(operation, parameters):
if not parameters:
return operation
return operation % ()

escaped_parameters = {key: escape(value) for key, value in parameters.items()}
return operation % escaped_parameters
Expand Down
9 changes: 7 additions & 2 deletions tests/db/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ def test_names_with_underscores(self, requests_post_mock):

def test_apply_parameters(self):
self.assertEqual(
apply_parameters('SELECT 100 AS "100%"', None), 'SELECT 100 AS "100%"'
apply_parameters('SELECT 100 AS "100%%"', None), 'SELECT 100 AS "100%"'
)

self.assertEqual(
apply_parameters('SELECT 100 AS "100%"', {}), 'SELECT 100 AS "100%"'
apply_parameters('SELECT 100 AS "100%%"', {}), 'SELECT 100 AS "100%"'
)

self.assertEqual(
Expand All @@ -147,6 +147,11 @@ def test_apply_parameters(self):
apply_parameters("SELECT %(key)s", {"key": False}), "SELECT FALSE"
)

self.assertEqual(
apply_parameters("SELECT * FROM t WHERE name LIKE '%%a'", None),
"SELECT * FROM t WHERE name LIKE '%a'",
)


if __name__ == "__main__":
unittest.main()