Really fix @INC munging of the taint test
[dbsrgits/DBIx-Class.git] / t / 746mssql.t
index 403d75c..2cc0281 100644 (file)
@@ -4,17 +4,13 @@ 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 DBIx::Class::Optional::Dependencies ();
 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;
+use lib qw(t/lib);
+use DBICTest;
 
 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
 
@@ -43,10 +39,9 @@ my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
 isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server' );
 
 {
-  my $schema2 = $schema->connect ($schema->storage->connect_info);
+  my $schema2 = $schema->connect (@{$schema->storage->connect_info});
   ok (! $schema2->storage->connected, 'a re-connected cloned schema starts unconnected');
 }
-
 $schema->storage->_dbh->disconnect;
 
 lives_ok {
@@ -58,11 +53,11 @@ my %opts = (
     { opts => { on_connect_call => 'use_mars' } },
   use_dynamic_cursors =>
     { opts => { on_connect_call => 'use_dynamic_cursors' },
-      required => $schema->storage->using_freetds ? 0 : 1,
+      required => $schema->storage->_using_freetds ? 0 : 1,
     },
   use_server_cursors =>
     { opts => { on_connect_call => 'use_server_cursors' } },
-  NO_OPTION =>
+  plain =>
     { opts => {}, required => 1 },
 );
 
@@ -76,12 +71,13 @@ for my $opts_name (keys %opts) {
     }
     catch {
       if ($opts{$opts_name}{required}) {
-        BAIL_OUT "on_connect_call option '$opts_name' is not functional: $_";
+        die "on_connect_call option '$opts_name' is not functional: $_";
       }
       else {
         skip
-"on_connect_call option '$opts_name' not functional in this configuration: $_",
-1;
+          "on_connect_call option '$opts_name' not functional in this configuration: $_",
+          1
+        ;
       }
     };
 
@@ -111,32 +107,40 @@ SQL
       skip 'not a multiple active statements configuration', 1
         if $opts_name eq 'plain';
 
-      my $artist_rs = $schema->resultset('Artist');
+      $schema->storage->ensure_connected;
 
-      $artist_rs->delete;
+      lives_ok {
 
-      $artist_rs->create({ name => "Artist$_" }) for (1..3);
+        no warnings 'redefine';
+        local *DBI::connect = sub { die "NO RECONNECTS!!!" };
 
-      my $forward  = $artist_rs->search({},
-        { order_by => { -asc  => 'artistid' } });
-      my $backward = $artist_rs->search({},
-        { order_by => { -desc => 'artistid' } });
+        my $artist_rs = $schema->resultset('Artist');
 
-      my @map = (
-        [qw/Artist1 Artist3/], [qw/Artist2 Artist2/], [qw/Artist3 Artist1/]
-      );
-      my @result;
+        $artist_rs->delete;
 
-      while (my $forward_row = $forward->next) {
-        my $backward_row = $backward->next;
-        push @result, [$forward_row->name, $backward_row->name];
-      }
+        $artist_rs->create({ name => "Artist$_" }) for (1..3);
+
+        my $forward  = $artist_rs->search({},
+          { order_by => { -asc  => 'artistid' } });
+        my $backward = $artist_rs->search({},
+          { order_by => { -desc => 'artistid' } });
 
-      is_deeply \@result, \@map, "multiple active statements in $opts_name";
+        my @map = (
+          [qw/Artist1 Artist3/], [qw/Artist2 Artist2/], [qw/Artist3 Artist1/]
+        );
+        my @result;
+
+        while (my $forward_row = $forward->next) {
+          my $backward_row = $backward->next;
+          push @result, [$forward_row->name, $backward_row->name];
+        }
 
-      $artist_rs->delete;
+        is_deeply \@result, \@map, "multiple active statements in $opts_name";
 
-      is($artist_rs->count, 0, '$dbh still viable');
+        $artist_rs->delete;
+
+        is($artist_rs->count, 0, '$dbh still viable');
+      } "Multiple active statements survive $opts_name";
     }
 
 # Test populate
@@ -243,7 +247,7 @@ SQL
         my $test_type = "Dialect:$dialect Quoted:$quoted";
 
         # basic limit support
-        TODO: {
+        {
           my $art_rs = $schema->resultset ('Artist');
           $art_rs->delete;
           $art_rs->create({ name => 'Artist ' . $_ }) for (1..6);
@@ -364,28 +368,11 @@ SQL
           },
         );
 
-        my ($sql, @bind) = @${$owners->page(3)->as_query};
-        is_same_bind (
-          \@bind,
-          [
-            ($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' ],
-          ],
-        );
-
         is ($owners->page(1)->all, 3, "$test_type: has_many prefetch returns correct number of rows");
         is ($owners->page(1)->count, 3, "$test_type: has-many prefetch returns correct count");
 
         is ($owners->page(3)->count, 2, "$test_type: has-many prefetch returns correct count");
-        TODO: {
+        {
           local $TODO = "Top-limit does not work when your limit ends up past the resultset"
             if $dialect eq 'Top';
           is ($owners->page(3)->all, 2, "$test_type: has_many prefetch returns correct number of rows");
@@ -408,37 +395,11 @@ SQL
           },
         );
 
-        ($sql, @bind) = @${$books->page(3)->as_query};
-        is_same_bind (
-          \@bind,
-          [
-            # inner
-            [ { 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
-            [ { 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' ],
-          ],
-        );
-
         is ($books->page(1)->all, 2, "$test_type: Prefetched grouped search returns correct number of rows");
         is ($books->page(1)->count, 2, "$test_type: Prefetched grouped search returns correct count");
 
         is ($books->page(2)->count, 1, "$test_type: Prefetched grouped search returns correct count");
-        TODO: {
+        {
           local $TODO = "Top-limit does not work when your limit ends up past the resultset"
             if $dialect eq 'Top';
           is ($books->page(2)->all, 1, "$test_type: Prefetched grouped search returns correct number of rows");
@@ -508,10 +469,10 @@ CREATE TABLE money_test (
 SQL
       });
 
-      TODO: {
+      {
         my $freetds_and_dynamic_cursors = 1
           if $opts_name eq 'use_dynamic_cursors' &&
-            $schema->storage->using_freetds;
+            $schema->storage->_using_freetds;
 
         local $TODO =
 'these tests fail on freetds with dynamic cursors for some reason'