Trailing WS crusade - got to save them bits
[dbsrgits/DBIx-Class.git] / t / 746mssql.t
index bb0b254..6557d49 100644 (file)
@@ -3,10 +3,18 @@ use warnings;
 
 use Test::More;
 use Test::Exception;
+use Try::Tiny;
+use DBIx::Class::SQLMaker::LimitDialects;
+use DBIx::Class::Optional::Dependencies ();
 use lib qw(t/lib);
 use DBICTest;
 use DBIC::SqlMakerTest;
-use Try::Tiny;
+
+plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_mssql_odbc')
+  unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_mssql_odbc');
+
+my $OFFSET = DBIx::Class::SQLMaker::LimitDialects->__offset_bindtype;
+my $TOTAL  = DBIx::Class::SQLMaker::LimitDialects->__total_bindtype;
 
 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
 
@@ -47,25 +55,32 @@ lives_ok {
 
 my %opts = (
   use_mars =>
-    { on_connect_call => 'use_mars' },
+    { opts => { on_connect_call => 'use_mars' } },
   use_dynamic_cursors =>
-    { on_connect_call => 'use_dynamic_cursors' },
+    { opts => { on_connect_call => 'use_dynamic_cursors' }, required => 1 },
   use_server_cursors =>
-    { on_connect_call => 'use_server_cursors' },
-  plain =>
-    {},
+    { opts => { on_connect_call => 'use_server_cursors' } },
+  NO_OPTION =>
+    { opts => {}, required => 1 },
 );
 
 for my $opts_name (keys %opts) {
   SKIP: {
-    my $opts = $opts{$opts_name};
+    my $opts = $opts{$opts_name}{opts};
     $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opts);
 
     try {
       $schema->storage->ensure_connected
     }
     catch {
-      skip "$opts_name not functional in this configuration: $_", 1;
+      if ($opts{$opts_name}{required}) {
+        BAIL_OUT "on_connect_call option '$opts_name' is not functional: $_";
+      }
+      else {
+        skip
+"on_connect_call option '$opts_name' not functional in this configuration: $_",
+1;
+      }
     };
 
     $schema->storage->dbh_do (sub {
@@ -375,11 +390,19 @@ SQL
         );
 
         my ($sql, @bind) = @${$owners->page(3)->as_query};
-        is_deeply (
+        is_same_bind (
           \@bind,
           [
-            $dialect eq 'Top' ? [ test => 'xxx' ] : (),                 # the extra re-order bind
-            ([ 'me.name' => 'somebogusstring' ], [ test => 'xxx' ]) x 2 # double because of the prefetch subq
+            ($dialect eq 'Top' ? [ { dbic_colname => 'test' } => 'xxx' ] : ()), # the extra re-order bind
+            [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'me.name' }
+              => 'somebogusstring' ],
+            [ { dbic_colname => 'test' }
+              => 'xxx' ],
+            ($dialect ne 'Top' ? ( [ $OFFSET => 7 ], [ $TOTAL => 9 ] ) : ()), # parameterised RNO
+            [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'me.name' }
+              => 'somebogusstring' ],
+            [ { dbic_colname => 'test' }
+              => 'xxx' ],
           ],
         );
 
@@ -411,13 +434,28 @@ SQL
         );
 
         ($sql, @bind) = @${$books->page(3)->as_query};
-        is_deeply (
+        is_same_bind (
           \@bind,
           [
             # inner
-            [ 'owner.name' => 'wiggle' ], [ 'owner.name' => 'woggle' ], [ source => 'Library' ], [ test => '1' ],
+            [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'owner.name' }
+              => 'wiggle' ],
+            [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'owner.name' }
+              => 'woggle' ],
+            [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
+              => 'Library' ],
+            [ { dbic_colname => 'test' }
+              => '1' ],
+
+            # rno(?)
+            $dialect ne 'Top' ? ( [ $OFFSET => 5 ], [ $TOTAL => 6 ] ) : (),
             # outer
-            [ 'owner.name' => 'wiggle' ], [ 'owner.name' => 'woggle' ], [ source => 'Library' ],
+            [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'owner.name' }
+              => 'wiggle' ],
+            [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'owner.name' }
+              => 'woggle' ],
+            [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
+              => 'Library' ],
           ],
         );
 
@@ -495,27 +533,41 @@ CREATE TABLE money_test (
 SQL
       });
 
-      my $rs = $schema->resultset('Money');
-      my $row;
+      TODO: {
+        my $freetds_and_dynamic_cursors = 1
+          if $opts_name eq 'use_dynamic_cursors' &&
+            $schema->storage->using_freetds;
 
-      lives_ok {
-        $row = $rs->create({ amount => 100 });
-      } 'inserted a money value';
+        local $TODO =
+'these tests fail on freetds with dynamic cursors for some reason'
+          if $freetds_and_dynamic_cursors;
+        local $ENV{DBIC_NULLABLE_KEY_NOWARN} = 1
+          if $freetds_and_dynamic_cursors;
 
-      cmp_ok $rs->find($row->id)->amount, '==', 100, 'money value round-trip';
+        my $rs = $schema->resultset('Money');
+        my $row;
 
-      lives_ok {
-        $row->update({ amount => 200 });
-      } 'updated a money value';
+        lives_ok {
+          $row = $rs->create({ amount => 100 });
+        } 'inserted a money value';
 
-      cmp_ok $rs->find($row->id)->amount, '==', 200,
-        'updated money value round-trip';
+        cmp_ok ((try { $rs->find($row->id)->amount })||0, '==', 100,
+          'money value round-trip');
 
-      lives_ok {
-        $row->update({ amount => undef });
-      } 'updated a money value to NULL';
+        lives_ok {
+          $row->update({ amount => 200 });
+        } 'updated a money value';
 
-      is $rs->find($row->id)->amount, undef,'updated money value to NULL round-trip';
+        cmp_ok ((try { $rs->find($row->id)->amount })||0, '==', 200,
+          'updated money value round-trip');
+
+        lives_ok {
+          $row->update({ amount => undef });
+        } 'updated a money value to NULL';
+
+        is try { $rs->find($row->id)->amount }, undef,
+          'updated money value to NULL round-trip';
+      }
     }
   }
 }