Fix random_map and random_unfinished_map on SQLite server

This commit is contained in:
Zwelf 2020-10-28 22:34:48 +01:00
parent dfd89ab7d4
commit 6eb95c6b96
4 changed files with 12 additions and 8 deletions

View file

@ -33,6 +33,8 @@ public:
virtual const char *CollateNocase() const = 0;
// syntax to insert a row into table or ignore if it already exists
virtual const char *InsertIgnore() const = 0;
// ORDER BY RANDOM()/RAND()
virtual const char *Random() const = 0;
enum Status
{

View file

@ -34,6 +34,7 @@ public:
virtual const char *InsertTimestampAsUtc() const { return "?"; }
virtual const char *CollateNocase() const { return "CONVERT(? USING utf8mb4) COLLATE utf8mb4_general_ci"; }
virtual const char *InsertIgnore() const { return "INSERT IGNORE"; };
virtual const char *Random() const { return "RAND()"; };
virtual Status Connect();
virtual void Disconnect();

View file

@ -21,6 +21,7 @@ public:
virtual const char *InsertTimestampAsUtc() const { return "DATETIME(?, 'utc')"; }
virtual const char *CollateNocase() const { return "? COLLATE NOCASE"; }
virtual const char *InsertIgnore() const { return "INSERT OR IGNORE"; };
virtual const char *Random() const { return "RANDOM()"; };
virtual Status Connect();
virtual void Disconnect();

View file

@ -1144,8 +1144,8 @@ bool CScore::RandomMapThread(IDbConnection *pSqlServer, const ISqlData *pGameDat
str_format(aBuf, sizeof(aBuf),
"SELECT Map FROM %s_maps "
"WHERE Server = ? AND Map != ? AND Stars = ? "
"ORDER BY RAND() LIMIT 1;",
pSqlServer->GetPrefix());
"ORDER BY %s LIMIT 1;",
pSqlServer->GetPrefix(), pSqlServer->Random());
pSqlServer->PrepareStatement(aBuf);
pSqlServer->BindInt(3, pData->m_Stars);
}
@ -1154,8 +1154,8 @@ bool CScore::RandomMapThread(IDbConnection *pSqlServer, const ISqlData *pGameDat
str_format(aBuf, sizeof(aBuf),
"SELECT Map FROM %s_maps "
"WHERE Server = ? AND Map != ? "
"ORDER BY RAND() LIMIT 1;",
pSqlServer->GetPrefix());
"ORDER BY %s LIMIT 1;",
pSqlServer->GetPrefix(), pSqlServer->Random());
pSqlServer->PrepareStatement(aBuf);
}
pSqlServer->BindString(1, pData->m_ServerType);
@ -1202,9 +1202,9 @@ bool CScore::RandomUnfinishedMapThread(IDbConnection *pSqlServer, const ISqlData
" SELECT Map "
" FROM %s_race "
" WHERE Name = ?"
") ORDER BY RAND() "
") ORDER BY %s "
"LIMIT 1;",
pSqlServer->GetPrefix(), pSqlServer->GetPrefix());
pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->Random());
pSqlServer->PrepareStatement(aBuf);
pSqlServer->BindString(1, pData->m_ServerType);
pSqlServer->BindString(2, pData->m_CurrentMap);
@ -1220,9 +1220,9 @@ bool CScore::RandomUnfinishedMapThread(IDbConnection *pSqlServer, const ISqlData
" SELECT Map "
" FROM %s_race as race "
" WHERE Name = ?"
") ORDER BY RAND() "
") ORDER BY %s "
"LIMIT 1;",
pSqlServer->GetPrefix(), pSqlServer->GetPrefix());
pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->Random());
pSqlServer->PrepareStatement(aBuf);
pSqlServer->BindString(1, pData->m_ServerType);
pSqlServer->BindString(2, pData->m_CurrentMap);