However, calling insertOrThrow raises SQLiteConstraintException, which does not contain the text of the raise specified in the schema. Instead, it just has: error code 19: constraint failed
Is there any way to get SQLite to honor the message in the raise in the schema definition? ----- Original Message ----- From: "Jim Showalter" <j...@jimandlisa.com> To: "General Discussion of SQLite Database" <sqlite-users@sqlite.org> Sent: Sunday, July 12, 2009 6:10 PM Subject: Re: [sqlite] Raise is not working > Nevermind--for whatever reason, Google saw fit to do this: > > /** > * Convenience method for inserting a row into the database. > * > * @param table the table to insert the row into > * @param nullColumnHack SQL doesn't allow inserting a completely > empty row, > * so if initialValues is empty this column will > explicitly be > * assigned a NULL value > * @param values this map contains the initial column values for > the > * row. The keys should be the column names and the > values the > * column values > * @return the row ID of the newly inserted row, or -1 if an > error > occurred > */ > public long insert(String table, String nullColumnHack, > ContentValues values) { > try { > return insertWithOnConflict(table, nullColumnHack, > values, > null); > } catch (SQLException e) { > Log.e(TAG, "Error inserting " + values, e); > return -1; > } > } > ----- Original Message ----- > From: "Jim Showalter" <j...@jimandlisa.com> > To: "General Discussion of SQLite Database" > <sqlite-users@sqlite.org> > Sent: Sunday, July 12, 2009 6:03 PM > Subject: [sqlite] Raise is not working > > >> Schema: >> >> create table words (_id integer primary key autoincrement, wordtext >> text not null unique); >> >> create table definitions (_id integer primary key autoincrement, >> owningWordId integer not null unique, deftext text not null); >> >> create trigger fki_definitions_words_id before insert on >> definitions >> for each row >> begin >> select raise (rollback, 'insert on table definitions violates >> foreign-key constraint fki_definitions_words_id') >> where (select _id from words where _id = NEW.owningWordId ) is >> null; >> >> end; >> >> Call db.insert, passing it a definition that has the owningWordId >> set >> to -1, and the insert returns a -1 instead of throwing. >> >> Because it doesn't throw, I don't have the error message "insert on >> table definitions violates foreign-key constraint >> fki_definitions_words_id" to work from. Information is simply lost. >> >> Why isn't it raising an exception? >> >> _______________________________________________ >> sqlite-users mailing list >> sqlite-users@sqlite.org >> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users