6 use SQL::Abstract::Test import => [qw(
7 eq_sql_bind eq_sql eq_bind is_same_sql_bind dumper $sql_differ
11 # WHERE condition - equal
15 q/SELECT foo FROM bar WHERE a = 1/,
16 q/SELECT foo FROM bar WHERE a=1/,
17 q/SELECT foo FROM bar WHERE (a = 1)/,
18 q/SELECT foo FROM bar WHERE (a=1)/,
19 q/SELECT foo FROM bar WHERE ( a = 1 )/,
44 q/SELECT foo FROM bar WHERE ((a = 1))/,
45 q/SELECT foo FROM bar WHERE ( (a = 1) )/,
46 q/SELECT foo FROM bar WHERE ( ( a = 1 ) )/,
52 q/SELECT foo FROM bar WHERE a = 1 AND b = 1/,
53 q/SELECT foo FROM bar WHERE (a = 1) AND (b = 1)/,
54 q/SELECT foo FROM bar WHERE ((a = 1) AND (b = 1))/,
55 q/SELECT foo FROM bar WHERE (a = 1 AND b = 1)/,
56 q/SELECT foo FROM bar WHERE ((a = 1 AND b = 1))/,
57 q/SELECT foo FROM bar WHERE (((a = 1) AND (b = 1)))/,
103 q/SELECT foo FROM bar WHERE a = 1 AND b = 1 AND c = 1/,
104 q/SELECT foo FROM bar WHERE (a = 1 AND b = 1 AND c = 1)/,
105 q/SELECT foo FROM bar WHERE (a = 1 AND b = 1) AND c = 1/,
106 q/SELECT foo FROM bar WHERE a = 1 AND (b = 1 AND c = 1)/,
107 q/SELECT foo FROM bar WHERE ((((a = 1))) AND (b = 1 AND c = 1))/,
113 q/SELECT foo FROM bar WHERE a = 1 OR b = 1 OR c = 1/,
114 q/SELECT foo FROM bar WHERE (a = 1 OR b = 1) OR c = 1/,
115 q/SELECT foo FROM bar WHERE a = 1 OR (b = 1 OR c = 1)/,
116 q/SELECT foo FROM bar WHERE a = 1 OR ((b = 1 OR (c = 1)))/,
122 q/SELECT foo FROM bar WHERE (a = 1) AND (b = 1 OR c = 1 OR d = 1) AND (e = 1 AND f = 1)/,
123 q/SELECT foo FROM bar WHERE a = 1 AND (b = 1 OR c = 1 OR d = 1) AND e = 1 AND (f = 1)/,
124 q/SELECT foo FROM bar WHERE ( ((a = 1) AND ( b = 1 OR (c = 1 OR d = 1) )) AND ((e = 1)) AND f = 1) /,
130 q/SELECT foo FROM bar WHERE (a) AND (b = 2)/,
131 q/SELECT foo FROM bar WHERE (a AND b = 2)/,
132 q/SELECT foo FROM bar WHERE (a AND (b = 2))/,
133 q/SELECT foo FROM bar WHERE a AND (b = 2)/,
139 q/SELECT foo FROM bar WHERE ((NOT a) AND b = 2)/,
140 q/SELECT foo FROM bar WHERE (NOT a) AND (b = 2)/,
141 q/SELECT foo FROM bar WHERE (NOT (a)) AND b = 2/,
147 q/SELECT foo FROM bar WHERE NOT a AND (b = 2)/,
148 q/SELECT foo FROM bar WHERE (NOT a) AND (b = 2)/,
153 opts => { parenthesis_significant => 1 },
155 q/SELECT foo FROM bar WHERE a = 1 AND b = 1 AND c = 1/,
156 q/SELECT foo FROM bar WHERE (a = 1 AND b = 1 AND c = 1)/,
157 q/SELECT foo FROM bar WHERE (a = 1 AND b = 1) AND c = 1/,
158 q/SELECT foo FROM bar WHERE a = 1 AND (b = 1 AND c = 1)/,
159 q/SELECT foo FROM bar WHERE ((((a = 1))) AND (b = 1 AND c = 1))/,
164 opts => { parenthesis_significant => 1 },
166 q/SELECT foo FROM bar WHERE a = 1 OR b = 1 OR c = 1/,
167 q/SELECT foo FROM bar WHERE (a = 1 OR b = 1) OR c = 1/,
168 q/SELECT foo FROM bar WHERE a = 1 OR (b = 1 OR c = 1)/,
169 q/SELECT foo FROM bar WHERE a = 1 OR ((b = 1 OR (c = 1)))/,
174 opts => { parenthesis_significant => 1 },
176 q/SELECT foo FROM bar WHERE (a = 1) AND (b = 1 OR c = 1 OR d = 1) AND (e = 1 AND f = 1)/,
177 q/SELECT foo FROM bar WHERE a = 1 AND (b = 1 OR c = 1 OR d = 1) AND e = 1 AND (f = 1)/,
178 q/SELECT foo FROM bar WHERE ( ((a = 1) AND ( b = 1 OR (c = 1 OR d = 1) )) AND ((e = 1)) AND f = 1) /,
182 # WHERE condition - different
186 q/SELECT foo FROM bar WHERE a = 1/,
187 q/SELECT quux FROM bar WHERE a = 1/,
188 q/SELECT foo FROM quux WHERE a = 1/,
189 q/FOOBAR foo FROM bar WHERE a = 1/,
191 q/SELECT foo FROM bar WHERE a = 2/,
192 q/SELECT foo FROM bar WHERE a < 1/,
193 q/SELECT foo FROM bar WHERE b = 1/,
194 q/SELECT foo FROM bar WHERE (c = 1)/,
195 q/SELECT foo FROM bar WHERE (d = 1)/,
197 q/SELECT foo FROM bar WHERE a = 1 AND quux/,
198 q/SELECT foo FROM bar WHERE a = 1 GROUP BY foo/,
199 q/SELECT foo FROM bar WHERE a = 1 ORDER BY foo/,
200 q/SELECT foo FROM bar WHERE a = 1 LIMIT 1/,
201 q/SELECT foo FROM bar WHERE a = 1 OFFSET 1/,
202 q/SELECT foo FROM bar JOIN quux WHERE a = 1/,
203 q/SELECT foo FROM bar JOIN quux ON a = 1 WHERE a = 1/,
209 q/SELECT foo FROM bar WHERE a = 1 AND b = 1/,
210 q/SELECT quux FROM bar WHERE a = 1 AND b = 1/,
211 q/SELECT foo FROM quux WHERE a = 1 AND b = 1/,
212 q/FOOBAR foo FROM bar WHERE a = 1 AND b = 1/,
214 q/SELECT foo FROM bar WHERE a = 2 AND b = 1/,
215 q/SELECT foo FROM bar WHERE a = 3 AND (b = 1)/,
216 q/SELECT foo FROM bar WHERE (a = 4) AND b = 1/,
217 q/SELECT foo FROM bar WHERE (a = 5) AND (b = 1)/,
218 q/SELECT foo FROM bar WHERE ((a = 6) AND (b = 1))/,
219 q/SELECT foo FROM bar WHERE ((a = 7) AND (b = 1))/,
221 q/SELECT foo FROM bar WHERE a = 1 AND b = 2/,
222 q/SELECT foo FROM bar WHERE a = 1 AND (b = 3)/,
223 q/SELECT foo FROM bar WHERE (a = 1) AND b = 4/,
224 q/SELECT foo FROM bar WHERE (a = 1) AND (b = 5)/,
225 q/SELECT foo FROM bar WHERE ((a = 1) AND (b = 6))/,
226 q/SELECT foo FROM bar WHERE ((a = 1) AND (b = 7))/,
228 q/SELECT foo FROM bar WHERE a < 1 AND b = 1/,
229 q/SELECT foo FROM bar WHERE b = 1 AND b = 1/,
230 q/SELECT foo FROM bar WHERE (c = 1) AND b = 1/,
231 q/SELECT foo FROM bar WHERE (d = 1) AND b = 1/,
233 q/SELECT foo FROM bar WHERE a = 1 AND b = 1 AND quux/,
234 q/SELECT foo FROM bar WHERE a = 1 AND b = 1 GROUP BY foo/,
235 q/SELECT foo FROM bar WHERE a = 1 AND b = 1 ORDER BY foo/,
236 q/SELECT foo FROM bar WHERE a = 1 AND b = 1 LIMIT 1/,
237 q/SELECT foo FROM bar WHERE a = 1 AND b = 1 OFFSET 1/,
238 q/SELECT foo FROM bar JOIN quux WHERE a = 1 AND b = 1/,
239 q/SELECT foo FROM bar JOIN quux ON a = 1 WHERE a = 1 AND b = 1/,
245 q/SELECT foo FROM bar WHERE a = 1 AND b = 1 OR c = 1/,
246 q/SELECT foo FROM bar WHERE (a = 1 AND b = 1) OR c = 1/,
247 q/SELECT foo FROM bar WHERE a = 1 AND (b = 1 OR c = 1)/,
253 q/SELECT foo FROM bar WHERE a = 1 OR b = 1 AND c = 1/,
254 q/SELECT foo FROM bar WHERE (a = 1 OR b = 1) AND c = 1/,
255 q/SELECT foo FROM bar WHERE a = 1 OR (b = 1 AND c = 1)/,
261 q/SELECT foo FROM bar WHERE a IN (1,3,2)/,
262 q/SELECT foo FROM bar WHERE a IN 1,2,3/,
263 q/SELECT foo FROM bar WHERE a IN (1,2,3)/,
264 q/SELECT foo FROM bar WHERE a IN ((1,2,3))/,
270 # BETWEEN with/without parenthesis around itself/RHS is a sticky business
271 # if I made a mistake here, simply rewrite the special BETWEEN handling in
275 q/SELECT foo FROM bar WHERE ( completion_date BETWEEN ? AND ? AND status = ? )/,
276 q/SELECT foo FROM bar WHERE completion_date BETWEEN (? AND ?) AND status = ?/,
277 q/SELECT foo FROM bar WHERE ( (completion_date BETWEEN (? AND ?) ) AND status = ? )/,
278 q/SELECT foo FROM bar WHERE ( (completion_date BETWEEN (? AND ? AND status = ?) ) )/,
282 # IS NULL (special LHS-only op)
286 q/WHERE a IS NOT NULL AND b IS NULL/,
287 q/WHERE (a IS NOT NULL) AND b IS NULL/,
288 q/WHERE a IS NOT NULL AND (b IS NULL)/,
289 q/WHERE (a IS NOT NULL) AND ((b IS NULL))/,
293 # JOIN condition - equal
297 q/SELECT foo FROM bar JOIN baz ON a = 1 WHERE x = 1/,
298 q/SELECT foo FROM bar JOIN baz ON a=1 WHERE x = 1/,
299 q/SELECT foo FROM bar JOIN baz ON (a = 1) WHERE x = 1/,
300 q/SELECT foo FROM bar JOIN baz ON (a=1) WHERE x = 1/,
301 q/SELECT foo FROM bar JOIN baz ON ( a = 1 ) WHERE x = 1/,
338 q/SELECT foo FROM bar JOIN baz ON ((a = 1)) WHERE x = 1/,
339 q/SELECT foo FROM bar JOIN baz ON ( (a = 1) ) WHERE x = 1/,
340 q/SELECT foo FROM bar JOIN baz ON ( ( a = 1 ) ) WHERE x = 1/,
346 q/SELECT foo FROM bar JOIN baz ON a = 1 AND b = 1 WHERE x = 1/,
347 q/SELECT foo FROM bar JOIN baz ON (a = 1) AND (b = 1) WHERE x = 1/,
348 q/SELECT foo FROM bar JOIN baz ON ((a = 1) AND (b = 1)) WHERE x = 1/,
349 q/SELECT foo FROM bar JOIN baz ON (a = 1 AND b = 1) WHERE x = 1/,
350 q/SELECT foo FROM bar JOIN baz ON ((a = 1 AND b = 1)) WHERE x = 1/,
351 q/SELECT foo FROM bar JOIN baz ON (((a = 1) AND (b = 1))) WHERE x = 1/,
411 # JOIN condition - different
415 q/SELECT foo FROM bar JOIN quux ON a = 1 WHERE quuux/,
416 q/SELECT quux FROM bar JOIN quux ON a = 1 WHERE quuux/,
417 q/SELECT foo FROM quux JOIN quux ON a = 1 WHERE quuux/,
418 q/FOOBAR foo FROM bar JOIN quux ON a = 1 WHERE quuux/,
420 q/SELECT foo FROM bar JOIN quux ON a = 2 WHERE quuux/,
421 q/SELECT foo FROM bar JOIN quux ON a < 1 WHERE quuux/,
422 q/SELECT foo FROM bar JOIN quux ON b = 1 WHERE quuux/,
423 q/SELECT foo FROM bar JOIN quux ON (c = 1) WHERE quuux/,
424 q/SELECT foo FROM bar JOIN quux ON (d = 1) WHERE quuux/,
426 q/SELECT foo FROM bar JOIN quux ON a = 1 AND quuux/,
427 q/SELECT foo FROM bar JOIN quux ON a = 1 GROUP BY foo/,
428 q/SELECT foo FROM bar JOIN quux ON a = 1 ORDER BY foo/,
429 q/SELECT foo FROM bar JOIN quux ON a = 1 LIMIT 1/,
430 q/SELECT foo FROM bar JOIN quux ON a = 1 OFFSET 1/,
431 q/SELECT foo FROM bar JOIN quux ON a = 1 JOIN quuux/,
432 q/SELECT foo FROM bar JOIN quux ON a = 1 JOIN quuux ON a = 1/,
438 q/SELECT foo FROM bar JOIN quux ON a = 1 AND b = 1 WHERE quuux/,
439 q/SELECT quux FROM bar JOIN quux ON a = 1 AND b = 1 WHERE quuux/,
440 q/SELECT foo FROM quux JOIN quux ON a = 1 AND b = 1 WHERE quuux/,
441 q/FOOBAR foo FROM bar JOIN quux ON a = 1 AND b = 1 WHERE quuux/,
443 q/SELECT foo FROM bar JOIN quux ON a = 2 AND b = 1 WHERE quuux/,
444 q/SELECT foo FROM bar JOIN quux ON a = 3 AND (b = 1) WHERE quuux/,
445 q/SELECT foo FROM bar JOIN quux ON (a = 4) AND b = 1 WHERE quuux/,
446 q/SELECT foo FROM bar JOIN quux ON (a = 5) AND (b = 1) WHERE quuux/,
447 q/SELECT foo FROM bar JOIN quux ON ((a = 6) AND (b = 1)) WHERE quuux/,
448 q/SELECT foo FROM bar JOIN quux ON ((a = 7) AND (b = 1)) WHERE quuux/,
450 q/SELECT foo FROM bar JOIN quux ON a = 1 AND b = 2 WHERE quuux/,
451 q/SELECT foo FROM bar JOIN quux ON a = 1 AND (b = 3) WHERE quuux/,
452 q/SELECT foo FROM bar JOIN quux ON (a = 1) AND b = 4 WHERE quuux/,
453 q/SELECT foo FROM bar JOIN quux ON (a = 1) AND (b = 5) WHERE quuux/,
454 q/SELECT foo FROM bar JOIN quux ON ((a = 1) AND (b = 6)) WHERE quuux/,
455 q/SELECT foo FROM bar JOIN quux ON ((a = 1) AND (b = 7)) WHERE quuux/,
457 q/SELECT foo FROM bar JOIN quux ON a < 1 AND b = 1 WHERE quuux/,
458 q/SELECT foo FROM bar JOIN quux ON b = 1 AND b = 1 WHERE quuux/,
459 q/SELECT foo FROM bar JOIN quux ON (c = 1) AND b = 1 WHERE quuux/,
460 q/SELECT foo FROM bar JOIN quux ON (d = 1) AND b = 1 WHERE quuux/,
462 q/SELECT foo FROM bar JOIN quux ON a = 1 AND b = 1 AND quuux/,
463 q/SELECT foo FROM bar JOIN quux ON a = 1 AND b = 1 GROUP BY foo/,
464 q/SELECT foo FROM bar JOIN quux ON a = 1 AND b = 1 ORDER BY foo/,
465 q/SELECT foo FROM bar JOIN quux ON a = 1 AND b = 1 LIMIT 1/,
466 q/SELECT foo FROM bar JOIN quux ON a = 1 AND b = 1 OFFSET 1/,
467 q/SELECT foo FROM bar JOIN quux JOIN quuux ON a = 1 AND b = 1/,
468 q/SELECT foo FROM bar JOIN quux ON a = 1 JOIN quuux ON a = 1 AND b = 1/,
472 # DISTINCT ON (...) not confused with JOIN ON (...)
476 q/SELECT DISTINCT ON (foo, quux) foo, quux FROM bar WHERE a = 1/,
477 q/SELECT DISTINCT ON (foo, quux) foo, quux FROM bar WHERE a=1/,
478 q/SELECT DISTINCT ON (foo, quux) foo, quux FROM bar WHERE (a = 1)/,
479 q/SELECT DISTINCT ON (foo, quux) foo, quux FROM bar WHERE (a=1)/,
480 q/SELECT DISTINCT ON (foo, quux) foo, quux FROM bar WHERE ( a = 1 )/,
482 SELECT DISTINCT ON (foo, quux)
491 SELECT DISTINCT ON (foo, quux)
500 SELECT DISTINCT ON (foo, quux)
508 q/SELECT DISTINCT ON (foo, quux) foo, quux FROM bar WHERE ((a = 1))/,
509 q/SELECT DISTINCT ON (foo, quux) foo, quux FROM bar WHERE ( (a = 1) )/,
510 q/SELECT DISTINCT ON (foo, quux) foo, quux FROM bar WHERE ( ( a = 1 ) )/,
518 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1) AS foo WHERE a = 1/,
519 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1) AS foo WHERE (a = 1)/,
520 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1)) AS foo WHERE a = 1/,
521 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1)) AS foo WHERE (a = 1)/,
527 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND c = 1) AS foo WHERE a = 1/,
528 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND (c = 1)) AS foo WHERE a = 1/,
529 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND c = 1) AS foo WHERE a = 1/,
530 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND (c = 1)) AS foo WHERE a = 1/,
531 q/SELECT * FROM (SELECT * FROM bar WHERE ((b = 1) AND (c = 1))) AS foo WHERE a = 1/,
533 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND c = 1) AS foo WHERE (a = 1)/,
534 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND (c = 1)) AS foo WHERE (a = 1)/,
535 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND c = 1) AS foo WHERE (a = 1)/,
536 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND (c = 1)) AS foo WHERE (a = 1)/,
537 q/SELECT * FROM (SELECT * FROM bar WHERE ((b = 1) AND (c = 1))) AS foo WHERE (a = 1)/,
541 # subselects - different
545 q/DELETE FROM cd WHERE ( cdid IN ( SELECT me.cdid FROM (SELECT * FROM cd me WHERE ( year != ? ) GROUP BY me.cdid) me WHERE ( year != ? ) ) )/,
546 q/DELETE FROM cd WHERE ( cdid IN ( SELECT me.cdid FROM cd me WHERE ( year != ? ) GROUP BY me.cdid ) )/,
552 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1) AS foo WHERE a = 1/,
553 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1) AS foo WHERE a = 2/,
554 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1) AS foo WHERE (a = 3)/,
555 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1)) AS foo WHERE a = 4/,
556 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1)) AS foo WHERE (a = 5)/,
557 q/SELECT * FROM (SELECT * FROM bar WHERE b = 2) AS foo WHERE a = 1/,
558 q/SELECT * FROM (SELECT * FROM bar WHERE b = 3) AS foo WHERE (a = 1)/,
559 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 4)) AS foo WHERE a = 1/,
560 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 5)) AS foo WHERE (a = 1)/,
566 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND c = 1) AS foo WHERE a = 1/,
567 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND c = 2) AS foo WHERE a = 1/,
568 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND (c = 3)) AS foo WHERE a = 1/,
569 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND (c = 4)) AS foo WHERE a = 1/,
570 q/SELECT * FROM (SELECT * FROM bar WHERE ((b = 1) AND (c = 5))) AS foo WHERE a = 1/,
572 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND c = 6) AS foo WHERE (a = 1)/,
573 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND c = 7) AS foo WHERE (a = 1)/,
574 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND (c = 8)) AS foo WHERE (a = 1)/,
575 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND (c = 9)) AS foo WHERE (a = 1)/,
576 q/SELECT * FROM (SELECT * FROM bar WHERE ((b = 1) AND (c = 10))) AS foo WHERE (a = 1)/,
578 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND c = 1) AS foo WHERE a = 2/,
579 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND c = 2) AS foo WHERE a = 2/,
580 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND (c = 3)) AS foo WHERE a = 2/,
581 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND (c = 4)) AS foo WHERE a = 2/,
582 q/SELECT * FROM (SELECT * FROM bar WHERE ((b = 1) AND (c = 5))) AS foo WHERE a = 2/,
584 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND c = 6) AS foo WHERE (a = 2)/,
585 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND c = 7) AS foo WHERE (a = 2)/,
586 q/SELECT * FROM (SELECT * FROM bar WHERE b = 1 AND (c = 8)) AS foo WHERE (a = 2)/,
587 q/SELECT * FROM (SELECT * FROM bar WHERE (b = 1) AND (c = 9)) AS foo WHERE (a = 2)/,
588 q/SELECT * FROM (SELECT * FROM bar WHERE ((b = 1) AND (c = 10))) AS foo WHERE (a = 2)/,
596 q/SELECT * FROM foo ORDER BY bar/,
597 q/SELECT * FROM foo ORDER BY bar ASC/,
598 q/SELECT * FROM foo ORDER BY bar asc/,
604 q/SELECT * FROM foo ORDER BY bar, baz ASC/,
605 q/SELECT * FROM foo ORDER BY bar ASC, baz/,
606 q/SELECT * FROM foo ORDER BY bar asc, baz ASC/,
607 q/SELECT * FROM foo ORDER BY bar, baz/,
613 q/ORDER BY colA, colB LIKE ? DESC, colC LIKE ?/,
614 q/ORDER BY colA ASC, colB LIKE ? DESC, colC LIKE ? ASC/,
620 q/ORDER BY name + ?, [me].[id]/,
621 q/ORDER BY name + ? ASC, [me].[id]/,
626 opts => { order_by_asc_significant => 1 },
628 q/SELECT * FROM foo ORDER BY bar/,
629 q/SELECT * FROM foo ORDER BY bar ASC/,
630 q/SELECT * FROM foo ORDER BY bar desc/,
638 'SELECT a,b,c FROM foo',
639 'SELECT a,c,b FROM foo',
640 'SELECT b,a,c FROM foo',
641 'SELECT b,c,a FROM foo',
642 'SELECT c,a,b FROM foo',
643 'SELECT c,b,a FROM foo',
649 'SELECT * FROM foo WHERE a IN (1,2,3)',
650 'SELECT * FROM foo WHERE a IN (1,3,2)',
651 'SELECT * FROM foo WHERE a IN (2,1,3)',
652 'SELECT * FROM foo WHERE a IN (2,3,1)',
653 'SELECT * FROM foo WHERE a IN (3,1,2)',
654 'SELECT * FROM foo WHERE a IN (3,2,1)',
662 'SELECT a,b FROM foo',
663 'SELECT a,,b FROM foo',
664 'SELECT a,b, FROM foo',
665 'SELECT ,a,b, FROM foo',
666 'SELECT ,a,,b, FROM foo',
674 'SELECT count(*) FROM foo',
675 'SELECT count(*) AS bar FROM foo',
676 'SELECT count(*) AS "bar" FROM foo',
677 'SELECT count(a) FROM foo',
678 'SELECT count(1) FROM foo',
684 'SELECT foo() bar FROM baz',
685 'SELECT foo ( )bar FROM baz',
686 'SELECT foo (())bar FROM baz',
687 'SELECT foo(( ) ) bar FROM baz',
693 'SELECT foo() FROM bar',
694 'SELECT foo FROM bar',
695 'SELECT foo FROM bar ()',
701 'SELECT COUNT * FROM foo',
702 'SELECT COUNT( * ) FROM foo',
705 # single ? of unknown funcs do not unroll unless
706 # explicitly allowed (e.g. Like)
710 'SELECT foo FROM bar WHERE bar > foo ?',
711 'SELECT foo FROM bar WHERE bar > foo( ? )',
717 'SELECT foo FROM bar WHERE bar LIKE ?',
718 'SELECT foo FROM bar WHERE bar LiKe (?)',
719 'SELECT foo FROM bar WHERE bar lIkE( (?))',
726 'SELECT foo FROM bar WHERE foo IN (?, ?)',
727 'SELECT foo FROM bar WHERE foo IN ?, ?',
734 'SELECT * FROM foo WHERE 1 = ( a > b)',
735 'SELECT * FROM foo WHERE 1 = a > b',
736 'SELECT * FROM foo WHERE (1 = a) > b',
742 'SELECT * FROM foo WHERE bar = baz(buzz)',
743 'SELECT * FROM foo WHERE bar = (baz( buzz ))',
750 'WHERE ( foo GLOB ? )',
757 'SELECT FIRST ? SKIP ? [me].[id], [me].[owner]
760 SELECT FIRST ? SKIP ? [owner].[id]
761 FROM [owners] [owner]
762 WHERE ( [books].[owner] = [owner].[id] )
763 )) AND [source] = ? ) )',
764 'SELECT FIRST ? SKIP ? [me].[id], [me].[owner]
767 SELECT FIRST ? SKIP ? [owner].[id]
768 FROM [owners] [owner]
769 WHERE ( [books].[owner] = [owner].[id] )
770 ) AND [source] = ? ) )',
776 'WHERE foo = ? FETCH FIRST 1 ROWS ONLY',
777 'WHERE ( foo = ? ) FETCH FIRST 1 ROWS ONLY',
778 'WHERE (( foo = ? )) FETCH FIRST 1 ROWS ONLY',
864 { foo => 42, bar => 1 },
865 { foo => 42, bar => 1 },
866 { foo => '42', bar => 1 },
870 # blessed object - equal
874 bless(\(local $_ = 42), 'Life::Universe::Everything'),
875 bless(\(local $_ = 42), 'Life::Universe::Everything'),
881 bless([42], 'Life::Universe::Everything'),
882 bless([42], 'Life::Universe::Everything'),
888 bless({ answer => 42 }, 'Life::Universe::Everything'),
889 bless({ answer => 42 }, 'Life::Universe::Everything'),
893 # complex data structure - equal
897 [42, { foo => 'bar', quux => [1, 2, \3, { quux => [4, 5] } ] }, 8 ],
898 [42, { foo => 'bar', quux => [1, 2, \3, { quux => [4, 5] } ] }, 8 ],
913 # scalarref - different
923 # arrayref - different
933 # hashref - different
954 # complex data structure - different
958 [42, { foo => 'bar', quux => [1, 2, \3, { quux => [4, 5] } ] }, 8 ],
959 [43, { foo => 'bar', quux => [1, 2, \3, { quux => [4, 5] } ] }, 8 ],
960 [42, { foo => 'baz', quux => [1, 2, \3, { quux => [4, 5] } ] }, 8 ],
961 [42, { bar => 'bar', quux => [1, 2, \3, { quux => [4, 5] } ] }, 8 ],
962 [42, { foo => 'bar', quuux => [1, 2, \3, { quux => [4, 5] } ] }, 8 ],
963 [42, { foo => 'bar', quux => [0, 1, 2, \3, { quux => [4, 5] } ] }, 8 ],
964 [42, { foo => 'bar', quux => [1, 2, 3, { quux => [4, 5] } ] }, 8 ],
965 [42, { foo => 'bar', quux => [1, 2, \4, { quux => [4, 5] } ] }, 8 ],
966 [42, { foo => 'bar', quux => [1, 2, \3, { quuux => [4, 5] } ] }, 8 ],
967 [42, { foo => 'bar', quux => [1, 2, \3, { quux => [4, 5, 6] } ] }, 8 ],
968 [42, { foo => 'bar', quux => [1, 2, \3, { quux => 4 } ] }, 8 ],
969 [42, { foo => 'bar', quux => [1, 2, \3, { quux => [4, 5], quuux => 1 } ] }, 8 ],
970 [42, { foo => 'bar', quux => [1, 2, \3, { quux => [4, 5] } ] }, 8, 9 ],
975 for my $test (@sql_tests) {
977 # this does not work on 5.8.8 and earlier :(
978 #local @{*SQL::Abstract::Test::}{keys %{$test->{opts}}} = map { \$_ } values %{$test->{opts}}
983 for (keys %{$test->{opts} || {} }) {
984 $restore_globals{$_} = ${${*SQL::Abstract::Test::}{$_}};
985 ${*SQL::Abstract::Test::}{$_} = \ do { my $cp = $test->{opts}{$_} };
988 my $statements = $test->{statements};
989 while (@$statements) {
990 my $sql1 = shift @$statements;
991 foreach my $sql2 (@$statements) {
993 my $equal = eq_sql($sql1, $sql2);
996 local $TODO = $test->{todo} if $test->{todo};
998 if ($test->{equal}) {
999 ok($equal, "equal SQL expressions should have been considered equal");
1001 ok(!$equal, "different SQL expressions should have been considered not equal");
1004 if ($equal ^ $test->{equal}) {
1005 my ($ast1, $ast2) = map { SQL::Abstract::Test::parse ($_) } ($sql1, $sql2);
1006 $_ = dumper($_) for ($ast1, $ast2);
1010 note $sql_differ || 'No differences found';
1018 ${*SQL::Abstract::Test::}{$_} = \$restore_globals{$_}
1019 for keys %restore_globals;
1022 for my $test (@bind_tests) {
1023 my $bindvals = $test->{bindvals};
1024 while (@$bindvals) {
1025 my $bind1 = shift @$bindvals;
1026 foreach my $bind2 (@$bindvals) {
1027 my $equal = eq_bind($bind1, $bind2);
1028 if ($test->{equal}) {
1029 ok($equal, "equal bind values considered equal");
1031 ok(!$equal, "different bind values considered not equal");
1034 if ($equal ^ $test->{equal}) {
1035 diag("bind1: " . dumper($bind1));
1036 diag("bind2: " . dumper($bind2));
1043 "SELECT * FROM foo WHERE id = ?", [42],
1044 "SELECT * FROM foo WHERE (id = ?)", [42],
1046 "eq_sql_bind considers equal SQL expressions and bind values equal"
1051 "SELECT * FROM foo WHERE id = ?", [42],
1052 "SELECT * FROM foo WHERE (id = ?)", [0],
1054 "eq_sql_bind considers equal SQL expressions and different bind values different"
1058 "SELECT * FROM foo WHERE id = ?", [42],
1059 "SELECT * FROM bar WHERE (id = ?)", [42],
1061 "eq_sql_bind considers different SQL expressions and equal bind values different"
1066 'SELECT owner_name FROM books me WHERE ( source = ? )',
1067 'SELECT owner_name FROM books me WHERE ( sUOrce = ? )',
1071 qr/\Q[ source ] != [ sUOrce ]/,
1072 'expected debug of literal diff',
1076 'SELECT owner_name FROM books me ORDER BY owner_name',
1077 'SELECT owner_name FROM books me GROUP BY owner_name',
1081 qr/\QOP [ORDER BY] != [GROUP BY]/,
1082 'expected debug of op diff',
1086 'SELECT owner_name FROM books WHERE ( source = ? )',
1087 'SELECT owner_name FROM books'
1092 qr|\Q[WHERE source = ?] != [N/A]|,
1093 'expected debug of missing branch',
1098 \[ 'SELECT foo FROM bar WHERE baz = ? or buzz = ?', [ {} => 1 ], 2 ],
1099 'SELECT foo FROM bar WHERE (baz = ?) OR buzz = ?',
1101 ), 'arrayrefref unpacks correctly' );
1104 \[ 'SELECT foo FROM bar WHERE baz = ? or buzz = ?', [ {} => 1 ], 2 ],
1105 \[ 'SELECT foo FROM bar WHERE (( baz = ? OR (buzz = ?) ))', [ {} => 1 ], 2 ],
1106 'double arrayrefref unpacks correctly'