Commit | Line | Data |
cc422895 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use SQL::Abstract; |
6 | use SQL::Abstract::Test import => [qw/is_same_sql_bind/]; |
7 | |
8 | for my $q ('', '"') { |
9 | for my $col_btype (0,1) { |
10 | |
11 | my $sql_maker = SQL::Abstract->new( |
12 | quote_char => $q, |
13 | name_sep => $q ? '.' : '', |
14 | $col_btype ? (bindtype => 'columns') : (), |
15 | ); |
16 | |
ca4f826a |
17 | my ($sql, @bind) = $sql_maker->select('artist', '*', { arr1 => { -value => [1,2] }, arr2 => { '>', { -value => [3,4] } }, field => [5,6] } ); |
cc422895 |
18 | |
19 | is_same_sql_bind ( |
20 | $sql, |
21 | \@bind, |
22 | "SELECT * |
23 | FROM ${q}artist${q} |
24 | WHERE ${q}arr1${q} = ? AND |
25 | ${q}arr2${q} > ? AND |
26 | ( ${q}field${q} = ? OR ${q}field${q} = ? ) |
27 | ", |
28 | [ |
29 | $col_btype |
30 | ? ( |
31 | [ arr1 => [ 1, 2 ] ], |
32 | [ arr2 => [ 3, 4 ] ], |
33 | [ field => 5 ], |
34 | [ field => 6 ], |
35 | ) : ( |
36 | [ 1, 2 ], |
37 | [ 3, 4 ], |
38 | 5, |
39 | 6, |
40 | ) |
41 | ], |
42 | ); |
422ed2de |
43 | |
44 | { |
45 | local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /Supplying an undefined argument to '(?:NOT )?LIKE'/ }; |
46 | |
ca4f826a |
47 | ($sql, @bind) = $sql_maker->where({ |
422ed2de |
48 | c1 => undef, |
49 | c2 => { -value => undef }, |
50 | c3 => { '=' => { -value => undef } }, |
51 | c4 => { '!=' => { -value => undef } }, |
52 | c5 => { '<>' => { -value => undef } }, |
53 | c6 => { '-like' => { -value => undef } }, |
54 | c7 => { '-not_like' => { -value => undef } }, |
55 | c8 => { 'is' => { -value => undef } }, |
56 | c9 => { 'is not' => { -value => undef } }, |
57 | }); |
58 | |
59 | is_same_sql_bind ( |
60 | $sql, |
61 | \@bind, |
62 | "WHERE ${q}c1${q} IS NULL |
63 | AND ${q}c2${q} IS NULL |
64 | AND ${q}c3${q} IS NULL |
65 | AND ${q}c4${q} IS NOT NULL |
66 | AND ${q}c5${q} IS NOT NULL |
67 | AND ${q}c6${q} IS NULL |
68 | AND ${q}c7${q} IS NOT NULL |
69 | AND ${q}c8${q} IS NULL |
70 | AND ${q}c9${q} IS NOT NULL |
71 | ", |
72 | [], |
73 | ); |
74 | } |
cc422895 |
75 | }} |
76 | |
77 | done_testing; |