9
BEGIN { plan tests => 52 }
13
my $driver = "ExampleP";
16
my $dbh = DBI->connect("dbi:$driver:", '', '');
18
my $sql = "select name from ?";
19
my $sth1 = $dbh->prepare_cached($sql);
20
ok($sth1->execute("."));
21
my $ck = $dbh->{CachedKids};
25
local $SIG{__WARN__} = sub { ++$warn if $_[0] =~ /still active/ };
26
my $sth2 = $dbh->prepare_cached($sql);
31
$sth2 = $dbh->prepare_cached($sql, { foo => 1 });
35
ok($sth1->execute("."));
37
$sth2 = $dbh->prepare_cached($sql, undef, 3);
39
ok($sth1->{Active}); # active but no longer cached
42
ok($sth2->execute("."));
44
$sth1 = $dbh->prepare_cached($sql, undef, 1);
52
my $drh = DBI->install_driver($driver);
57
# --- handle reference leak tests
61
my $dbh = DBI->connect("dbi:$driver:", '', '');
62
ok(ref $dbh->{Driver}) if $args{Driver};
63
my $sth = $dbh->prepare_cached("select name from ?");
64
ok(ref $sth->{Database}) if $args{Database};
66
# both handles should be freed here
73
{ Driver => 1, Database => 1 },
75
print "ref leak using @{[ %$args ]}\n";
80
# --- handle take_imp_data test
82
print "take_imp_data\n";
83
unless ($DBI::PurePerl) {
85
my $dbh = DBI->connect("dbi:$driver:", '', '');
88
my $imp_data = $dbh->take_imp_data;
90
# generally length($imp_data) = 112 for 32bit, 116 for 64 bit
91
# (as of DBI 1.37) but it can differ on some platforms
92
# depending on structure packing by the compiler
93
# so we just test that it's something reasonable:
94
ok(length($imp_data) >= 80);
95
#print Dumper($imp_data);
99
local $SIG{__WARN__} = sub { ++$warn if $_[0] =~ /after take_imp_data/ };
100
is($tmp=$dbh->{Driver}, undef);
101
is($tmp=$dbh->{TraceLevel}, undef);
102
is($dbh->disconnect, undef);
103
is($dbh->quote(42), undef);
107
print "use dbi_imp_data\n";
108
my $dbh2 = DBI->connect("dbi:$driver:", '', '', { dbi_imp_data => $imp_data });
110
# need a way to test dbi_imp_data has been used
117
print "NullP statement handle attributes without execute\n";
118
my $dbh = DBI->connect("dbi:NullP:", '', '');
119
my $sth = $dbh->prepare("foo bar");
120
is $sth->{NUM_OF_PARAMS}, 0;
121
is $sth->{NUM_OF_FIELDS}, undef;
122
is $sth->{Statement}, "foo bar";
123
is $sth->{NAME}, undef;
124
is $sth->{TYPE}, undef;
125
is $sth->{SCALE}, undef;
126
is $sth->{PRECISION}, undef;
127
is $sth->{NULLABLE}, undef;
128
is $sth->{RowsInCache}, undef;
129
is $sth->{ParamValues}, undef;
130
# derived NAME attributes
131
is $sth->{NAME_uc}, undef;
132
is $sth->{NAME_lc}, undef;
133
is $sth->{NAME_hash}, undef;
134
is $sth->{NAME_uc_hash}, undef;
135
is $sth->{NAME_lc_hash}, undef;
137
ok ref($dbh)->can("prepare");
138
ok !ref($dbh)->can("nonesuch");
139
ok ref($sth)->can("execute");
141
# I don't know why this warning has the "(perhaps ...)" suffix, it shouldn't:
142
# Can't locate object method "nonesuch" via package "DBI::db" (perhaps you forgot to load "DBI::db"?)
143
eval { ref($dbh)->nonesuch; };