public void Close() { DB_CONNECTION_MUTEX.WaitOne(); Tuple <bool, Mutex, SQLiteConnection> connection = DB_CONNECTIONS[DB_PATH]; SharedUtils.RetryOnException(() => connection.Item3.Close()); connection.Item2.Dispose(); DB_CONNECTIONS.Remove(DB_PATH); DB_CONNECTION_MUTEX.ReleaseMutex(); }
public int InsertOrReplace(object obj) { try { return(SharedUtils.RetryOnException(() => DB_CONNECTIONS[DB_PATH].Item3.InsertOrReplace(obj)));; } catch (Exception e) { Logger.Error("Failed to execute DB insert or replace!", e); return(-1); } }
public List <T> ExecuteCommand <T>(bool readOnly, SQLiteCommand cmd) where T : new() { try { return(SharedUtils.RetryOnException(() => cmd.ExecuteQuery <T>())); } catch (Exception e) { Logger.Error("Failed to execute DB execute command!", e); return(new List <T>()); } }
public int DeleteAll <T>() { try { return(SharedUtils.RetryOnException(() => DB_CONNECTIONS[DB_PATH].Item3.DeleteAll <T>())); } catch (Exception e) { Logger.Error("Failed to execute DB delete all!", e); return(-1); } }
public void BeginTransaction() { Tuple <bool, Mutex, SQLiteConnection> connection = DB_CONNECTIONS[DB_PATH]; connection.Item2.WaitOne(); if (connection.Item1) { SharedUtils.RetryOnException(() => connection.Item3.BeginTransaction()); DB_CONNECTIONS[DB_PATH] = new Tuple <bool, Mutex, SQLiteConnection>(true, connection.Item2, connection.Item3); } connection.Item2.ReleaseMutex(); }
/// <param name="readOnly">Unused/placeholder!</param> public List <T> Query <T>(bool readOnly, string query, params object[] args) where T : new() { try { return(SharedUtils.RetryOnException(() => DB_CONNECTIONS[DB_PATH].Item3.Query <T>(query, args))); } catch (Exception e) { Logger.Error("Failed to execute DB query!", e); return(new List <T>()); } }
public int Execute(string query, params object[] args) { try { return(SharedUtils.RetryOnException(() => DB_CONNECTIONS[DB_PATH].Item3.Execute(query, args))); } catch (Exception e) { Logger.Error("Failed to execute DB execute!", e); return(-1); } }
public int InsertAll(IEnumerable <object> objects, bool runInTransaction = true) { try { return(SharedUtils.RetryOnException(() => DB_CONNECTIONS[DB_PATH].Item3.InsertAll(objects))); } catch (Exception e) { Logger.Error("Failed to execute DB insert all!", e); return(-1); } }
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\ #region --Set-, Get- Methods-- #endregion //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\ #region --Misc Methods (Public)-- public SQLiteCommand CreateCommand(string cmdText, params object[] args) { return(SharedUtils.RetryOnException(() => DB_CONNECTIONS[DB_PATH].Item3.CreateCommand(cmdText, args))); }
public CreateTableResult RecreateTable <T>() where T : new() { SharedUtils.RetryOnException(() => DB_CONNECTIONS[DB_PATH].Item3.DropTable <T>()); return(SharedUtils.RetryOnException(() => DB_CONNECTIONS[DB_PATH].Item3.CreateTable <T>())); }
public int DropTable <T>() where T : new() { return(SharedUtils.RetryOnException(() => DB_CONNECTIONS[DB_PATH].Item3.DropTable <T>())); }