call op expanders for unop hashpairs, move ident and value to op-only expand
[scpubgit/Q-Branch.git] / t / 08special_ops.t
index 131f99e..c4b303e 100644 (file)
@@ -33,6 +33,24 @@ my $sqlmaker = SQL::Abstract->new(special_ops => [
      }
    },
 
+  # PRIOR op from DBIx::Class::SQLMaker::Oracle
+
+  {
+    regex => qr/^prior$/i,
+    handler => sub {
+      my ($self, $lhs, $op, $rhs) = @_;
+      my ($sql, @bind) = $self->_recurse_where ($rhs);
+
+      $sql = sprintf ('%s = %s %s ',
+        $self->_convert($self->_quote($lhs)),
+        $self->_sqlcase ($op),
+        $sql
+      );
+
+      return ($sql, @bind);
+    },
+  },
+
 ], unary_ops => [
   # unary op from Mojo::Pg
   {regex => qr/^json$/i,
@@ -67,6 +85,16 @@ my @tests = (
     bind => [ { json => { bar => 'baz' } } ],
   },
 
+  # Verify inconsistent behaviour from DBIx::Class:SQLMaker::Oracle works
+  # (unary use of special op is not equivalent to special op + =)
+  {
+    where => {
+      foo_id => { '=' => { '-prior' => { -ident => 'bar_id' } } },
+      baz_id => { '-prior' => { -ident => 'quux_id' } },
+    },
+    stmt        => ' WHERE ( baz_id = PRIOR quux_id AND foo_id = ( PRIOR bar_id ) )',
+    bind        => [],
+  },
 );
 
 for (@tests) {