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

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