Example #1
0
        public IEnumerable <SavedSource> GetSources(SourceOrder order = SourceOrder.None)
        {
            const string defaultCommand = "SELECT * FROM program";
            string       commandOrder;

            var conn = Connect();

            using var command = conn.CreateCommand();
            if (order == SourceOrder.None)
            {
                commandOrder = "ORDER BY priority desc, id";
            }
            else if (order == SourceOrder.Reverse)
            {
                commandOrder = "ORDER BY priority desc, id desc";
            }
            else
            {
                throw new InvalidEnumArgumentException(nameof(order), (int)order, typeof(SourceOrder));
            }
            command.CommandText = $"{defaultCommand} {commandOrder}";
            using var reader    = command.ExecuteReader();
            while (reader.Read())
            {
                yield return(SavedSource.FromReader(reader));
            }
        }
Example #2
0
        public SavedSource?GetSourceById(int id)
        {
            var conn = Connect();

            using var command   = conn.CreateCommand();
            command.CommandText = "SELECT * FROM program WHERE id = @id";
            command.Parameters.Add(new SQLiteParameter("@id", id));

            using var reader = command.ExecuteReader();
            return(reader.Read() ? SavedSource.FromReader(reader) : null);
        }
Example #3
0
        public IEnumerable <SavedSource> GetSourcesByUrl(string url)
        {
            var conn = Connect();

            using var command   = conn.CreateCommand();
            command.CommandText = "SELECT * FROM program WHERE TaskUrl = @url";
            command.Parameters.Add(new SQLiteParameter("@url", url));

            using var reader = command.ExecuteReader();
            while (reader.Read())
            {
                yield return(SavedSource.FromReader(reader));
            }
        }