private static void ClearDB(DbInfo dbInfo) { using (var connection = GetDbConnection(dbInfo)) { (new SQLiteCommand($"delete from {dbInfo.tableName}", connection)).ExecuteNonQuery(); } }
internal static SQLiteConnection GetDbConnection(DbInfo dbInfo) { var connection = new SQLiteConnection($"Data Source={dbInfo.fileName};Version=3;"); connection.Open(); return(connection); }
private static int CreateDatabase(DbInfo dbInfo) { using (var connection = GetDbConnection(dbInfo)) { // -1 if table already existed, 0 if it was created return((new SQLiteCommand(dbInfo.createTableTemplate, connection)).ExecuteNonQuery());; } }
internal static int DbRowCount(DbInfo dbInfo) { using (var connection = GetDbConnection(dbInfo)) { var command = new SQLiteCommand($"select count(@column) from {dbInfo.tableName}", connection); command.Parameters.AddWithValue("@column", dbInfo.mainColumn); return(Convert.ToInt32(command.ExecuteScalar())); } }
internal static bool RemoveFromDb(string itemIdentifier, DbInfo dbInfo) { using (var connection = GetDbConnection(dbInfo)) { var command = new SQLiteCommand($"delete from {dbInfo.tableName} where {dbInfo.mainColumn} == @item", connection); command.Parameters.AddWithValue("@item", itemIdentifier); return(Convert.ToBoolean(command.ExecuteNonQuery())); } }