X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FRetrieve.pm;h=34be5f3833690e34fc9b757d8ba38eab09a583d5;hb=d4daee7b54e38e4b3d3d0a77759bddc1a4ede6e5;hp=b2e891d7b3a0b8ddae3e6d583cca42e144a9a923;hpb=e2bdf48529d8b9d772e50e490657297382f8d093;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/CDBICompat/Retrieve.pm b/lib/DBIx/Class/CDBICompat/Retrieve.pm index b2e891d..34be5f3 100644 --- a/lib/DBIx/Class/CDBICompat/Retrieve.pm +++ b/lib/DBIx/Class/CDBICompat/Retrieve.pm @@ -50,22 +50,31 @@ sub retrieve_from_sql { $cond =~ s/^\s*WHERE//i; - if( $cond =~ s/\bLIMIT (\d+)\s*$//i ) { - push @rest, { rows => $1 }; + # Need to parse the SQL clauses after WHERE in reverse + # order of appearance. + + my %attrs; + + if( $cond =~ s/\bLIMIT\s+(\d+)\s*$//i ) { + $attrs{rows} = $1; } - if ( $cond =~ s/\bORDER\s+BY\s+(.*)$//i ) { - push @rest, { order_by => $1 }; + if ( $cond =~ s/\bORDER\s+BY\s+(.*)\s*$//i ) { + $attrs{order_by} = $1; } - return $class->search_literal($cond, @rest); + if( $cond =~ s/\bGROUP\s+BY\s+(.*)\s*$//i ) { + $attrs{group_by} = $1; + } + + return $class->search_literal($cond, @rest, ( %attrs ? \%attrs : () ) ); } sub construct { my $class = shift; my $obj = $class->resultset_instance->new_result(@_); $obj->in_storage(1); - + return $obj; }