Beispiel #1
0
 private static void ClearDB(DbInfo dbInfo)
 {
     using (var connection = GetDbConnection(dbInfo))
     {
         (new SQLiteCommand($"delete from {dbInfo.tableName}", connection)).ExecuteNonQuery();
     }
 }
Beispiel #2
0
        internal static SQLiteConnection GetDbConnection(DbInfo dbInfo)
        {
            var connection = new SQLiteConnection($"Data Source={dbInfo.fileName};Version=3;");

            connection.Open();
            return(connection);
        }
Beispiel #3
0
 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());;
     }
 }
Beispiel #4
0
 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()));
     }
 }
Beispiel #5
0
 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()));
     }
 }