9 use SQL::Abstract::Test import => ['is_same_sql_bind'];
17 args => ['test', '*'],
18 stmt => 'SELECT * FROM test',
19 stmt_q => 'SELECT * FROM `test`',
25 args => ['test', [qw(one two three)]],
26 stmt => 'SELECT one, two, three FROM test',
27 stmt_q => 'SELECT `one`, `two`, `three` FROM `test`',
33 args => ['test', '*', { a => 0 }, [qw/boom bada bing/]],
34 stmt => 'SELECT * FROM test WHERE ( a = ? ) ORDER BY boom, bada, bing',
35 stmt_q => 'SELECT * FROM `test` WHERE ( `a` = ? ) ORDER BY `boom`, `bada`, `bing`',
41 args => ['test', '*', [ { a => 5 }, { b => 6 } ]],
42 stmt => 'SELECT * FROM test WHERE ( ( a = ? ) OR ( b = ? ) )',
43 stmt_q => 'SELECT * FROM `test` WHERE ( ( `a` = ? ) OR ( `b` = ? ) )',
49 args => ['test', '*', undef, ['id']],
50 stmt => 'SELECT * FROM test ORDER BY id',
51 stmt_q => 'SELECT * FROM `test` ORDER BY `id`',
57 args => ['test', '*', { a => 'boom' } , ['id']],
58 stmt => 'SELECT * FROM test WHERE ( a = ? ) ORDER BY id',
59 stmt_q => 'SELECT * FROM `test` WHERE ( `a` = ? ) ORDER BY `id`',
65 args => ['test', '*', { a => ['boom', 'bang'] }],
66 stmt => 'SELECT * FROM test WHERE ( ( ( a = ? ) OR ( a = ? ) ) )',
67 stmt_q => 'SELECT * FROM `test` WHERE ( ( ( `a` = ? ) OR ( `a` = ? ) ) )',
68 bind => ['boom', 'bang']
73 args => [[qw/test1 test2/], '*', { 'test1.a' => { 'In', ['boom', 'bang'] } }],
74 stmt => 'SELECT * FROM test1, test2 WHERE ( test1.a IN ( ?, ? ) )',
75 stmt_q => 'SELECT * FROM `test1`, `test2` WHERE ( `test1`.`a` IN ( ?, ? ) )',
76 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']
89 args => ['test', '*', { a => { '!=', 'boom' } }],
90 stmt => 'SELECT * FROM test WHERE ( a != ? )',
91 stmt_q => 'SELECT * FROM `test` WHERE ( `a` != ? )',
97 args => ['test', {a => 'boom'}, {a => undef}],
98 stmt => 'UPDATE test SET a = ? WHERE ( a IS NULL )',
99 stmt_q => 'UPDATE `test` SET `a` = ? WHERE ( `a` IS NULL )',
105 args => ['test', {a => 'boom'}, { a => {'!=', "bang" }} ],
106 stmt => 'UPDATE test SET a = ? WHERE ( a != ? )',
107 stmt_q => 'UPDATE `test` SET `a` = ? WHERE ( `a` != ? )',
108 bind => ['boom', 'bang']
113 args => ['test', {'a-funny-flavored-candy' => 'yummy', b => 'oops'}, { a42 => "bang" }],
114 stmt => 'UPDATE test SET a-funny-flavored-candy = ?, b = ? WHERE ( a42 = ? )',
115 stmt_q => 'UPDATE `test` SET `a-funny-flavored-candy` = ?, `b` = ? WHERE ( `a42` = ? )',
116 bind => ['yummy', 'oops', 'bang']
121 args => ['test', {requestor => undef}],
122 stmt => 'DELETE FROM test WHERE ( requestor IS NULL )',
123 stmt_q => 'DELETE FROM `test` WHERE ( `requestor` IS NULL )',
129 args => [[qw/test1 test2 test3/],
130 { 'test1.field' => \'!= test2.field',
131 user => {'!=','nwiger'} },
133 stmt => 'DELETE FROM test1, test2, test3 WHERE ( test1.field != test2.field AND user != ? )',
134 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/],
148 args => ['test', [qw/1 2 3 4 5/]],
149 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?)',
150 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?)',
151 bind => [qw/1 2 3 4 5/],
156 args => ['test', [qw/1 2 3 4 5/, undef]],
157 stmt => 'INSERT INTO test VALUES (?, ?, ?, ?, ?, ?)',
158 stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?, ?)',
159 bind => [qw/1 2 3 4 5/, undef],
164 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => 5}],
165 stmt => 'UPDATE test SET a = ?, b = ?, c = ?, d = ?, e = ?',
166 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?, `c` = ?, `d` = ?, `e` = ?',
167 bind => [qw/1 2 3 4 5/],
172 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => 5}, {a => {'in', [1..5]}}],
173 stmt => 'UPDATE test SET a = ?, b = ?, c = ?, d = ?, e = ? WHERE ( a IN ( ?, ?, ?, ?, ? ) )',
174 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?, `c` = ?, `d` = ?, `e` = ? WHERE ( `a` IN ( ?, ?, ?, ?, ? ) )',
175 bind => [qw/1 2 3 4 5 1 2 3 4 5/],
180 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, {a => {'between', [1,2]}}],
181 stmt => 'UPDATE test SET a = ?, b = to_date(?, \'MM/DD/YY\') WHERE ( a BETWEEN ? AND ? )',
182 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = to_date(?, \'MM/DD/YY\') WHERE ( `a` BETWEEN ? AND ? )',
183 bind => [qw(1 02/02/02 1 2)],
188 args => ['test.table', {high_limit => \'max(all_limits)', low_limit => 4} ],
189 stmt => 'INSERT INTO test.table (high_limit, low_limit) VALUES (max(all_limits), ?)',
190 stmt_q => 'INSERT INTO `test`.`table` (`high_limit`, `low_limit`) VALUES (max(all_limits), ?)',
195 args => ['test.table', [ \'max(all_limits)', 4 ] ],
196 stmt => 'INSERT INTO test.table VALUES (max(all_limits), ?)',
197 stmt_q => 'INSERT INTO `test`.`table` VALUES (max(all_limits), ?)',
203 new => {bindtype => 'columns'},
204 args => ['test.table', {one => 2, three => 4, five => 6} ],
205 stmt => 'INSERT INTO test.table (five, one, three) VALUES (?, ?, ?)',
206 stmt_q => 'INSERT INTO `test`.`table` (`five`, `one`, `three`) VALUES (?, ?, ?)',
207 bind => [['five', 6], ['one', 2], ['three', 4]], # alpha order, man...
212 new => {bindtype => 'columns', case => 'lower'},
213 args => ['test.table', [qw/one two three/], {one => 2, three => 4, five => 6} ],
214 stmt => 'select one, two, three from test.table where ( five = ? and one = ? and three = ? )',
215 stmt_q => 'select `one`, `two`, `three` from `test`.`table` where ( `five` = ? and `one` = ? and `three` = ? )',
216 bind => [['five', 6], ['one', 2], ['three', 4]], # alpha order, man...
221 new => {bindtype => 'columns', cmp => 'like'},
222 args => ['testin.table2', {One => 22, Three => 44, FIVE => 66},
223 {Beer => 'is', Yummy => '%YES%', IT => ['IS','REALLY','GOOD']}],
224 stmt => 'UPDATE testin.table2 SET FIVE = ?, One = ?, Three = ? WHERE '
225 . '( Beer LIKE ? AND ( ( IT LIKE ? ) OR ( IT LIKE ? ) OR ( IT LIKE ? ) ) AND Yummy LIKE ? )',
226 stmt_q => 'UPDATE `testin`.`table2` SET `FIVE` = ?, `One` = ?, `Three` = ? WHERE '
227 . '( `Beer` LIKE ? AND ( ( `IT` LIKE ? ) OR ( `IT` LIKE ? ) OR ( `IT` LIKE ? ) ) AND `Yummy` LIKE ? )',
228 bind => [['FIVE', 66], ['One', 22], ['Three', 44], ['Beer','is'],
229 ['IT','IS'], ['IT','REALLY'], ['IT','GOOD'], ['Yummy','%YES%']],
234 args => ['test', '*', {priority => [ -and => {'!=', 2}, {'!=', 1} ]}],
235 stmt => 'SELECT * FROM test WHERE ( ( ( priority != ? ) AND ( priority != ? ) ) )',
236 stmt_q => 'SELECT * FROM `test` WHERE ( ( ( `priority` != ? ) AND ( `priority` != ? ) ) )',
242 args => ['Yo Momma', '*', { user => 'nwiger',
243 -nest => [ workhrs => {'>', 20}, geo => 'ASIA' ] }],
244 stmt => 'SELECT * FROM Yo Momma WHERE ( ( ( workhrs > ? ) OR ( geo = ? ) ) AND user = ? )',
245 stmt_q => 'SELECT * FROM `Yo Momma` WHERE ( ( ( `workhrs` > ? ) OR ( `geo` = ? ) ) AND `user` = ? )',
246 bind => [qw(20 ASIA nwiger)],
251 args => ['taco_punches', { one => 2, three => 4 },
252 { bland => [ -and => {'!=', 'yes'}, {'!=', 'YES'} ],
253 tasty => { '!=', [qw(yes YES)] },
254 -nest => [ face => [ -or => {'=', 'mr.happy'}, {'=', undef} ] ] },
256 # LDNOTE : modified the test below, same reasons as #14 in 00where.t
257 stmt => 'UPDATE taco_punches SET one = ?, three = ? WHERE ( ( ( ( ( face = ? ) OR ( face IS NULL ) ) ) )'
258 # . ' AND ( ( bland != ? ) AND ( bland != ? ) ) AND ( ( tasty != ? ) OR ( tasty != ? ) ) )',
259 . ' AND ( ( bland != ? ) AND ( bland != ? ) ) AND ( ( tasty != ? ) AND ( tasty != ? ) ) )',
260 stmt_q => 'UPDATE `taco_punches` SET `one` = ?, `three` = ? WHERE ( ( ( ( ( `face` = ? ) OR ( `face` IS NULL ) ) ) )'
261 # . ' AND ( ( `bland` != ? ) AND ( `bland` != ? ) ) AND ( ( `tasty` != ? ) OR ( `tasty` != ? ) ) )',
262 . ' AND ( ( `bland` != ? ) AND ( `bland` != ? ) ) AND ( ( `tasty` != ? ) AND ( `tasty` != ? ) ) )',
263 bind => [qw(2 4 mr.happy yes YES yes YES)],
268 args => ['jeff', '*', { name => {'like', '%smith%', -not_in => ['Nate','Jim','Bob','Sally']},
269 -nest => [ -or => [ -and => [age => { -between => [20,30] }, age => {'!=', 25} ],
270 yob => {'<', 1976} ] ] } ],
271 # LDNOTE : original test below was WRONG with respect to the doc.
272 # [-and, [cond1, cond2], cond3] should mean (cond1 OR cond2) AND cond3
273 # instead of (cond1 AND cond2) OR cond3.
274 # Probably a misconception because of '=>' notation
275 # in [-and => [cond1, cond2], cond3].
276 # Also some differences in parentheses, but without impact on semantics.
277 # stmt => 'SELECT * FROM jeff WHERE ( ( ( ( ( ( ( age BETWEEN ? AND ? ) AND ( age != ? ) ) ) OR ( yob < ? ) ) ) )'
278 # . ' AND name NOT IN ( ?, ?, ?, ? ) AND name LIKE ? )',
279 # stmt_q => 'SELECT * FROM `jeff` WHERE ( ( ( ( ( ( ( `age` BETWEEN ? AND ? ) AND ( `age` != ? ) ) ) OR ( `yob` < ? ) ) ) )'
280 # . ' AND `name` NOT IN ( ?, ?, ?, ? ) AND `name` LIKE ? )',
281 stmt => 'SELECT * FROM jeff WHERE ( ( ( ( ( age BETWEEN ? AND ? ) OR ( age != ? ) ) AND ( yob < ? ) ) )'
282 . ' AND ( name NOT IN ( ?, ?, ?, ? ) AND name LIKE ? ) )',
283 stmt_q => 'SELECT * FROM `jeff` WHERE ( ( ( ( ( `age` BETWEEN ? AND ? ) OR ( `age` != ? ) ) AND ( `yob` < ? ) ) )'
284 . ' AND ( `name` NOT IN ( ?, ?, ?, ? ) AND `name` LIKE ? ) )',
285 bind => [qw(20 30 25 1976 Nate Jim Bob Sally %smith%)]
290 # LDNOTE : removed the "-maybe", because we no longer admit unknown ops
291 # args => ['fhole', {fpoles => 4}, [-maybe => {race => [-and => [qw(black white asian)]]},
292 args => ['fhole', {fpoles => 4}, [ {race => [-and => [qw(black white asian)]]},
293 {-nest => {firsttime => [-or => {'=','yes'}, undef]}},
294 [ -and => {firstname => {-not_like => 'candace'}}, {lastname => {-in => [qw(jugs canyon towers)]}} ] ] ],
295 stmt => 'UPDATE fhole SET fpoles = ? WHERE ( ( ( ( ( ( ( race = ? ) OR ( race = ? ) OR ( race = ? ) ) ) ) ) )'
296 . ' OR ( ( ( ( firsttime = ? ) OR ( firsttime IS NULL ) ) ) ) OR ( ( ( firstname NOT LIKE ? ) ) AND ( lastname IN ( ?, ?, ? ) ) ) )',
297 stmt_q => 'UPDATE `fhole` SET `fpoles` = ? WHERE ( ( ( ( ( ( ( `race` = ? ) OR ( `race` = ? ) OR ( `race` = ? ) ) ) ) ) )'
298 . ' OR ( ( ( ( `firsttime` = ? ) OR ( `firsttime` IS NULL ) ) ) ) OR ( ( ( `firstname` NOT LIKE ? ) ) AND ( `lastname` IN ( ?, ?, ? ) ) ) )',
299 bind => [qw(4 black white asian yes candace jugs canyon towers)]
304 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}],
305 stmt => 'INSERT INTO test (a, b) VALUES (?, to_date(?, \'MM/DD/YY\'))',
306 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, to_date(?, \'MM/DD/YY\'))',
307 bind => [qw(1 02/02/02)],
312 # LDNOTE: modified test below because we agreed with MST that literal SQL
313 # should not automatically insert a '='; the user has to do it
314 # args => ['test', '*', { a => \["to_date(?, 'MM/DD/YY')", '02/02/02']}],
315 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", '02/02/02']}],
316 stmt => q{SELECT * FROM test WHERE ( a = to_date(?, 'MM/DD/YY') )},
317 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = to_date(?, 'MM/DD/YY') )},
318 bind => ['02/02/02'],
323 new => {array_datatypes => 1},
324 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
325 stmt => 'INSERT INTO test (a, b) VALUES (?, ?)',
326 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, ?)',
327 bind => [1, [1, 1, 2, 3, 5, 8]],
332 new => {bindtype => 'columns', array_datatypes => 1},
333 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
334 stmt => 'INSERT INTO test (a, b) VALUES (?, ?)',
335 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, ?)',
336 bind => [[a => 1], [b => [1, 1, 2, 3, 5, 8]]],
341 new => {array_datatypes => 1},
342 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
343 stmt => 'UPDATE test SET a = ?, b = ?',
344 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?',
345 bind => [1, [1, 1, 2, 3, 5, 8]],
350 new => {bindtype => 'columns', array_datatypes => 1},
351 args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}],
352 stmt => 'UPDATE test SET a = ?, b = ?',
353 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?',
354 bind => [[a => 1], [b => [1, 1, 2, 3, 5, 8]]],
359 args => ['test', '*', { a => {'>', \'1 + 1'}, b => 8 }],
360 stmt => 'SELECT * FROM test WHERE ( a > 1 + 1 AND b = ? )',
361 stmt_q => 'SELECT * FROM `test` WHERE ( `a` > 1 + 1 AND `b` = ? )',
367 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, b => 8 }],
368 stmt => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )',
369 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )',
370 bind => ['02/02/02', 8],
373 { #TODO in SQLA >= 2.0 it will die instead (we kept this just because old SQLA passed it through)
375 args => ['test', {a => 1, b => 2, c => 3, d => 4, e => { answer => 42 }}],
376 stmt => 'INSERT INTO test (a, b, c, d, e) VALUES (?, ?, ?, ?, ?)',
377 stmt_q => 'INSERT INTO `test` (`a`, `b`, `c`, `d`, `e`) VALUES (?, ?, ?, ?, ?)',
378 bind => [qw/1 2 3 4/, { answer => 42}],
379 warning_like => qr/HASH ref as bind value in insert is not supported/i,
384 args => ['test', {a => 1, b => \["42"]}, {a => {'between', [1,2]}}],
385 stmt => 'UPDATE test SET a = ?, b = 42 WHERE ( a BETWEEN ? AND ? )',
386 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = 42 WHERE ( `a` BETWEEN ? AND ? )',
392 args => ['test', {a => 1, b => \["42"]}],
393 stmt => 'INSERT INTO test (a, b) VALUES (?, 42)',
394 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, 42)',
400 args => ['test', '*', { a => \["= 42"], b => 1}],
401 stmt => q{SELECT * FROM test WHERE ( a = 42 ) AND (b = ? )},
402 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = 42 ) AND ( `b` = ? )},
408 args => ['test', '*', { a => {'<' => \["42"]}, b => 8 }],
409 stmt => 'SELECT * FROM test WHERE ( a < 42 AND b = ? )',
410 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < 42 AND `b` = ? )',
416 new => {bindtype => 'columns'},
417 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}],
418 stmt => 'INSERT INTO test (a, b) VALUES (?, to_date(?, \'MM/DD/YY\'))',
419 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, to_date(?, \'MM/DD/YY\'))',
420 bind => [[a => '1'], [dummy => '02/02/02']],
425 new => {bindtype => 'columns'},
426 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}, {a => {'between', [1,2]}}],
427 stmt => 'UPDATE test SET a = ?, b = to_date(?, \'MM/DD/YY\') WHERE ( a BETWEEN ? AND ? )',
428 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = to_date(?, \'MM/DD/YY\') WHERE ( `a` BETWEEN ? AND ? )',
429 bind => [[a => '1'], [dummy => '02/02/02'], [a => '1'], [a => '2']],
434 new => {bindtype => 'columns'},
435 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}],
436 stmt => q{SELECT * FROM test WHERE ( a = to_date(?, 'MM/DD/YY') )},
437 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = to_date(?, 'MM/DD/YY') )},
438 bind => [[dummy => '02/02/02']],
443 new => {bindtype => 'columns'},
444 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", [dummy => '02/02/02']]}, b => 8 }],
445 stmt => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )',
446 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )',
447 bind => [[dummy => '02/02/02'], [b => 8]],
452 new => {bindtype => 'columns'},
453 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}],
454 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
459 new => {bindtype => 'columns'},
460 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, {a => {'between', [1,2]}}],
461 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
466 new => {bindtype => 'columns'},
467 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", '02/02/02']}],
468 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
473 new => {bindtype => 'columns'},
474 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, b => 8 }],
475 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
480 new => {bindtype => 'columns'},
481 args => ['test', '*', { a => {-in => \["(SELECT d FROM to_date(?, 'MM/DD/YY') AS d)", [dummy => '02/02/02']]}, b => 8 }],
482 stmt => 'SELECT * FROM test WHERE ( a IN (SELECT d FROM to_date(?, \'MM/DD/YY\') AS d) AND b = ? )',
483 stmt_q => 'SELECT * FROM `test` WHERE ( `a` IN (SELECT d FROM to_date(?, \'MM/DD/YY\') AS d) AND `b` = ? )',
484 bind => [[dummy => '02/02/02'], [b => 8]],
489 new => {bindtype => 'columns'},
490 args => ['test', '*', { a => {-in => \["(SELECT d FROM to_date(?, 'MM/DD/YY') AS d)", '02/02/02']}, b => 8 }],
491 exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/,
496 new => {bindtype => 'columns'},
497 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']]}],
498 stmt => 'INSERT INTO test (a, b) VALUES (?, to_date(?, \'MM/DD/YY\'))',
499 stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, to_date(?, \'MM/DD/YY\'))',
500 bind => [[a => '1'], [{dummy => 1} => '02/02/02']],
505 new => {bindtype => 'columns'},
506 args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']]}, {a => {'between', [1,2]}}],
507 stmt => 'UPDATE test SET a = ?, b = to_date(?, \'MM/DD/YY\') WHERE ( a BETWEEN ? AND ? )',
508 stmt_q => 'UPDATE `test` SET `a` = ?, `b` = to_date(?, \'MM/DD/YY\') WHERE ( `a` BETWEEN ? AND ? )',
509 bind => [[a => '1'], [{dummy => 1} => '02/02/02'], [a => '1'], [a => '2']],
514 new => {bindtype => 'columns'},
515 args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']]}],
516 stmt => q{SELECT * FROM test WHERE ( a = to_date(?, 'MM/DD/YY') )},
517 stmt_q => q{SELECT * FROM `test` WHERE ( `a` = to_date(?, 'MM/DD/YY') )},
518 bind => [[{dummy => 1} => '02/02/02']],
523 new => {bindtype => 'columns'},
524 args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']]}, b => 8 }],
525 stmt => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )',
526 stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )',
527 bind => [[{dummy => 1} => '02/02/02'], [b => 8]],
532 plan tests => scalar(grep { !$_->{warning_like} } @tests) * 2
533 + scalar(grep { $_->{warning_like} } @tests) * 4;
538 my $new = $_->{new} || {};
539 $new->{debug} = $ENV{DEBUG} || 0;
541 # test without quoting labels
543 my $sql = SQL::Abstract->new(%$new);
545 my $func = $_->{func};
548 ($stmt, @bind) = $sql->$func(@{$_->{args}})
550 if ($_->{exception_like}) {
551 throws_ok { &$test } $_->{exception_like}, "throws the expected exception ($_->{exception_like})";
553 if ($_->{warning_like}) {
554 warning_like { &$test } $_->{warning_like}, "throws the expected warning ($_->{warning_like})";
558 is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});
562 # test with quoted labels
564 my $sql_q = SQL::Abstract->new(%$new, quote_char => '`', name_sep => '.');
566 my $func_q = $_->{func};
567 my($stmt_q, @bind_q);
569 ($stmt_q, @bind_q) = $sql_q->$func_q(@{$_->{args}})
571 if ($_->{exception_like}) {
572 throws_ok { &$test } $_->{exception_like}, "throws the expected exception ($_->{exception_like})";
574 if ($_->{warning_like}) {
575 warning_like { &$test } $_->{warning_like}, "throws the expected warning ($_->{warning_like})";
580 is_same_sql_bind($stmt_q, \@bind_q, $_->{stmt_q}, $_->{bind});