diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-04-17 10:55:08 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-06-27 21:30:37 -0400 |
commit | 08c46eea924d23a234bf3feea1a928eb8ae8a00a (patch) | |
tree | 3795e1d04fa0e35c1e93080320b43c8fe0ed792e /lib/sqlalchemy/engine/default.py | |
parent | 2d9387354f11da322c516412eb5dfe937163c90b (diff) | |
download | sqlalchemy-08c46eea924d23a234bf3feea1a928eb8ae8a00a.tar.gz |
ORM executemany returning
Build on #5401 to allow the ORM to take advanage
of executemany INSERT + RETURNING.
Implemented the feature
updated tests
to support INSERT DEFAULT VALUES, needed to come up with
a new syntax for compiler INSERT INTO table (anycol) VALUES (DEFAULT)
which can then be iterated out for executemany.
Added graceful degrade to plain executemany for PostgreSQL <= 8.2
Renamed EXECUTEMANY_DEFAULT to EXECUTEMANY_PLAIN
Fix issue where unicode identifiers or parameter names wouldn't
work with execute_values() under Py2K, because we have to
encode the statement and therefore have to encode the
insert_single_values_expr too.
Correct issue from #5401 to support executemany + return_defaults
for a PK that is explicitly pre-generated, meaning we aren't actually
getting RETURNING but need to return it from compiled_parameters.
Fixes: #5263
Change-Id: Id68e5c158c4f9ebc33b61c06a448907921c2a657
Diffstat (limited to 'lib/sqlalchemy/engine/default.py')
-rw-r--r-- | lib/sqlalchemy/engine/default.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 790f68de7..f2f30455a 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -824,7 +824,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): if self.isinsert or self.isupdate or self.isdelete: self.is_crud = True self._is_explicit_returning = bool(compiled.statement._returning) - self._is_implicit_returning = ( + self._is_implicit_returning = bool( compiled.returning and not compiled.statement._returning ) @@ -1291,11 +1291,12 @@ class DefaultExecutionContext(interfaces.ExecutionContext): result.out_parameters = out_parameters def _setup_dml_or_text_result(self): - if self.isinsert and not self.executemany: + if self.isinsert: if ( not self._is_implicit_returning and not self.compiled.inline and self.dialect.postfetch_lastrowid + and not self.executemany ): self._setup_ins_pk_from_lastrowid() @@ -1375,7 +1376,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): getter = self.compiled._inserted_primary_key_from_lastrowid_getter self.inserted_primary_key_rows = [ - getter(None, self.compiled_parameters[0]) + getter(None, param) for param in self.compiled_parameters ] def _setup_ins_pk_from_implicit_returning(self, result, rows): |