Skip to content
Permalink
Browse files
fix(dbapi): avoid running % format with no query parameters (#348)
* fix: aviod running %format when no query params

* fix: nit

* fix: change in unit test
  • Loading branch information
HemangChothani committed Oct 29, 2020
1 parent e51fd45 commit 5dd1a5e77f13b8e576e917069e247c5390a81900
Showing with 7 additions and 1 deletion.
  1. +1 −1 google/cloud/bigquery/dbapi/cursor.py
  2. +6 −0 tests/unit/test_dbapi_cursor.py
@@ -441,7 +441,7 @@ def _format_operation(operation, parameters=None):
if a parameter used in the operation is not found in the
``parameters`` argument.
"""
if parameters is None:
if parameters is None or len(parameters) == 0:
return operation

if isinstance(parameters, collections_abc.Mapping):
@@ -601,3 +601,9 @@ def test__format_operation_w_too_short_sequence(self):
"SELECT %s, %s;",
("hello",),
)

def test__format_operation_w_empty_dict(self):
from google.cloud.bigquery.dbapi import cursor

formatted_operation = cursor._format_operation("SELECT '%f'", {})
self.assertEqual(formatted_operation, "SELECT '%f'")

0 comments on commit 5dd1a5e

Please sign in to comment.