mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #3211
3211: Fix random_map and random_unfinished_map on SQLite server r=def- a=Zwelf <!-- What is the motivation for the changes of this pull request --> Fixes #3210 ## Checklist - [x] Tested the change ingame (both on MySQL and SQLite) - [x] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [x] Considered possible null pointers and out of bounds array indexing - [x] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Zwelf <zwelf@strct.cc>
This commit is contained in:
commit
3a3b9b1b1c
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue