fix expr.include to generate alias nodes correctly
Matt S Trout [Sat, 28 Jul 2012 11:38:59 +0000 (11:38 +0000)]
lib/Data/Query/Renderer/SQL/Slice/GenericSubQ.pm
t/expr.include

index 92379af..f912f61 100644 (file)
@@ -129,7 +129,11 @@ sub _render_slice {
     where => {
       type => DQ_OPERATOR,
       operator => {
-        'SQL.Naive' => $dq->{offset} ? 'BETWEEN' : '<'
+        'SQL.Naive' => (
+          $dq->{offset}
+            ? 'BETWEEN'
+            : $order_nodes[0]{reverse} ? '>' : '<'
+        ),
       },
       args => [
         {
@@ -159,7 +163,9 @@ sub _render_slice {
             },
             where => {
               type => DQ_OPERATOR,
-              operator => { 'SQL.Naive' => '<' },
+              operator => {
+                'SQL.Naive' => $order_nodes[0]{reverse} ? '>' : '<'
+              },
               args => [
                 map +{
                   type => DQ_IDENTIFIER,
@@ -172,8 +178,14 @@ sub _render_slice {
             }
           },
         },
-        $dq->{limit},
-        ($dq->{offset} ? ($dq->{offset} : ())),
+        ($dq->{offset}
+           ? ($dq->{offset},
+               { %{$dq->{limit}},
+                 value => $dq->{offset}{value} + $dq->{limit}{value} - 1
+               }
+             )
+           : ($dq->{limit})
+        ),
       ]
     },
   };
index beaff7c..6d80c9d 100644 (file)
@@ -34,8 +34,8 @@ sub SELECT (&;@) {
       (ref($select[0]) eq 'LIES::AS'
         ? +{
              type => DQ_ALIAS,
-             alias => $e->{expr},
-             as => ${shift(@select)}
+             from => $e->{expr},
+             to => ${shift(@select)}
           }
         : $e->{expr}
      );