[Bast-commits] r3568 - in trunk/DBIx-Class: lib/DBIx/Class/Storage t

captainL at dev.catalyst.perl.org captainL at dev.catalyst.perl.org
Wed Jul 4 13:35:37 GMT 2007


Author: captainL
Date: 2007-07-04 13:35:37 +0100 (Wed, 04 Jul 2007)
New Revision: 3568

Modified:
   trunk/DBIx-Class/lib/DBIx/Class/Storage/DBI.pm
   trunk/DBIx-Class/t/73oracle.t
Log:
fixed group_by problem with oracle limit syntax

Modified: trunk/DBIx-Class/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- trunk/DBIx-Class/lib/DBIx/Class/Storage/DBI.pm	2007-07-03 02:11:27 UTC (rev 3567)
+++ trunk/DBIx-Class/lib/DBIx/Class/Storage/DBI.pm	2007-07-04 12:35:37 UTC (rev 3568)
@@ -115,18 +115,18 @@
 }
 
 sub _recurse_fields {
-  my ($self, $fields) = @_;
+  my ($self, $fields, $params) = @_;
   my $ref = ref $fields;
   return $self->_quote($fields) unless $ref;
   return $$fields if $ref eq 'SCALAR';
 
   if ($ref eq 'ARRAY') {
-    return join(', ', map {
+		return join(', ', map {
       $self->_recurse_fields($_)
-      .(exists $self->{rownum_hack_count}
-         ? ' AS col'.$self->{rownum_hack_count}++
-         : '')
-     } @$fields);
+				.(exists $self->{rownum_hack_count} && !($params && $params->{no_rownum_hack})
+					? ' AS col'.$self->{rownum_hack_count}++
+					: '')
+      } @$fields);
   } elsif ($ref eq 'HASH') {
     foreach my $func (keys %$fields) {
       return $self->_sqlcase($func)
@@ -142,7 +142,7 @@
   if (ref $_[0] eq 'HASH') {
     if (defined $_[0]->{group_by}) {
       $ret = $self->_sqlcase(' group by ')
-               .$self->_recurse_fields($_[0]->{group_by});
+               .$self->_recurse_fields($_[0]->{group_by}, { no_rownum_hack => 1 });
     }
     if (defined $_[0]->{having}) {
       my $frag;

Modified: trunk/DBIx-Class/t/73oracle.t
===================================================================
--- trunk/DBIx-Class/t/73oracle.t	2007-07-03 02:11:27 UTC (rev 3567)
+++ trunk/DBIx-Class/t/73oracle.t	2007-07-04 12:35:37 UTC (rev 3568)
@@ -11,7 +11,7 @@
   'Warning: This test drops and creates tables called \'artist\', \'cd\' and \'track\''
   unless ($dsn && $user && $pass);
 
-plan tests => 6;
+plan tests => 7;
 
 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
 
@@ -26,7 +26,7 @@
 $dbh->do("CREATE SEQUENCE artist_seq START WITH 1 MAXVALUE 999999 MINVALUE 0");
 $dbh->do("CREATE TABLE artist (artistid NUMBER(12), name VARCHAR(255))");
 $dbh->do("CREATE TABLE cd (cdid NUMBER(12), artist NUMBER(12), title VARCHAR(255), year VARCHAR(4))");
-$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255))");
+$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE)");
 
 $dbh->do("ALTER TABLE artist ADD (CONSTRAINT artist_pk PRIMARY KEY (artistid))");
 $dbh->do(qq{
@@ -89,6 +89,12 @@
 $it->next;
 is( $it->next, undef, "next past end of resultset ok" );
 
+{
+  my $rs = $schema->resultset('Track')->search( undef, { columns=>[qw/trackid position/], group_by=> [ qw/trackid position/ ] , rows => 2, offset=>1 });
+  my @results = $rs->all;
+  is( scalar @results, 1, "Group by with limit OK" );
+}
+
 # clean up our mess
 END {
     if($dbh) {




More information about the Bast-commits mailing list