A
A
Alexey Grichenko2011-05-13 05:55:17
Android
Alexey Grichenko, 2011-05-13 05:55:17

Android SQLiteDatabase - incorrect insertWithOnConflict result?

And again I have a question about android. I'm trying to fill a small base. There is a simple table like (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, UNIQUE (name) ON CONFLICT IGNORE). I checked in the usual sqlite3 - everything works as it should, no duplicates are inserted.

In android I am trying to execute insertWithOnConflict(... INGORE) to either insert a new record or get the number of an existing one. But the method returns completely left numbers (looks like the nearest free key, but not sure). In this case, there is no real insertion. I end up with a key that is not only useless, but also harmful - I'm never sure if it really refers to any record.

Am I doing something wrong or is there a glitch in the API? Google on this topic says a little, but there are mentions of a glitch. Well, this is some kind of shame ... And what should I do with it now? Of course, you can first make a select, but you really don’t want to - it will slow down. :(

PS And in order not to get up twice: is it possible to make a prepared select in android? So far I have found only SQLiteStatement, but it doesn’t seem to be suitable for sampling. Or will I have to parse the query again every time?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question