尝试使用whereClause:
更新匹配的行时出现以下错误android.database.sqlite.SQLiteException: near "AS": syntax error (code 1): ,
while compiling:
UPDATE messages SET message=? WHERE (user_id = ? ) AND (message = ? ) AND (time = ? AS long) AND (chat_with_user_id = ? ) AND (from_me = ? AS integer ) AND (user_full_name = ? )
我正在使用的代码是 :
int fromMeInt = 0;
if (fromMe) {
fromMeInt = 1;
}
ContentValues dataToInsert = new ContentValues();
dataToInsert.put(SQLiteHelper.COLUMN_MESSAGE, urlFileName);
String userId ="("+ SQLiteHelper.COLUMN_USER_ID+" = ? )";
String message ="("+ SQLiteHelper.COLUMN_MESSAGE+" = ? )";
String time = "("+SQLiteHelper.COLUMN_TIME_STAMP+" = ? AS long)";
String chatWithId ="("+ SQLiteHelper.COLUMN_CHAT_WITH_USER_ID+" = ? )";
String fromMeS = "("+SQLiteHelper.COLUMN_FROM_ME+" = ? AS integer )";
String UserNamee = "("+SQLiteHelper.COLUMN_USER_NAME+" = ? )";
String where = userId +" AND "+ message +" AND "+ time +" AND "+ chatWithId +" AND "+ fromMeS +" AND "+ UserNamee;
String[] whereArgs = new String[] {String.valueOf(myUserId),
String.valueOf(message),
String.valueOf(timeStamp),
String.valueOf(chatWithUserId),
String.valueOf(fromMeInt),
String.valueOf(UserName)};
int count = database.update(SQLiteHelper.TABLE_MESSAGES, dataToInsert, where, whereArgs);
Lg.info(TAG, "updateMessage updated: " + count);
Lg.info(TAG, "updateMessage where: " + where);
任何建议都会有所帮助,在此先感谢。
答案 0 :(得分:0)
要转换数据类型,您必须使用CAST expression:
UPDATE messages
SET message = ?
WHERE user_id = ?
AND message = ?
AND time = CAST(? AS long)
AND chat_with_user_id = ?
AND from_me = CAST(? AS integer)
AND user_full_name = ?;