# Make sure to test the examples, since having them break is somewhat
# embarrassing. :-(
-my $not_stringifiable = SQLA::NotStringifiable->new();
+my $not_stringifiable = bless {}, 'SQLA::NotStringifiable';
my @handle_tests = (
{
},
{
+ where => [
+ status => 'completed',
+ user => 'nwiger',
+ ],
+ stmt => " WHERE ( status = ? OR user = ? )",
+ bind => [qw/completed nwiger/],
+ },
+
+ {
where => {
user => 'nwiger',
status => 'completed'
stmt => " WHERE ( (bar > ? AND bar < ?) AND foo IN (?, ?) )",
bind => [44, 55, 22, 33],
},
-
{
where => { -and => [{}, { 'me.id' => '1'}] },
stmt => " WHERE ( ( me.id = ? ) )",
},
{
- where => { foo => SQLA::FourtyTwo->new(), },
+ where => { foo => $not_stringifiable, },
stmt => " WHERE ( foo = ? )",
- bind => [ 'The Life, the Universe and Everything.' ],
+ bind => [ $not_stringifiable ],
},
{
- where => { foo => $not_stringifiable, },
- stmt => " WHERE ( foo = ? )",
- bind => [ $not_stringifiable ],
+ where => \[ 'foo = ?','bar' ],
+ stmt => " WHERE (foo = ?)",
+ bind => [ "bar" ],
},
+ {
+ where => [ \[ 'foo = ?','bar' ] ],
+ stmt => " WHERE (foo = ?)",
+ bind => [ "bar" ],
+ },
);
-
-plan tests => scalar(@handle_tests) + 1;
+plan tests => ( @handle_tests * 2 ) + 1;
for my $case (@handle_tests) {
my $sql = SQL::Abstract->new;
- my($stmt, @bind) = $sql->where($case->{where}, $case->{order});
- is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind})
+ my($stmt, @bind);
+ lives_ok (sub {
+ ($stmt, @bind) = $sql->where($case->{where}, $case->{order});
+ is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind});
+ });
}
dies_ok {
my $sql = SQL::Abstract->new;
$sql->where({ foo => { '>=' => [] }},);
};
-
-
-
-#======================================================================
-package SQLA::FourtyTwo; # testing stringification of arguments
-#======================================================================
-
-use strict;
-use warnings;
-
-use overload
- '""' => \&to_str;
-
-sub new
-{
- bless {}, shift;
-}
-
-sub to_str
-{
- return "The Life, the Universe and Everything.";
-}
-
-1;
-
-
-#======================================================================
-package SQLA::NotStringifiable; # testing stringification of arguments
-#======================================================================
-
-use strict;
-use warnings;
-
-sub new
-{
- bless {}, shift;
-}
-
-1;