Minor cleanup on throwing exception in Database

This commit is contained in:
Sébastien Rombauts 2019-12-29 22:24:07 +01:00
parent dc3f1ac271
commit ae01dfb895

View File

@ -216,7 +216,7 @@ void Database::loadExtension(const char* apExtensionName, const char *apEntryPoi
(void)apExtensionName;
(void)apEntryPointName;
throw std::runtime_error("sqlite extensions are disabled");
throw SQLite::Exception("sqlite extensions are disabled");
#else
#ifdef SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION // Since SQLite 3.13 (2016-05-18):
// Security warning:
@ -248,8 +248,7 @@ void Database::key(const std::string& aKey) const
#else // SQLITE_HAS_CODEC
if (passLen > 0)
{
const SQLite::Exception exception("No encryption support, recompile with SQLITE_HAS_CODEC to enable.");
throw exception;
throw SQLite::Exception("No encryption support, recompile with SQLITE_HAS_CODEC to enable.");
}
#endif // SQLITE_HAS_CODEC
}
@ -271,16 +270,18 @@ void Database::rekey(const std::string& aNewKey) const
}
#else // SQLITE_HAS_CODEC
static_cast<void>(aNewKey); // silence unused parameter warning
const SQLite::Exception exception("No encryption support, recompile with SQLITE_HAS_CODEC to enable.");
throw exception;
throw SQLite::Exception("No encryption support, recompile with SQLITE_HAS_CODEC to enable.");
#endif // SQLITE_HAS_CODEC
}
// Test if a file contains an unencrypted database.
bool Database::isUnencrypted(const std::string& aFilename)
{
if (aFilename.length() > 0)
if (aFilename.empty())
{
throw SQLite::Exception("Could not open database, the aFilename parameter was empty.");
}
std::ifstream fileBuffer(aFilename.c_str(), std::ios::in | std::ios::binary);
char header[16];
if (fileBuffer.is_open())
@ -291,13 +292,10 @@ bool Database::isUnencrypted(const std::string& aFilename)
}
else
{
const SQLite::Exception exception("Error opening file: " + aFilename);
throw exception;
throw SQLite::Exception("Error opening file: " + aFilename);
}
return strncmp(header, "SQLite format 3\000", 16) == 0;
}
const SQLite::Exception exception("Could not open database, the aFilename parameter was empty.");
throw exception;
}
// This is a reference implementation of live backup taken from the official sit: