I am trying to update my SQLite database through this method in my SQLiteHelper class and I am getting the error:
android.database.sqlite.SQLiteException: unrecognized token: "55c7e253afcf48" (code 1): , while compiling: UPDATE login SET user_group=? WHERE uid=55c7e253afcf48.85187730
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
The uid is correct other than the extra ".85187730" at the end... I'm not sure what those numbers mean. Here is my update method:
//updating sqlite database with the group name
public void updateUserGroup(String groupName) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_GROUP, groupName);
HashMap<String, String> user = getUserDetails();
String userID = user.get("uid");
System.out.println("User id is: " + userID);
db.update(TABLE_LOGIN, values, SQLiteHandler.KEY_UID + "=" + "userID", null);
}
/**
* Getting user data from database
* */
public HashMap<String, String> getUserDetails() {
HashMap<String, String> user = new HashMap<String, String>();
String selectQuery = "SELECT * FROM " + TABLE_LOGIN;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
if (cursor.getCount() > 0) {
user.put("name", cursor.getString(1));
user.put("email", cursor.getString(2));
user.put("user_group", cursor.getString(3));
user.put("uid", cursor.getString(4));
user.put("created_at", cursor.getString(5));
}
cursor.close();
//db.close();
// return user
Log.d(TAG, "Fetching user from Sqlite: " + user.toString());
return user;
}
Any help is appreciated.
You've missed quotation marks around your uid
.
You should pass every string as below to avoid errors.
UPDATE login SET user_group=? WHERE uid="55c7e253afcf48.85187730"
and in your case query will be like
HashMap<String, String> user = getUserDetails();
String userID = user.get("uid");
db.update(TABLE_LOGIN, values, SQLiteHandler.KEY_UID + "=\"" + userID + "\"", null);
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