This repository has been archived on 2020-05-25. You can view files and clone it, but cannot push or open issues or pull requests.
tdlib-fork/tddb/td/db/detail/RawSqliteDb.cpp
levlam 5cbda834bd Update copyright year.
GitOrigin-RevId: 1369d3af1195221f6ddb9462d5f8b74fb5fef20f
2018-01-02 16:45:09 +03:00

40 lines
1.0 KiB
C++

//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/db/detail/RawSqliteDb.h"
#include "sqlite/sqlite3.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/port/path.h"
namespace td {
namespace detail {
Status RawSqliteDb::last_error(sqlite3 *db) {
return Status::Error(Slice(sqlite3_errmsg(db)));
}
Status RawSqliteDb::destroy(Slice path) {
with_db_path(path, [](auto path) { unlink(path).ignore(); });
return Status::OK();
}
Status RawSqliteDb::last_error() {
//If database was corrupted, try to delete it.
auto code = sqlite3_errcode(db_);
if (code == SQLITE_CORRUPT) {
destroy(path_).ignore();
}
return last_error(db_);
}
RawSqliteDb::~RawSqliteDb() {
auto rc = sqlite3_close(db_);
LOG_IF(FATAL, rc != SQLITE_OK) << last_error(db_);
}
} // namespace detail
} // namespace td