-#!/usr/bin/perl
-
use strict;
use warnings;
use Test::More;
my $sqlmaker = SQL::Abstract->new(special_ops => [
# special op for MySql MATCH (field) AGAINST(word1, word2, ...)
- {regex => qr/^match$/i,
+ {regex => qr/^match$/i,
handler => sub {
my ($self, $field, $op, $arg) = @_;
$arg = [$arg] if not ref $arg;
},
# special op for Basis+ NATIVE
- {regex => qr/^native$/i,
+ {regex => qr/^native$/i,
handler => sub {
my ($self, $field, $op, $arg) = @_;
$arg =~ s/'/''/g;
}
},
+ # 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,
+ handler => sub { '?', { json => $_[2] } }
+ },
]);
my @tests = (
- #1
+ #1
{ where => {foo => {-match => 'foo'},
bar => {-match => [qw/foo bar/]}},
stmt => " WHERE ( MATCH (bar) AGAINST (?, ?) AND MATCH (foo) AGAINST (?) )",
bind => [],
},
-);
+ #3
+ { where => { foo => { -json => { bar => 'baz' } } },
+ stmt => "WHERE foo = ?",
+ bind => [ { json => { bar => 'baz' } } ],
+ },
+ #4
+ { where => { foo => { '@>' => { -json => { bar => 'baz' } } } },
+ stmt => "WHERE foo @> ?",
+ bind => [ { json => { bar => 'baz' } } ],
+ },
-plan tests => scalar(@tests);
+ # Verify inconsistent behaviour from DBIx::Class:SQLMaker::Oracle works
+ {
+ where => {
+ manager_id => { '-prior' => { -ident => 'employee_id' } },
+ customer_id => { '>', { '-prior' => \'account_mgr_id' } },
+ },
+ stmt => ' WHERE ( customer_id > ( PRIOR account_mgr_id ) AND manager_id = PRIOR employee_id )',
+ bind => [],
+ },
+);
for (@tests) {
is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});
}
-
-
-
-
+done_testing;