public void PutMany(IEnumerable <KeyValuePair <TKey, TValue> > values) { ThrowIfReadOnly(); ThrowIfDropped(); if (values == null) { throw new ArgumentNullException(nameof(values)); } using (var transaction = _connection.BeginTransaction()) using (var command = _connection.CreateCommand()) { command.CommandText = _putQuery; var keyParameter = command.Parameters.Add("@key", _keySerializer.DatabaseType); var valueParameter = command.Parameters.Add("@value", _valueSerializer.DatabaseType); foreach (var pair in values) { if (pair.Key == null) { throw new ArgumentException("Null keys cannot be added to this collection"); } keyParameter.Value = _keySerializer.Serialize(pair.Key); valueParameter.Value = _valueSerializer.Serialize(pair.Value); command.ExecuteNonQuery(); } transaction.Commit(); } }
public void Enqueue(T value) { ThrowIfReadOnly(); ThrowIfDropped(); using (var command = _connection.CreateCommand()) { command.CommandText = _put; command.Parameters.AddWithValue("@value", _serializer.Serialize(value)); command.ExecuteNonQuery(); } }
public RowId Put(T value) { ThrowIfReadOnly(); ThrowIfDropped(); using (var command = _connection.CreateCommand()) { command.CommandText = _put; command.Parameters.AddWithValue("@value", _serializer.Serialize(value)); command.ExecuteNonQuery(); return(new RowId(_connection.LastInsertRowId)); } }
public void Put(TKey key, TValue value) { ThrowIfReadOnly(); ThrowIfDropped(); using (var command = _connection.CreateCommand()) { command.CommandText = string.Format("INSERT OR REPLACE INTO {0} (key, value) VALUES (@key, @value)", _tableName); command.Parameters.AddWithValue("@key", _keySerializer.Serialize(key)); command.Parameters.AddWithValue("@value", _valueSerializer.Serialize(value)); command.ExecuteNonQuery(); } }
public RowId Put(Point2D key, TValue value) { ThrowIfReadOnly(); ThrowIfDropped(); using (var command = _connection.CreateCommand()) { command.CommandText = _putQuery; command.Parameters.AddWithValue("@x", key.X); command.Parameters.AddWithValue("@y", key.Y); command.Parameters.AddWithValue("@value", _valueSerializer.Serialize(value)); command.ExecuteNonQuery(); var id = _connection.LastInsertRowId; return(new RowId(id)); } }
public bool Add(T value) { ThrowIfReadOnly(); ThrowIfDropped(); if (value == null) { throw new ArgumentNullException(nameof(value)); } using (var command = _connection.CreateCommand()) { command.CommandText = string.Format("INSERT OR IGNORE INTO {0} (value) VALUES (@value)", _tableName); command.Parameters.AddWithValue("@value", _serializer.Serialize(value)); int numRowsAffected = command.ExecuteNonQuery(); return(numRowsAffected > 0); } }
public void Put(Interval <TKey> interval, TValue value) { ThrowIfReadOnly(); ThrowIfDropped(); using (var command = _connection.CreateCommand()) { var id = Interlocked.Increment(ref _lastId); command.CommandText = string.Format("INSERT INTO {0} (id, minimum, maximum, value) VALUES (@id, @minimum, @maximum, @value)", _tableName); command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@minimum", _keySerializer.Serialize(interval.Minimum)); command.Parameters.AddWithValue("@maximum", _keySerializer.Serialize(interval.Maximum)); command.Parameters.AddWithValue("@value", _valueSerializer.Serialize(value)); command.ExecuteNonQuery(); } }
public RowId Put(TKey key, TValue value) { ThrowIfReadOnly(); ThrowIfDropped(); if (key == null) { throw new ArgumentNullException(nameof(key)); } using (var command = _connection.CreateCommand()) { command.CommandText = _putQuery; command.Parameters.AddWithValue("@key", _keySerializer.Serialize(key)); command.Parameters.AddWithValue("@value", _valueSerializer.Serialize(value)); command.ExecuteNonQuery(); var id = _connection.LastInsertRowId; return(new RowId(id)); } }
public bool ContainsKey(TKey key) { ThrowIfDropped(); if (key == null) { throw new ArgumentNullException(nameof(key)); } using (var command = _connection.CreateCommand()) { command.CommandText = _existsQuery; command.Parameters.AddWithValue("@key", _keySerializer.Serialize(key)); var value = Convert.ToInt64(command.ExecuteScalar()); return(value != 0); } }