9 use SQL::Abstract::Test import => ['is_same_sql_bind'];
15 # -nest has been undocumented on purpose, but is still supported for the
16 # foreseable future. Do not rip out the -nest tests before speaking to
17 # someone on the DBIC mailing list or in irc.perl.org#dbix-class
25 args => ['test', '*'],
26 stmt => 'SELECT * FROM test',
27 stmt_q => 'SELECT * FROM `test`',
32 args => ['test', [qw(one two three)]],
33 stmt => 'SELECT one, two, three FROM test',
34 stmt_q => 'SELECT `one`, `two`, `three` FROM `test`',
39 args => ['test', '*', { a => 0 }, [qw/boom bada bing/]],
40 stmt => 'SELECT * FROM test WHERE ( a = ? ) ORDER BY boom, bada, bing',
41 stmt_q => 'SELECT * FROM `test` WHERE ( `a` = ? ) ORDER BY `boom`, `bada`, `bing`',
46 args => ['test', '*', [ { a => 5 }, { b => 6 } ]],
47 stmt => 'SELECT * FROM test WHERE ( ( a = ? ) OR ( b = ? ) )',
48 stmt_q => 'SELECT * FROM `test` WHERE ( ( `a` = ? ) OR ( `b` = ? ) )',
53 args => ['test', '*', undef, ['id']],
54 stmt => 'SELECT * FROM test ORDER BY id',
55 stmt_q => 'SELECT * FROM `test` ORDER BY `id`',
60 args => ['test', '*', { a => 'boom' } , ['id']],
61 stmt => 'SELECT * FROM test WHERE ( a = ? ) ORDER BY id',
62 stmt_q => 'SELECT * FROM `test` WHERE ( `a` = ? ) ORDER BY `id`',
67 args => ['test', '*', { a => ['boom', 'bang'] }],
68 stmt => 'SELECT * FROM test WHERE ( ( ( a = ? ) OR ( a = ? ) ) )',
69 stmt_q => 'SELECT * FROM `test` WHERE ( ( ( `a` = ? ) OR ( `a` = ? ) ) )',
70 bind => ['boom', 'bang']
74 args => [[qw/test1 test2/], '*', { 'test1.a' => { 'In', ['boom', 'bang'] } }],
75 stmt => 'SELECT * FROM test1, test2 WHERE ( test1.a IN ( ?, ? ) )',
76 stmt_q => 'SELECT * FROM `test1`, `test2` WHERE ( `test1`.`a` IN ( ?, ? ) )',
77 bind => ['boom', 'bang']
81 args => [[\'test1', 'test2'], '*', { 'test1.a' => { 'In', ['boom', 'bang'] } }],
82 stmt => 'SELECT * FROM test1, test2 WHERE ( test1.a IN ( ?, ? ) )',
83 stmt_q => 'SELECT * FROM test1, `test2` WHERE ( `test1`.`a` IN ( ?, ? ) )',
84 bind => ['boom', 'bang']
88 args => ['test', '*', { a => { 'between', ['boom', 'bang'] } }],
89 stmt => 'SELECT * FROM test WHERE ( a BETWEEN ? AND ? )',
90 stmt_q => 'SELECT * FROM `test` WHERE ( `a` BETWEEN ? AND ? )',
91 bind => ['boom', 'bang']
95 args => ['test', '*', { a => { '!=', 'boom' } }],
96 stmt => 'SELECT * FROM test WHERE ( a != ? )',
97 stmt_q => 'SELECT * FROM `test` WHERE ( `a` != ? )',
102 args => ['test', {a => 'boom'}, {a => undef}],
103 stmt => 'UPDATE test SET a = ? WHERE ( a IS NULL )',
104 stmt_q => 'UPDATE `test` SET `a` = ? WHERE ( `a` IS NULL )',
109 args => ['test', {a => 'boom'}, { a => {'!=', "bang" }} ],
110 stmt => 'UPDATE test SET a = ? WHERE ( a != ? )',
111 stmt_q => 'UPDATE `test` SET `a` = ? WHERE ( `a` != ? )',
112 bind => ['boom', 'bang']
116 args => ['test', {'a-funny-flavored-candy' => 'yummy', b => 'oops'}, { a42 => "bang" }],
117 stmt => 'UPDATE test SET a-funny-flavored-candy = ?, b = ? WHERE ( a42 = ? )',
118 stmt_q => 'UPDATE `test` SET `a-funny-flavored-candy` = ?, `b` = ? WHERE ( `a42` = ? )',
119 bind => ['yummy', 'oops', 'bang']
123 args => ['test', {requestor => undef}],
124 stmt => 'DELETE FROM test WHERE ( requestor IS NULL )',
125 stmt_q => 'DELETE FROM `test` WHERE ( `requestor` IS NULL )',
130 args => [[qw/test1 test2 test3/],
131 { 'test1.field' => \'!= test2.field',
132 user => {'!=','nwiger'} },
134 stmt => 'DELETE FROM test1, test2, test3 WHERE ( test1.field != test2.field AND user != ? )',
135 stmt_q => 'DELETE FROM `test1`, `test2`, `test3` WHERE ( `test1`.`field` != test2.field AND `user` != ? )', # test2.field is a literal value, cannnot be quoted.
140 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => 5}],
141 stmt => 'INSERT INTO test (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)',
142 stmt_q => 'INSERT INTO `test` (`a`, `b`, `c`, `d`, `e`) VALUES (?, ?, ?, ?, ?)',
143 bind => [qw/1 2 3 4 5/],
147 args => ['test', [qw/1 2 3 4 5/]],
148 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?)',
149 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?)',
150 bind => [qw/1 2 3 4 5/],
154 args => ['test', [qw/1 2 3 4 5/, undef]],
155 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?, ?)',
156 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?, ?)',
157 bind => [qw/1 2 3 4 5/, undef],
161 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => 5}],
162 stmt => 'UPDATE test SET a = ?, b = ?, c = ?, d = ?, e = ?',
163 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?, `c` = ?, `d` = ?, `e` = ?',
164 bind => [qw/1 2 3 4 5/],
168 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => 5}, {a => {'in', [1..5]}}],
169 stmt => 'UPDATE test SET a = ?, b = ?, c = ?, d = ?, e = ? WHERE ( a IN ( ?, ?, ?, ?, ? ) )',
170 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?, `c` = ?, `d` = ?, `e` = ? WHERE ( `a` IN ( ?, ?, ?, ?, ? ) )',
171 bind => [qw/1 2 3 4 5 1 2 3 4 5/],
175 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, {a => {'between', [1,2]}}],
176 stmt => 'UPDATE test SET a = ?, b = to_date(?, \'MM/DD/YY\') WHERE ( a BETWEEN ? AND ? )',
177 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = to_date(?, \'MM/DD/YY\') WHERE ( `a` BETWEEN ? AND ? )',
178 bind => [qw(1 02/02/02 1 2)],
182 args => ['test.table', {high_limit => \'max(all_limits)', low_limit => 4} ],
183 stmt => 'INSERT INTO test.table (high_limit, low_limit) VALUES (max(all_limits), ?)',
184 stmt_q => 'INSERT INTO `test`.`table` (`high_limit`, `low_limit`) VALUES (max(all_limits), ?)',
189 args => ['test.table', [ \'max(all_limits)', 4 ] ],
190 stmt => 'INSERT INTO test.table VALUES (max(all_limits), ?)',
191 stmt_q => 'INSERT INTO `test`.`table` VALUES (max(all_limits), ?)',
196 new => {bindtype => 'columns'},
197 args => ['test.table', {one => 2, three => 4, five => 6} ],
198 stmt => 'INSERT INTO test.table (five, one, three) VALUES (?, ?, ?)',
199 stmt_q => 'INSERT INTO `test`.`table` (`five`, `one`, `three`) VALUES (?, ?, ?)',
200 bind => [['five', 6], ['one', 2], ['three', 4]], # alpha order, man...
204 new => {bindtype => 'columns', case => 'lower'},
205 args => ['test.table', [qw/one two three/], {one => 2, three => 4, five => 6} ],
206 stmt => 'select one, two, three from test.table where ( five = ? and one = ? and three = ? )',
207 stmt_q => 'select `one`, `two`, `three` from `test`.`table` where ( `five` = ? and `one` = ? and `three` = ? )',
208 bind => [['five', 6], ['one', 2], ['three', 4]], # alpha order, man...
212 new => {bindtype => 'columns', cmp => 'like'},
213 args => ['testin.table2', {One => 22, Three => 44, FIVE => 66},
214 {Beer => 'is', Yummy => '%YES%', IT => ['IS','REALLY','GOOD']}],
215 stmt => 'UPDATE testin.table2 SET FIVE = ?, One = ?, Three = ? WHERE '
216 . '( Beer LIKE ? AND ( ( IT LIKE ? ) OR ( IT LIKE ? ) OR ( IT LIKE ? ) ) AND Yummy LIKE ? )',
217 stmt_q => 'UPDATE `testin`.`table2` SET `FIVE` = ?, `One` = ?, `Three` = ? WHERE '
218 . '( `Beer` LIKE ? AND ( ( `IT` LIKE ? ) OR ( `IT` LIKE ? ) OR ( `IT` LIKE ? ) ) AND `Yummy` LIKE ? )',
219 bind => [['FIVE', 66], ['One', 22], ['Three', 44], ['Beer','is'],
220 ['IT','IS'], ['IT','REALLY'], ['IT','GOOD'], ['Yummy','%YES%']],
224 args => ['test', '*', {priority => [ -and => {'!=', 2}, { -not_like => '3%'} ]}],
225 stmt => 'SELECT * FROM test WHERE ( ( ( priority != ? ) AND ( priority NOT LIKE ? ) ) )',
226 stmt_q => 'SELECT * FROM `test` WHERE ( ( ( `priority` != ? ) AND ( `priority` NOT LIKE ? ) ) )',
231 args => ['Yo Momma', '*', { user => 'nwiger',
232 -nest => [ workhrs => {'>', 20}, geo => 'ASIA' ] }],
233 stmt => 'SELECT * FROM Yo Momma WHERE ( ( ( workhrs > ? ) OR ( geo = ? ) ) AND user = ? )',
234 stmt_q => 'SELECT * FROM `Yo Momma` WHERE ( ( ( `workhrs` > ? ) OR ( `geo` = ? ) ) AND `user` = ? )',
235 bind => [qw(20 ASIA nwiger)],
239 args => ['taco_punches', { one => 2, three => 4 },
240 { bland => [ -and => {'!=', 'yes'}, {'!=', 'YES'} ],
241 tasty => { '!=', [qw(yes YES)] },
242 -nest => [ face => [ -or => {'=', 'mr.happy'}, {'=', undef} ] ] },
244 stmt => 'UPDATE taco_punches SET one = ?, three = ? WHERE ( ( ( ( ( face = ? ) OR ( face IS NULL ) ) ) )'
245 . ' AND ( ( bland != ? ) AND ( bland != ? ) ) AND ( ( tasty != ? ) OR ( tasty != ? ) ) )',
246 stmt_q => 'UPDATE `taco_punches` SET `one` = ?, `three` = ? WHERE ( ( ( ( ( `face` = ? ) OR ( `face` IS NULL ) ) ) )'
247 . ' AND ( ( `bland` != ? ) AND ( `bland` != ? ) ) AND ( ( `tasty` != ? ) OR ( `tasty` != ? ) ) )',
248 bind => [qw(2 4 mr.happy yes YES yes YES)],
252 args => ['jeff', '*', { name => {'ilike', '%smith%', -not_in => ['Nate','Jim','Bob','Sally']},
253 -nest => [ -or => [ -and => [age => { -between => [20,30] }, age => {'!=', 25} ],
254 yob => {'<', 1976} ] ] } ],
255 stmt => 'SELECT * FROM jeff WHERE ( ( ( ( ( ( ( age BETWEEN ? AND ? ) AND ( age != ? ) ) ) OR ( yob < ? ) ) ) )'
256 . ' AND name NOT IN ( ?, ?, ?, ? ) AND name ILIKE ? )',
257 stmt_q => 'SELECT * FROM `jeff` WHERE ( ( ( ( ( ( ( `age` BETWEEN ? AND ? ) AND ( `age` != ? ) ) ) OR ( `yob` < ? ) ) ) )'
258 . ' AND `name` NOT IN ( ?, ?, ?, ? ) AND `name` ILIKE ? )',
259 bind => [qw(20 30 25 1976 Nate Jim Bob Sally %smith%)]
263 # LDNOTE : removed the "-maybe", because we no longer admit unknown ops
266 # args => ['fhole', {fpoles => 4}, [-maybe => {race => [-and => [qw(black white asian)]]},
267 args => ['fhole', {fpoles => 4}, [
268 { race => [qw/-or black white asian /] },
269 { -nest => { firsttime => [-or => {'=','yes'}, undef] } },
270 { -and => [ { firstname => {-not_like => 'candace'} }, { lastname => {-in => [qw(jugs canyon towers)] } } ] },
272 stmt => 'UPDATE fhole SET fpoles = ? WHERE ( ( ( ( ( ( ( race = ? ) OR ( race = ? ) OR ( race = ? ) ) ) ) ) )'
273 . ' OR ( ( ( ( firsttime = ? ) OR ( firsttime IS NULL ) ) ) ) OR ( ( ( firstname NOT LIKE ? ) ) AND ( lastname IN (?, ?, ?) ) ) )',
274 stmt_q => 'UPDATE `fhole` SET `fpoles` = ? WHERE ( ( ( ( ( ( ( `race` = ? ) OR ( `race` = ? ) OR ( `race` = ? ) ) ) ) ) )'
275 . ' OR ( ( ( ( `firsttime` = ? ) OR ( `firsttime` IS NULL ) ) ) ) OR ( ( ( `firstname` NOT LIKE ? ) ) AND ( `lastname` IN( ?, ?, ? )) ) )',
276 bind => [qw(4 black white asian yes candace jugs canyon towers)]
280 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}],
281 stmt => 'INSERT INTO test (a, b) VALUES (?, to_date(?, \'MM/DD/YY\'))',
282 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, to_date(?, \'MM/DD/YY\'))',
283 bind => [qw(1 02/02/02)],
287 # LDNOTE: modified test below because we agreed with MST that literal SQL
288 # should not automatically insert a '='; the user has to do it
291 # args => ['test', '*', { a => \["to_date(?, 'MM/DD/YY')", '02/02/02']}],
292 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", '02/02/02']}],
293 stmt => q{SELECT * FROM test WHERE ( a = to_date(?, 'MM/DD/YY') )},
294 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = to_date(?, 'MM/DD/YY') )},
295 bind => ['02/02/02'],
299 new => {array_datatypes => 1},
300 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
301 stmt => 'INSERT INTO test (a, b) VALUES (?, ?)',
302 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, ?)',
303 bind => [1, [1, 1, 2, 3, 5, 8]],
307 new => {bindtype => 'columns', array_datatypes => 1},
308 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
309 stmt => 'INSERT INTO test (a, b) VALUES (?, ?)',
310 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, ?)',
311 bind => [[a => 1], [b => [1, 1, 2, 3, 5, 8]]],
315 new => {array_datatypes => 1},
316 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
317 stmt => 'UPDATE test SET a = ?, b = ?',
318 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?',
319 bind => [1, [1, 1, 2, 3, 5, 8]],
323 new => {bindtype => 'columns', array_datatypes => 1},
324 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
325 stmt => 'UPDATE test SET a = ?, b = ?',
326 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?',
327 bind => [[a => 1], [b => [1, 1, 2, 3, 5, 8]]],
331 args => ['test', '*', { a => {'>', \'1 + 1'}, b => 8 }],
332 stmt => 'SELECT * FROM test WHERE ( a > 1 + 1 AND b = ? )',
333 stmt_q => 'SELECT * FROM `test` WHERE ( `a` > 1 + 1 AND `b` = ? )',
338 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, b => 8 }],
339 stmt => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )',
340 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )',
341 bind => ['02/02/02', 8],
345 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => { -answer => 42 }}],
346 stmt => 'INSERT INTO test (a, b, c, d, e) VALUES (?, ?, ?, ?, ANSWER(?))',
347 stmt_q => 'INSERT INTO `test` (`a`, `b`, `c`, `d`, `e`) VALUES (?, ?, ?, ?, ANSWER(?))',
348 bind => [qw/1 2 3 4 42/],
352 args => ['test', {a => 1, b => \["42"]}, {a => {'between', [1,2]}}],
353 stmt => 'UPDATE test SET a = ?, b = 42 WHERE ( a BETWEEN ? AND ? )',
354 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = 42 WHERE ( `a` BETWEEN ? AND ? )',
359 args => ['test', {a => 1, b => \["42"]}],
360 stmt => 'INSERT INTO test (a, b) VALUES (?, 42)',
361 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, 42)',
366 args => ['test', '*', { a => \["= 42"], b => 1}],
367 stmt => q{SELECT * FROM test WHERE ( a = 42 ) AND (b = ? )},
368 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = 42 ) AND ( `b` = ? )},
373 args => ['test', '*', { a => {'<' => \["42"]}, b => 8 }],
374 stmt => 'SELECT * FROM test WHERE ( a < 42 AND b = ? )',
375 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < 42 AND `b` = ? )',
380 new => {bindtype => 'columns'},
381 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}],
382 stmt => 'INSERT INTO test (a, b) VALUES (?, to_date(?, \'MM/DD/YY\'))',
383 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, to_date(?, \'MM/DD/YY\'))',
384 bind => [[a => '1'], [dummy => '02/02/02']],
388 new => {bindtype => 'columns'},
389 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}, {a => {'between', [1,2]}}],
390 stmt => 'UPDATE test SET a = ?, b = to_date(?, \'MM/DD/YY\') WHERE ( a BETWEEN ? AND ? )',
391 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = to_date(?, \'MM/DD/YY\') WHERE ( `a` BETWEEN ? AND ? )',
392 bind => [[a => '1'], [dummy => '02/02/02'], [a => '1'], [a => '2']],
396 new => {bindtype => 'columns'},
397 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}],
398 stmt => q{SELECT * FROM test WHERE ( a = to_date(?, 'MM/DD/YY') )},
399 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = to_date(?, 'MM/DD/YY') )},
400 bind => [[dummy => '02/02/02']],
404 new => {bindtype => 'columns'},
405 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}, b => 8 }],
406 stmt => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )',
407 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )',
408 bind => [[dummy => '02/02/02'], [b => 8]],
412 new => {bindtype => 'columns'},
413 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}],
414 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
418 new => {bindtype => 'columns'},
419 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, {a => {'between', [1,2]}}],
420 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
424 new => {bindtype => 'columns'},
425 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", '02/02/02']}],
426 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
430 new => {bindtype => 'columns'},
431 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, b => 8 }],
432 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
436 new => {bindtype => 'columns'},
437 args => ['test', '*', { a => {-in => \["(SELECT d FROM to_date(?, 'MM/DD/YY') AS d)", [dummy => '02/02/02']]}, b => 8 }],
438 stmt => 'SELECT * FROM test WHERE ( a IN (SELECT d FROM to_date(?, \'MM/DD/YY\') AS d) AND b = ? )',
439 stmt_q => 'SELECT * FROM `test` WHERE ( `a` IN (SELECT d FROM to_date(?, \'MM/DD/YY\') AS d) AND `b` = ? )',
440 bind => [[dummy => '02/02/02'], [b => 8]],
444 new => {bindtype => 'columns'},
445 args => ['test', '*', { a => {-in => \["(SELECT d FROM to_date(?, 'MM/DD/YY') AS d)", '02/02/02']}, b => 8 }],
446 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
450 new => {bindtype => 'columns'},
451 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']]}],
452 stmt => 'INSERT INTO test (a, b) VALUES (?, to_date(?, \'MM/DD/YY\'))',
453 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, to_date(?, \'MM/DD/YY\'))',
454 bind => [[a => '1'], [{dummy => 1} => '02/02/02']],
458 new => {bindtype => 'columns'},
459 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']], c => { -lower => 'foo' }}, {a => {'between', [1,2]}}],
460 stmt => "UPDATE test SET a = ?, b = to_date(?, 'MM/DD/YY'), c = LOWER(?) WHERE ( a BETWEEN ? AND ? )",
461 stmt_q => "UPDATE `test` SET `a` = ?, `b` = to_date(?, 'MM/DD/YY'), `c` = LOWER(?) WHERE ( `a` BETWEEN ? AND ? )",
462 bind => [[a => '1'], [{dummy => 1} => '02/02/02'], [c => 'foo'], [a => '1'], [a => '2']],
466 new => {bindtype => 'columns'},
467 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']]}],
468 stmt => q{SELECT * FROM test WHERE ( a = to_date(?, 'MM/DD/YY') )},
469 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = to_date(?, 'MM/DD/YY') )},
470 bind => [[{dummy => 1} => '02/02/02']],
474 new => {bindtype => 'columns'},
475 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']]}, b => 8 }],
476 stmt => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )',
477 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )',
478 bind => [[{dummy => 1} => '02/02/02'], [b => 8]],
482 new => {bindtype => 'columns'},
483 args => ['test', '*', { -or => [ -and => [ a => 'a', b => 'b' ], -and => [ c => 'c', d => 'd' ] ] }],
484 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? ) OR ( c = ? AND d = ? )',
485 stmt_q => 'SELECT * FROM `test` WHERE ( `a` = ? AND `b` = ? ) OR ( `c` = ? AND `d` = ? )',
486 bind => [[a => 'a'], [b => 'b'], [ c => 'c'],[ d => 'd']],
490 new => {bindtype => 'columns'},
491 args => ['test', '*', [ { a => 1, b => 1}, [ a => 2, b => 2] ] ],
492 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? ) OR ( a = ? OR b = ? )',
493 stmt_q => 'SELECT * FROM `test` WHERE ( `a` = ? AND `b` = ? ) OR ( `a` = ? OR `b` = ? )',
494 bind => [[a => 1], [b => 1], [ a => 2], [ b => 2]],
498 new => {bindtype => 'columns'},
499 args => ['test', '*', [ [ a => 1, b => 1], { a => 2, b => 2 } ] ],
500 stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? ) OR ( a = ? AND b = ? )',
501 stmt_q => 'SELECT * FROM `test` WHERE ( `a` = ? OR `b` = ? ) OR ( `a` = ? AND `b` = ? )',
502 bind => [[a => 1], [b => 1], [ a => 2], [ b => 2]],
506 args => ['test', [qw/1 2 3 4 5/], { returning => 'id' }],
507 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?) RETURNING id',
508 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING `id`',
509 bind => [qw/1 2 3 4 5/],
513 args => ['test', [qw/1 2 3 4 5/], { returning => 'id, foo, bar' }],
514 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?) RETURNING id, foo, bar',
515 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING `id, foo, bar`',
516 bind => [qw/1 2 3 4 5/],
520 args => ['test', [qw/1 2 3 4 5/], { returning => [qw(id foo bar) ] }],
521 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?) RETURNING id, foo, bar',
522 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING `id`, `foo`, `bar`',
523 bind => [qw/1 2 3 4 5/],
527 args => ['test', [qw/1 2 3 4 5/], { returning => \'id, foo, bar' }],
528 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?) RETURNING id, foo, bar',
529 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING id, foo, bar',
530 bind => [qw/1 2 3 4 5/],
534 args => ['test', [qw/1 2 3 4 5/], { returning => \'id' }],
535 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?) RETURNING id',
536 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING id',
537 bind => [qw/1 2 3 4 5/],
541 new => {bindtype => 'columns'},
542 args => ['test', '*', [ Y => { '=' => { -max => { -LENGTH => { -min => 'x' } } } } ] ],
543 stmt => 'SELECT * FROM test WHERE ( Y = ( MAX( LENGTH( MIN ? ) ) ) )',
544 stmt_q => 'SELECT * FROM `test` WHERE ( `Y` = ( MAX( LENGTH( MIN ? ) ) ) )',
545 bind => [[Y => 'x']],
550 plan tests => scalar(grep { !$_->{warning_like} } @tests) * 2
551 + scalar(grep { $_->{warning_like} } @tests) * 4;
556 my $new = $t->{new} || {};
557 $new->{debug} = $ENV{DEBUG} || 0;
559 for my $quoted (0, 1) {
561 my $maker = SQL::Abstract->new(%$new, $quoted
562 ? (quote_char => '`', name_sep => '.')
570 ($stmt, @bind) = $maker->$op (@ { $t->{args} } );
573 if ($t->{exception_like}) {
576 $t->{exception_like},
577 "throws the expected exception ($t->{exception_like})"
580 if ($t->{warning_like}) {
584 "issues the expected warning ($t->{warning_like})"
593 $quoted ? $t->{stmt_q}: $t->{stmt},