mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 22:28:47 -04:00
fixed rt-96050; sqlite_db_filename returns an error (instead of segfault) if database connection is closed
This commit is contained in:
parent
1831efe1dc
commit
81d4d11fa1
2 changed files with 30 additions and 1 deletions
7
dbdimp.c
7
dbdimp.c
|
@ -444,6 +444,7 @@ sqlite_db_disconnect(SV *dbh, imp_dbh_t *imp_dbh)
|
||||||
sqlite_error(dbh, rc, sqlite3_errmsg(imp_dbh->db));
|
sqlite_error(dbh, rc, sqlite3_errmsg(imp_dbh->db));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
imp_dbh->db = NULL;
|
||||||
|
|
||||||
av_undef(imp_dbh->functions);
|
av_undef(imp_dbh->functions);
|
||||||
SvREFCNT_dec(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)) {
|
if (DBIc_ACTIVE(imp_dbh)) {
|
||||||
sqlite_db_disconnect(dbh, imp_dbh);
|
sqlite_db_disconnect(dbh, imp_dbh);
|
||||||
}
|
}
|
||||||
imp_dbh->db = NULL;
|
|
||||||
|
|
||||||
DBIc_IMPSET_off(imp_dbh);
|
DBIc_IMPSET_off(imp_dbh);
|
||||||
}
|
}
|
||||||
|
@ -1372,6 +1372,11 @@ sqlite_db_filename(pTHX_ SV *dbh)
|
||||||
D_imp_dbh(dbh);
|
D_imp_dbh(dbh);
|
||||||
const char *filename;
|
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();
|
croak_if_db_is_null();
|
||||||
|
|
||||||
filename = sqlite3_db_filename(imp_dbh->db, "main");
|
filename = sqlite3_db_filename(imp_dbh->db, "main");
|
||||||
|
|
24
t/rt_96050_db_filename_for_a_closed_database.t
Normal file
24
t/rt_96050_db_filename_for_a_closed_database.t
Normal 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";
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue