[Bast-commits] r9449 - in DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121: lib/DBIx/Class lib/DBIx/Class/SQLAHacks t

rbo at dev.catalyst.perl.org rbo at dev.catalyst.perl.org
Thu May 27 08:17:35 GMT 2010


Author: rbo
Date: 2010-05-27 09:17:35 +0100 (Thu, 27 May 2010)
New Revision: 9449

Modified:
   DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/lib/DBIx/Class/SQLAHacks.pm
   DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/lib/DBIx/Class/SQLAHacks/Oracle.pm
   DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/t/73oracle.t
Log:
Fixed group_by bind position problem, reported and patch by Alexande Keusch. Patch has been adjusted.


Modified: DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/lib/DBIx/Class/SQLAHacks/Oracle.pm
===================================================================
--- DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/lib/DBIx/Class/SQLAHacks/Oracle.pm	2010-05-26 16:46:08 UTC (rev 9448)
+++ DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/lib/DBIx/Class/SQLAHacks/Oracle.pm	2010-05-27 08:17:35 UTC (rev 9449)
@@ -27,10 +27,9 @@
 sub select {
     my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_;
 
-    my ($sql, @bind) = $self->SUPER::select($table, $fields, $where, $rs_attrs, @rest);
-    push @bind, @{$self->{_oracle_connect_by_binds}};
+    my $sql = $self->SUPER::select($table, $fields, $where, $rs_attrs, @rest);
 
-    return wantarray ? ($sql, @bind) : $sql;
+    return wantarray ? ($sql, @{$self->{from_bind}}, @{$self->{where_bind}}, @{$self->{_oracle_connect_by_binds}}, @{$self->{having_bind}}, @{$self->{order_bind}} ) : $sql;
 }
 
 sub _emulate_limit {

Modified: DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/lib/DBIx/Class/SQLAHacks.pm
===================================================================
--- DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/lib/DBIx/Class/SQLAHacks.pm	2010-05-26 16:46:08 UTC (rev 9448)
+++ DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/lib/DBIx/Class/SQLAHacks.pm	2010-05-27 08:17:35 UTC (rev 9449)
@@ -399,7 +399,7 @@
 sub select {
   my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_;
 
-  $self->{"${_}_bind"} = [] for (qw/having from order/);
+  $self->{"${_}_bind"} = [] for (qw/having from order where/);
 
   if (not ref($table) or ref($table) eq 'SCALAR') {
     $table = $self->_quote($table);
@@ -409,10 +409,11 @@
   croak "LIMIT 0 Does Not Compute" if $rest[0] == 0;
     # and anyway, SQL::Abstract::Limit will cause a barf if we don't first
 
-  my ($sql, @where_bind) = $self->SUPER::select(
+  my $sql = '';
+  ($sql, @{$self->{where_bind}}) = $self->SUPER::select(
     $table, $self->_recurse_fields($fields), $where, $rs_attrs, @rest
   );
-  return wantarray ? ($sql, @{$self->{from_bind}}, @where_bind, @{$self->{having_bind}}, @{$self->{order_bind}} ) : $sql;
+  return wantarray ? ($sql, @{$self->{from_bind}}, @{$self->{where_bind}}, @{$self->{having_bind}}, @{$self->{order_bind}} ) : $sql;
 }
 
 # Quotes table names, and handles default inserts

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-05-26 16:46:08 UTC (rev 9448)
+++ DBIx-Class/0.08/branches/oracle_hierarchical_queries_rt39121/t/73oracle.t	2010-05-27 08:17:35 UTC (rev 9449)
@@ -343,13 +343,16 @@
 
     $schema->resultset('Artist')->create ({
         name => 'root',
+        rank => 1,
         cds => [],
         children => [
             {
                 name => 'child1',
+                rank => 2,
                 children => [
                     {
                         name => 'grandchild',
+                        rank => 3,
                         cds => [
                             {
                                 title => "grandchilds's cd" ,
@@ -365,6 +368,7 @@
                         children => [
                             {
                                 name => 'greatgrandchild',
+                                rank => 3,
                             }
                         ],
                     }
@@ -372,6 +376,7 @@
             },
             {
                 name => 'child2',
+                rank => 3,
             },
         ],
     });
@@ -623,6 +628,36 @@
       is( $rs->count, 2, 'Connect By; LIMIT count ok' );
     }
 
+    # combine a connect_by with group_by and having
+    {
+      my $rs = $schema->resultset('Artist')->search({}, {
+        select => ['count(rank)'],
+        start_with => { name => 'root' },
+        connect_by => { parentid => { -prior => \ 'artistid' } },
+        group_by => ['rank'],
+        having => { 'count(rank)' => { '<', 2 } },
+      });
+
+      is_same_sql_bind (
+        $rs->as_query,
+        '(
+            SELECT count(rank)
+            FROM artist me
+            START WITH name = ?
+            CONNECT BY parentid = PRIOR artistid
+            GROUP BY rank HAVING count(rank) < ?
+        )',
+        [ [ name => 'root' ], [ 'count(rank)' => 2 ] ],
+      );
+
+      is_deeply (
+        [ $rs->get_column ('count(rank)')->all ],
+        [1, 1],
+        'Group By a Connect By query - correct values'
+      );
+    }
+
+
     # select the whole cycle tree without nocylce
     {
       my $rs = $schema->resultset('Artist')->search({}, {




More information about the Bast-commits mailing list