[Bast-commits] r7179 - in DBIx-Class/0.08/branches/mssql_storage_minor_refactor: lib/DBIx/Class/Storage/DBI/ODBC t

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Mon Aug 3 11:42:31 GMT 2009


Author: caelum
Date: 2009-08-03 11:42:31 +0000 (Mon, 03 Aug 2009)
New Revision: 7179

Modified:
   DBIx-Class/0.08/branches/mssql_storage_minor_refactor/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm
   DBIx-Class/0.08/branches/mssql_storage_minor_refactor/t/746mssql.t
Log:
check that dynamic cursors are functional if enabled

Modified: DBIx-Class/0.08/branches/mssql_storage_minor_refactor/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm
===================================================================
--- DBIx-Class/0.08/branches/mssql_storage_minor_refactor/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm	2009-08-03 10:41:32 UTC (rev 7178)
+++ DBIx-Class/0.08/branches/mssql_storage_minor_refactor/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm	2009-08-03 11:42:31 UTC (rev 7179)
@@ -44,12 +44,13 @@
 Will add C<< odbc_cursortype => 2 >> to your DBI connection attributes. See
 L<DBD::ODBC/odbc_cursortype> for more information.
 
-Alternatively, you can add it yourself and dynamic cursor will be automatically
-enabled.
+Alternatively, you can add it yourself and dynamic cursor support will be
+automatically enabled.
 
-This will not work with CODE ref connect_info's and will do nothing if you set
-C<odbc_cursortype> yourself.
+If you're using FreeTDS, C<tds_version> must be set to at least C<8.0>.
 
+This will not work with CODE ref connect_info's.
+
 B<WARNING:> this will break C<SCOPE_IDENTITY()>, and C<SELECT @@IDENTITY> will
 be used instead, which on SQL Server 2005 and later will return erroneous
 results on tables which have an on insert trigger that inserts into another
@@ -83,6 +84,21 @@
 
 sub _set_dynamic_cursors {
   my $self = shift;
+  my $dbh  = $self->_dbh;
+
+  eval {
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
+    $dbh->do('SELECT @@IDENTITY');
+  };
+  if ($@) {
+    croak <<'EOF';
+
+Your drivers do not seem to support dynamic cursors (odbc_cursortype => 2),
+if you're using FreeTDS, make sure to set tds_version to 8.0 or greater.
+EOF
+  }
+
   $self->_using_dynamic_cursors(1);
   $self->_identity_method('@@identity');
 }

Modified: DBIx-Class/0.08/branches/mssql_storage_minor_refactor/t/746mssql.t
===================================================================
--- DBIx-Class/0.08/branches/mssql_storage_minor_refactor/t/746mssql.t	2009-08-03 10:41:32 UTC (rev 7178)
+++ DBIx-Class/0.08/branches/mssql_storage_minor_refactor/t/746mssql.t	2009-08-03 11:42:31 UTC (rev 7179)
@@ -54,13 +54,24 @@
 
 # test Auto-PK with different options
 for my $opts (@opts) {
-  $schema = DBICTest::Schema->clone;
-  $schema->connection($dsn, $user, $pass, $opts);
+  SKIP: {
+    $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opts);
 
-  $schema->resultset('Artist')->search({ name => 'foo' })->delete;
+    eval {
+      $schema->storage->ensure_connected
+    };
+    if ($@ =~ /dynamic cursors/) {
+      skip
+'Dynamic Cursors not functional, tds_version 8.0 or greater required if using'.
+' FreeTDS', 1;
+    }
 
-  $new = $schema->resultset('Artist')->create({ name => 'foo' });
-  ok($new->artistid > 0, "Auto-PK worked");
+    $schema->resultset('Artist')->search({ name => 'foo' })->delete;
+
+    $new = $schema->resultset('Artist')->create({ name => 'foo' });
+
+    ok($new->artistid > 0, "Auto-PK worked");
+  }
 }
 
 $seen_id{$new->artistid}++;




More information about the Bast-commits mailing list