diff --git a/pydruid/db/api.py b/pydruid/db/api.py index a06e970a..41f6a64f 100644 --- a/pydruid/db/api.py +++ b/pydruid/db/api.py @@ -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 diff --git a/tests/db/test_cursor.py b/tests/db/test_cursor.py index 9287b403..3dc25954 100644 --- a/tests/db/test_cursor.py +++ b/tests/db/test_cursor.py @@ -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( @@ -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()