Skip to content

Commit

Permalink
Unify set SQLite PRAGMAs.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Sep 23, 2021
1 parent 626caad commit 23f585c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
3 changes: 3 additions & 0 deletions sqlite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ endif()

target_compile_definitions(tdsqlite PRIVATE
-DSQLITE_DEFAULT_MEMSTATUS=0
-DSQLITE_DEFAULT_SYNCHRONOUS=1
-DSQLITE_DEFAULT_RECURSIVE_TRIGGERS=1
-DSQLITE_TEMP_STORE=2
-DSQLITE_OMIT_LOAD_EXTENSION
-DSQLITE_OMIT_DECLTYPE
-DSQLITE_OMIT_PROGRESS_CALLBACK
Expand Down
3 changes: 0 additions & 3 deletions td/telegram/LanguagePackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ bool LanguagePackManager::is_custom_language_code(Slice language_code) {

static Result<SqliteDb> open_database(const string &path) {
TRY_RESULT(database, SqliteDb::open_with_key(path, true, DbKey::empty()));
TRY_STATUS(database.exec("PRAGMA synchronous=NORMAL"));
TRY_STATUS(database.exec("PRAGMA temp_store=MEMORY"));
TRY_STATUS(database.exec("PRAGMA encoding=\"UTF-8\""));
TRY_STATUS(database.exec("PRAGMA journal_mode=WAL"));
return std::move(database);
}
Expand Down
15 changes: 2 additions & 13 deletions td/telegram/TdDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,6 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
return Status::OK();
}

Status init_db(SqliteDb &db) {
TRY_STATUS(db.exec("PRAGMA encoding=\"UTF-8\""));
TRY_STATUS(db.exec("PRAGMA journal_mode=WAL"));

TRY_STATUS(db.exec("PRAGMA synchronous=NORMAL"));
TRY_STATUS(db.exec("PRAGMA temp_store=MEMORY"));
TRY_STATUS(db.exec("PRAGMA secure_delete=1"));

return Status::OK();
}

} // namespace

std::shared_ptr<FileDbInterface> TdDb::get_file_db_shared() {
Expand Down Expand Up @@ -310,8 +299,8 @@ Status TdDb::init_sqlite(int32 scheduler_id, const TdParameters &parameters, DbK
sql_connection_ = std::make_shared<SqliteConnectionSafe>(sql_database_path, key, db_instance.get_cipher_version());
sql_connection_->set(std::move(db_instance));
auto &db = sql_connection_->get();

TRY_STATUS(init_db(db));
TRY_STATUS(db.exec("PRAGMA journal_mode=WAL"));
TRY_STATUS(db.exec("PRAGMA secure_delete=1"));

// Init databases
// Do initialization once and before everything else to avoid "database is locked" error.
Expand Down
4 changes: 1 addition & 3 deletions tddb/td/db/SqliteConnectionSafe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ SqliteConnectionSafe::SqliteConnectionSafe(string path, DbKey key, optional<int3
LOG(FATAL) << "Can't open database: " << r_db.error().message();
}
auto db = r_db.move_as_ok();
db.exec("PRAGMA synchronous=NORMAL").ensure();
db.exec("PRAGMA temp_store=MEMORY").ensure();
db.exec("PRAGMA journal_mode=WAL").ensure();
db.exec("PRAGMA secure_delete=1").ensure();
db.exec("PRAGMA recursive_triggers=1").ensure();
return db;
}) {
}
Expand Down

0 comments on commit 23f585c

Please sign in to comment.