fixup gensym behaviour
Matt S Trout [Fri, 20 Apr 2012 10:52:46 +0000 (10:52 +0000)]
lib/Data/Query/Renderer/SQL/Slice/FetchFirst.pm

index 6dd07fe..c45f836 100644 (file)
@@ -46,7 +46,7 @@ sub _render_slice {
     } else {
       die "XXX not implemented yet";
     }
-    $name ||= 'GENSYM__'.++$gensym_count;
+    $name ||= sprintf("GENSYM__%03i",++$gensym_count);
     push @inside_select_list, +{
       type => DQ_ALIAS,
       from => $s,
@@ -68,7 +68,7 @@ sub _render_slice {
       $order_map{$by}
         = $alias_map{join('.', @{$by->{elements}})}
           ||= do {
-                my $name = 'ORDER__BY__'.++$order_gensym_count;
+                my $name = sprintf("ORDER__BY__%03i",++$order_gensym_count);
                 push @inside_select_list, +{
                   type => DQ_ALIAS,
                   from => $by,
@@ -121,7 +121,10 @@ sub _render_slice {
     type => DQ_SELECT,
     select => (
       $dq->{preserve_order}
-        ? [ @outside_select_list, @order_map{map $_->{by}, @order_nodes} ]
+        ? [
+            @outside_select_list,
+            grep @{$_->{elements}} == 1, @order_map{map $_->{by}, @order_nodes}
+          ]
         : \@outside_select_list,
     ),
     from => $outside_order,