[Dbix-class] can't get PK::Auto with MSSQL thru Sybase - fix?

Christopher H. Laco claco at chrislaco.com
Tue Sep 5 21:32:58 CEST 2006


Robert Dobbs wrote:
>> From: "Robert Dobbs" <bobisdobbs at hotmail.com>
>>
>>           * For some drivers the value may only be available if 
>> placeholders
>>           have not been used (e.g., Sybase, MS SQL). In this case the 
>> value
>>           returned would be from the last non-placeholder insert 
>> statement.
>>
>> Bleah.  I guess I have to use SQL and be very careful about de-sqlifying 
>> input.
> 
> Hey guess what.  This doesn't seem to matter.  As a test, I changed line 941 
> of DBIC:Storage::DBI to do "return $self->dbh->selectrow_array('SELECT 
> @@IDENTITY')" and it works great.  I think the subclassed PK::Auto for 
> MS-SQL needs to be brought back to life.
> 
> Mark

Be aware, @@IDENTITY can lead to odd things (MSSQL)...


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

IDENT_CURRENT is not limited by scope and session; it is limited to a
specified table. IDENT_CURRENT returns the identity value generated for
a specific table in any session and any scope. For more information, see
IDENT_CURRENT.

The scope of the @@IDENTITY function is the local server on which it is
executed. This function cannot be applied to remote or linked servers.
To obtain an identity value on a different server, execute a stored
procedure on that remote or linked server and have that stored
procedure, which is executing in the context of the remote or linked
server, gather the identity value and return it to the calling
connection on the local server.
--

On top of that, should the connection be dropped/reset/ping-ed between
the insert and the SELECT @@IDENTITY call, you may no get the correct value.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060905/311d9969/attachment.pgp 


More information about the Dbix-class mailing list