7 use SQL::Abstract::Test import => ['is_same_sql_bind'];
18 * [scalarref, scalarref]
20 * \["? AND ?", scalar, scalar]
21 * \["1 AND ?", scalar]
22 * \["? AND 2", scalar]
26 my @in_between_tests = (
28 where => { x => { -between => [1, 2] } },
29 stmt => 'WHERE (x BETWEEN ? AND ?)',
31 test => '-between with two placeholders',
34 where => { x => { -between => [\"1", 2] } },
35 stmt => 'WHERE (x BETWEEN 1 AND ?)',
37 test => '-between with one literal sql arg and one placeholder',
40 where => { x => { -between => [1, \"2"] } },
41 stmt => 'WHERE (x BETWEEN ? AND 2)',
43 test => '-between with one placeholder and one literal sql arg',
46 where => { x => { -between => [\'current_date - 1', \'current_date - 0'] } },
47 stmt => 'WHERE (x BETWEEN current_date - 1 AND current_date - 0)',
49 test => '-between with two literal sql arguments',
52 where => { x => { -between => [ \['current_date - ?', 1], \['current_date - ?', 0] ] } },
53 stmt => 'WHERE (x BETWEEN current_date - ? AND current_date - ?)',
55 test => '-between with two literal sql arguments with bind',
58 where => { x => { -between => \['? AND ?', 1, 2] } },
59 stmt => 'WHERE (x BETWEEN ? AND ?)',
61 test => '-between with literal sql with placeholders (\["? AND ?", scalar, scalar])',
64 where => { x => { -between => \["'something' AND ?", 2] } },
65 stmt => "WHERE (x BETWEEN 'something' AND ?)",
67 test => '-between with literal sql with one literal arg and one placeholder (\["\'something\' AND ?", scalar])',
70 where => { x => { -between => \["? AND 'something'", 1] } },
71 stmt => "WHERE (x BETWEEN ? AND 'something')",
73 test => '-between with literal sql with one placeholder and one literal arg (\["? AND \'something\'", scalar])',
76 where => { x => { -between => \"'this' AND 'that'" } },
77 stmt => "WHERE (x BETWEEN 'this' AND 'that')",
79 test => '-between with literal sql with a literal (\"\'this\' AND \'that\'")',
83 plan tests => @in_between_tests*4;
85 for my $case (@in_between_tests) {
87 local $TODO = $case->{todo} if $case->{todo};
89 local $Data::Dumper::Terse = 1;
94 local $SIG{__WARN__} = sub { push @w, @_ };
95 my $sql = SQL::Abstract->new ($case->{args} || {});
97 my ($stmt, @bind) = $sql->where($case->{where});
104 || diag "Search term:\n" . Dumper $case->{where};
106 is (@w, 0, $case->{test} || 'No warnings within in-between tests')
107 || diag join "\n", 'Emitted warnings:', @w;
108 }, "$case->{test} doesn't die");