1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00

fixed rt-96050; sqlite_db_filename returns an error (instead of segfault) if database connection is closed

This commit is contained in:
Kenichi Ishigaki 2014-05-29 16:05:45 +09:00
parent 1831efe1dc
commit 81d4d11fa1
2 changed files with 30 additions and 1 deletions

View file

@ -444,6 +444,7 @@ sqlite_db_disconnect(SV *dbh, imp_dbh_t *imp_dbh)
sqlite_error(dbh, rc, sqlite3_errmsg(imp_dbh->db));
}
}
imp_dbh->db = NULL;
av_undef(imp_dbh->functions);
SvREFCNT_dec(imp_dbh->functions);
@ -467,7 +468,6 @@ sqlite_db_destroy(SV *dbh, imp_dbh_t *imp_dbh)
if (DBIc_ACTIVE(imp_dbh)) {
sqlite_db_disconnect(dbh, imp_dbh);
}
imp_dbh->db = NULL;
DBIc_IMPSET_off(imp_dbh);
}
@ -1372,6 +1372,11 @@ sqlite_db_filename(pTHX_ SV *dbh)
D_imp_dbh(dbh);
const char *filename;
if (!imp_dbh->db) {
sqlite_error(dbh, -1, "Can't tell the filename of a closed database");
return &PL_sv_undef;
}
croak_if_db_is_null();
filename = sqlite3_db_filename(imp_dbh->db, "main");

View file

@ -0,0 +1,24 @@
#!/usr/bin/env perl
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use t::lib::Test;
use Test::More tests => 4;
use Test::NoWarnings;
my $dbh = connect_ok( RaiseError => 1, PrintError => 0 );
{
my $filename = eval { $dbh->sqlite_db_filename };
ok !$@, "no filename (because it's in-memory); no error";
}
$dbh->disconnect;
{
my $filename = eval { $dbh->sqlite_db_filename };
ok $@ && !$filename, "got an error; no filename; and no segfault";
}