protected IObservable <Unit> Initialize() { var ret = Observable.Create <Unit>(subj => { // NB: This is in its own try block because depending on the // platform, we may not have a modern SQLite3, where these // PRAGMAs are supported. These aren't critical, so let them // fail silently try { // NB: Setting journal_mode returns a row, nfi Connection.ExecuteScalar <int>("PRAGMA journal_mode=WAL"); Connection.Execute("PRAGMA temp_store=MEMORY"); Connection.Execute("PRAGMA synchronous=OFF"); } catch (SQLiteException) { } try { Connection.CreateTable <CacheElement>(); var schemaVersion = GetSchemaVersion(); if (schemaVersion < 2) { Connection.Execute("ALTER TABLE CacheElement RENAME TO VersionOneCacheElement;"); Connection.CreateTable <CacheElement>(); var sql = "INSERT INTO CacheElement SELECT Key,TypeName,Value,Expiration,\"{0}\" AS CreatedAt FROM VersionOneCacheElement;"; Connection.Execute(string.Format(sql, BlobCache.TaskpoolScheduler.Now.UtcDateTime.Ticks)); Connection.Execute("DROP TABLE VersionOneCacheElement;"); Connection.Insert(new SchemaInfo() { Version = 2, }); } // NB: We have to do this here because you can't prepare // statements until you've got the backing table opQueue = new SqliteOperationQueue(Connection, Scheduler); queueThread = opQueue.Start(); subj.OnNext(Unit.Default); subj.OnCompleted(); } catch (Exception ex) { subj.OnError(ex); } return(Disposable.Empty); }); return(ret.PublishLast().PermaRef()); }
internal void ReplaceOperationQueue(SqliteOperationQueue queue) { _initializer.Wait(); opQueue.Dispose(); opQueue = queue; opQueue.Start(); }