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

            connection.Open();
            return(connection);
        }
Esempio n. 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());;
     }
 }
Esempio n. 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()));
     }
 }
Esempio n. 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()));
     }
 }