Make getting birthday compatible with SQLite

This commit is contained in:
Zwelf 2020-07-13 21:19:40 +02:00
parent eb4d77f071
commit a6df9be98e

View file

@ -206,22 +206,25 @@ bool CScore::LoadPlayerDataThread(IDbConnection *pSqlServer, const ISqlData *pGa
// birthday check // birthday check
str_format(aBuf, sizeof(aBuf), str_format(aBuf, sizeof(aBuf),
"SELECT YEAR(Current) - YEAR(Stamp) AS YearsAgo "
"FROM ("
"SELECT CURRENT_TIMESTAMP AS Current, MIN(Timestamp) AS Stamp " "SELECT CURRENT_TIMESTAMP AS Current, MIN(Timestamp) AS Stamp "
"FROM %s_race " "FROM %s_race "
"WHERE Name=?" "WHERE Name = ?",
") AS l "
"WHERE DAYOFMONTH(Current) = DAYOFMONTH(Stamp) AND MONTH(Current) = MONTH(Stamp) "
"AND YEAR(Current) > YEAR(Stamp);",
pSqlServer->GetPrefix()); pSqlServer->GetPrefix());
pSqlServer->PrepareStatement(aBuf); pSqlServer->PrepareStatement(aBuf);
pSqlServer->BindString(1, pData->m_RequestingPlayer); pSqlServer->BindString(1, pData->m_RequestingPlayer);
if(pSqlServer->Step()) if(pSqlServer->Step() && !pSqlServer->IsNull(2))
{ {
int YearsAgo = pSqlServer->GetInt(1); char aCurrent[TIMESTAMP_STR_LENGTH];
pData->m_pResult->m_Data.m_Info.m_Birthday = YearsAgo; pSqlServer->GetString(1, aCurrent, sizeof(aCurrent));
char aStamp[TIMESTAMP_STR_LENGTH];
pSqlServer->GetString(2, aStamp, sizeof(aStamp));
int CurrentYear, CurrentMonth, CurrentDay;
int StampYear, StampMonth, StampDay;
if(sscanf(aCurrent, "%d-%d-%d", &CurrentYear, &CurrentMonth, &CurrentDay) == 3
&& sscanf(aStamp, "%d-%d-%d", &StampYear, &StampMonth, &StampDay) == 3
&& CurrentMonth == StampMonth && CurrentDay == StampDay)
pData->m_pResult->m_Data.m_Info.m_Birthday = CurrentYear - StampYear;
} }
pData->m_pResult->m_Done = true; pData->m_pResult->m_Done = true;
return true; return true;