| 491 | } |
| 492 | |
| 493 | bool CScoreWorker::SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize) |
| 494 | { |
| 495 | const auto *pData = dynamic_cast<const CSqlScoreData *>(pGameData); |
| 496 | auto *pResult = dynamic_cast<CScorePlayerResult *>(pGameData->m_pResult.get()); |
| 497 | auto *paMessages = pResult->m_Data.m_aaMessages; |
| 498 | |
| 499 | char aBuf[1024]; |
| 500 | |
| 501 | if(w == Write::NORMAL_SUCCEEDED) |
| 502 | { |
| 503 | str_format(aBuf, sizeof(aBuf), |
| 504 | "DELETE FROM %s_race_backup WHERE GameId=? AND Name=? AND Timestamp=%s", |
| 505 | pSqlServer->GetPrefix(), pSqlServer->InsertTimestampAsUtc()); |
| 506 | if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) |
| 507 | { |
| 508 | return false; |
| 509 | } |
| 510 | pSqlServer->BindString(1, pData->m_aGameUuid); |
| 511 | pSqlServer->BindString(2, pData->m_aName); |
| 512 | pSqlServer->BindString(3, pData->m_aTimestamp); |
| 513 | pSqlServer->Print(); |
| 514 | int NumDeleted; |
| 515 | if(!pSqlServer->ExecuteUpdate(&NumDeleted, pError, ErrorSize)) |
| 516 | { |
| 517 | return false; |
| 518 | } |
| 519 | if(NumDeleted == 0) |
| 520 | { |
| 521 | log_warn("sql", "Rank got moved out of backup database, will show up as duplicate rank in MySQL"); |
| 522 | } |
| 523 | return true; |
| 524 | } |
| 525 | if(w == Write::NORMAL_FAILED) |
| 526 | { |
| 527 | int NumUpdated; |
| 528 | // move to non-tmp table succeeded. delete from backup again |
| 529 | str_format(aBuf, sizeof(aBuf), |
| 530 | "INSERT INTO %s_race SELECT * FROM %s_race_backup WHERE GameId=? AND Name=? AND Timestamp=%s", |
| 531 | pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->InsertTimestampAsUtc()); |
| 532 | if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) |
| 533 | { |
| 534 | return false; |
| 535 | } |
| 536 | pSqlServer->BindString(1, pData->m_aGameUuid); |
| 537 | pSqlServer->BindString(2, pData->m_aName); |
| 538 | pSqlServer->BindString(3, pData->m_aTimestamp); |
| 539 | pSqlServer->Print(); |
| 540 | if(!pSqlServer->ExecuteUpdate(&NumUpdated, pError, ErrorSize)) |
| 541 | { |
| 542 | return false; |
| 543 | } |
| 544 | |
| 545 | // move to non-tmp table succeeded. delete from backup again |
| 546 | str_format(aBuf, sizeof(aBuf), |
| 547 | "DELETE FROM %s_race_backup WHERE GameId=? AND Name=? AND Timestamp=%s", |
| 548 | pSqlServer->GetPrefix(), pSqlServer->InsertTimestampAsUtc()); |
| 549 | if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) |
| 550 | { |
nothing calls this directly
no test coverage detected