I got a little problem with my SQLite database in my app.
My goal is to insert a row into my database if it’s not exist, otherwise to update the row.
How can I check if the row with the given condition exists?
I tried:
Cursor cursor = dbAdapter.query(dbName, null, "xcoord="+xcoord+" AND ycoord="+ycoord+" AND mac='"+mac+"'"+" AND ssid='"+ssid+"'", null, null, null, null);
cursor.isNull(cursor.getColumnIndex("ssid"));
and then to check if the cursor is null? But so I got this SQLException:
FATAL EXCEPTION: main
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
Thanks for help.
Before working with a cursor in anyway I always do an
if (cursor != null && cursor.moveToFirst())If that evaluates to false, you either don’t have a table, or you don’t have a record.