8 # use a BEGIN block so we print our plan before SQL::Abstract is loaded
9 BEGIN { plan tests => 14 }
16 args => {logic => 'OR'},
17 stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )'
22 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
26 args => {case => "upper"},
27 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
31 args => {case => "upper", cmp => "="},
32 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
36 args => {cmp => "=", logic => 'or'},
37 stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )'
41 args => {cmp => "like"},
42 stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )'
46 args => {logic => "or", cmp => "like"},
47 stmt => 'SELECT * FROM test WHERE ( a LIKE ? OR b LIKE ? )'
51 args => {case => "lower"},
52 stmt => 'select * from test where ( a = ? and b = ? )'
56 args => {case => "lower", cmp => "="},
57 stmt => 'select * from test where ( a = ? and b = ? )'
61 args => {case => "lower", cmp => "like"},
62 stmt => 'select * from test where ( a like ? and b like ? )'
66 args => {case => "lower", convert => "lower", cmp => "like"},
67 stmt => 'select * from test where ( lower(a) like lower(?) and lower(b) like lower(?) )'
71 args => {convert => "Round"},
72 stmt => 'SELECT * FROM test WHERE ( ROUND(a) = ROUND(?) AND ROUND(b) = ROUND(?) )',
76 args => {convert => "lower"},
77 stmt => 'SELECT * FROM test WHERE ( ( LOWER(ticket) = LOWER(?) ) OR ( LOWER(hostname) = LOWER(?) ) OR ( LOWER(taco) = LOWER(?) ) OR ( LOWER(salami) = LOWER(?) ) )',
78 bind => [ { ticket => 11 }, { hostname => 11 }, { taco => 'salad' }, { salami => 'punch' } ],
82 args => {convert => "upper"},
83 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(?) ) ) )',
84 bind => [ { ticket => [11, 12, 13], hostname => { in => ['ntf', 'avd', 'bvd', '123'] } },
85 { tack => { between => [qw/tick tock/] } },
86 { a => [qw/b c d/], e => { '!=', [qw(f g)] }, q => { 'not in', [14..20] } } ],
92 #print "creating a handle with args ($_->{args}): ";
93 my $sql = SQL::Abstract->new($_->{args});
94 my $bind = $_->{bind} || { a => 4, b => 0};
95 my($stmt, @bind) = $sql->select('test', '*', $bind);
96 ok($stmt eq $_->{stmt} && @bind) or
100 "[$_->{stmt}] [4, 0]\n\n";