public int ExecuteNonQuery(object [] source) { if (Initialized && Statement == NullStatement) { throw new ObjectDisposedException(nameof(PreparedSqlLiteInsertCommand)); } if (Connection.Trace) { Connection.Tracer?.Invoke("Executing: " + CommandText); } var r = Result.OK; if (!Initialized) { Statement = SQLite3.Prepare2(Connection.Handle, CommandText); Initialized = true; } //bind the values. if (source != null) { for (int i = 0; i < source.Length; i++) { SQLiteCommand.BindParameter(Statement, i + 1, source [i], Connection.StoreDateTimeAsTicks, Connection.DateTimeStringFormat, Connection.StoreTimeSpanAsTicks); } } r = SQLite3.Step(Statement); if (r == Result.Done) { int rowsAffected = SQLite3.Changes(Connection.Handle); SQLite3.Reset(Statement); return(rowsAffected); } else if (r == Result.Error) { string msg = SQLite3.GetErrmsg(Connection.Handle); SQLite3.Reset(Statement); throw SQLiteException.New(r, msg); } else if (r == Result.Constraint && SQLite3.ExtendedErrCode(Connection.Handle) == ExtendedResult.ConstraintNotNull) { SQLite3.Reset(Statement); throw NotNullConstraintViolationException.New(r, SQLite3.GetErrmsg(Connection.Handle)); } else { SQLite3.Reset(Statement); throw SQLiteException.New(r, r.ToString()); } }
public static Sqlite3Statement Prepare2(Sqlite3DatabaseHandle db, string query) { Sqlite3Statement stmt = default(Sqlite3Statement); stmt = new Sqlite3Statement(); var r = Sqlite3.sqlite3_prepare_v2(db, query, -1, ref stmt, 0); if (r != 0) { throw SQLiteException.New((Result)r, GetErrmsg(db)); } return(stmt); }
public static NotNullConstraintViolationException New(SQLiteException exception, TableMapping mapping, object obj) { return(new NotNullConstraintViolationException(exception.Result, exception.Message, mapping, obj)); }