int LanCDB::getFriendList(quint32 dwUserId, quint32& dwUserNum, UserInfoList& strus) { std::stringstream oss; oss.str(""); oss << "select user_name, user_flag from users where user_id in(select user_id_b from userGrant where deal_flag=1 and user_id_a=" << dwUserId; oss << " union select user_id_a from userGrant where deal_flag=1 and user_id_b=" << dwUserId << ")"; qDebug() << "SQL=[" << oss.str().c_str() << "]"; QSqlQuery *sqlQuery = new QSqlQuery(db); if (!sqlQuery->exec((char *)(oss.str().c_str()))) { qDebug() << "Err_SQL=[" << oss.str().c_str() << "]"; qDebug() << sqlQuery->lastError().databaseText(); return LCDB_ERR_DBDATA_ERROR; } dwUserNum = 0; if (sqlQuery->numRowsAffected()) { while (sqlQuery->next()) { UserInfo stru; stru.szUsername = sqlQuery->value(0).toString(); stru.shFlag = (quint16)sqlQuery->value(1).toInt(); strus.push_back(stru); dwUserNum++; qDebug() << "int LanCDB::getFriendList(quint32 dwUserId, quint32& dwUserNum, UserInfoList& strus), username=" << stru.szUsername; } } return LCDB_ERR_SUCCESS; }
// 处理已接收数据 bool GetUsersInfoTask::Handle(const TransportProtocol* tp) { bool result = false; // callback 参数 UserInfoList userInfoList; AmfParser parser; amf_object_handle root = parser.Decode((char*)tp->data, tp->GetDataLength()); if (!root.isnull()) { // 解析成功协议 if (root->type == DT_ARRAY) { size_t i = 0; for (i = 0; i < root->childrens.size(); i++) { UserInfoItem item; if (ParsingUserInfoItem(root->childrens[i], item)) { userInfoList.push_back(item); } } result = true; } if (!result) { // 解析失败协议 int errType = 0; string errMsg = ""; if (GetAMFProtocolError(root, errType, errMsg)) { m_errType = (LCC_ERR_TYPE)errType; m_errMsg = errMsg; result = true; } } else { m_errType = LCC_ERR_SUCCESS; string errMsg = ""; } } // 协议解析失败 if (!result) { m_errType = LCC_ERR_PROTOCOLFAIL; m_errMsg = ""; } // 打log FileLog("LiveChatClient", "GetUsersInfoTask::Handle() listener:%p, errType:%d, errMsg:%s, userInfoList.size:%d" , m_listener, m_errType, m_errMsg.c_str(), userInfoList.size()); // 通知listener if (NULL != m_listener) { m_listener->OnGetUsersInfo(m_errType, m_errMsg, m_seq, m_userIdList, userInfoList); } return result; }