Skip to content

Commit 51a5f14

Browse files
committed
fix(paramstyle): resolve issue with pyformat
1 parent 857e01a commit 51a5f14

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

redshift_connector/core.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
# in order to be identified by database
149149
# example: INSERT INTO book (title) VALUES (:title) -> INSERT INTO book (title) VALUES ($1)
150150
# also return the function: make_args()
151-
def convert_paramstyle(style: str, query, args) -> typing.Tuple[str, typing.Any]:
151+
def convert_paramstyle(style: str, query) -> typing.Tuple[str, typing.Any]:
152152
# I don't see any way to avoid scanning the query string char by char,
153153
# so we might as well take that careful approach and create a
154154
# state-based scanner. We'll use int variables for the state.
@@ -274,11 +274,16 @@ def convert_paramstyle(style: str, query, args) -> typing.Tuple[str, typing.Any]
274274
prev_c = c
275275

276276
if style in ("numeric", "qmark", "format"):
277-
vals = args
277+
278+
def make_args(vals):
279+
return vals
280+
278281
else:
279-
vals = tuple(args[p] for p in placeholders)
280282

281-
return "".join(output_query), vals
283+
def make_args(vals):
284+
return tuple(vals[p] for p in placeholders)
285+
286+
return "".join(output_query), make_args
282287

283288

284289
# Message codes
@@ -1110,11 +1115,9 @@ def execute(self: "Connection", cursor: Cursor, operation: str, vals) -> None:
11101115
try:
11111116
statement, make_args = cache["statement"][operation]
11121117
except KeyError:
1113-
statement, make_args = cache["statement"][operation] = convert_paramstyle(
1114-
cursor.paramstyle, operation, vals
1115-
)
1118+
statement, make_args = cache["statement"][operation] = convert_paramstyle(cursor.paramstyle, operation)
11161119

1117-
args = vals
1120+
args = make_args(vals)
11181121
# change the args to the format that the DB will identify
11191122
# take reference from self.py_types
11201123
params = self.make_params(args)

redshift_connector/cursor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ def callproc(self, procname, parameters=None):
245245
from redshift_connector.core import convert_paramstyle
246246

247247
try:
248-
statement, vals = convert_paramstyle("format", operation, args)
248+
statement, make_args = convert_paramstyle("format", operation)
249+
vals = make_args(args)
249250
self.execute(statement, vals)
250251

251252
except AttributeError as e:

0 commit comments

Comments
 (0)