|
148 | 148 | # in order to be identified by database |
149 | 149 | # example: INSERT INTO book (title) VALUES (:title) -> INSERT INTO book (title) VALUES ($1) |
150 | 150 | # 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]: |
152 | 152 | # I don't see any way to avoid scanning the query string char by char, |
153 | 153 | # so we might as well take that careful approach and create a |
154 | 154 | # 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] |
274 | 274 | prev_c = c |
275 | 275 |
|
276 | 276 | if style in ("numeric", "qmark", "format"): |
277 | | - vals = args |
| 277 | + |
| 278 | + def make_args(vals): |
| 279 | + return vals |
| 280 | + |
278 | 281 | else: |
279 | | - vals = tuple(args[p] for p in placeholders) |
280 | 282 |
|
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 |
282 | 287 |
|
283 | 288 |
|
284 | 289 | # Message codes |
@@ -1110,11 +1115,9 @@ def execute(self: "Connection", cursor: Cursor, operation: str, vals) -> None: |
1110 | 1115 | try: |
1111 | 1116 | statement, make_args = cache["statement"][operation] |
1112 | 1117 | 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) |
1116 | 1119 |
|
1117 | | - args = vals |
| 1120 | + args = make_args(vals) |
1118 | 1121 | # change the args to the format that the DB will identify |
1119 | 1122 | # take reference from self.py_types |
1120 | 1123 | params = self.make_params(args) |
|
0 commit comments