diff --git a/databases/backends/mysql.py b/databases/backends/mysql.py index bf24e3b5..2922f3f2 100644 --- a/databases/backends/mysql.py +++ b/databases/backends/mysql.py @@ -227,10 +227,13 @@ def _compile_many( compiled = queries[0].compile( dialect=self._dialect, compile_kwargs={"render_postcompile": True} ) - for args in values: - for key, val in args.items(): - if key in compiled._bind_processors: - args[key] = compiled._bind_processors[key](val) + if not isinstance(queries[0], DDLElement): + for args in values: + for key, val in args.items(): + if key in compiled._bind_processors: + args[key] = compiled._bind_processors[key](val) + else: + values = [] return compiled.string, values @property diff --git a/databases/backends/postgres.py b/databases/backends/postgres.py index 69e65fb2..77a40171 100644 --- a/databases/backends/postgres.py +++ b/databases/backends/postgres.py @@ -272,11 +272,23 @@ def _compile_many( compiled = queries[0].compile( dialect=self._dialect, compile_kwargs={"render_postcompile": True} ) - for args in values: - for key, val in args.items(): - if key in compiled._bind_processors: - args[key] = compiled._bind_processors[key](val) - return compiled.string, values + new_values = [] + if not isinstance(queries[0], DDLElement): + for args in values: + sorted_args = sorted(args.items()) + mapping = { + key: "$" + str(i) for i, (key, _) in enumerate(sorted_args, start=1) + } + compiled_query = compiled.string % mapping + processors = compiled._bind_processors + values = [ + processors[key](val) if key in processors else val + for key, val in sorted_args + ] + new_values.append(values) + else: + compiled_query = compiled.string + return compiled_query, new_values @staticmethod def _create_column_maps( diff --git a/databases/backends/sqlite.py b/databases/backends/sqlite.py index 8f6c9748..5e88c061 100644 --- a/databases/backends/sqlite.py +++ b/databases/backends/sqlite.py @@ -203,11 +203,19 @@ def _compile_many( compiled = queries[0].compile( dialect=self._dialect, compile_kwargs={"render_postcompile": True} ) - for args in values: - for key, val in args.items(): - if key in compiled._bind_processors: - args[key] = compiled._bind_processors[key](val) - return compiled.string, values + new_values = [] + if not isinstance(queries[0], DDLElement): + for args in values: + temp_arr = [] + for key in compiled.positiontup: + raw_val = args[key] + if key in compiled._bind_processors: + val = compiled._bind_processors[key](raw_val) + else: + val = raw_val + temp_arr.append(val) + new_values.append(temp_arr) + return compiled.string, new_values @property def raw_connection(self) -> aiosqlite.core.Connection: