bool CWizDatabase::updateMessages(const CWizMessageDataArray& arrayMsg) { // TODO: delete messages not exist on remote if (arrayMsg.empty()) return false; qint64 nVersion = -1; bool bHasError = false; CWizMessageDataArray::const_iterator it; for (it = arrayMsg.begin(); it != arrayMsg.end(); it++) { const WIZMESSAGEDATA& msg = *it; if (!updateMessage(msg)) { bHasError = true; } nVersion = qMax(nVersion, msg.nVersion); } if (!bHasError) { SetObjectVersion(WIZMESSAGEDATA::ObjectName(), nVersion); } return !bHasError; }
void MessageListView::addMessages(const CWizMessageDataArray& arrayMessage) { CWizMessageDataArray::const_iterator it; for (it = arrayMessage.begin(); it != arrayMessage.end(); it++) { addMessage(*it, false); } sortItems(); }
bool CWizIndexBase::messageFromId(qint64 nId, WIZMESSAGEDATA& data) { CString strWhere; strWhere.Format("MESSAGE_ID=%s", WizInt64ToStr(nId).utf16()); CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_MESSAGE, FIELD_LIST_WIZ_MESSAGE, strWhere); CWizMessageDataArray arrayMessage; if (!SQLToMessageDataArray(strSQL, arrayMessage)) { TOLOG("[messageFromId] failed to get message by id"); return false; } if (arrayMessage.empty()) return false; data = arrayMessage[0]; return true; }
void CWizCategoryViewMessageItem::getDocuments(CWizDatabase& db, CWizDocumentDataArray& arrayDocument) { CWizMessageDataArray arrayMsg; db.getLastestMessages(arrayMsg); for (CWizMessageDataArray::const_iterator it = arrayMsg.begin(); it != arrayMsg.end(); it++) { const WIZMESSAGEDATA& msg = *it; WIZDOCUMENTDATAEX doc; doc.strKbGUID = msg.kbGUID; doc.strGUID = msg.documentGUID; doc.strTitle = msg.title; // CWizCategoryView responsible for converting to full field message data // refer to CWizCategoryView::setDocuments() arrayDocument.push_back(doc); } }
bool CWizIndexBase::messageFromDocumentGUID(const QString& strGUID, WIZMESSAGEDATA& data) { CString strWhere; strWhere.Format("DOCUMENT_GUID=%s", STR2SQL(strGUID).utf16()); CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_MESSAGE, FIELD_LIST_WIZ_MESSAGE, strWhere); CWizMessageDataArray arrayMessage; if (!SQLToMessageDataArray(strSQL, arrayMessage)) { TOLOG("[messageFromId] failed to get message by document guid"); return false; } if (arrayMessage.empty()) return false; // FIXME: return the lastest message data = arrayMessage[0]; return true; }
bool CWizIndexBase::SQLToMessageDataArray(const QString& strSQL, CWizMessageDataArray& arrayMessage) { try { CppSQLite3Query query = m_db.execQuery(strSQL); while (!query.eof()) { WIZMESSAGEDATA data; data.nId = query.getInt64Field(msgMESSAGE_ID); data.bizGUID = query.getStringField(msgBIZ_GUID); data.kbGUID = query.getStringField(msgKB_GUID); data.documentGUID = query.getStringField(msgDOCUMENT_GUID); data.senderAlias = query.getStringField(msgSENDER); data.senderId = query.getStringField(msgSENDER_ID); data.senderGUID = query.getStringField(msgSENDER_GUID); data.receiverAlias = query.getStringField(msgRECEIVER); data.receiverId = query.getStringField(msgRECEIVER_ID); data.receiverGUID = query.getStringField(msgRECEIVER_GUID); data.nMessageType = query.getIntField(msgMESSAGE_TYPE); data.nReadStatus = query.getIntField(msgREAD_STATUS); data.tCreated = query.getTimeField(msgDT_CREATED); data.title = query.getStringField(msgMESSAGE_TITLE); data.messageBody = query.getStringField(msgMESSAGE_TEXT); data.nVersion = query.getInt64Field(msgWIZ_VERSION); arrayMessage.push_back(data); query.nextRow(); } return true; } catch (const CppSQLite3Exception& e) { return LogSQLException(e, strSQL); } }