diff --git a/dbdimp.c b/dbdimp.c index fcc2161..4ef2805 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -1312,6 +1312,11 @@ sqlite_st_FETCH_attrib(SV *sth, imp_sth_t *imp_sth, SV *keysv) croak_if_db_is_null(); croak_if_stmt_is_null(); + if (!DBIc_ACTIVE(imp_dbh)) { + sqlite_error(sth, -2, "attempt to fetch on inactive database handle"); + return FALSE; + } + if (strEQ(key, "sqlite_unprepared_statements")) { return sv_2mortal(newSVpv(imp_sth->unprepared_statements, 0)); } diff --git a/t/32_inactive_error.t b/t/32_inactive_error.t index 58f4034..a8fecc7 100644 --- a/t/32_inactive_error.t +++ b/t/32_inactive_error.t @@ -6,7 +6,7 @@ BEGIN { $^W = 1; } -use Test::More tests => 4; +use Test::More tests => 7; use lib "t/lib"; use SQLiteTest; @@ -33,3 +33,18 @@ like( qr/attempt to execute on inactive database handle/, 'Got the expected warning', ); + +@warning = (); +SCOPE: { + local $SIG{__WARN__} = sub { push @warning, @_; return }; + my $ret = eval { $sth->{NUM_OF_PARAMS}; }; + # we need PrintError => 1, or warn $@ if $@; + ok !$ret; +} + +is( scalar(@warning), 1, 'Got 1 warning' ); +like( + $warning[0], + qr/attempt to fetch on inactive database handle/, + 'Got the expected warning', +);