[Zope] identity values from sql server , mxodbc da

Josh Burvill jburvill at mri.com.au
Wed Apr 21 17:28:51 EDT 2010


Hi I am using zope 2.8.11

I am using mxodbc da to connect to sql server and I was wondering what is
the best way to get the new value of the primary key (an identity field)
after inserting.

It looks like there are 3 slightly different functions I could use:

"""""""""""

SCOPE_IDENTITY, IDENT_CURRENT, and @@IDENTITY are similar functions because
they return values that are inserted into identity columns.

IDENT_CURRENT is not limited by scope and session; it is limited to a
specified table. IDENT_CURRENT returns the value generated for a specific
table in any session and any scope. For more information, see IDENT_CURRENT
(Transact-SQL) <http://msdn.microsoft.com/en-us/library/ms175098.aspx>.

SCOPE_IDENTITY and @@IDENTITY return the last identity values that are
generated in any table in the current session. However, SCOPE_IDENTITY
returns values inserted only within the current scope; @@IDENTITY is not
limited to a specific scope.

""""""     (from http://msdn.microsoft.com/en-us/library/ms190315.aspx)
It seems like scope_identity might be the best one to use, but is it
possible that two zope transactions might occur within the one sql server
"scope" and "session" and therefore get the wrong identity value depending
on timing etc.

Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20100422/f16e64f4/attachment.html 


More information about the Zope mailing list