summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/suite/test_insert.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-12-21 10:16:31 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2016-12-21 13:41:25 -0500
commitf472405e598ad3088308db8bfef2879a57b26025 (patch)
treefe650b30a2f04a8432a5cfba71231105edf95ca4 /lib/sqlalchemy/testing/suite/test_insert.py
parentd5bb919aa6d5b9961f85987dfaa58d5999910d15 (diff)
downloadsqlalchemy-f472405e598ad3088308db8bfef2879a57b26025.tar.gz
Don't select lastrowid for inline=True
- Fixed bug where SQL Server dialects would attempt to select the last row identity for an INSERT from SELECT, failing in the case when the SELECT has no rows. For such a statement, the inline flag is set to True indicating no last primary key should be fetched. Change-Id: Ic40d56d9eadadc3024a4d71245f9eed4c420024a Fixes: #3876
Diffstat (limited to 'lib/sqlalchemy/testing/suite/test_insert.py')
-rw-r--r--lib/sqlalchemy/testing/suite/test_insert.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_insert.py b/lib/sqlalchemy/testing/suite/test_insert.py
index 70e8a6b17..c0b6b18eb 100644
--- a/lib/sqlalchemy/testing/suite/test_insert.py
+++ b/lib/sqlalchemy/testing/suite/test_insert.py
@@ -141,6 +141,56 @@ class InsertBehaviorTest(fixtures.TablesTest):
assert len(r.fetchall())
@requirements.insert_from_select
+ def test_insert_from_select_autoinc(self):
+ src_table = self.tables.manual_pk
+ dest_table = self.tables.autoinc_pk
+ config.db.execute(
+ src_table.insert(),
+ [
+ dict(id=1, data="data1"),
+ dict(id=2, data="data2"),
+ dict(id=3, data="data3"),
+ ]
+ )
+
+ result = config.db.execute(
+ dest_table.insert().
+ from_select(
+ ("data",),
+ select([src_table.c.data]).
+ where(src_table.c.data.in_(["data2", "data3"]))
+ )
+ )
+
+ eq_(result.inserted_primary_key, [None])
+
+ result = config.db.execute(
+ select([dest_table.c.data]).order_by(dest_table.c.data)
+ )
+ eq_(result.fetchall(), [("data2", ), ("data3", )])
+
+ @requirements.insert_from_select
+ def test_insert_from_select_autoinc_no_rows(self):
+ src_table = self.tables.manual_pk
+ dest_table = self.tables.autoinc_pk
+
+ result = config.db.execute(
+ dest_table.insert().
+ from_select(
+ ("data",),
+ select([src_table.c.data]).
+ where(src_table.c.data.in_(["data2", "data3"]))
+ )
+ )
+ eq_(result.inserted_primary_key, [None])
+
+ result = config.db.execute(
+ select([dest_table.c.data]).order_by(dest_table.c.data)
+ )
+
+ eq_(result.fetchall(), [])
+
+ @requirements.insert_from_select
def test_insert_from_select(self):
table = self.tables.manual_pk
config.db.execute(