protected IDatabaseConnection CreateConnection(bool isReadOnly = false) { if (_connection != null) { return(_connection.Clone(false)); } lock (lock_manager.getLockItem()) { if (!_versionLogged) { _versionLogged = true; Logger.Info("Sqlite version: " + SQLite3.Version); Logger.Info("Sqlite compiler options: " + string.Join(",", SQLite3.CompilerOptions.ToArray())); } ConnectionFlags connectionFlags; if (isReadOnly) { //Logger.Info("Opening read connection"); //connectionFlags = ConnectionFlags.ReadOnly; connectionFlags = ConnectionFlags.Create; connectionFlags |= ConnectionFlags.ReadWrite; } else { //Logger.Info("Opening write connection"); connectionFlags = ConnectionFlags.Create; connectionFlags |= ConnectionFlags.ReadWrite; } if (EnableSingleConnection) { connectionFlags |= ConnectionFlags.PrivateCache; } else { connectionFlags |= ConnectionFlags.SharedCached; } connectionFlags |= ConnectionFlags.NoMutex; var db = SQLite3.Open(DbFilePath, connectionFlags, null, false); try { if (string.IsNullOrWhiteSpace(_defaultWal)) { using (var statement = PrepareStatement(db, "PRAGMA journal_mode".AsSpan())) { foreach (var row in statement.ExecuteQuery()) { _defaultWal = row.GetString(0); break; } } Logger.Info("Default journal_mode for {0} is {1}", DbFilePath, _defaultWal); } var queries = new List <string> { //"PRAGMA cache size=-10000" //"PRAGMA read_uncommitted = true", "PRAGMA synchronous=Normal" }; if (CacheSize.HasValue) { queries.Add("PRAGMA cache_size=" + CacheSize.Value.ToString(CultureInfo.InvariantCulture)); } if (EnableTempStoreMemory) { queries.Add("PRAGMA temp_store = memory"); } else { queries.Add("PRAGMA temp_store = file"); } //foreach (var query in queries) //{ // db.Execute(query); //} db.ExecuteAll(string.Join(";", queries.ToArray())); } catch { using (db) { } throw; } _connection = db; return(db); } }