X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FRetrieve.pm;h=34be5f3833690e34fc9b757d8ba38eab09a583d5;hb=49eb5522ff64004f2fb7667b0e032555521bad32;hp=1186ae4583a76066e5c474e55a18af4356ea15d0;hpb=9387c9042568a6c4dcc8e197f0000e7c7c4bbf13;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/CDBICompat/Retrieve.pm b/lib/DBIx/Class/CDBICompat/Retrieve.pm index 1186ae4..34be5f3 100644 --- a/lib/DBIx/Class/CDBICompat/Retrieve.pm +++ b/lib/DBIx/Class/CDBICompat/Retrieve.pm @@ -47,12 +47,48 @@ sub _build_query { sub retrieve_from_sql { my ($class, $cond, @rest) = @_; + $cond =~ s/^\s*WHERE//i; - $class->search_literal($cond, @rest); + + # 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+(.*)\s*$//i ) { + $attrs{order_by} = $1; + } + + 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; } sub retrieve_all { shift->search } sub count_all { shift->count } - # Contributed by Numa. No test for this though. + +sub maximum_value_of { + my($class, $col) = @_; + return $class->resultset_instance->get_column($col)->max; +} + +sub minimum_value_of { + my($class, $col) = @_; + return $class->resultset_instance->get_column($col)->min; +} 1;