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 => ['test', '*', { a => { 'between', ['boom', 'bang'] } }],
82 stmt => 'SELECT * FROM test WHERE ( a BETWEEN ? AND ? )',
83 stmt_q => 'SELECT * FROM `test` WHERE ( `a` BETWEEN ? AND ? )',
84 bind => ['boom', 'bang']
88 args => ['test', '*', { a => { '!=', 'boom' } }],
89 stmt => 'SELECT * FROM test WHERE ( a != ? )',
90 stmt_q => 'SELECT * FROM `test` WHERE ( `a` != ? )',
95 args => ['test', {a => 'boom'}, {a => undef}],
96 stmt => 'UPDATE test SET a = ? WHERE ( a IS NULL )',
97 stmt_q => 'UPDATE `test` SET `a` = ? WHERE ( `a` IS NULL )',
102 args => ['test', {a => 'boom'}, { a => {'!=', "bang" }} ],
103 stmt => 'UPDATE test SET a = ? WHERE ( a != ? )',
104 stmt_q => 'UPDATE `test` SET `a` = ? WHERE ( `a` != ? )',
105 bind => ['boom', 'bang']
109 args => ['test', {'a-funny-flavored-candy' => 'yummy', b => 'oops'}, { a42 => "bang" }],
110 stmt => 'UPDATE test SET a-funny-flavored-candy = ?, b = ? WHERE ( a42 = ? )',
111 stmt_q => 'UPDATE `test` SET `a-funny-flavored-candy` = ?, `b` = ? WHERE ( `a42` = ? )',
112 bind => ['yummy', 'oops', 'bang']
116 args => ['test', {requestor => undef}],
117 stmt => 'DELETE FROM test WHERE ( requestor IS NULL )',
118 stmt_q => 'DELETE FROM `test` WHERE ( `requestor` IS NULL )',
123 args => [[qw/test1 test2 test3/],
124 { 'test1.field' => \'!= test2.field',
125 user => {'!=','nwiger'} },
127 stmt => 'DELETE FROM test1, test2, test3 WHERE ( test1.field != test2.field AND user != ? )',
128 stmt_q => 'DELETE FROM `test1`, `test2`, `test3` WHERE ( `test1`.`field` != test2.field AND `user` != ? )', # test2.field is a literal value, cannnot be quoted.
133 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => 5}],
134 stmt => 'INSERT INTO test (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)',
135 stmt_q => 'INSERT INTO `test` (`a`, `b`, `c`, `d`, `e`) VALUES (?, ?, ?, ?, ?)',
136 bind => [qw/1 2 3 4 5/],
140 args => ['test', [qw/1 2 3 4 5/]],
141 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?)',
142 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?)',
143 bind => [qw/1 2 3 4 5/],
147 args => ['test', [qw/1 2 3 4 5/, undef]],
148 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?, ?)',
149 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?, ?)',
150 bind => [qw/1 2 3 4 5/, undef],
154 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => 5}],
155 stmt => 'UPDATE test SET a = ?, b = ?, c = ?, d = ?, e = ?',
156 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?, `c` = ?, `d` = ?, `e` = ?',
157 bind => [qw/1 2 3 4 5/],
161 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => 5}, {a => {'in', [1..5]}}],
162 stmt => 'UPDATE test SET a = ?, b = ?, c = ?, d = ?, e = ? WHERE ( a IN ( ?, ?, ?, ?, ? ) )',
163 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?, `c` = ?, `d` = ?, `e` = ? WHERE ( `a` IN ( ?, ?, ?, ?, ? ) )',
164 bind => [qw/1 2 3 4 5 1 2 3 4 5/],
168 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, {a => {'between', [1,2]}}],
169 stmt => 'UPDATE test SET a = ?, b = to_date(?, \'MM/DD/YY\') WHERE ( a BETWEEN ? AND ? )',
170 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = to_date(?, \'MM/DD/YY\') WHERE ( `a` BETWEEN ? AND ? )',
171 bind => [qw(1 02/02/02 1 2)],
175 args => ['test.table', {high_limit => \'max(all_limits)', low_limit => 4} ],
176 stmt => 'INSERT INTO test.table (high_limit, low_limit) VALUES (max(all_limits), ?)',
177 stmt_q => 'INSERT INTO `test`.`table` (`high_limit`, `low_limit`) VALUES (max(all_limits), ?)',
182 args => ['test.table', [ \'max(all_limits)', 4 ] ],
183 stmt => 'INSERT INTO test.table VALUES (max(all_limits), ?)',
184 stmt_q => 'INSERT INTO `test`.`table` VALUES (max(all_limits), ?)',
189 new => {bindtype => 'columns'},
190 args => ['test.table', {one => 2, three => 4, five => 6} ],
191 stmt => 'INSERT INTO test.table (five, one, three) VALUES (?, ?, ?)',
192 stmt_q => 'INSERT INTO `test`.`table` (`five`, `one`, `three`) VALUES (?, ?, ?)',
193 bind => [['five', 6], ['one', 2], ['three', 4]], # alpha order, man...
197 new => {bindtype => 'columns', case => 'lower'},
198 args => ['test.table', [qw/one two three/], {one => 2, three => 4, five => 6} ],
199 stmt => 'select one, two, three from test.table where ( five = ? and one = ? and three = ? )',
200 stmt_q => 'select `one`, `two`, `three` from `test`.`table` where ( `five` = ? and `one` = ? and `three` = ? )',
201 bind => [['five', 6], ['one', 2], ['three', 4]], # alpha order, man...
205 new => {bindtype => 'columns', cmp => 'like'},
206 args => ['testin.table2', {One => 22, Three => 44, FIVE => 66},
207 {Beer => 'is', Yummy => '%YES%', IT => ['IS','REALLY','GOOD']}],
208 stmt => 'UPDATE testin.table2 SET FIVE = ?, One = ?, Three = ? WHERE '
209 . '( Beer LIKE ? AND ( ( IT LIKE ? ) OR ( IT LIKE ? ) OR ( IT LIKE ? ) ) AND Yummy LIKE ? )',
210 stmt_q => 'UPDATE `testin`.`table2` SET `FIVE` = ?, `One` = ?, `Three` = ? WHERE '
211 . '( `Beer` LIKE ? AND ( ( `IT` LIKE ? ) OR ( `IT` LIKE ? ) OR ( `IT` LIKE ? ) ) AND `Yummy` LIKE ? )',
212 bind => [['FIVE', 66], ['One', 22], ['Three', 44], ['Beer','is'],
213 ['IT','IS'], ['IT','REALLY'], ['IT','GOOD'], ['Yummy','%YES%']],
217 args => ['test', '*', {priority => [ -and => {'!=', 2}, { -not_like => '3%'} ]}],
218 stmt => 'SELECT * FROM test WHERE ( ( ( priority != ? ) AND ( priority NOT LIKE ? ) ) )',
219 stmt_q => 'SELECT * FROM `test` WHERE ( ( ( `priority` != ? ) AND ( `priority` NOT LIKE ? ) ) )',
224 args => ['Yo Momma', '*', { user => 'nwiger',
225 -nest => [ workhrs => {'>', 20}, geo => 'ASIA' ] }],
226 stmt => 'SELECT * FROM Yo Momma WHERE ( ( ( workhrs > ? ) OR ( geo = ? ) ) AND user = ? )',
227 stmt_q => 'SELECT * FROM `Yo Momma` WHERE ( ( ( `workhrs` > ? ) OR ( `geo` = ? ) ) AND `user` = ? )',
228 bind => [qw(20 ASIA nwiger)],
232 args => ['taco_punches', { one => 2, three => 4 },
233 { bland => [ -and => {'!=', 'yes'}, {'!=', 'YES'} ],
234 tasty => { '!=', [qw(yes YES)] },
235 -nest => [ face => [ -or => {'=', 'mr.happy'}, {'=', undef} ] ] },
237 stmt => 'UPDATE taco_punches SET one = ?, three = ? WHERE ( ( ( ( ( face = ? ) OR ( face IS NULL ) ) ) )'
238 . ' AND ( ( bland != ? ) AND ( bland != ? ) ) AND ( ( tasty != ? ) OR ( tasty != ? ) ) )',
239 stmt_q => 'UPDATE `taco_punches` SET `one` = ?, `three` = ? WHERE ( ( ( ( ( `face` = ? ) OR ( `face` IS NULL ) ) ) )'
240 . ' AND ( ( `bland` != ? ) AND ( `bland` != ? ) ) AND ( ( `tasty` != ? ) OR ( `tasty` != ? ) ) )',
241 bind => [qw(2 4 mr.happy yes YES yes YES)],
245 args => ['jeff', '*', { name => {'ilike', '%smith%', -not_in => ['Nate','Jim','Bob','Sally']},
246 -nest => [ -or => [ -and => [age => { -between => [20,30] }, age => {'!=', 25} ],
247 yob => {'<', 1976} ] ] } ],
248 stmt => 'SELECT * FROM jeff WHERE ( ( ( ( ( ( ( age BETWEEN ? AND ? ) AND ( age != ? ) ) ) OR ( yob < ? ) ) ) )'
249 . ' AND name NOT IN ( ?, ?, ?, ? ) AND name ILIKE ? )',
250 stmt_q => 'SELECT * FROM `jeff` WHERE ( ( ( ( ( ( ( `age` BETWEEN ? AND ? ) AND ( `age` != ? ) ) ) OR ( `yob` < ? ) ) ) )'
251 . ' AND `name` NOT IN ( ?, ?, ?, ? ) AND `name` ILIKE ? )',
252 bind => [qw(20 30 25 1976 Nate Jim Bob Sally %smith%)]
256 # LDNOTE : removed the "-maybe", because we no longer admit unknown ops
259 # args => ['fhole', {fpoles => 4}, [-maybe => {race => [-and => [qw(black white asian)]]},
260 args => ['fhole', {fpoles => 4}, [
261 { race => [qw/-or black white asian /] },
262 { -nest => { firsttime => [-or => {'=','yes'}, undef] } },
263 { -and => [ { firstname => {-not_like => 'candace'} }, { lastname => {-in => [qw(jugs canyon towers)] } } ] },
265 stmt => 'UPDATE fhole SET fpoles = ? WHERE ( ( ( ( ( ( ( race = ? ) OR ( race = ? ) OR ( race = ? ) ) ) ) ) )'
266 . ' OR ( ( ( ( firsttime = ? ) OR ( firsttime IS NULL ) ) ) ) OR ( ( ( firstname NOT LIKE ? ) ) AND ( lastname IN (?, ?, ?) ) ) )',
267 stmt_q => 'UPDATE `fhole` SET `fpoles` = ? WHERE ( ( ( ( ( ( ( `race` = ? ) OR ( `race` = ? ) OR ( `race` = ? ) ) ) ) ) )'
268 . ' OR ( ( ( ( `firsttime` = ? ) OR ( `firsttime` IS NULL ) ) ) ) OR ( ( ( `firstname` NOT LIKE ? ) ) AND ( `lastname` IN( ?, ?, ? )) ) )',
269 bind => [qw(4 black white asian yes candace jugs canyon towers)]
273 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}],
274 stmt => 'INSERT INTO test (a, b) VALUES (?, to_date(?, \'MM/DD/YY\'))',
275 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, to_date(?, \'MM/DD/YY\'))',
276 bind => [qw(1 02/02/02)],
280 # LDNOTE: modified test below because we agreed with MST that literal SQL
281 # should not automatically insert a '='; the user has to do it
284 # args => ['test', '*', { a => \["to_date(?, 'MM/DD/YY')", '02/02/02']}],
285 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", '02/02/02']}],
286 stmt => q{SELECT * FROM test WHERE ( a = to_date(?, 'MM/DD/YY') )},
287 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = to_date(?, 'MM/DD/YY') )},
288 bind => ['02/02/02'],
292 new => {array_datatypes => 1},
293 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
294 stmt => 'INSERT INTO test (a, b) VALUES (?, ?)',
295 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, ?)',
296 bind => [1, [1, 1, 2, 3, 5, 8]],
300 new => {bindtype => 'columns', array_datatypes => 1},
301 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
302 stmt => 'INSERT INTO test (a, b) VALUES (?, ?)',
303 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, ?)',
304 bind => [[a => 1], [b => [1, 1, 2, 3, 5, 8]]],
308 new => {array_datatypes => 1},
309 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
310 stmt => 'UPDATE test SET a = ?, b = ?',
311 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?',
312 bind => [1, [1, 1, 2, 3, 5, 8]],
316 new => {bindtype => 'columns', array_datatypes => 1},
317 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
318 stmt => 'UPDATE test SET a = ?, b = ?',
319 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?',
320 bind => [[a => 1], [b => [1, 1, 2, 3, 5, 8]]],
324 args => ['test', '*', { a => {'>', \'1 + 1'}, b => 8 }],
325 stmt => 'SELECT * FROM test WHERE ( a > 1 + 1 AND b = ? )',
326 stmt_q => 'SELECT * FROM `test` WHERE ( `a` > 1 + 1 AND `b` = ? )',
331 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, b => 8 }],
332 stmt => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )',
333 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )',
334 bind => ['02/02/02', 8],
336 { #TODO in SQLA >= 2.0 it will die instead (we kept this just because old SQLA passed it through)
338 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => { answer => 42 }}],
339 stmt => 'INSERT INTO test (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)',
340 stmt_q => 'INSERT INTO `test` (`a`, `b`, `c`, `d`, `e`) VALUES (?, ?, ?, ?, ?)',
341 bind => [qw/1 2 3 4/, { answer => 42}],
342 warning_like => qr/HASH ref as bind value in insert is not supported/i,
346 args => ['test', {a => 1, b => \["42"]}, {a => {'between', [1,2]}}],
347 stmt => 'UPDATE test SET a = ?, b = 42 WHERE ( a BETWEEN ? AND ? )',
348 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = 42 WHERE ( `a` BETWEEN ? AND ? )',
353 args => ['test', {a => 1, b => \["42"]}],
354 stmt => 'INSERT INTO test (a, b) VALUES (?, 42)',
355 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, 42)',
360 args => ['test', '*', { a => \["= 42"], b => 1}],
361 stmt => q{SELECT * FROM test WHERE ( a = 42 ) AND (b = ? )},
362 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = 42 ) AND ( `b` = ? )},
367 args => ['test', '*', { a => {'<' => \["42"]}, b => 8 }],
368 stmt => 'SELECT * FROM test WHERE ( a < 42 AND b = ? )',
369 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < 42 AND `b` = ? )',
374 new => {bindtype => 'columns'},
375 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}],
376 stmt => 'INSERT INTO test (a, b) VALUES (?, to_date(?, \'MM/DD/YY\'))',
377 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, to_date(?, \'MM/DD/YY\'))',
378 bind => [[a => '1'], [dummy => '02/02/02']],
382 new => {bindtype => 'columns'},
383 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}, {a => {'between', [1,2]}}],
384 stmt => 'UPDATE test SET a = ?, b = to_date(?, \'MM/DD/YY\') WHERE ( a BETWEEN ? AND ? )',
385 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = to_date(?, \'MM/DD/YY\') WHERE ( `a` BETWEEN ? AND ? )',
386 bind => [[a => '1'], [dummy => '02/02/02'], [a => '1'], [a => '2']],
390 new => {bindtype => 'columns'},
391 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}],
392 stmt => q{SELECT * FROM test WHERE ( a = to_date(?, 'MM/DD/YY') )},
393 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = to_date(?, 'MM/DD/YY') )},
394 bind => [[dummy => '02/02/02']],
398 new => {bindtype => 'columns'},
399 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}, b => 8 }],
400 stmt => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )',
401 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )',
402 bind => [[dummy => '02/02/02'], [b => 8]],
406 new => {bindtype => 'columns'},
407 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}],
408 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
412 new => {bindtype => 'columns'},
413 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, {a => {'between', [1,2]}}],
414 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
418 new => {bindtype => 'columns'},
419 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", '02/02/02']}],
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']}, b => 8 }],
426 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
430 new => {bindtype => 'columns'},
431 args => ['test', '*', { a => {-in => \["(SELECT d FROM to_date(?, 'MM/DD/YY') AS d)", [dummy => '02/02/02']]}, b => 8 }],
432 stmt => 'SELECT * FROM test WHERE ( a IN (SELECT d FROM to_date(?, \'MM/DD/YY\') AS d) AND b = ? )',
433 stmt_q => 'SELECT * FROM `test` WHERE ( `a` IN (SELECT d FROM to_date(?, \'MM/DD/YY\') AS d) AND `b` = ? )',
434 bind => [[dummy => '02/02/02'], [b => 8]],
438 new => {bindtype => 'columns'},
439 args => ['test', '*', { a => {-in => \["(SELECT d FROM to_date(?, 'MM/DD/YY') AS d)", '02/02/02']}, b => 8 }],
440 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
444 new => {bindtype => 'columns'},
445 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']]}],
446 stmt => 'INSERT INTO test (a, b) VALUES (?, to_date(?, \'MM/DD/YY\'))',
447 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, to_date(?, \'MM/DD/YY\'))',
448 bind => [[a => '1'], [{dummy => 1} => '02/02/02']],
452 new => {bindtype => 'columns'},
453 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']], c => { -lower => 'foo' }}, {a => {'between', [1,2]}}],
454 stmt => "UPDATE test SET a = ?, b = to_date(?, 'MM/DD/YY'), c = LOWER ? WHERE ( a BETWEEN ? AND ? )",
455 stmt_q => "UPDATE `test` SET `a` = ?, `b` = to_date(?, 'MM/DD/YY'), `c` = LOWER ? WHERE ( `a` BETWEEN ? AND ? )",
456 bind => [[a => '1'], [{dummy => 1} => '02/02/02'], [c => 'foo'], [a => '1'], [a => '2']],
460 new => {bindtype => 'columns'},
461 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']]}],
462 stmt => q{SELECT * FROM test WHERE ( a = to_date(?, 'MM/DD/YY') )},
463 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = to_date(?, 'MM/DD/YY') )},
464 bind => [[{dummy => 1} => '02/02/02']],
468 new => {bindtype => 'columns'},
469 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']]}, b => 8 }],
470 stmt => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )',
471 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )',
472 bind => [[{dummy => 1} => '02/02/02'], [b => 8]],
476 new => {bindtype => 'columns'},
477 args => ['test', '*', { -or => [ -and => [ a => 'a', b => 'b' ], -and => [ c => 'c', d => 'd' ] ] }],
478 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? ) OR ( c = ? AND d = ? )',
479 stmt_q => 'SELECT * FROM `test` WHERE ( `a` = ? AND `b` = ? ) OR ( `c` = ? AND `d` = ? )',
480 bind => [[a => 'a'], [b => 'b'], [ c => 'c'],[ d => 'd']],
484 new => {bindtype => 'columns'},
485 args => ['test', '*', [ { a => 1, b => 1}, [ a => 2, b => 2] ] ],
486 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? ) OR ( a = ? OR b = ? )',
487 stmt_q => 'SELECT * FROM `test` WHERE ( `a` = ? AND `b` = ? ) OR ( `a` = ? OR `b` = ? )',
488 bind => [[a => 1], [b => 1], [ a => 2], [ b => 2]],
492 new => {bindtype => 'columns'},
493 args => ['test', '*', [ [ a => 1, b => 1], { a => 2, b => 2 } ] ],
494 stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? ) OR ( a = ? AND b = ? )',
495 stmt_q => 'SELECT * FROM `test` WHERE ( `a` = ? OR `b` = ? ) OR ( `a` = ? AND `b` = ? )',
496 bind => [[a => 1], [b => 1], [ a => 2], [ b => 2]],
500 args => ['test', [qw/1 2 3 4 5/], { returning => 'id' }],
501 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?) RETURNING id',
502 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING `id`',
503 bind => [qw/1 2 3 4 5/],
507 args => ['test', [qw/1 2 3 4 5/], { returning => 'id, foo, bar' }],
508 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?) RETURNING id, foo, bar',
509 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING `id, foo, bar`',
510 bind => [qw/1 2 3 4 5/],
514 args => ['test', [qw/1 2 3 4 5/], { returning => [qw(id foo bar) ] }],
515 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?) RETURNING id, foo, bar',
516 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING `id`, `foo`, `bar`',
517 bind => [qw/1 2 3 4 5/],
521 args => ['test', [qw/1 2 3 4 5/], { returning => \'id, foo, bar' }],
522 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?) RETURNING id, foo, bar',
523 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING id, foo, bar',
524 bind => [qw/1 2 3 4 5/],
528 args => ['test', [qw/1 2 3 4 5/], { returning => \'id' }],
529 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?) RETURNING id',
530 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING id',
531 bind => [qw/1 2 3 4 5/],
535 new => {bindtype => 'columns'},
536 args => ['test', '*', [ Y => { '=' => { -max => { -LENGTH => { -min => 'x' } } } } ] ],
537 stmt => 'SELECT * FROM test WHERE ( Y = ( MAX( LENGTH( MIN ? ) ) ) )',
538 stmt_q => 'SELECT * FROM `test` WHERE ( `Y` = ( MAX( LENGTH( MIN ? ) ) ) )',
539 bind => [[Y => 'x']],
544 plan tests => scalar(grep { !$_->{warning_like} } @tests) * 2
545 + scalar(grep { $_->{warning_like} } @tests) * 4;
550 my $new = $t->{new} || {};
551 $new->{debug} = $ENV{DEBUG} || 0;
553 for my $quoted (0, 1) {
555 my $maker = SQL::Abstract->new(%$new, $quoted
556 ? (quote_char => '`', name_sep => '.')
564 ($stmt, @bind) = $maker->$op (@ { $t->{args} } );
567 if ($t->{exception_like}) {
570 $t->{exception_like},
571 "throws the expected exception ($t->{exception_like})"
574 if ($t->{warning_like}) {
578 "issues the expected warning ($t->{warning_like})"
587 $quoted ? $t->{stmt_q}: $t->{stmt},