I need help to make correct query to db. There are columns SENDER_ID, RECIPIENT_ID. my query is as follows:
private static final String CHAT_MSG_SELECTION = new StringBuilder()
.append(ChatsHistory.Tables.ChatHistoryTable.NoCaseColumns.SENDER_ID)
.append(" = ? OR ")
.append(ChatsHistory.Tables.ChatHistoryTable.NoCaseColumns.RECIPIENT_ID)
.append(" = ? AND (")
.append(ChatsHistory.Tables.ChatHistoryTable.NoCaseColumns.RECIPIENT_ID)
.append(" = ? OR ")
.append(ChatsHistory.Tables.ChatHistoryTable.NoCaseColumns.SENDER_ID)
.append(" = ?)")
.toString();
Then I make query to db . It returns the sum of messages in chat.
int messagesCount = getChatDbManager().getMsgsCount(selection, selectionArgs);
Then I check if messagesCount >0, I remove all messages by pressing a certain control. Else I show Toast.
In getMsgCount:
final String selection = CHAT_MSG_SELECTION;
final String[] selectionArgs = new String[4];
selectionArgs[0] = ownerId;
selectionArgs[1] = name;
selectionArgs[2] = name;
selectionArgs[3] = ownerId;
The check works not correct. If I send message emulator on the client installed on PC, messagesCount = above zero. If I send message from PC to emulator - messagesCount =0. I debugged it. mistake is in the query. help make it right because I'm not good at this. Thanks
Aucun commentaire:
Enregistrer un commentaire