public T ExecuteScalar <T> () { if (_conn.Trace) { Debug.WriteLine("Executing Query: " + this); } T val = default(T); var stmt = Prepare(); if (SQLite3.Step(stmt) == SQLite3.Result.Row) { var colType = SQLite3.ColumnType(stmt, 0); val = (T)ReadCol(stmt, 0, colType, typeof(T)); } Finalize(stmt); return(val); }
public IEnumerable <T> ExecuteDeferredQuery <T> (TableMapping map) { if (_conn.Trace) { Debug.WriteLine("Executing Query: " + this); } var stmt = Prepare(); try { var cols = new TableMapping.Column[SQLite3.ColumnCount(stmt)]; for (int i = 0; i < cols.Length; i++) { var name = SQLite3.ColumnName16(stmt, i); cols [i] = map.FindColumn(name); } while (SQLite3.Step(stmt) == SQLite3.Result.Row) { var obj = Activator.CreateInstance(map.MappedType); for (int i = 0; i < cols.Length; i++) { if (cols [i] == null) { continue; } var colType = SQLite3.ColumnType(stmt, i); var val = ReadCol(stmt, i, colType, cols [i].ColumnType); cols [i].SetValue(obj, val); } OnInstanceCreated(obj); yield return((T)obj); } } finally { SQLite3.Finalize(stmt); } }