4 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Multiple inserts and...
FromSent OnAttachments
Paul Johnston25 Nov 2007 14:45 
Michael Bayer25 Nov 2007 15:22 
Jason R. Coombs27 Nov 2007 08:18 
Michael Bayer27 Nov 2007 08:27 
Subject:[sqlalchemy] Re: Multiple inserts and last_inserted_ids (MSSQL)
From:Michael Bayer (mike@zzzcomputing.com)
Date:11/27/2007 08:27:16 AM
List:com.googlegroups.sqlalchemy

On Nov 27, 2007, at 11:18 AM, Jason R. Coombs wrote:

This issue seems to be causing me some trouble as well. Using sqlalchemy-0.4.2dev_r3832, I'm getting the following error when attempting to flush my session:

if not len(self._last_inserted_ids) or self._last_inserted_ids[0] is None: AttributeError: 'MSSQLExecutionContext_pyodbc' object has no attribute '_last_inserted_ids'

I presume this is one of the unit tests that are currently failing, but I wanted to mention that I'm experiencing trouble with this is in practice as well. I get the same error in 0.4.0. I did not encounter this problem in 0.3.x.

Let me know if a fix is not in the works for this issue and what I can do to provide more helpful details.

im not sure if theres a ticket in trac for this but the fix is as such (MSSQL people please test/commit); the comment says "turn off INDENTITY_INSERT" but I dont see where that's happening; if its one of those SELECT statements, and it needs to happen for executemany as well, then the patch below needs to be adjusted:

Index: lib/sqlalchemy/databases/mssql.py =================================================================== --- lib/sqlalchemy/databases/mssql.py (revision 3832) +++ lib/sqlalchemy/databases/mssql.py (working copy) @@ -333,7 +333,7 @@ one column). """

- if self.compiled.isinsert and self.HASIDENT and not self.IINSERT: + if self.compiled.isinsert and self.HASIDENT and not self.IINSERT and not self.executemany: if not len(self._last_inserted_ids) or self._last_inserted_ids[0] is None: if self.dialect.use_scope_identity: self.cursor.execute("SELECT scope_identity() AS lastrowid")