X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F08special_ops.t;h=c4b303e7b5ab616f8b26c35118b2a93d5041c3ac;hb=4598593cc34a306241318b4c55b871e8588a53f2;hp=5348e0e42fac3b9c2af1b3ad10f00afb7ad601be;hpb=4f30591bc0678f8a5d657e79c6985606b064cd1d;p=scpubgit%2FQ-Branch.git diff --git a/t/08special_ops.t b/t/08special_ops.t index 5348e0e..c4b303e 100644 --- a/t/08special_ops.t +++ b/t/08special_ops.t @@ -1,5 +1,3 @@ -#!/usr/bin/perl - use strict; use warnings; use Test::More; @@ -11,7 +9,7 @@ use SQL::Abstract; 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; @@ -26,7 +24,7 @@ my $sqlmaker = SQL::Abstract->new(special_ops => [ }, # special op for Basis+ NATIVE - {regex => qr/^native$/i, + {regex => qr/^native$/i, handler => sub { my ($self, $field, $op, $arg) = @_; $arg =~ s/'/''/g; @@ -35,11 +33,34 @@ 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, + 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 (?) )", @@ -52,10 +73,29 @@ my @tests = ( 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 + # (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) { @@ -63,7 +103,4 @@ for (@tests) { is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind}); } - - - - +done_testing;