:I have this table:
id | name | chapter | book
1 hamlet I Hamlet
2 Ismael IV Moby Dick
The behaviour I expect for new values is:
Same name && same book => Character exists so Same id than the existing one:
2 Ismael X Moby Dick
Same name && different book => Character doesn’t exist so Changes the id:
3 Ismael XX The Bible
My question is:
Do I have to make the query before insert new values and then insert the new value?
or there is a way to do it in a automatic way by setting up a trigger or something?
My CREATE TABLE statement
db.execSQL("CREATE TABLE characters (id INTEGER NOT NULL ,
name TEXT NOT NULL , chapter TEXT NOT NULL , book TEXT NOT NULL );");
I think the most elegant way of doing so would be for you to isolate the properties of your rows which permit to identify them UNIQUELY. Lets say for instance that name + book make the line unique, then you could concatenate these strings into one identifier in your object, add a column to your database, put and index on it and search on this index when you want to insert new elements.