Esempio n. 1
0
        public static void InsertFileHMAC(FileHmac file)
        {
            string value = string.Empty;

            using var connection = new SQLiteConnection(connectionString);

            string sqlS = "select " + FILEHMAC_PATH + " FROM " + TABLE_FILEHMAC + " WHERE " + FILEHMAC_PATH + " = @path";

            connection.Open();
            using (var selectSQL = new SQLiteCommand(sqlS, connection))
            {
                selectSQL.Parameters.AddWithValue("@path", file.path);

                using (var rd = selectSQL.ExecuteReader())
                {
                    try
                    {
                        while (rd.Read())
                        {
                            value = (string)rd[FILEHMAC_PATH];
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
            connection.Close();


            if (value != file.path)
            {
                string sql = "INSERT INTO " + TABLE_FILEHMAC + " ( " + FILEHMAC_PATH + " , " + FILEHMAC_HMAC + " ,  " + FILEHMAC_DIR + " ) VALUES (@Path, @Hmac, @Dir)";

                connection.Open();
                using (var insertSQL = new SQLiteCommand(sql, connection))
                {
                    insertSQL.Parameters.AddWithValue("@Path", file.path);
                    insertSQL.Parameters.AddWithValue("@Hmac", file.hmac);
                    insertSQL.Parameters.AddWithValue("@Dir", file.dir);

                    insertSQL.ExecuteNonQuery();
                }
            }
        }
Esempio n. 2
0
        public static int DeleteFileHMAC(FileHmac file)
        {
            using var connection = new SQLiteConnection(connectionString);

            string sql = "DELETE FROM " + TABLE_FILEHMAC + " WHERE " + FILEHMAC_PATH + " = @Path";

            connection.Open();
            using (var updateSQL = new SQLiteCommand(sql, connection))
            {
                updateSQL.Parameters.AddWithValue("@Path", file.path);

                try
                {
                    return(updateSQL.ExecuteNonQuery());
                }
                catch (Exception e)
                {
                    throw new Exception(e.ToString());
                }
            }
        }