add support for nulls => "none" in order nodes
[dbsrgits/Data-Query.git] / lib / Data / Query / Renderer / SQL / Slice / GenericSubquery.pm
index 5320cbb..41d1f37 100644 (file)
@@ -46,7 +46,8 @@ sub _render_slice {
         or (@{$order->{by}{elements}} == 1))
     ) {
       push @main_order, [
-        $outside->{by}, $order->{by}{elements}[-1], $order->{reverse}
+        $outside->{by}, $order->{by}{elements}[-1], $order->{reverse},
+        $order->{nulls}
       ];
     } else {
       last;
@@ -59,27 +60,40 @@ sub _render_slice {
     my $lhs = $b->[0];
     my $rhs = Identifier($count_alias, $b->[1]);
     ($lhs, $rhs) = ($rhs, $lhs) if $b->[2];
-    my $this = Operator($op_or, [
-      Operator($op_and, [
-        Operator({ 'SQL.Naive' => 'IS NOT NULL' }, [ $lhs ]),
-        Operator({ 'SQL.Naive' => 'IS NULL' }, [ $rhs ]),
-      ]),
-      Operator({ 'SQL.Naive' => '>' }, [ $lhs, $rhs ]),
-    ]);
-    ($a
-      ? Operator($op_or, [
-          $this,
-          Operator($op_and, [
-            Operator($op_or, [
-              Operator($op_and, [
-                map Operator({ 'SQL.Naive' => 'IS NULL' }, [ $_ ]), $lhs, $rhs
-              ]),
-              Operator({ 'SQL.Naive' => '=' }, [ $lhs, $rhs ])
+    my $no_nulls = ($b->[3]||'') eq 'none';
+    my ($this) = map {
+      $no_nulls
+        ? $_
+        : Operator($op_or, [
+            Operator($op_and, [
+              Operator({ 'SQL.Naive' => 'IS NOT NULL' }, [ $lhs ]),
+              Operator({ 'SQL.Naive' => 'IS NULL' }, [ $rhs ]),
             ]),
-            $a
+            $_
           ])
-        ])
-      : $this)
+    } Operator({ 'SQL.Naive' => '>' }, [ $lhs, $rhs ]);
+    my $final = (
+      $a
+        ? Operator($op_or, [
+            $this,
+            Operator($op_and, [
+              (map {
+                $no_nulls
+                  ? $_
+                  : Operator($op_or, [
+                      Operator($op_and, [
+                        map Operator({ 'SQL.Naive' => 'IS NULL' }, [ $_ ]),
+                          $lhs, $rhs
+                      ]),
+                      $_,
+                    ])
+              } Operator({ 'SQL.Naive' => '=' }, [ $lhs, $rhs ])),
+              $a
+            ])
+          ])
+        : $this
+    );
+    $final;
   } @main_order, undef;
   my $count_sel = Select(
     [ Operator({ 'SQL.Naive' => 'apply' }, [ Identifier('COUNT'), Identifier('*') ]) ],