summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h')
-rw-r--r--protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h47
1 files changed, 27 insertions, 20 deletions
diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h b/protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h
index 40137464ce..899b02e4a5 100644
--- a/protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h
+++ b/protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h
@@ -1,5 +1,5 @@
//
-// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// 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)
@@ -11,23 +11,19 @@
#include "td/db/detail/RawSqliteDb.h"
-#include "td/utils/logging.h"
+#include "td/utils/optional.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include <memory>
-struct sqlite3;
+struct tdsqlite3;
namespace td {
class SqliteDb {
public:
SqliteDb() = default;
- explicit SqliteDb(CSlice path) {
- auto status = init(path);
- LOG_IF(FATAL, status.is_error()) << status;
- }
SqliteDb(SqliteDb &&) = default;
SqliteDb &operator=(SqliteDb &&) = default;
SqliteDb(const SqliteDb &) = delete;
@@ -36,7 +32,7 @@ class SqliteDb {
// dangerous
SqliteDb clone() const {
- return SqliteDb(raw_);
+ return SqliteDb(raw_, enable_logging_);
}
bool empty() const {
@@ -46,26 +42,28 @@ class SqliteDb {
*this = SqliteDb();
}
- Status init(CSlice path, bool *was_created = nullptr) TD_WARN_UNUSED_RESULT;
Status exec(CSlice cmd) TD_WARN_UNUSED_RESULT;
Result<bool> has_table(Slice table);
Result<string> get_pragma(Slice name);
- Status begin_transaction();
- Status commit_transaction();
+ Result<string> get_pragma_string(Slice name);
+
+ Status begin_read_transaction() TD_WARN_UNUSED_RESULT;
+ Status begin_write_transaction() TD_WARN_UNUSED_RESULT;
+ Status commit_transaction() TD_WARN_UNUSED_RESULT;
Result<int32> user_version();
- Status set_user_version(int32 version);
+ Status set_user_version(int32 version) TD_WARN_UNUSED_RESULT;
void trace(bool flag);
static Status destroy(Slice path) TD_WARN_UNUSED_RESULT;
- // Anyway we can't change the key on the fly, so static functions is more than enough
- static Result<SqliteDb> open_with_key(CSlice path, const DbKey &db_key);
- static Status change_key(CSlice path, const DbKey &new_db_key, const DbKey &old_db_key);
-
- Status last_error();
+ // we can't change the key on the fly, so static functions are more than enough
+ static Result<SqliteDb> open_with_key(CSlice path, bool allow_creation, const DbKey &db_key,
+ optional<int32> cipher_version = {});
+ static Result<SqliteDb> change_key(CSlice path, bool allow_creation, const DbKey &new_db_key,
+ const DbKey &old_db_key);
- sqlite3 *get_native() const {
+ tdsqlite3 *get_native() const {
return raw_->db();
}
@@ -76,11 +74,20 @@ class SqliteDb {
detail::RawSqliteDb::with_db_path(main_path, f);
}
+ optional<int32> get_cipher_version() const;
+
private:
- explicit SqliteDb(std::shared_ptr<detail::RawSqliteDb> raw) : raw_(std::move(raw)) {
+ SqliteDb(std::shared_ptr<detail::RawSqliteDb> raw, bool enable_logging)
+ : raw_(std::move(raw)), enable_logging_(enable_logging) {
}
std::shared_ptr<detail::RawSqliteDb> raw_;
+ bool enable_logging_ = false;
+
+ Status init(CSlice path, bool allow_creation) TD_WARN_UNUSED_RESULT;
- bool is_encrypted();
+ Status check_encryption();
+ static Result<SqliteDb> do_open_with_key(CSlice path, bool allow_creation, const DbKey &db_key, int32 cipher_version);
+ void set_cipher_version(int32 cipher_version);
};
+
} // namespace td