Пример #1
0
        public static void SaveOrUpdate(VolumeEntry volumeEntry)
        {
            if (volumeEntry == null)
            {
                throw new ArgumentNullException("volumeEntry");
            }

            using (var cmd = db.CreateCommand())
            {
                cmd.CommandText = (volumeEntry.VolumeId > 0)
                                                                        ? "UPDATE volumes SET volumeServerId=?, volumeUsername=?, volumeGain=? WHERE volumeId=?"
                                                                        : "INSERT INTO volumes (volumeServerId,volumeUsername,volumeGain) VALUES (?,?,?)";

                cmd.Parameters.Add(new SQLiteParameter("serverId", volumeEntry.ServerId));
                cmd.Parameters.Add(new SQLiteParameter("username", volumeEntry.Username));
                cmd.Parameters.Add(new SQLiteParameter("gain", volumeEntry.Gain));

                if (volumeEntry.VolumeId > 0)
                {
                    cmd.Parameters.Add(new SQLiteParameter("id", volumeEntry.VolumeId));
                }

                cmd.ExecuteNonQuery();
            }
        }
Пример #2
0
        public static void Delete(VolumeEntry volumeEntry)
        {
            if (volumeEntry == null)
            {
                throw new ArgumentNullException("volumeEntry");
            }
            if (volumeEntry.VolumeId < 1)
            {
                throw new ArgumentException("Can't delete a non-existent server", "volumeEntry");
            }

            using (var cmd = db.CreateCommand("DELETE FROM volumes WHERE (volumeId=?)"))
            {
                cmd.Parameters.Add(new SQLiteParameter("id", volumeEntry.VolumeId));
                cmd.ExecuteNonQuery();
            }
        }