This todo is active on the cpan 1.51 release, still needs resolving thus leaving...
[scpubgit/Q-Branch.git] / t / 08special_ops.t
CommitLineData
96449e8e 1#!/usr/bin/perl\r
2\r
3use strict;\r
4use warnings;\r
5use Test::More;\r
6\r
5aad8cf3 7use SQL::Abstract::Test import => ['is_same_sql_bind'];\r
96449e8e 8\r
9use SQL::Abstract;\r
10\r
11my $sqlmaker = SQL::Abstract->new(special_ops => [\r
12\r
13 # special op for MySql MATCH (field) AGAINST(word1, word2, ...)\r
14 {regex => qr/^match$/i, \r
15 handler => sub {\r
16 my ($self, $field, $op, $arg) = @_;\r
17 $arg = [$arg] if not ref $arg;\r
18 my $label = $self->_quote($field);\r
19 my ($placeholder) = $self->_convert('?');\r
20 my $placeholders = join ", ", (($placeholder) x @$arg);\r
21 my $sql = $self->_sqlcase('match') . " ($label) "\r
22 . $self->_sqlcase('against') . " ($placeholders) ";\r
23 my @bind = $self->_bindtype($field, @$arg);\r
24 return ($sql, @bind);\r
25 }\r
26 },\r
27\r
28 # special op for Basis+ NATIVE\r
29 {regex => qr/^native$/i, \r
30 handler => sub {\r
31 my ($self, $field, $op, $arg) = @_;\r
32 $arg =~ s/'/''/g;\r
33 my $sql = "NATIVE (' $field $arg ')";\r
34 return ($sql);\r
35 }\r
36 },\r
37\r
38]);\r
39\r
40my @tests = (\r
41\r
42 #1 \r
43 { where => {foo => {-match => 'foo'},\r
44 bar => {-match => [qw/foo bar/]}},\r
45 stmt => " WHERE ( MATCH (bar) AGAINST (?, ?) AND MATCH (foo) AGAINST (?) )",\r
46 bind => [qw/foo bar foo/],\r
47 },\r
48\r
49 #2\r
50 { where => {foo => {-native => "PH IS 'bar'"}},\r
51 stmt => " WHERE ( NATIVE (' foo PH IS ''bar'' ') )",\r
52 bind => [],\r
53 },\r
54\r
55);\r
56\r
57\r
6dcf723c 58plan tests => scalar(@tests);\r
59\r
96449e8e 60for (@tests) {\r
61\r
62 my($stmt, @bind) = $sqlmaker->where($_->{where}, $_->{order});\r
63 is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});\r
64}\r
65\r
66\r
67\r
68\r
69\r