mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-16 05:37:16 -04:00
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
This commit is contained in:
+15
-1
@@ -936,11 +936,25 @@ class EmptyTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
|
||||
dialect = default.DefaultDialect()
|
||||
dialect.supports_empty_insert = dialect.supports_default_values = True
|
||||
|
||||
stmt = table1.insert().values({}) # hide from 2to3
|
||||
stmt = table1.insert().values({})
|
||||
self.assert_compile(
|
||||
stmt, "INSERT INTO mytable DEFAULT VALUES", dialect=dialect
|
||||
)
|
||||
|
||||
def test_supports_empty_insert_true_executemany_mode(self):
|
||||
table1 = self.tables.mytable
|
||||
|
||||
dialect = default.DefaultDialect()
|
||||
dialect.supports_empty_insert = dialect.supports_default_values = True
|
||||
|
||||
stmt = table1.insert().values({})
|
||||
self.assert_compile(
|
||||
stmt,
|
||||
"INSERT INTO mytable (myid) VALUES (DEFAULT)",
|
||||
dialect=dialect,
|
||||
for_executemany=True,
|
||||
)
|
||||
|
||||
def test_supports_empty_insert_false(self):
|
||||
table1 = self.tables.mytable
|
||||
|
||||
|
||||
Reference in New Issue
Block a user