| 933 | } |
| 934 | |
| 935 | bool CScoreWorker::ShowTeamRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize) |
| 936 | { |
| 937 | const auto *pData = dynamic_cast<const CSqlPlayerRequest *>(pGameData); |
| 938 | auto *pResult = dynamic_cast<CScorePlayerResult *>(pGameData->m_pResult.get()); |
| 939 | |
| 940 | // check sort method |
| 941 | char aBuf[2400]; |
| 942 | |
| 943 | str_format(aBuf, sizeof(aBuf), |
| 944 | "SELECT l.Id, Name, Time, Ranking, PercentRank " |
| 945 | "FROM (" // teamrank score board |
| 946 | " SELECT RANK() OVER w AS Ranking, PERCENT_RANK() OVER w AS PercentRank, Id " |
| 947 | " FROM %s_teamrace " |
| 948 | " WHERE Map = ? " |
| 949 | " GROUP BY ID " |
| 950 | " WINDOW w AS (ORDER BY Min(Time))" |
| 951 | ") AS TeamRank INNER JOIN (" // select rank with Name in team |
| 952 | " SELECT ID " |
| 953 | " FROM %s_teamrace " |
| 954 | " WHERE Map = ? AND Name = ? " |
| 955 | " ORDER BY Time " |
| 956 | " LIMIT 1" |
| 957 | ") AS l ON TeamRank.Id = l.Id " |
| 958 | "INNER JOIN %s_teamrace AS r ON l.Id = r.Id ", |
| 959 | pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix()); |
| 960 | if(!pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) |
| 961 | { |
| 962 | return false; |
| 963 | } |
| 964 | pSqlServer->BindString(1, pData->m_aMap); |
| 965 | pSqlServer->BindString(2, pData->m_aMap); |
| 966 | pSqlServer->BindString(3, pData->m_aName); |
| 967 | |
| 968 | bool End; |
| 969 | if(!pSqlServer->Step(&End, pError, ErrorSize)) |
| 970 | { |
| 971 | return false; |
| 972 | } |
| 973 | if(!End) |
| 974 | { |
| 975 | float Time = pSqlServer->GetFloat(3); |
| 976 | str_time_float(Time, TIME_HOURS_CENTISECS, aBuf, sizeof(aBuf)); |
| 977 | int Rank = pSqlServer->GetInt(4); |
| 978 | // CEIL and FLOOR are not supported in SQLite |
| 979 | int BetterThanPercent = std::floor(100.0f - 100.0f * pSqlServer->GetFloat(5)); |
| 980 | CTeamrank Teamrank; |
| 981 | if(!Teamrank.NextSqlResult(pSqlServer, &End, pError, ErrorSize)) |
| 982 | { |
| 983 | return false; |
| 984 | } |
| 985 | |
| 986 | char aFormattedNames[512] = ""; |
| 987 | for(unsigned int Name = 0; Name < Teamrank.m_NumNames; Name++) |
| 988 | { |
| 989 | str_append(aFormattedNames, Teamrank.m_aaNames[Name]); |
| 990 | |
| 991 | if(Name < Teamrank.m_NumNames - 2) |
| 992 | str_append(aFormattedNames, ", "); |
nothing calls this directly
no test coverage detected