Fixed a regression where the "last inserted id" mechanics would
fail to store the correct value for MSSQL on an INSERT where the
- primary key value was present in the insert params before execution.
+ primary key value was present in the insert params before execution,
+ as well as in the case where an INSERT from SELECT would state the
+ target columns as column objects, instead of string keys.
+
.. change::
:tags: bug, mssql
"""
from .base import Executable, _generative, _from_objects, DialectKWArgs
-from .elements import ClauseElement, _literal_as_text, Null, and_, _clone
+from .elements import ClauseElement, _literal_as_text, Null, and_, _clone, \
+ _column_as_key
from .selectable import _interpret_as_from, _interpret_as_select, HasPrefixes
from .. import util
from .. import exc
"This construct already inserts value expressions")
self.parameters, self._has_multi_parameters = \
- self._process_colparams(dict((n, Null()) for n in names))
+ self._process_colparams(
+ dict((_column_as_key(n), Null()) for n in names))
self.select_names = names
self.inline = True
r = t6.insert().values(manual_id=id).execute()
eq_(r.inserted_primary_key, [12, 1])
- def test_implicit_id_insert_select(self):
+ def test_implicit_id_insert_select_columns(self):
stmt = users.insert().from_select(
(users.c.user_id, users.c.user_name),
users.select().where(users.c.user_id == 20))
testing.db.execute(stmt)
+ def test_implicit_id_insert_select_keys(self):
+ stmt = users.insert().from_select(
+ ["user_id", "user_name"],
+ users.select().where(users.c.user_id == 20))
+
+ testing.db.execute(stmt)
+
def test_row_iteration(self):
users.insert().execute(
{'user_id': 7, 'user_name': 'jack'},