- if (ref($opt{query}) eq 'HASH') {
- @query = ( $opt{query} );
- } elsif (ref($opt{query}) eq 'ARRAY') {
- @query = @{ $opt{query} };
+ if (ref($query) eq 'HASH') {
+ @query = $query;
+
+ if ( $order_by ) {
+ if ( $query->{'order_by'} ) {
+ if ( $query->{'order_by'} =~ /^(\s*ORDER\s+BY\s+)?(\S.*)$/is ) {
+ $query->{'order_by'} = "ORDER BY $order_by, $2";
+ } else {
+ warn "unparsable query order_by: ". $query->{'order_by'};
+ die "unparsable query order_by: ". $query->{'order_by'};
+ }
+ } else {
+ $query->{'order_by'} = "ORDER BY $order_by";
+ }
+ }
+
+ $query->{'order_by'} .= " $limit";
+
+ } elsif (ref($query) eq 'ARRAY') {
+ # do we still use this? it was for the old 477 report.
+ @query = @{ $query };