9 use lib "$FindBin::Bin";
16 # Make sure to test the examples, since having them break is somewhat
23 worker => ['nwiger', 'rcwe', 'sfz'],
24 status => { '!=', 'completed' }
27 stmt => " WHERE ( requestor = ? AND status != ? AND ( ( worker = ? ) OR"
28 . " ( worker = ? ) OR ( worker = ? ) ) )",
29 bind => [qw/inna completed nwiger rcwe sfz/],
37 order => [qw/ticket/],
38 stmt => " WHERE ( status = ? AND user = ? ) ORDER BY ticket",
39 bind => [qw/completed nwiger/],
45 status => { '!=', 'completed' }
47 order => [qw/ticket/],
48 stmt => " WHERE ( status != ? AND user = ? ) ORDER BY ticket",
49 bind => [qw/completed nwiger/],
54 status => 'completed',
55 reportid => { 'in', [567, 2335, 2] }
58 stmt => " WHERE ( reportid IN ( ?, ?, ? ) AND status = ? )",
59 bind => [qw/567 2335 2 completed/],
64 status => 'completed',
65 reportid => { 'not in', [567, 2335, 2] }
68 stmt => " WHERE ( reportid NOT IN ( ?, ?, ? ) AND status = ? )",
69 bind => [qw/567 2335 2 completed/],
74 status => 'completed',
75 completion_date => { 'between', ['2002-10-01', '2003-02-06'] },
77 order => \'ticket, requestor',
78 #LDNOTE: modified parentheses
79 # stmt => " WHERE ( completion_date BETWEEN ? AND ? AND status = ? ) ORDER BY ticket, requestor",
80 stmt => " WHERE ( ( completion_date BETWEEN ? AND ? ) AND status = ? ) ORDER BY ticket, requestor",
81 bind => [qw/2002-10-01 2003-02-06 completed/],
88 status => { 'in', ['pending', 'dispatched'] },
92 status => 'unassigned',
96 stmt => " WHERE ( ( status IN ( ?, ? ) AND user = ? ) OR ( status = ? AND user = ? ) )",
97 bind => [qw/pending dispatched nwiger unassigned robot/],
102 priority => [ {'>', 3}, {'<', 1} ],
103 requestor => \'is not null',
106 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor is not null ) ORDER BY priority",
112 priority => [ {'>', 3}, {'<', 1} ],
113 requestor => { '!=', undef },
115 order => [qw/a b c d e f g/],
116 stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor IS NOT NULL )"
117 . " ORDER BY a, b, c, d, e, f, g",
123 priority => { 'between', [1, 3] },
124 requestor => { 'like', undef },
126 order => \'requestor, ticket',
127 #LDNOTE: modified parentheses
128 # stmt => " WHERE ( priority BETWEEN ? AND ? AND requestor IS NULL ) ORDER BY requestor, ticket",
129 stmt => " WHERE ( ( priority BETWEEN ? AND ? ) AND requestor IS NULL ) ORDER BY requestor, ticket",
142 # LDNOTE : modified test below, just parentheses differ
143 # stmt => " WHERE ( id = ? AND num <= ? AND num > ? )",
144 stmt => " WHERE ( id = ? AND ( num <= ? AND num > ? ) )",
145 bind => [qw/1 20 10/],
149 where => { foo => {-not_like => [7,8,9]},
150 fum => {'like' => [qw/a b/]},
151 nix => {'between' => [100,200] },
152 nox => {'not between' => [150,160] },
153 wix => {'in' => [qw/zz yy/]},
154 wux => {'not_in' => [qw/30 40/]}
156 # LDNOTE: modified parentheses for BETWEEN (trivial).
157 # Also modified the logic of "not_like" (severe, same reasons as #14 in 00where.t)
158 # 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 ( ?, ? ) )",
159 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 ( ?, ? ) )",
160 bind => [7,8,9,'a','b',100,200,150,160,'zz','yy','30','40'],
168 stmt => " WHERE ( 1=1 AND 0=1 )",
175 foo => \["IN (?, ?)", 22, 33],
176 bar => [-and => \["> ?", 44], \["< ?", 55] ],
178 stmt => " WHERE ( (bar > ? AND bar < ?) AND foo IN (?, ?) )",
179 bind => [44, 55, 22, 33],
184 for my $case (@handle_tests) {
185 my $sql = SQL::Abstract->new;
186 my($stmt, @bind) = $sql->where($case->{where}, $case->{order});
187 is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind})
191 my $sql = SQL::Abstract->new;
192 $sql->where({ foo => { '>=' => [] }},);