11 # Make sure to test the examples, since having them break is somewhat
18 worker => ['nwiger', 'rcwe', 'sfz'],
19 status => { '!=', 'completed' }
22 stmt => " WHERE ( requestor = ? AND status != ? AND ( ( worker = ? ) OR"
23 . " ( worker = ? ) OR ( worker = ? ) ) )",
24 bind => [qw/inna completed nwiger rcwe sfz/],
32 order => [qw/ticket/],
33 stmt => " WHERE ( status = ? AND user = ? ) ORDER BY ticket",
34 bind => [qw/completed nwiger/],
40 status => { '!=', 'completed' }
42 order => [qw/ticket/],
43 stmt => " WHERE ( status != ? AND user = ? ) ORDER BY ticket",
44 bind => [qw/completed nwiger/],
49 status => 'completed',
50 reportid => { 'in', [567, 2335, 2] }
53 stmt => " WHERE ( reportid IN ( ?, ?, ? ) AND status = ? )",
54 bind => [qw/567 2335 2 completed/],
59 status => 'completed',
60 reportid => { 'not in', [567, 2335, 2] }
63 stmt => " WHERE ( reportid NOT IN ( ?, ?, ? ) AND status = ? )",
64 bind => [qw/567 2335 2 completed/],
69 status => 'completed',
70 completion_date => { 'between', ['2002-10-01', '2003-02-06'] },
72 order => \'ticket, requestor',
73 stmt => " WHERE ( completion_date BETWEEN ? AND ? AND status = ? ) ORDER BY ticket, requestor",
74 bind => [qw/2002-10-01 2003-02-06 completed/],
81 status => { 'in', ['pending', 'dispatched'] },
85 status => 'unassigned',
89 stmt => " WHERE ( ( status IN ( ?, ? ) AND user = ? ) OR ( status = ? AND user = ? ) )",
90 bind => [qw/pending dispatched nwiger unassigned robot/],
95 priority => [ {'>', 3}, {'<', 1} ],
96 requestor => \'is not null',
99 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor is not null ) ORDER BY priority",
105 priority => [ {'>', 3}, {'<', 1} ],
106 requestor => { '!=', undef },
108 order => [qw/a b c d e f g/],
109 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor IS NOT NULL )"
110 . " ORDER BY a, b, c, d, e, f, g",
116 priority => { 'between', [1, 3] },
117 requestor => { 'like', undef },
119 order => \'requestor, ticket',
120 stmt => " WHERE ( priority BETWEEN ? AND ? AND requestor IS NULL ) ORDER BY requestor, ticket",
133 stmt => " WHERE ( id = ? AND num <= ? AND num > ? )",
134 bind => [qw/1 20 10/],
138 where => { foo => {-not_like => [7,8,9]},
139 fum => {'like' => [qw/a b/]},
140 nix => {'between' => [100,200] },
141 nox => {'not between' => [150,160] },
142 wix => {'in' => [qw/zz yy/]},
143 wux => {'not_in' => [qw/30 40/]}
145 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 ( ?, ? ) )",
146 bind => [7,8,9,'a','b',100,200,150,160,'zz','yy','30','40'],
151 for (@handle_tests) {
153 #print "creating a handle with args ($_->{args}): ";
154 my $sql = SQL::Abstract->new;
157 for (my $i=0; $i < 2; $i++) {
158 my($stmt, @bind) = $sql->where($_->{where}, $_->{order});
160 for(my $i=0; $i < @{$_->{bind}}; $i++) {
161 $bad++ unless $_->{bind}[$i] eq $bind[$i];
164 ok($stmt eq $_->{stmt} && @bind == @{$_->{bind}} && ! $bad) or
168 "[$_->{stmt}] [@{$_->{bind}}]\n\n";