我想通过Update查询更新ContentProvider,但它总是返回错误,我无法识别未运行更新查询的确切原因。
错误日志:
syntax error (code 1): , while compiling: UPDATE chats SET media_type=?,jid=?,pid=?,sender_name=?,is_upload=?,read=?,from_me=?,date=?,message=?,sender_ph_no=? WHERE jid=amit@chat.spectratech.in and sender_name=sanat@chat.spectratech.in and date=1450252580946
代码:
private void updateChatMessageToDB(int direction, String JID, String message, int delivery_status, long ts, String packetID, String group_chat_sender_name, String group_chat_sender_ph_no, String media_type) {
android.content.ContentValues values = new android.content.ContentValues();
values.put(ChatProvider.ChatConstants.DIRECTION, direction);
values.put(ChatProvider.ChatConstants.JID, JID);
values.put(ChatProvider.ChatConstants.MESSAGE, message);
values.put(ChatProvider.ChatConstants.DELIVERY_STATUS, delivery_status);
values.put(ChatProvider.ChatConstants.DATE, ts);
values.put(ChatProvider.ChatConstants.PACKET_ID, packetID);
values.put(ChatProvider.ChatConstants.GROUP_CHAT_SENDER_NAME, group_chat_sender_name);
values.put(ChatProvider.ChatConstants.GROUP_CHAT_SENDER_PHONE, group_chat_sender_ph_no);
values.put(ChatProvider.ChatConstants.MEDIA_TYPE, media_type);
values.put(ChatProvider.ChatConstants.IS_UPLOAD, -1);
/* if (media_type.equalsIgnoreCase("text"))
values.put(ChatProvider.ChatConstants.MEDIA_URL, "N/A");
else {
JSONObject mJSONObject = null;
try {
mJSONObject = new JSONObject(message);
values.put(ChatProvider.ChatConstants.MEDIA_URL, mJSONObject.optString("media_url"));
} catch (JSONException e) {
e.printStackTrace();
}
}
*/
mContentResolver.update(ChatProvider.CONTENT_URI, values, ChatProvider.ChatConstants.JID +"="+JID+" and "+ChatProvider.ChatConstants.GROUP_CHAT_SENDER_NAME+"="+group_chat_sender_ph_no+" and "+ChatProvider.ChatConstants.DATE+"="+ts, null);
//mContentResolver.insert(ChatProvider.CONTENT_URI, values);
}
请提出任何解决方案。
感谢所有人。
答案 0 :(得分:0)
在字符串''
中添加引号[HttpPost]
public void test (Disciplines discipline)
{
}
答案 1 :(得分:0)
将JID
和group_chat_sender_ph_no
放在单引号中。
mContentResolver.update(ChatProvider.CONTENT_URI, values, ChatProvider.ChatConstants.JID +"='"+JID+"' and "+ChatProvider.ChatConstants.GROUP_CHAT_SENDER_NAME+"='"+group_chat_sender_ph_no+"' and "+ChatProvider.ChatConstants.DATE+"="+ts, null);