It's an update. The Java code for my DataAccessor (a lightweight wrapper over Android's wrapper over SQLite) checks the ID. If the ID is set to -1, it's an insert, otherwise it's an update.
A Word (word2) has been previously saved, and its ID has been saved to word2Id. The test code is doing this: Word differentTextWord = new Word(); differentTextWord.setId(word2Id); <<< reuse existing ID differentTextWord.setText(word2.getText() + "_different"); boolean caughtExpectedException = false; try { dataAccessor.saveWord(differentTextWord); } catch (SQLiteConstraintException e) { caughtExpectedException = true; } assertTrue(caughtExpectedException); <<<< this fails I don't know how to test this with the SQLite console, because it's actually running on the Android emulator. ----- Original Message ----- From: "Simon Slavin" <slav...@hearsay.demon.co.uk> To: "General Discussion of SQLite Database" <sqlite-users@sqlite.org> Sent: Friday, July 17, 2009 11:00 PM Subject: Re: [sqlite] Problem getting trigger to work > > On 18 Jul 2009, at 4:32am, Jim Showalter wrote: > >> create table words >> ( >> _id integer primary key autoincrement, >> wordText text not null unique >> ); >> >> I have triggers that work, which I got from >> http://www.sqlite.org/cvstrac/wiki?p=ForeignKeyTriggers. >> >> Now I'm trying to modify the update trigger to prevent saving a >> word >> with the same ID but different text: >> >> create trigger ut_words_cannotChangeWordTextOnUpdate >> before update on words >> for each row >> begin >> select raise( >> rollback, >> 'update on table WORDS violates constraint >> ut_words_cannotChangeWordTextOnUpdate') >> where OLD.wordText <> NEW.wordText; >> end; > > What command are you using to make the modification ? Is it an > INSERT > or an UPDATE ? > > Have you tried executing the appropriate command in the sqlite3 > command-line application ? > > Simon. > _______________________________________________ > 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