| 1298 | } |
| 1299 | |
| 1300 | bool CScoreWorker::ShowTimes(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize) |
| 1301 | { |
| 1302 | const auto *pData = dynamic_cast<const CSqlPlayerRequest *>(pGameData); |
| 1303 | auto *pResult = dynamic_cast<CScorePlayerResult *>(pGameData->m_pResult.get()); |
| 1304 | auto *paMessages = pResult->m_Data.m_aaMessages; |
| 1305 | |
| 1306 | int LimitStart = maximum(absolute(pData->m_Offset) - 1, 0); |
| 1307 | const char *pOrder = pData->m_Offset >= 0 ? "DESC" : "ASC"; |
| 1308 | |
| 1309 | char aCurrentTimestamp[512]; |
| 1310 | pSqlServer->ToUnixTimestamp("CURRENT_TIMESTAMP", aCurrentTimestamp, sizeof(aCurrentTimestamp)); |
| 1311 | char aTimestamp[512]; |
| 1312 | pSqlServer->ToUnixTimestamp("Timestamp", aTimestamp, sizeof(aTimestamp)); |
| 1313 | char aBuf[512]; |
| 1314 | if(pData->m_aName[0] != '\0') // last 5 times of a player |
| 1315 | { |
| 1316 | str_format(aBuf, sizeof(aBuf), |
| 1317 | "SELECT Time, (%s-%s) as Ago, %s as Stamp, Server " |
| 1318 | "FROM %s_race " |
| 1319 | "WHERE Map = ? AND Name = ? " |
| 1320 | "ORDER BY Timestamp %s " |
| 1321 | "LIMIT ?, 5", |
| 1322 | aCurrentTimestamp, aTimestamp, aTimestamp, |
| 1323 | pSqlServer->GetPrefix(), pOrder); |
| 1324 | if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) |
| 1325 | { |
| 1326 | return false; |
| 1327 | } |
| 1328 | pSqlServer->BindString(1, pData->m_aMap); |
| 1329 | pSqlServer->BindString(2, pData->m_aName); |
| 1330 | pSqlServer->BindInt(3, LimitStart); |
| 1331 | } |
| 1332 | else // last 5 times of server |
| 1333 | { |
| 1334 | str_format(aBuf, sizeof(aBuf), |
| 1335 | "SELECT Time, (%s-%s) as Ago, %s as Stamp, Server, Name " |
| 1336 | "FROM %s_race " |
| 1337 | "WHERE Map = ? " |
| 1338 | "ORDER BY Timestamp %s " |
| 1339 | "LIMIT ?, 5", |
| 1340 | aCurrentTimestamp, aTimestamp, aTimestamp, |
| 1341 | pSqlServer->GetPrefix(), pOrder); |
| 1342 | if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) |
| 1343 | { |
| 1344 | return false; |
| 1345 | } |
| 1346 | pSqlServer->BindString(1, pData->m_aMap); |
| 1347 | pSqlServer->BindInt(2, LimitStart); |
| 1348 | } |
| 1349 | |
| 1350 | // show top5 |
| 1351 | bool End; |
| 1352 | if(!pSqlServer->Step(&End, pError, ErrorSize)) |
| 1353 | { |
| 1354 | return false; |
| 1355 | } |
| 1356 | if(End) |
| 1357 | { |
nothing calls this directly
no test coverage detected