12 # Make sure to test the examples, since having them break is somewhat
19 worker => ['nwiger', 'rcwe', 'sfz'],
20 status => { '!=', 'completed' }
23 stmt => " WHERE ( requestor = ? AND status != ? AND ( ( worker = ? ) OR"
24 . " ( worker = ? ) OR ( worker = ? ) ) )",
25 bind => [qw/inna completed nwiger rcwe sfz/],
33 order => [qw/ticket/],
34 stmt => " WHERE ( status = ? AND user = ? ) ORDER BY ticket",
35 bind => [qw/completed nwiger/],
41 status => { '!=', 'completed' }
43 order => [qw/ticket/],
44 stmt => " WHERE ( status != ? AND user = ? ) ORDER BY ticket",
45 bind => [qw/completed nwiger/],
50 status => 'completed',
51 reportid => { 'in', [567, 2335, 2] }
54 stmt => " WHERE ( reportid IN ( ?, ?, ? ) AND status = ? )",
55 bind => [qw/567 2335 2 completed/],
60 status => 'completed',
61 reportid => { 'not in', [567, 2335, 2] }
64 stmt => " WHERE ( reportid NOT IN ( ?, ?, ? ) AND status = ? )",
65 bind => [qw/567 2335 2 completed/],
70 status => 'completed',
71 completion_date => { 'between', ['2002-10-01', '2003-02-06'] },
73 order => \'ticket, requestor',
74 stmt => " WHERE ( completion_date BETWEEN ? AND ? AND status = ? ) ORDER BY ticket, requestor",
75 bind => [qw/2002-10-01 2003-02-06 completed/],
82 status => { 'in', ['pending', 'dispatched'] },
86 status => 'unassigned',
90 stmt => " WHERE ( ( status IN ( ?, ? ) AND user = ? ) OR ( status = ? AND user = ? ) )",
91 bind => [qw/pending dispatched nwiger unassigned robot/],
96 priority => [ {'>', 3}, {'<', 1} ],
97 requestor => \'is not null',
100 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor is not null ) ORDER BY priority",
106 priority => [ {'>', 3}, {'<', 1} ],
107 requestor => { '!=', undef },
109 order => [qw/a b c d e f g/],
110 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor IS NOT NULL )"
111 . " ORDER BY a, b, c, d, e, f, g",
117 priority => { 'between', [1, 3] },
118 requestor => { 'like', undef },
120 order => \'requestor, ticket',
121 stmt => " WHERE ( priority BETWEEN ? AND ? AND requestor IS NULL ) ORDER BY requestor, ticket",
134 stmt => " WHERE ( id = ? AND num <= ? AND num > ? )",
135 bind => [qw/1 20 10/],
139 where => { foo => {-not_like => [7,8,9]},
140 fum => {'like' => [qw/a b/]},
141 nix => {'between' => [100,200] },
142 nox => {'not between' => [150,160] },
143 wix => {'in' => [qw/zz yy/]},
144 wux => {'not_in' => [qw/30 40/]}
146 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 ( ?, ? ) )",
147 bind => [7,8,9,'a','b',100,200,150,160,'zz','yy','30','40'],
155 stmt => " WHERE ( 1=1 AND 0=1 )",
161 for my $case (@handle_tests) {
162 my $sql = SQL::Abstract->new;
163 my($stmt, @bind) = $sql->where($case->{where}, $case->{order});
164 is($stmt, $case->{stmt});
165 is_deeply(\@bind, $case->{bind});
169 my $sql = SQL::Abstract->new;
170 $sql->where({ foo => { '>=' => [] }},);