7 use SQL::Abstract::Test qw/is_same_sql_bind/;
13 # Make sure to test the examples, since having them break is somewhat
20 worker => ['nwiger', 'rcwe', 'sfz'],
21 status => { '!=', 'completed' }
24 stmt => " WHERE ( requestor = ? AND status != ? AND ( ( worker = ? ) OR"
25 . " ( worker = ? ) OR ( worker = ? ) ) )",
26 bind => [qw/inna completed nwiger rcwe sfz/],
34 order => [qw/ticket/],
35 stmt => " WHERE ( status = ? AND user = ? ) ORDER BY ticket",
36 bind => [qw/completed nwiger/],
42 status => { '!=', 'completed' }
44 order => [qw/ticket/],
45 stmt => " WHERE ( status != ? AND user = ? ) ORDER BY ticket",
46 bind => [qw/completed nwiger/],
51 status => 'completed',
52 reportid => { 'in', [567, 2335, 2] }
55 stmt => " WHERE ( reportid IN ( ?, ?, ? ) AND status = ? )",
56 bind => [qw/567 2335 2 completed/],
61 status => 'completed',
62 reportid => { 'not in', [567, 2335, 2] }
65 stmt => " WHERE ( reportid NOT IN ( ?, ?, ? ) AND status = ? )",
66 bind => [qw/567 2335 2 completed/],
71 status => 'completed',
72 completion_date => { 'between', ['2002-10-01', '2003-02-06'] },
74 order => \'ticket, requestor',
75 #LDNOTE: modified parentheses
76 # stmt => " WHERE ( completion_date BETWEEN ? AND ? AND status = ? ) ORDER BY ticket, requestor",
77 stmt => " WHERE ( ( completion_date BETWEEN ? AND ? ) AND status = ? ) ORDER BY ticket, requestor",
78 bind => [qw/2002-10-01 2003-02-06 completed/],
85 status => { 'in', ['pending', 'dispatched'] },
89 status => 'unassigned',
93 stmt => " WHERE ( ( status IN ( ?, ? ) AND user = ? ) OR ( status = ? AND user = ? ) )",
94 bind => [qw/pending dispatched nwiger unassigned robot/],
99 priority => [ {'>', 3}, {'<', 1} ],
100 requestor => \'is not null',
103 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor is not null ) ORDER BY priority",
109 priority => [ {'>', 3}, {'<', 1} ],
110 requestor => { '!=', undef },
112 order => [qw/a b c d e f g/],
113 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor IS NOT NULL )"
114 . " ORDER BY a, b, c, d, e, f, g",
120 priority => { 'between', [1, 3] },
121 requestor => { 'like', undef },
123 order => \'requestor, ticket',
124 #LDNOTE: modified parentheses
125 # stmt => " WHERE ( priority BETWEEN ? AND ? AND requestor IS NULL ) ORDER BY requestor, ticket",
126 stmt => " WHERE ( ( priority BETWEEN ? AND ? ) AND requestor IS NULL ) ORDER BY requestor, ticket",
139 # LDNOTE : modified test below, just parentheses differ
140 # stmt => " WHERE ( id = ? AND num <= ? AND num > ? )",
141 stmt => " WHERE ( id = ? AND ( num <= ? AND num > ? ) )",
142 bind => [qw/1 20 10/],
146 where => { foo => {-not_like => [7,8,9]},
147 fum => {'like' => [qw/a b/]},
148 nix => {'between' => [100,200] },
149 nox => {'not between' => [150,160] },
150 wix => {'in' => [qw/zz yy/]},
151 wux => {'not_in' => [qw/30 40/]}
153 # LDNOTE: modified parentheses for BETWEEN (trivial).
154 # Also modified the logic of "not_like" (severe, same reasons as #14 in 00where.t)
155 # stmt => " WHERE ( ( ( foo NOT LIKE ? ) OR ( foo NOT LIKE ? ) OR ( foo NOT LIKE ? ) ) AND ( ( fum LIKE ? ) OR ( fum LIKE ? ) ) AND nix BETWEEN ? AND ? AND nox NOT BETWEEN ? AND ? AND wix IN ( ?, ? ) AND wux NOT IN ( ?, ? ) )",
156 stmt => " WHERE ( ( foo NOT LIKE ? AND foo NOT LIKE ? AND foo NOT LIKE ? ) AND ( ( fum LIKE ? ) OR ( fum LIKE ? ) ) AND ( nix BETWEEN ? AND ? ) AND ( nox NOT BETWEEN ? AND ? ) AND wix IN ( ?, ? ) AND wux NOT IN ( ?, ? ) )",
157 bind => [7,8,9,'a','b',100,200,150,160,'zz','yy','30','40'],
165 stmt => " WHERE ( 1=1 AND 0=1 )",
172 foo => \["IN (?, ?)", 22, 33],
173 bar => [-and => \["> ?", 44], \["< ?", 55] ],
175 stmt => " WHERE ( (bar > ? AND bar < ?) AND foo IN (?, ?) )",
176 bind => [44, 55, 22, 33],
180 where => { -and => [{}, { 'me.id' => '1'}] },
181 stmt => " WHERE ( ( me.id = ? ) )",
186 where => { foo => SQLA::FourtyTwo->new(), },
187 stmt => " WHERE ( foo = ? )",
188 bind => [ 'The Life, the Universe and Everything.' ],
194 for my $case (@handle_tests) {
195 my $sql = SQL::Abstract->new;
196 my($stmt, @bind) = $sql->where($case->{where}, $case->{order});
197 is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind})
201 my $sql = SQL::Abstract->new;
202 $sql->where({ foo => { '>=' => [] }},);
207 #======================================================================
208 package SQLA::FourtyTwo; # testing stringification of arguments
209 #======================================================================
224 return "The Life, the Universe and Everything.";