int CMySQLDynamicRecordSet::MoveTo(int Index) { if(m_hStmt) { if(m_CacheAllData) { mysql_stmt_data_seek(m_hStmt,Index); int Ret=FetchRow(); if(Ret==DBERR_NO_RECORDS) { m_IsEOF=true; return DBERR_IS_RECORDSET_TAIL; } else { return Ret; } } else { return DBERR_NOT_IMPLEMENT; } } else { return DBERR_NO_RECORDS; } }
int CMySQLDynamicRecordSet::NextResults() { if(m_pDBConnection==NULL||m_hStmt==NULL) return DBERR_INVALID_PARAM; int RetCode; RetCode=mysql_stmt_next_result(m_hStmt); if(RetCode>0) return DBERR_FETCH_RESULT_FAIL; if(mysql_stmt_bind_result(m_hStmt,&(m_FetchBuffer[0]))) { m_pDBConnection->ProcessErrorMsg(m_hStmt,"绑定结果集失败"); return DBERR_BINDCOLFAIL; } if(m_CacheAllData) { if(mysql_stmt_store_result(m_hStmt)) { m_pDBConnection->ProcessErrorMsg(m_hStmt,"缓存结果集失败"); return DBERR_BUFFER_OVERFLOW; } } int Ret=FetchRow(); return Ret; }
int CMySQLDynamicRecordSet::MovePrevious() { if(m_hStmt) { if(m_CacheAllData) { MYSQL_ROW_OFFSET Offset=mysql_stmt_row_tell(m_hStmt); Offset--; mysql_stmt_row_seek(m_hStmt,Offset); int Ret=FetchRow(); if(Ret==DBERR_NO_RECORDS) { m_IsBOF=true; return DBERR_IS_RECORDSET_HEAD; } else { return Ret; } } else { return DBERR_NOT_IMPLEMENT; } } else { return DBERR_NO_RECORDS; } }
// Runs a query that counts a row and returns the result int _Database::RunCountQuery(const char *TQueryString) { RunDataQuery(TQueryString); FetchRow(); int Count = GetInt(0); CloseQuery(); return Count; }
int CMySQLDynamicRecordSet::MoveNext() { if(m_hStmt) { return FetchRow(); } else { return DBERR_NO_RECORDS; } }
bool_t MySQLHandle::Fetch() { bool_t ret = FALSE; ret = FetchRow(); if(!ret) { ECILA_TRACE(); return FALSE; } ret = FetchField(); if(!ret) { ECILA_TRACE(); return FALSE; } return TRUE; }
//-------------------------------------------------------------------- // @mfunc Tokenize the Data values and retursn the column record // // @rdesc HRESULT // @flag S_OK | Parsing yielded no Error // @flag E_FAIL | Data value could not be parsed or stored // HRESULT CParseInitFile::GetData(DBCOUNTITEM ulRow,DBORDINAL ulColumn, WCHAR* pwszData, DBTYPE *pwType) { ASSERT(pwszData); //NOTE: Since we are moving the file pointer here, we need to block so that //our data access to the low level file is atomic. Otherwise threading variations //comparing data will get bogus data since the starting location is not correct... CAutoBlock autoBlock(m_csFile.GetCS()); DBLENGTH dwLength = 0; CHAR* pszOffset = NULL; HRESULT hr = S_OK; TRACE_CALL(L"PRIVLIB: CParseInitFile::GetData.\n"); if(FAILED(hr = FetchRow(ulRow))) goto CLEANUP; if(FAILED(hr = ParseRowValues(ulColumn, &pszOffset, &dwLength, pwType))) goto CLEANUP; //Check for (null) data if(hr == S_FALSE) return hr; //Indicate NULL if(dwLength > MAXDATALEN) dwLength = MAXDATALEN; if(dwLength) { //Convert to WCHAR. //NOTE: ParseRowValues returns the actual number of bytes obtained. We need to //know the actual number of characters which may be different for MBCS dwLength = MultiByteToWideChar(CP_ACP, 0, pszOffset, (INT)dwLength, pwszData, MAXDATALEN); if(!dwLength) TESTC_(hr = E_FAIL, S_OK); } //Add NULL terminator pwszData[dwLength] = L'\0'; CLEANUP: return hr; }
int CMySQLDynamicRecordSet::MoveLast() { if(m_hStmt) { if(m_CacheAllData) { my_ulonglong RowCount=mysql_stmt_num_rows(m_hStmt); mysql_stmt_data_seek(m_hStmt,RowCount-1); return FetchRow(); } else { return DBERR_NOT_IMPLEMENT; } } else { return DBERR_NO_RECORDS; } }
int CMySQLDynamicRecordSet::MoveFirst() { if(m_hStmt) { if(m_CacheAllData) { mysql_stmt_data_seek(m_hStmt,0); return FetchRow(); } else { return DBERR_NOT_IMPLEMENT; } } else { return DBERR_NO_RECORDS; } }
void CLobbyServerPlayer::ProcessSessionAcknowledgement(const PacketData& packetData) { std::string sessionId = reinterpret_cast<const char*>(&packetData[0x30]); std::string clientVersion = reinterpret_cast<const char*>(&packetData[0x70]); CLog::GetInstance().LogMessage(LOG_NAME, "Got acknowledgment for secure session."); CLog::GetInstance().LogMessage(LOG_NAME, "SESSION_ID: %s", sessionId.c_str()); CLog::GetInstance().LogMessage(LOG_NAME, "CLIENT_VERSION: %s", clientVersion.c_str()); if(m_dbConnection.IsEmpty()) { CLog::GetInstance().LogMessage(LOG_NAME, "No database connection available. Bailing."); m_disconnect = true; return; } try { auto query = string_format("SELECT userId FROM ffxiv_sessions WHERE id = '%s' AND expiration > NOW()", sessionId.c_str()); auto result = m_dbConnection.Query(query.c_str()); if(result.GetRowCount() == 0) { throw std::runtime_error("Session expired or doesn't exist."); } auto row = result.FetchRow(); assert(row != nullptr); assert(result.GetFieldCount() == 1); m_userId = boost::lexical_cast<uint32>(row[0]); CLog::GetInstance().LogMessage(LOG_NAME, "User (id: %u) logged in.", m_userId); } catch(const std::exception& exception) { CLog::GetInstance().LogError(LOG_NAME, "Failed to validate user session (id: %s): %s.", sessionId.c_str(), exception.what()); m_disconnect = true; return; } std::vector<uint8> outgoingPacket(std::begin(g_loginAcknowledgment), std::end(g_loginAcknowledgment)); CPacketUtils::EncryptPacket(outgoingPacket); QueuePacket(outgoingPacket); }
int CMySQLDynamicRecordSet::Init(CMySQLConnection * pDBConnection,MYSQL_STMT_HANDLE hStmt) { if(pDBConnection==NULL||hStmt==NULL) return DBERR_INVALID_PARAM; Destory(); m_pDBConnection=pDBConnection; m_hStmt=hStmt; MYSQL_RES_HANDLE hResult=mysql_stmt_result_metadata(m_hStmt); if(hResult==NULL) { return DBERR_NO_RECORDS; } int ColNum=mysql_num_fields(hResult); m_pColumnInfos.Resize(ColNum); m_RowBuffer.Resize(ColNum); m_FetchBuffer.Resize(ColNum); ZeroMemory(&(m_FetchBuffer[0]),sizeof(MYSQL_BIND)*ColNum); MYSQL_FIELD * pFields=mysql_fetch_fields(hResult); UINT FetchBufferLen=0; for(int i=0;i<ColNum;i++) { UINT Size=pFields[i].length; UINT DigitalSize=pFields[i].decimals; int DBType=CMySQLConnection::MySQLTypeToDBLibType(pFields[i].type,Size,DigitalSize); strncpy_0(m_pColumnInfos[i].Name,MAX_COLUMN_NAME,pFields[i].name,MAX_COLUMN_NAME); m_pColumnInfos[i].Type=DBType; m_pColumnInfos[i].Size=Size; m_pColumnInfos[i].DigitSize=DigitalSize; FetchBufferLen+=CMySQLConnection::GetMySQLTypeBinLength(pFields[i].type,pFields[i].length,pFields[i].decimals)+sizeof(UINT)+sizeof(my_bool); } m_FetchDataBuffer.Create(FetchBufferLen); for(int i=0;i<ColNum;i++) { m_FetchBuffer[i].buffer_type=pFields[i].type; m_FetchBuffer[i].is_unsigned=(pFields[i].flags&UNSIGNED_FLAG)?1:0; m_FetchBuffer[i].buffer=(char *)m_FetchDataBuffer.GetFreeBuffer(); m_FetchBuffer[i].buffer_length=CMySQLConnection::GetMySQLTypeBinLength(pFields[i].type,pFields[i].length,pFields[i].decimals); m_FetchDataBuffer.PushBack(NULL,m_FetchBuffer[i].buffer_length); m_FetchBuffer[i].length=(ULONG *)m_FetchDataBuffer.GetFreeBuffer(); m_FetchDataBuffer.PushConstBack(m_pColumnInfos[i].Size,sizeof(ULONG)); m_FetchBuffer[i].is_null=(my_bool *)m_FetchDataBuffer.GetFreeBuffer(); m_FetchDataBuffer.PushConstBack(0,sizeof(my_bool)); } mysql_free_result(hResult); if(mysql_stmt_bind_result(m_hStmt,&(m_FetchBuffer[0]))) { m_pDBConnection->ProcessErrorMsg(m_hStmt,"绑定结果集失败"); return DBERR_BINDCOLFAIL; } if(m_CacheAllData) { if(mysql_stmt_store_result(m_hStmt)) { m_pDBConnection->ProcessErrorMsg(m_hStmt,"缓存结果集失败"); return DBERR_BUFFER_OVERFLOW; } } int Ret=FetchRow(); return Ret; }