7 use SQL::Abstract::Test import => ['is_same_sql_bind'];
13 # Make sure to test the examples, since having them break is somewhat
16 my $not_stringifiable = SQLA::NotStringifiable->new();
22 worker => ['nwiger', 'rcwe', 'sfz'],
23 status => { '!=', 'completed' }
26 stmt => " WHERE ( requestor = ? AND status != ? AND ( ( worker = ? ) OR"
27 . " ( worker = ? ) OR ( worker = ? ) ) )",
28 bind => [qw/inna completed nwiger rcwe sfz/],
36 order => [qw/ticket/],
37 stmt => " WHERE ( status = ? AND user = ? ) ORDER BY ticket",
38 bind => [qw/completed nwiger/],
44 status => { '!=', 'completed' }
46 order => [qw/ticket/],
47 stmt => " WHERE ( status != ? AND user = ? ) ORDER BY ticket",
48 bind => [qw/completed nwiger/],
53 status => 'completed',
54 reportid => { 'in', [567, 2335, 2] }
57 stmt => " WHERE ( reportid IN ( ?, ?, ? ) AND status = ? )",
58 bind => [qw/567 2335 2 completed/],
63 status => 'completed',
64 reportid => { 'not in', [567, 2335, 2] }
67 stmt => " WHERE ( reportid NOT IN ( ?, ?, ? ) AND status = ? )",
68 bind => [qw/567 2335 2 completed/],
73 status => 'completed',
74 completion_date => { 'between', ['2002-10-01', '2003-02-06'] },
76 order => \'ticket, requestor',
77 #LDNOTE: modified parentheses
78 # stmt => " WHERE ( completion_date BETWEEN ? AND ? AND status = ? ) ORDER BY ticket, requestor",
79 stmt => " WHERE ( ( completion_date BETWEEN ? AND ? ) AND status = ? ) ORDER BY ticket, requestor",
80 bind => [qw/2002-10-01 2003-02-06 completed/],
87 status => { 'in', ['pending', 'dispatched'] },
91 status => 'unassigned',
95 stmt => " WHERE ( ( status IN ( ?, ? ) AND user = ? ) OR ( status = ? AND user = ? ) )",
96 bind => [qw/pending dispatched nwiger unassigned robot/],
101 priority => [ {'>', 3}, {'<', 1} ],
102 requestor => \'is not null',
105 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor is not null ) ORDER BY priority",
111 priority => [ {'>', 3}, {'<', 1} ],
112 requestor => { '!=', undef },
114 order => [qw/a b c d e f g/],
115 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor IS NOT NULL )"
116 . " ORDER BY a, b, c, d, e, f, g",
122 priority => { 'between', [1, 3] },
123 requestor => { 'like', undef },
125 order => \'requestor, ticket',
126 #LDNOTE: modified parentheses
127 # stmt => " WHERE ( priority BETWEEN ? AND ? AND requestor IS NULL ) ORDER BY requestor, ticket",
128 stmt => " WHERE ( ( priority BETWEEN ? AND ? ) AND requestor IS NULL ) ORDER BY requestor, ticket",
141 # LDNOTE : modified test below, just parentheses differ
142 # stmt => " WHERE ( id = ? AND num <= ? AND num > ? )",
143 stmt => " WHERE ( id = ? AND ( num <= ? AND num > ? ) )",
144 bind => [qw/1 20 10/],
148 where => { foo => {-not_like => [7,8,9]},
149 fum => {'like' => [qw/a b/]},
150 nix => {'between' => [100,200] },
151 nox => {'not between' => [150,160] },
152 wix => {'in' => [qw/zz yy/]},
153 wux => {'not_in' => [qw/30 40/]}
155 # LDNOTE: modified parentheses for BETWEEN (trivial).
156 # Also modified the logic of "not_like" (severe, same reasons as #14 in 00where.t)
157 # 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 ( ?, ? ) )",
158 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 ( ?, ? ) )",
159 bind => [7,8,9,'a','b',100,200,150,160,'zz','yy','30','40'],
167 stmt => " WHERE ( 1=1 AND 0=1 )",
174 foo => \["IN (?, ?)", 22, 33],
175 bar => [-and => \["> ?", 44], \["< ?", 55] ],
177 stmt => " WHERE ( (bar > ? AND bar < ?) AND foo IN (?, ?) )",
178 bind => [44, 55, 22, 33],
182 where => { -and => [{}, { 'me.id' => '1'}] },
183 stmt => " WHERE ( ( me.id = ? ) )",
188 where => { foo => SQLA::FourtyTwo->new(), },
189 stmt => " WHERE ( foo = ? )",
190 bind => [ 'The Life, the Universe and Everything.' ],
194 where => { foo => $not_stringifiable, },
195 stmt => " WHERE ( foo = ? )",
196 bind => [ $not_stringifiable ],
202 for my $case (@handle_tests) {
203 my $sql = SQL::Abstract->new;
204 my($stmt, @bind) = $sql->where($case->{where}, $case->{order});
205 is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind})
209 my $sql = SQL::Abstract->new;
210 $sql->where({ foo => { '>=' => [] }},);
215 #======================================================================
216 package SQLA::FourtyTwo; # testing stringification of arguments
217 #======================================================================
232 return "The Life, the Universe and Everything.";
238 #======================================================================
239 package SQLA::NotStringifiable; # testing stringification of arguments
240 #======================================================================