· 8 years ago · Jul 16, 2018, 01:18 PM
1use DBI 1.615;
2use Test::More;
3
4my $callback = sub {
5 my ($obj,$query,$attr,@binds) = @_;
6 my $i=0;
7 map { ! defined $_ && die("undefined bind value found at \#$i, in query \x27$query\x27"); $i++ } @binds;
8 return;
9};
10
11my %callbacks;
12$callbacks{$_} = $callback for qw/do selectrow_array selectrow_arrayref
13 selectrow_hashref selectall_arrayref
14 selectall_hashref selectcol_arrayref/;
15
16my $dbh = DBI->connect('dbi:SQLite:dbname=test.db','','', {
17 RaiseError => 1,
18 Callbacks => {
19 %callbacks,
20 ChildCallbacks => {
21 'execute' => sub {
22 my ($obj,@binds)=@_;
23 $callback->($obj, $obj->{Statement}, undef, @binds);
24 return;
25 },
26 },
27 },
28});
29
30eval {
31$dbh->do(<<EOF);
32CREATE TABLE IF NOT EXISTS hoge (
33 foo VARCHAR(255) NOT NULL
34)
35EOF
36};
37ok(!$@);
38
39my $foo;
40
41eval {
42 my $sth = $dbh->prepare("SELECT * FROM hoge WHERE foo=?");
43 $sth->execute($foo);
44};
45like( $@, qr/undefined bind value found/);
46
47eval {
48 $dbh->selectrow_arrayref("SELECT * FROM hoge WHERE foo=?",undef,$foo);
49};
50like( $@, qr/undefined bind value found/);
51
52eval {
53 $dbh->do("SELECT * FROM hoge WHERE foo=?",undef,$foo);
54};
55like( $@, qr/undefined bind value found/);
56
57done_testing();