| 650 | } |
| 651 | |
| 652 | bool CScoreWorker::SaveTeamScore(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize) |
| 653 | { |
| 654 | const auto *pData = dynamic_cast<const CSqlTeamScoreData *>(pGameData); |
| 655 | |
| 656 | char aBuf[512]; |
| 657 | |
| 658 | if(w == Write::NORMAL_SUCCEEDED) |
| 659 | { |
| 660 | str_format(aBuf, sizeof(aBuf), |
| 661 | "DELETE FROM %s_teamrace_backup WHERE Id=?", |
| 662 | pSqlServer->GetPrefix()); |
| 663 | if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) |
| 664 | { |
| 665 | return false; |
| 666 | } |
| 667 | |
| 668 | // copy uuid, because mysql BindBlob doesn't support const buffers |
| 669 | CUuid TeamrankId = pData->m_TeamrankUuid; |
| 670 | pSqlServer->BindBlob(1, TeamrankId.m_aData, sizeof(TeamrankId.m_aData)); |
| 671 | pSqlServer->Print(); |
| 672 | int NumDeleted; |
| 673 | if(!pSqlServer->ExecuteUpdate(&NumDeleted, pError, ErrorSize)) |
| 674 | { |
| 675 | return false; |
| 676 | } |
| 677 | if(NumDeleted == 0) |
| 678 | { |
| 679 | log_warn("sql", "Teamrank got moved out of backup database, will show up as duplicate teamrank in MySQL"); |
| 680 | } |
| 681 | return true; |
| 682 | } |
| 683 | if(w == Write::NORMAL_FAILED) |
| 684 | { |
| 685 | int NumInserted; |
| 686 | CUuid TeamrankId = pData->m_TeamrankUuid; |
| 687 | |
| 688 | str_format(aBuf, sizeof(aBuf), |
| 689 | "INSERT INTO %s_teamrace SELECT * FROM %s_teamrace_backup WHERE Id=?", |
| 690 | pSqlServer->GetPrefix(), pSqlServer->GetPrefix()); |
| 691 | if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) |
| 692 | { |
| 693 | return false; |
| 694 | } |
| 695 | pSqlServer->BindBlob(1, TeamrankId.m_aData, sizeof(TeamrankId.m_aData)); |
| 696 | pSqlServer->Print(); |
| 697 | if(!pSqlServer->ExecuteUpdate(&NumInserted, pError, ErrorSize)) |
| 698 | { |
| 699 | return false; |
| 700 | } |
| 701 | |
| 702 | str_format(aBuf, sizeof(aBuf), |
| 703 | "DELETE FROM %s_teamrace_backup WHERE Id=?", |
| 704 | pSqlServer->GetPrefix()); |
| 705 | if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) |
| 706 | { |
| 707 | return false; |
| 708 | } |
| 709 | pSqlServer->BindBlob(1, TeamrankId.m_aData, sizeof(TeamrankId.m_aData)); |
nothing calls this directly
no test coverage detected