5 use SQL::Abstract::Test import => ['is_same_sql_bind'];
9 my $sqlmaker = SQL::Abstract->new(special_ops => [
11 # special op for MySql MATCH (field) AGAINST(word1, word2, ...)
12 {regex => qr/^match$/i,
14 my ($self, $field, $op, $arg) = @_;
15 $arg = [$arg] if not ref $arg;
16 my $label = $self->_quote($field);
17 my ($placeholder) = $self->_convert('?');
18 my $placeholders = join ", ", (($placeholder) x @$arg);
19 my $sql = $self->_sqlcase('match') . " ($label) "
20 . $self->_sqlcase('against') . " ($placeholders) ";
21 my @bind = $self->_bindtype($field, @$arg);
26 # special op for Basis+ NATIVE
27 {regex => qr/^native$/i,
29 my ($self, $field, $op, $arg) = @_;
31 my $sql = "NATIVE (' $field $arg ')";
36 # PRIOR op from DBIx::Class::SQLMaker::Oracle
39 regex => qr/^prior$/i,
41 my ($self, $lhs, $op, $rhs) = @_;
42 my ($sql, @bind) = $self->_recurse_where ($rhs);
44 $sql = sprintf ('%s = %s %s ',
45 $self->_convert($self->_quote($lhs)),
46 $self->_sqlcase ($op),
55 # unary op from Mojo::Pg
56 {regex => qr/^json$/i,
57 handler => sub { '?', { json => $_[2] } }
64 { where => {foo => {-match => 'foo'},
65 bar => {-match => [qw/foo bar/]}},
66 stmt => " WHERE ( MATCH (bar) AGAINST (?, ?) AND MATCH (foo) AGAINST (?) )",
67 bind => [qw/foo bar foo/],
71 { where => {foo => {-native => "PH IS 'bar'"}},
72 stmt => " WHERE ( NATIVE (' foo PH IS ''bar'' ') )",
77 { where => { foo => { -json => { bar => 'baz' } } },
78 stmt => "WHERE foo = ?",
79 bind => [ { json => { bar => 'baz' } } ],
83 { where => { foo => { '@>' => { -json => { bar => 'baz' } } } },
84 stmt => "WHERE foo @> ?",
85 bind => [ { json => { bar => 'baz' } } ],
88 # Verify inconsistent behaviour from DBIx::Class:SQLMaker::Oracle works
89 # (unary use of special op is not equivalent to special op + =)
92 foo_id => { '=' => { '-prior' => { -ident => 'bar_id' } } },
93 baz_id => { '-prior' => { -ident => 'quux_id' } },
95 stmt => ' WHERE ( baz_id = PRIOR quux_id AND foo_id = ( PRIOR bar_id ) )',
102 my($stmt, @bind) = $sqlmaker->where($_->{where}, $_->{order});
103 is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});