PROBLEM BACKGROUND: I have two tables where the Primary Key's are Text fields.
When I repeatedly use SQLiteDatabase.insertWithOnConflict(myTable, null, myValues, SQLiteDatabase.CONFLICT_REPLACE)
with the same data, I see ever increasing values being returned.
So it looks like INSERT is being performed (instead of REPLACE) for the same data sets.
PROBLEM: However, looking at these tables with "SQLite Database Browser" I see the correct number of records that I'd expect when REPLACE is performed.
The root to my confusion is the description Android documentation that states : *Returns the row ID of the newly inserted row OR the primary key of the existing row if the input param 'conflictAlgorithm' = CONFLICT_IGNORE OR -1 if any error*
QUESTION: Why is it that a REPLACE is done, but the row ID of the existing data isn't returned ?
Important Methods in SQLite DatabaseThis method will return the number of rows in the cursor. This method returns a Boolean value when our cursor is closed. This method returns the total number of columns present in our table. This method will return the name of the column when we passed the index of our column in it.
How to check whether the value is inserted or not in Android? if inserted==true return true; else return false; This is my code: SQLiteDatabase db = this.
SQLite is an open-source relational database i.e. used to perform database operations on android devices such as storing, manipulating or retrieving persistent data from the database. It is embedded in android bydefault. So, there is no need to perform any database setup or administration task.
Android SQLite is the most preferred method of storing data in any android applications. Android SQLite is a relational database, therefore, It supports all types of relational database features.
Seems to me like it is doing exactly what you are asking it to? You are asking it to replace and it does exactly that. It will remove the old row and insert the new one.
It would leave the old row and return that ID if you instead passed CONFLICT_IGNORE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With