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); }
public void EnableLoadExtension(int onoff) { SQLite3.Result r = SQLite3.EnableLoadExtension(Handle, onoff); if (r != SQLite3.Result.OK) { string msg = SQLite3.GetErrmsg(Handle); throw SQLiteException.New(r, msg); } }
public void Close() { if (_open && Handle != NullHandle) { try { var r = SQLite3.Close(Handle); if (r != SQLite3.Result.OK) { string msg = SQLite3.GetErrmsg(Handle); throw SQLiteException.New(r, msg); } } finally { Handle = NullHandle; _open = false; } } }