Not so difficult question, however i cant find ant half-decent documentation onto it. Right so I have produced my SQLite db however it has two problems a treadmill depending how your perception! The db produces fine and that i can display the information inside a fundamental listview, however on altering the orientation from the phone/emulator the place claims run again and duplicate all of the records. Im speculating it has something related to all of the code being placed inside the OnCreate() method. My primary question however is how you can do Place UNIQUE or query the db to ascertain if the record is available? I simply may find worthwhile documentation on SQLite DB parameters around the Android platform.
Any assistance is much obliged !
SQLite comes with an
INSERT OR REPLACE command (
REPLACE for brief, or use
SQLiteDatabase.replace()) that may do what you would like.
However I'd claim that the application should not be re-placing in to the database each time your Activity is produced unless of course it truly must, so you might like to consider altering the look.
You need to take advantage from the DatabaseUtils.stringForQuery() static method that's already in Android SDK to simply retrieve something, this situation is perfect for
String bot there's also way of
stringForQuery(SQLiteDatabase db, String query, String selectionArgs)
Utility approach to run the query around the db and return the worthiness within the first column from the first row.
Something similar to
This situation was to obtain a string value, but it is simple to adapt to obtain a
Long value, as well as your query ought to be something similar to
select count(*) from mytable where field1='stringtocheckagainst'
if the returns several more zero, then your area already is available within the database.
Also consider code to handle orientation changes.
One factor is you have to handle your orientation change problem, to gain access to db on every orientation change consumes a great deal.
Second factor, concerning the check duplicate record problem, you are able to define the column as unique like create table table_title(column_definition, unique(column_names) on conflict replace) you'll be able to perform place as always, the db would ensure no duplicate.