X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F08special_ops.t;h=5348e0e42fac3b9c2af1b3ad10f00afb7ad601be;hb=fab0bed9d6f7c688660726c1f23448c136ba222b;hp=5bc599602ce3a5edb48a62c021fec83d209925ea;hpb=96449e8ea5159e5448ebfc81dfa200dc674f366b;p=dbsrgits%2FSQL-Abstract.git diff --git a/t/08special_ops.t b/t/08special_ops.t index 5bc5996..5348e0e 100644 --- a/t/08special_ops.t +++ b/t/08special_ops.t @@ -1,71 +1,69 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use Test::More; - -use FindBin; -use lib "$FindBin::Bin"; -use TestSqlAbstract; - -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}); -} - - - - - +#!/usr/bin/perl + +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 => [], + }, + +); + + +plan tests => scalar(@tests); + +for (@tests) { + + my($stmt, @bind) = $sqlmaker->where($_->{where}, $_->{order}); + is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind}); +} + + + + +