8 # use a BEGIN block so we print our plan before SQL::Abstract is loaded
9 # we run each test TWICE to make sure _anoncopy is working
10 BEGIN { plan tests => 24 }
14 # Make sure to test the examples, since having them break is somewhat
21 worker => ['nwiger', 'rcwe', 'sfz'],
22 status => { '!=', 'completed' }
25 stmt => " WHERE ( requestor = ? AND status != ? AND ( ( worker = ? ) OR"
26 . " ( worker = ? ) OR ( worker = ? ) ) )",
27 bind => [qw/inna completed nwiger rcwe sfz/],
35 order => [qw/ticket/],
36 stmt => " WHERE ( status = ? AND user = ? ) ORDER BY ticket",
37 bind => [qw/completed nwiger/],
43 status => { '!=', 'completed' }
45 order => [qw/ticket/],
46 stmt => " WHERE ( status != ? AND user = ? ) ORDER BY ticket",
47 bind => [qw/completed nwiger/],
52 status => 'completed',
53 reportid => { 'in', [567, 2335, 2] }
56 stmt => " WHERE ( reportid IN ( ?, ?, ? ) AND status = ? )",
57 bind => [qw/567 2335 2 completed/],
62 status => 'completed',
63 reportid => { 'not in', [567, 2335, 2] }
66 stmt => " WHERE ( reportid NOT IN ( ?, ?, ? ) AND status = ? )",
67 bind => [qw/567 2335 2 completed/],
72 status => 'completed',
73 completion_date => { 'between', ['2002-10-01', '2003-02-06'] },
75 order => \'ticket, requestor',
76 stmt => " WHERE ( completion_date BETWEEN ? AND ? AND status = ? ) ORDER BY ticket, requestor",
77 bind => [qw/2002-10-01 2003-02-06 completed/],
84 status => { 'in', ['pending', 'dispatched'] },
88 status => 'unassigned',
92 stmt => " WHERE ( ( status IN ( ?, ? ) AND user = ? ) OR ( status = ? AND user = ? ) )",
93 bind => [qw/pending dispatched nwiger unassigned robot/],
98 priority => [ {'>', 3}, {'<', 1} ],
99 requestor => \'is not null',
102 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor is not null ) ORDER BY priority",
108 priority => [ {'>', 3}, {'<', 1} ],
109 requestor => { '!=', undef },
111 order => [qw/a b c d e f g/],
112 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor IS NOT NULL )"
113 . " ORDER BY a, b, c, d, e, f, g",
119 priority => { 'between', [1, 3] },
120 requestor => { 'like', undef },
122 order => \'requestor, ticket',
123 stmt => " WHERE ( priority BETWEEN ? AND ? AND requestor IS NULL ) ORDER BY requestor, ticket",
136 stmt => " WHERE ( id = ? AND num <= ? AND num > ? )",
137 bind => [qw/1 20 10/],
141 where => { foo => {-not_like => [7,8,9]},
142 fum => {'like' => [qw/a b/]},
143 nix => {'between' => [100,200] },
144 nox => {'not between' => [150,160] },
145 wix => {'in' => [qw/zz yy/]},
146 wux => {'not_in' => [qw/30 40/]}
148 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 ( ?, ? ) )",
149 bind => [7,8,9,'a','b',100,200,150,160,'zz','yy','30','40'],
154 for (@handle_tests) {
156 #print "creating a handle with args ($_->{args}): ";
157 my $sql = SQL::Abstract->new;
160 for (my $i=0; $i < 2; $i++) {
161 my($stmt, @bind) = $sql->where($_->{where}, $_->{order});
163 for(my $i=0; $i < @{$_->{bind}}; $i++) {
164 $bad++ unless $_->{bind}[$i] eq $bind[$i];
167 ok($stmt eq $_->{stmt} && @bind == @{$_->{bind}} && ! $bad) or
171 "[$_->{stmt}] [@{$_->{bind}}]\n\n";