Improve SQLite logging.
GitOrigin-RevId: 5a779f25594f518508a0a9df7f6c64cfb9cbc9e4
This commit is contained in:
parent
9679cef0bb
commit
d5ebf00b72
@ -93,9 +93,13 @@ void SqliteDb::trace(bool flag) {
|
||||
Status SqliteDb::exec(CSlice cmd) {
|
||||
CHECK(!empty());
|
||||
char *msg;
|
||||
VLOG(sqlite) << "Start exec " << tag("query", cmd) << tag("database", raw_->db());
|
||||
if (enable_logging_) {
|
||||
VLOG(sqlite) << "Start exec " << tag("query", cmd) << tag("database", raw_->db());
|
||||
}
|
||||
auto rc = sqlite3_exec(raw_->db(), cmd.c_str(), nullptr, nullptr, &msg);
|
||||
VLOG(sqlite) << "Finish exec " << tag("query", cmd) << tag("database", raw_->db());
|
||||
if (enable_logging_) {
|
||||
VLOG(sqlite) << "Finish exec " << tag("query", cmd) << tag("database", raw_->db());
|
||||
}
|
||||
if (rc != SQLITE_OK) {
|
||||
CHECK(msg != nullptr);
|
||||
return Status::Error(PSLICE() << tag("query", cmd) << " to database \"" << raw_->path() << "\" failed: " << msg);
|
||||
@ -151,7 +155,11 @@ Status SqliteDb::commit_transaction() {
|
||||
}
|
||||
|
||||
Status SqliteDb::check_encryption() {
|
||||
return exec("SELECT count(*) FROM sqlite_master");
|
||||
auto status = exec("SELECT count(*) FROM sqlite_master");
|
||||
if (status.is_ok()) {
|
||||
enable_logging_ = true;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
Result<SqliteDb> SqliteDb::open_with_key(CSlice path, const DbKey &db_key) {
|
||||
|
@ -80,6 +80,7 @@ class SqliteDb {
|
||||
explicit SqliteDb(std::shared_ptr<detail::RawSqliteDb> raw) : raw_(std::move(raw)) {
|
||||
}
|
||||
std::shared_ptr<detail::RawSqliteDb> raw_;
|
||||
bool enable_logging_ = false;
|
||||
|
||||
Status check_encryption();
|
||||
};
|
||||
|
Reference in New Issue
Block a user