Issue
I have an in-memory SQLite DB and created a row with an ID, username and password in runtime. That insert returns 1.
Afterwards I run the following function to check the user credentials of the created user with those that are in the input fields, which are the exact same credentials used for the created user above. (basically, I check if the user is already existing, if not, I use the credentials entered to create the user and instantly check to authenticate the login)
The getCount at the end always returns 0 and I don't know why. Debugger shows the correct credentials for username and password, and I'm starting to run out of time... Final exam project...
public boolean checkUser(String username, String password) {
String[] columns = new String[]{
COL_USERNAME,
COL_PASSWORD
};
SQLiteDatabase db = this.getReadableDatabase();
String selection = COL_USERNAME + " = ?" + " AND " + COL_PASSWORD + " = ?";
String[] selectionArgs = {username, password};
Cursor c = db.query(
T_USER,
columns,
selection,
selectionArgs,
null,
null,
null);
int cursorCount = c.getCount();
c.close();
db.close();
if (cursorCount > 0) {
return true;
}
return false;
}
Solution
In-memory database is alive only as long you have the database open. Either switch to a file-based database, or keep one reference to the SQLiteDatabase around without calling close() on it.
Answered By - laalto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.