コード例 #1
0
 public void Insert(SimpleWithPrimary entry)
 {
     using SqliteCommand command = this.connection.CreateCommand();
     command.CommandText         = @"INSERT INTO SimpleWithPrimary (Id, StringProperty) VALUES (@id, @stringProperty);";
     command.Parameters.Add(new SqliteParameter("@id", entry.Id));
     command.Parameters.Add(new SqliteParameter("@stringProperty", entry.StringProperty ?? (object)DBNull.Value));
     command.ExecuteNonQuery();
 }
コード例 #2
0
        public void Delete(SimpleWithPrimary entry)
        {
            using SqliteCommand command = this.connection.CreateCommand();
            command.CommandText         = @"
DELETE FROM SimpleWithPrimary
WHERE Id = @id";
            command.Parameters.Add(new SqliteParameter("@id", entry.Id));
            command.ExecuteNonQuery();
        }
コード例 #3
0
        public void Update(SimpleWithPrimary entry)
        {
            using SqliteCommand command = this.connection.CreateCommand();
            command.CommandText         = @"
UPDATE SimpleWithPrimary
SET StringProperty = @stringProperty
WHERE Id = @id";
            command.Parameters.Add(new SqliteParameter("@id", entry.Id));
            command.Parameters.Add(new SqliteParameter("@stringProperty", entry.StringProperty ?? (object)DBNull.Value));
            command.ExecuteNonQuery();
        }
コード例 #4
0
        public List <SimpleWithPrimary> Get(string filter = null)
        {
            using SqliteCommand command = this.connection.CreateCommand();
            command.CommandText         = @"
SELECT Id, StringProperty
FROM SimpleWithPrimary";
            List <SimpleWithPrimary> result = new List <SimpleWithPrimary>();

            if (!string.IsNullOrEmpty(filter))
            {
                command.CommandText += "\nWHERE " + filter;
            }
            using SqliteDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                SimpleWithPrimary entry = new SimpleWithPrimary();
                entry.Id             = reader.GetInt32(0);
                entry.StringProperty = reader.IsDBNull(1) ? null : reader.GetString(1);
                result.Add(entry);
            }
            return(result);
        }