Reputation: 89
I have trouble with SQLite error: Caused by:
android.database.sqlite.SQLiteException: no such column: ٢٠٦٦١٤٨ (code 1): , while compiling: UPDATE History SET unreadNum=? WHERE senderId = ٢٠٦٦١٤٨
And my code is:
public void resetHistoryMessageUnreadNum(Integer senderID) {
openWrite();
ContentValues result = new ContentValues();
result.put(COLUMN_HISTORY_UNREAD_NUM, 0);
String whereClause = String.format("%s = %d", COLUMN_HISTORY_SENDER_ID,
senderID);
database.update(TABLE_HISTORY, result, whereClause, null);
database.close();
}
I dont know what is "٢٠٦٦١٤٨" and why does it appear? But i use google translate: ٢٠٦٦١٤٨ = 2066148. 2066148 is my senderID. How to fix it? Thanks in advance.
Upvotes: 0
Views: 92
Reputation: 89
Yes. DON'T USE STRING.FORMAT IN SQL STATEMENT.
I use
database.update(TABLE_HISTORY, result, COLUMN_HISTORY_SENDER_ID
+ " = ?", new String[] { String.valueOf(senderID) });
It work perfect!
Upvotes: 0
Reputation: 180070
String.format
uses the user's default locale, which might not be appropriate for SQL (as you've seen).
Either specify a proper locale explicitly:
whereClause = String.format(Locale.US, "%s = %d", COLUMN_HISTORY_SENDER_ID, senderID);
or don't use format
:
whereClause = COLUMN_HISTORY_SENDER_ID + " = " + senderID;
Upvotes: 2