Backout sybase changes
[dbsrgits/DBIx-Class.git] / t / 746mssql.t
index f9cbf85..a75001e 100644 (file)
@@ -12,8 +12,6 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PA
 plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN}, _USER and _PASS to run this test'
   unless ($dsn && $user);
 
-plan tests => 39;
-
 DBICTest::Schema->load_classes('ArtistGUID');
 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
 
@@ -54,13 +52,24 @@ my $new;
 
 # 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);
+
+    eval {
+      $schema->storage->ensure_connected
+    };
+    if ($@ =~ /dynamic cursors/) {
+      skip
+'Dynamic Cursors not functional, tds_version 8.0 or greater required if using'.
+' FreeTDS', 1;
+    }
+
+    $schema->resultset('Artist')->search({ name => 'foo' })->delete;
 
-  $schema->resultset('Artist')->search({ name => 'foo' })->delete;
+    $new = $schema->resultset('Artist')->create({ name => 'foo' });
 
-  $new = $schema->resultset('Artist')->create({ name => 'foo' });
-  ok($new->artistid > 0, "Auto-PK worked");
+    ok($new->artistid > 0, "Auto-PK worked");
+  }
 }
 
 $seen_id{$new->artistid}++;
@@ -100,6 +109,9 @@ CREATE TABLE artist (
 SQL
 });
 
+# start disconnected to make sure insert works on an un-reblessed storage
+$schema = DBICTest::Schema->connect($dsn, $user, $pass);
+
 my $row;
 lives_ok {
   $row = $schema->resultset('ArtistGUID')->create({ name => 'mtfnpy' })
@@ -147,13 +159,14 @@ lives_ok {
   $row = $rs->create({ amount => 100 });
 } 'inserted a money value';
 
-is $rs->find($row->id)->amount, '100.00', 'money value round-trip';
+cmp_ok $rs->find($row->id)->amount, '==', 100, 'money value round-trip';
 
 lives_ok {
   $row->update({ amount => 200 });
 } 'updated a money value';
 
-is $rs->find($row->id)->amount, '200.00', 'updated money value round-trip';
+cmp_ok $rs->find($row->id)->amount, '==', 200,
+  'updated money value round-trip';
 
 lives_ok {
   $row->update({ amount => undef });
@@ -183,6 +196,8 @@ SQL
 });
 
 lives_ok ( sub {
+  # start a new connection, make sure rebless works
+  my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
   $schema->populate ('Owners', [
     [qw/id  name  /],
     [qw/1   wiggle/],
@@ -203,7 +218,22 @@ lives_ok ( sub {
   ]);
 }, 'populate with PKs supplied ok' );
 
+lives_ok (sub {
+  # start a new connection, make sure rebless works
+  # test an insert with a supplied identity, followed by one without
+  my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
+  for (1..2) {
+    my $id = $_ * 20 ;
+    $schema->resultset ('Owners')->create ({ id => $id, name => "troglodoogle $id" });
+    $schema->resultset ('Owners')->create ({ name => "troglodoogle " . ($id + 1) });
+  }
+}, 'create with/without PKs ok' );
+
+is ($schema->resultset ('Owners')->count, 19, 'owner rows really in db' );
+
 lives_ok ( sub {
+  # start a new connection, make sure rebless works
+  my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
   $schema->populate ('BooksInLibrary', [
     [qw/source  owner title   /],
     [qw/Library 1     secrets0/],
@@ -249,7 +279,7 @@ $schema->storage->_sql_maker->{name_sep} = '.';
     is ($owners->page(3)->count, 2, 'has-many prefetch returns correct count');
     is ($owners->page(3)->count_rs->next, 2, 'has-many prefetch returns correct count_rs');
 
-    # make sure count does not become overly complex FIXME
+    # make sure count does not become overly complex
     is_same_sql_bind (
       $owners->page(3)->count_rs->as_query,
       '(
@@ -289,7 +319,7 @@ $schema->storage->_sql_maker->{name_sep} = '.';
     is ($books->page(2)->count, 1, 'Prefetched grouped search returns correct count');
     is ($books->page(2)->count_rs->next, 1, 'Prefetched grouped search returns correct count_rs');
 
-    # make sure count does not become overly complex FIXME
+    # make sure count does not become overly complex (FIXME - the distinct-induced group_by is incorrect)
     is_same_sql_bind (
       $books->page(2)->count_rs->as_query,
       '(
@@ -299,7 +329,7 @@ $schema->storage->_sql_maker->{name_sep} = '.';
               FROM [books] [me]
               JOIN [owners] [owner] ON [owner].[id] = [me].[owner]
             WHERE ( ( ( [owner].[name] = ? OR [owner].[name] = ? ) AND [source] = ? ) )
-            GROUP BY [me].[id], [me].[source], [me].[owner], [me].[title], [me].[price], [owner].[id], [owner].[name]
+            GROUP BY [me].[id], [me].[source], [me].[owner], [me].[title], [me].[price]
             ORDER BY [me].[id] DESC
           ) [count_subq]
       )',
@@ -310,9 +340,10 @@ $schema->storage->_sql_maker->{name_sep} = '.';
       ],
     );
   }
-
 }
 
+done_testing;
+
 # clean up our mess
 END {
   if (my $dbh = eval { $schema->storage->_dbh }) {