Add eval => try
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / SQLAHacks.pm
index 71b89ff..c362e91 100644 (file)
@@ -140,7 +140,7 @@ sub _subqueried_limit_attrs {
       next if $in_sel_index->{$chunk};
 
       $extra_order_sel{$chunk} ||= $self->_quote (
-        '__ORDER_BY_' . scalar keys %extra_order_sel
+        'ORDER__BY__' . scalar keys %extra_order_sel
       );
     }
   }
@@ -381,7 +381,7 @@ sub _Top {
     $sql,
     $quoted_rs_alias,
     $order_by_requested,
-  ) if ($order_by_requested || ($mid_sel ne $out_sel));
+  ) if ( ($offset && $order_by_requested) || ($mid_sel ne $out_sel) );
 
   return $sql;
 }
@@ -405,8 +405,6 @@ sub select {
     $table = $self->_quote($table);
   }
 
-  local $self->{rownum_hack_count} = 1
-    if (defined $rest[0] && $self->{limit_dialect} eq 'RowNum');
   @rest = (-1) unless defined $rest[0];
   croak "LIMIT 0 Does Not Compute" if $rest[0] == 0;
     # and anyway, SQL::Abstract::Limit will cause a barf if we don't first
@@ -487,6 +485,8 @@ sub _recurse_fields {
       croak "Malformed select argument - too many keys in hash: " . join (',', keys %$fields );
     }
 
+    $func =~ s/^\-+//;  # strip leading dash, at some point the dash itself should become mandatory
+
     if (lc ($func) eq 'distinct' && ref $args eq 'ARRAY' && @$args > 1) {
       croak (
         'The select => { distinct => ... } syntax is not supported for multiple columns.'
@@ -532,7 +532,7 @@ sub _parse_rs_attrs {
 
   my $sql = '';
 
-  if (my $g = $self->_recurse_fields($arg->{group_by}, { no_rownum_hack => 1 }) ) {
+  if (my $g = $self->_recurse_fields($arg->{group_by}) ) {
     $sql .= $self->_sqlcase(' group by ') . $g;
   }
 
@@ -577,6 +577,23 @@ sub _order_directions {
   ]);
 }
 
+sub _order_by_chunks {
+  my ($self, $arg) = @_;
+  if (  # non-empty hash with neither an -asc or a -desc
+    ref $arg eq 'HASH'
+      &&
+    keys %$arg
+      &&
+    ! exists $arg->{-desc}
+      &&
+    ! exists $arg->{-asc}
+  ) {
+    return $self->_recurse_fields ($arg);
+  }
+
+  return $self->SUPER::_order_by_chunks ($arg);
+}
+
 sub _table {
   my ($self, $from) = @_;
   if (ref $from eq 'ARRAY') {