Unify set SQLite PRAGMAs.
This commit is contained in:
parent
626caad19a
commit
23f585caf0
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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() {
|
||||
@ -310,8 +299,8 @@ Status TdDb::init_sqlite(int32 scheduler_id, const TdParameters ¶meters, 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.
|
||||
|
@ -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;
|
||||
}) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user