public int ExecuteNonQuery() { if (_conn.Trace) { Debug.WriteLine("Executing: " + this); } var r = SQLite3.Result.OK; var stmt = Prepare(); r = SQLite3.Step(stmt); Finalize(stmt); if (r == SQLite3.Result.Done) { int rowsAffected = SQLite3.Changes(_conn.Handle); return(rowsAffected); } else if (r == SQLite3.Result.Error) { string msg = SQLite3.GetErrmsg(_conn.Handle); throw SQLiteException.New(r, msg); } else if (r == SQLite3.Result.Constraint) { if (SQLite3.ExtendedErrCode(_conn.Handle) == SQLite3.ExtendedResult.ConstraintNotNull) { throw NotNullConstraintViolationException.New(r, SQLite3.GetErrmsg(_conn.Handle)); } } throw SQLiteException.New(r, r.ToString()); }
internal T ExecuteScalar <T>() { if (_conn.Trace) { Debug.WriteLine("Executing Query: " + this); } T val = default(T); var stmt = Prepare(); try { var r = SQLite3.Step(stmt); if (r == SQLite3.Result.Row) { var colType = SQLite3.ColumnType(stmt, 0); val = (T)ReadCol(stmt, 0, colType, typeof(T)); } else if (r == SQLite3.Result.Done) { } else { throw SQLiteException.New(r, SQLite3.GetErrmsg(_conn.Handle)); } } finally { Finalize(stmt); } return(val); }
internal IEnumerable <T> ExecuteDeferredQuery <T>() where T : IDictionary <string, object> { if (_conn.Trace) { Debug.WriteLine("Executing Query: " + this); } var stmt = Prepare(); try { var cols = new TableMapping.Column[SQLite3.ColumnCount(stmt)]; // We have a valid row, get the correct datatypes and columns if (SQLite3.Step(stmt) == SQLite3.Result.Row) { for (int i = 0; i < cols.Length; i++) { var name = SQLite3.ColumnName16(stmt, i); cols[i] = new TableMapping.Column(name, SQLiteTypeConverter.convertTypeToCLRType(SQLite3.ColumnType(stmt, i))); } } else { yield break; } do { IDictionary <string, object> obj = new Dictionary <string, object>(); 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); } yield return((T)obj); } while (SQLite3.Step(stmt) == SQLite3.Result.Row); } finally { SQLite3.Finalize(stmt); } }