Skip to content

Commit 8392da6

Browse files
author
Micheal Gendy
committed
fix issues
1 parent 2871fdb commit 8392da6

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

databases/backends/mysql.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,13 @@ def _compile_many(
227227
compiled = queries[0].compile(
228228
dialect=self._dialect, compile_kwargs={"render_postcompile": True}
229229
)
230-
for args in values:
231-
for key, val in args.items():
232-
if key in compiled._bind_processors:
233-
args[key] = compiled._bind_processors[key](val)
230+
if not isinstance(queries[0], DDLElement):
231+
for args in values:
232+
for key, val in args.items():
233+
if key in compiled._bind_processors:
234+
args[key] = compiled._bind_processors[key](val)
235+
else:
236+
values = []
234237
return compiled.string, values
235238

236239
@property

databases/backends/postgres.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,24 @@ def _compile_many(
272272
compiled = queries[0].compile(
273273
dialect=self._dialect, compile_kwargs={"render_postcompile": True}
274274
)
275-
for args in values:
276-
for key, val in args.items():
277-
if key in compiled._bind_processors:
278-
args[key] = compiled._bind_processors[key](val)
279-
return compiled.string, values
275+
new_values = []
276+
if not isinstance(queries[0], DDLElement):
277+
for args in values:
278+
sorted_args = sorted(args.items())
279+
mapping = {
280+
key: "$" + str(i) for i, (key, _) in enumerate(sorted_args, start=1)
281+
}
282+
compiled_query = compiled.string % mapping
283+
processors = compiled._bind_processors
284+
values = [
285+
processors[key](val) if key in processors else val
286+
for key, val in sorted_args
287+
]
288+
new_values.append(values)
289+
else:
290+
compiled_query = compiled.string
291+
new_values = []
292+
return compiled_query, new_values
280293

281294
@staticmethod
282295
def _create_column_maps(

databases/backends/sqlite.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,19 @@ def _compile_many(
203203
compiled = queries[0].compile(
204204
dialect=self._dialect, compile_kwargs={"render_postcompile": True}
205205
)
206-
for args in values:
207-
for key, val in args.items():
208-
if key in compiled._bind_processors:
209-
args[key] = compiled._bind_processors[key](val)
210-
return compiled.string, values
206+
new_values = []
207+
if not isinstance(queries[0], DDLElement):
208+
for args in values:
209+
temp_arr = []
210+
for key in compiled.positiontup:
211+
raw_val = args[key]
212+
if key in compiled._bind_processors:
213+
val = compiled._bind_processors[key](raw_val)
214+
else:
215+
val = raw_val
216+
temp_arr.append(val)
217+
new_values.append(temp_arr)
218+
return compiled.string, new_values
211219

212220
@property
213221
def raw_connection(self) -> aiosqlite.core.Connection:

0 commit comments

Comments
 (0)