X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F08special_ops.t;h=d989a79b0b78819cde60bcf7899c0163d1bdcbdf;hb=a5f91febe5c3b54e262891687517e89c62d338cc;hp=bbccd146089808be69d8b2e04302941d9c989ee4;hpb=c461c25c909bf7be7f4562f564a82af90b6fb71a;p=dbsrgits%2FSQL-Abstract.git diff --git a/t/08special_ops.t b/t/08special_ops.t index bbccd14..d989a79 100644 --- a/t/08special_ops.t +++ b/t/08special_ops.t @@ -1,68 +1,61 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use Test::More; - -use SQL::Abstract::Test qw/is_same_sql_bind/; -plan tests => 2; - -use SQL::Abstract; - -my $sqlmaker = SQL::Abstract->new(special_ops => [ - - # special op for MySql MATCH (field) AGAINST(word1, word2, ...) - {regex => qr/^match$/i, - handler => sub { - my ($self, $field, $op, $arg) = @_; - $arg = [$arg] if not ref $arg; - my $label = $self->_quote($field); - my ($placeholder) = $self->_convert('?'); - my $placeholders = join ", ", (($placeholder) x @$arg); - my $sql = $self->_sqlcase('match') . " ($label) " - . $self->_sqlcase('against') . " ($placeholders) "; - my @bind = $self->_bindtype($field, @$arg); - return ($sql, @bind); - } - }, - - # special op for Basis+ NATIVE - {regex => qr/^native$/i, - handler => sub { - my ($self, $field, $op, $arg) = @_; - $arg =~ s/'/''/g; - my $sql = "NATIVE (' $field $arg ')"; - return ($sql); - } - }, - -]); - -my @tests = ( - - #1 - { where => {foo => {-match => 'foo'}, - bar => {-match => [qw/foo bar/]}}, - stmt => " WHERE ( MATCH (bar) AGAINST (?, ?) AND MATCH (foo) AGAINST (?) )", - bind => [qw/foo bar foo/], - }, - - #2 - { where => {foo => {-native => "PH IS 'bar'"}}, - stmt => " WHERE ( NATIVE (' foo PH IS ''bar'' ') )", - bind => [], - }, - -); - - -for (@tests) { - - my($stmt, @bind) = $sqlmaker->where($_->{where}, $_->{order}); - is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind}); -} - - - - - +use strict; +use warnings; +use Test::More; + +use SQL::Abstract::Test import => ['is_same_sql_bind']; + +use SQL::Abstract; + +my $sqlmaker = SQL::Abstract->new(special_ops => [ + + # special op for MySql MATCH (field) AGAINST(word1, word2, ...) + {regex => qr/^match$/i, + handler => sub { + my ($self, $field, $op, $arg) = @_; + $arg = [$arg] if not ref $arg; + my $label = $self->_quote($field); + my ($placeholder) = $self->_convert('?'); + my $placeholders = join ", ", (($placeholder) x @$arg); + my $sql = $self->_sqlcase('match') . " ($label) " + . $self->_sqlcase('against') . " ($placeholders) "; + my @bind = $self->_bindtype($field, @$arg); + return ($sql, @bind); + } + }, + + # special op for Basis+ NATIVE + {regex => qr/^native$/i, + handler => sub { + my ($self, $field, $op, $arg) = @_; + $arg =~ s/'/''/g; + my $sql = "NATIVE (' $field $arg ')"; + return ($sql); + } + }, + +]); + +my @tests = ( + + #1 + { where => {foo => {-match => 'foo'}, + bar => {-match => [qw/foo bar/]}}, + stmt => " WHERE ( MATCH (bar) AGAINST (?, ?) AND MATCH (foo) AGAINST (?) )", + bind => [qw/foo bar foo/], + }, + + #2 + { where => {foo => {-native => "PH IS 'bar'"}}, + stmt => " WHERE ( NATIVE (' foo PH IS ''bar'' ') )", + bind => [], + }, + +); + +for (@tests) { + + my($stmt, @bind) = $sqlmaker->where($_->{where}, $_->{order}); + is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind}); +} + +done_testing;