Trying to get the value of the “value” column where the “option” column is = “lastclick” in sqlite for my android app.
Here is my code for the function:
public String getLastClick() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT value FROM config where option='lastclick'", null);
cursor.moveToFirst();
return cursor.getString(0);
}
It does not seem to be working correctly… I am using the following code for a conditional statement and it doesn’t ever recognize the string as being 0 even when I first install the app on the VD, my onCreate function inserts a row with a “lastclick” value of “0” into the database.
Anyway here is that code:
DatabaseHandler db = new DatabaseHandler(this);
String lastClick = db.getLastClick();
// check if its the first time they've ever clicked
if (lastClick != "0") {
String millis = String.valueOf(Long.parseLong(dateString) - Long.parseLong(lastClick));
db.insertRecord(millis);
}
“option” and “value” are both varchar’s.
The correct way to compare
Stringsis to use theequalsmethod, so instead of :write: