[Bast-commits] r9081 - DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/t

rbo at dev.catalyst.perl.org rbo at dev.catalyst.perl.org
Sun Apr 4 10:56:37 GMT 2010


Author: rbo
Date: 2010-04-04 11:56:37 +0100 (Sun, 04 Apr 2010)
New Revision: 9081

Modified:
   DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/t/73oracle.t
Log:
Add missing nocycle test for hierarchical queries with oracle


Modified: DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/t/73oracle.t
===================================================================
--- DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/t/73oracle.t	2010-04-04 00:17:37 UTC (rev 9080)
+++ DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/t/73oracle.t	2010-04-04 10:56:37 UTC (rev 9081)
@@ -376,6 +376,22 @@
         ],
     });
 
+    $schema->resultset('Artist')->create(
+        {
+            name     => 'cycle-root',
+            children => [
+                {
+                    name     => 'cycle-child1',
+                    children => [ { name => 'cycle-grandchild' } ],
+                },
+                { name => 'cycle-child2' },
+            ],
+        }
+    );
+
+    $schema->resultset('Artist')->find({ name => 'cycle-root' })
+      ->update({ parentid => \'artistid' });
+
     # select the whole tree
     {
       my $rs = $schema->resultset('Artist')->search({}, {
@@ -609,29 +625,49 @@
       # is( $rs->count, 2, 'Connect By; LIMIT count ok' );
     }
 
-    # select the whole tree with nocylce
+    # select the whole cycle tree without nocylce
     {
       my $rs = $schema->resultset('Artist')->search({}, {
+        start_with => { name => 'cycle-root' },
+        connect_by => { parentid => { -prior => \ 'artistid' } },
+      });
+      eval { $rs->get_column ('name')->all };
+      if ( $@ =~ /ORA-01436/ ){ # ORA-01436:	CONNECT BY loop in user data
+        pass "connect by initify loop detection without nocycle";
+      }else{
+        fail "connect by initify loop detection without nocycle, not detected by oracle";
+      }
+    }
+
+    # select the whole cycle tree with nocylce
+    {
+      my $rs = $schema->resultset('Artist')->search({}, {
         nocycle    => 1,
-        start_with => { name => 'root' },
+        start_with => { name => 'cycle-root' },
+        '+select'  => [ \ 'CONNECT_BY_ISCYCLE' ],
         connect_by => { parentid => { -prior => \ 'artistid' } },
       });
 
       is_same_sql_bind (
         $rs->as_query,
         '(
-          SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid
+          SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid, CONNECT_BY_ISCYCLE
             FROM artist me
           START WITH name = ?
           CONNECT BY NOCYCLE parentid = PRIOR( artistid )
         )',
-        [ [ name => 'root'] ],
+        [ [ name => 'cycle-root'] ],
       );
       is_deeply (
         [ $rs->get_column ('name')->all ],
-        [ qw/root child1 grandchild greatgrandchild child2/ ],
-        'got artist tree with nocycle',
+        [ qw/cycle-root cycle-child1 cycle-grandchild cycle-child2/ ],
+        'got artist tree with nocycle (name)',
       );
+      is_deeply (
+        [ $rs->get_column ('CONNECT_BY_ISCYCLE')->all ],
+        [ qw/1 0 0 0/ ],
+        'got artist tree with nocycle (CONNECT_BY_ISCYCLE)',
+      );
 
 
       is_same_sql_bind (
@@ -642,10 +678,10 @@
           START WITH name = ?
           CONNECT BY NOCYCLE parentid = PRIOR( artistid )
         )',
-        [ [ name => 'root'] ],
+        [ [ name => 'cycle-root'] ],
       );
 
-      is( $rs->count, 5, 'Connect By Nocycle count ok' );
+      is( $rs->count, 4, 'Connect By Nocycle count ok' );
     }
 }
 




More information about the Bast-commits mailing list