public void Insert( SqliteDatabase database, IEnumerable <T> records, ConflictResolution conflictResolution = ConflictResolution.Default) { int count = 0; var recordBuffer = new T[database.VariableLimit / _properties.Length]; var sql = InsertSql(recordBuffer.Length, conflictResolution); var statement = database.Prepare(sql); try { foreach (var record in records) { recordBuffer[count++] = record; if (count == recordBuffer.Length) { InsertAll(); count = 0; } } if (count > 0) { statement.Dispose(); sql = InsertSql(count, conflictResolution); statement = database.Prepare(sql); InsertAll(); } } finally { statement?.Dispose(); } void InsertAll() { int n = 0; for (int i = 0; i < count; ++i) { foreach (var property in _properties) { property.PropertyHandler.BindRecord(statement, ++n, recordBuffer[i]); } } statement.Execute(); } }
public SqliteTableInsert( SqliteTable <T> table, SqliteDatabase database, ConflictResolution conflictResolution = ConflictResolution.Default) { _table = table; var sql = table.InsertSql(1, conflictResolution); _statement = database.Prepare(sql); }
public bool Exists(SqliteDatabase database) { string sql = "SELECT 1 FROM sqlite_master WHERE type='table' AND name=?"; using (var statement = database.Prepare(sql)) { statement.BindText(1, TableName); using (var reader = statement.GetReader()) return(reader.TryRead()); } }
public void Insert( SqliteDatabase database, T record, ConflictResolution conflictResolution = ConflictResolution.Default) { var sql = InsertSql(1, conflictResolution); using (var statement = database.Prepare(sql)) { for (int i = 0; i < _properties.Length; ++i) { _properties[i].PropertyHandler.BindRecord(statement, i + 1, record); } statement.Execute(); } }
public void InsertWithTransaction( SqliteDatabase database, IEnumerable <T> records, ConflictResolution conflictResolution = ConflictResolution.Default) { using (var transaction = new SqliteTransaction(database)) { var sql = InsertSql(1, conflictResolution); using (var statement = database.Prepare(sql)) { foreach (var record in records) { for (int i = 0; i < _properties.Length; ++i) { _properties[i].PropertyHandler.BindRecord(statement, i + 1, record); } statement.Execute(); } } transaction.Commit(); } }