Created
December 3, 2010 09:16
-
-
Save kazeburo/726754 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use DBI 1.615; | |
use Test::More; | |
my $callback = sub { | |
my ($obj,$query,$attr,@binds) = @_; | |
my $i=0; | |
map { ! defined $_ && die("undefined bind value found at \#$i, in query \x27$query\x27"); $i++ } @binds; | |
return; | |
}; | |
my %callbacks; | |
$callbacks{$_} = $callback for qw/do selectrow_array selectrow_arrayref | |
selectrow_hashref selectall_arrayref | |
selectall_hashref selectcol_arrayref/; | |
my $dbh = DBI->connect('dbi:SQLite:dbname=test.db','','', { | |
RaiseError => 1, | |
Callbacks => { | |
%callbacks, | |
ChildCallbacks => { | |
'execute' => sub { | |
my ($obj,@binds)=@_; | |
$callback->($obj, $obj->{Statement}, undef, @binds); | |
return; | |
}, | |
}, | |
}, | |
}); | |
eval { | |
$dbh->do(<<EOF); | |
CREATE TABLE IF NOT EXISTS hoge ( | |
foo VARCHAR(255) NOT NULL | |
) | |
EOF | |
}; | |
ok(!$@); | |
my $foo; | |
eval { | |
my $sth = $dbh->prepare("SELECT * FROM hoge WHERE foo=?"); | |
$sth->execute($foo); | |
}; | |
like( $@, qr/undefined bind value found/); | |
eval { | |
$dbh->selectrow_arrayref("SELECT * FROM hoge WHERE foo=?",undef,$foo); | |
}; | |
like( $@, qr/undefined bind value found/); | |
eval { | |
$dbh->do("SELECT * FROM hoge WHERE foo=?",undef,$foo); | |
}; | |
like( $@, qr/undefined bind value found/); | |
done_testing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment