7 use SQL::Abstract::Test import => [ qw(is_same_sql dumper) ];
13 args => {logic => 'OR'},
14 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
19 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
23 args => {case => "upper"},
24 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
28 args => {case => "upper", cmp => "="},
29 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
33 args => {cmp => "=", logic => 'or'},
34 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
38 args => {cmp => "like"},
39 stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )'
43 args => {logic => "or", cmp => "like"},
44 stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )'
48 args => {case => "lower"},
49 stmt => 'select * from test where ( a = ? and b = ? )'
53 args => {case => "lower", cmp => "="},
54 stmt => 'select * from test where ( a = ? and b = ? )'
58 args => {case => "lower", cmp => "like"},
59 stmt => 'select * from test where ( a like ? and b like ? )'
63 args => {case => "lower", convert => "lower", cmp => "like"},
64 stmt => 'select * from test where ( lower(a) like lower(?) and lower(b) like lower(?) )'
68 args => {convert => "Round"},
69 stmt => 'SELECT * FROM test WHERE ( ROUND(a) = ROUND(?) AND ROUND(b) = ROUND(?) )',
73 args => {convert => "lower"},
74 stmt => 'SELECT * FROM test WHERE ( ( LOWER(ticket) = LOWER(?) ) OR ( LOWER(hostname) = LOWER(?) ) OR ( LOWER(taco) = LOWER(?) ) OR ( LOWER(salami) = LOWER(?) ) )',
75 where => [ { ticket => 11 }, { hostname => 11 }, { taco => 'salad' }, { salami => 'punch' } ],
79 args => {convert => "upper"},
80 stmt => 'SELECT * FROM test WHERE ( ( UPPER(hostname) IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) AND ( ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) ) ) OR ( UPPER(tack) BETWEEN UPPER(?) AND UPPER(?) ) OR ( ( ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) ) AND ( ( UPPER(e) != UPPER(?) ) OR ( UPPER(e) != UPPER(?) ) ) AND UPPER(q) NOT IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) ) )',
81 where => [ { ticket => [11, 12, 13],
82 hostname => { in => ['ntf', 'avd', 'bvd', '123'] } },
83 { tack => { between => [qw/tick tock/] } },
85 e => { '!=', [qw(f g)] },
86 q => { 'not in', [14..20] } } ],
87 warns => qr/\QA multi-element arrayref as an argument to the inequality op '!=' is technically equivalent to an always-true 1=1/,
92 my $sqla = SQL::Abstract->new($_->{args});
96 $stmt = $sqla->select(
99 $_->{where} || { a => 4, b => 0}
101 } $_->{warns} || []) || diag dumper($_);
102 }) or diag dumper({ %$_, threw => $@ });
104 is_same_sql($stmt, $_->{stmt});