From: Luke Saunders Date: Wed, 4 Jul 2007 12:35:37 +0000 (+0000) Subject: fixed group_by problem with oracle limit syntax X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e8e971f256b0989484ac29ece5843cf2c9427429;p=dbsrgits%2FDBIx-Class-Historic.git fixed group_by problem with oracle limit syntax --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index ab28f83..d458e54 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -115,18 +115,18 @@ sub _emulate_limit { } 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 @@ sub _order_by { 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; diff --git a/t/73oracle.t b/t/73oracle.t index 5f4d67a..67a52b2 100644 --- a/t/73oracle.t +++ b/t/73oracle.t @@ -11,7 +11,7 @@ plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. '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 @@ eval { $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; $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) {