[Bast-commits] r5313 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class/Storage/DBI

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Fri Jan 16 10:29:16 GMT 2009


Author: ribasushi
Date: 2009-01-16 10:29:16 +0000 (Fri, 16 Jan 2009)
New Revision: 5313

Modified:
   DBIx-Class/0.08/trunk/Changes
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/MSSQL.pm
Log:
Proper MSSQL last_insert_id() scoping patch by abraxxa
No tests as it is very hard to simulate the problematic behavior - it would only manifest if:
  1) An INSERT statement is issued from connection A
  2) An INSERT statement is issued from connection B
  3) last_insert_id is called from connection A

Without this patch the last id from the second INSERT will be returned in step 3
Tested with both DBICTEST_MSSQL_ODBC_DSN and DBICTEST_MSSQL_DSN against a MSSQL 2005

Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes	2009-01-14 08:02:12 UTC (rev 5312)
+++ DBIx-Class/0.08/trunk/Changes	2009-01-16 10:29:16 UTC (rev 5313)
@@ -5,8 +5,10 @@
         - 'result_class' resultset attribute, identical to result_class()
         - add 'undef_on_null_fk' option for relationship accessors of type 'single'. 
           This will prevent DBIC from querying the database if one or more of
-          the key columns IS NULL. Tests + docs (groditi)
-           - for 'belongs_to' rels, 'null_on_fk' defaults to true.
+          the key columns IS NULL
+        - for 'belongs_to' rels, 'undef_on_null_fk' defaults to true.
+        - fixed scope unaware last_insert_id fetching for MSSQL
+          (http://msdn.microsoft.com/en-us/library/ms190315.aspx)
 
 0.08099_05 2008-10-30 21:30:00 (UTC)
         - Rewritte of Storage::DBI::connect_info(), extended with an

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/MSSQL.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/MSSQL.pm	2009-01-14 08:02:12 UTC (rev 5312)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/MSSQL.pm	2009-01-16 10:29:16 UTC (rev 5313)
@@ -7,7 +7,7 @@
 
 sub _dbh_last_insert_id {
   my ($self, $dbh, $source, $col) = @_;
-  my ($id) = $dbh->selectrow_array('SELECT @@IDENTITY');
+  my ($id) = $dbh->selectrow_array('SELECT SCOPE_IDENTITY()');
   return $id;
 }
 




More information about the Bast-commits mailing list