Commit f69afcb2 authored by JINMEI Tatuya's avatar JINMEI Tatuya

prevented duplicate DB open


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1384 e5f2f494-b856-4b98-b285-d166d9295462
parent cfb196fd
......@@ -37,7 +37,7 @@ namespace auth {
namespace {
// Note: this cannot be std::string to avoid
// "static initialization order fiasco".
static const char* DEFAULT_DB_FILE = "/tmp/zone.sqlite3";
const char* DEFAULT_DB_FILE = "/tmp/zone.sqlite3";
}
//
......@@ -95,7 +95,8 @@ Sqlite3DataSrc::hasExactZone(const char* name) const {
return (i);
}
static int
namespace {
int
importSqlite3Rows(sqlite3_stmt* query, const Name& qname, const RRClass& qclass,
const RRType& qtype, const bool nsec3_tree,
RRsetList& result_sets, uint32_t& flags)
......@@ -181,6 +182,7 @@ importSqlite3Rows(sqlite3_stmt* query, const Name& qname, const RRClass& qclass,
return (rows);
}
}
int
Sqlite3DataSrc::findRecords(const Name& name, const RRType& rdtype,
......@@ -685,6 +687,9 @@ Sqlite3DataSrc::findReferral(const Name& qname,
//
void
Sqlite3DataSrc::open(const string& name) {
if (db != NULL) {
isc_throw(Sqlite3Error, "Duplicate Sqlite3 open with " << name);
}
if (sqlite3_open(name.c_str(), &db) != 0) {
// sqlite3_close() must be called even when open fails.
sqlite3_close(db);
......
......@@ -365,6 +365,11 @@ TEST_F(Sqlite3DataSourceTest, openFail) {
EXPECT_THROW(data_source.init(SQLITE_DBFILE_NOTEXIST), Sqlite3Error);
}
TEST_F(Sqlite3DataSourceTest, doubleOpen) {
// An attempt of duplicate open should trigger an exception.
EXPECT_THROW(data_source.init(SQLITE_DBFILE_EXAMPLE), Sqlite3Error);
}
TEST_F(Sqlite3DataSourceTest, findClosestEnclosure) {
NameMatch name_match(www_name);
data_source.findClosestEnclosure(name_match, rrclass);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment