mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
Align InsertIgnore with other SQL query related functions
This commit is contained in:
parent
d1aa014357
commit
46b0ff354e
|
@ -31,6 +31,8 @@ public:
|
||||||
virtual const char *InsertTimestampAsUtc() const = 0;
|
virtual const char *InsertTimestampAsUtc() const = 0;
|
||||||
// can be used in the context of `LIKE Map`, adds `? COLLATE`
|
// can be used in the context of `LIKE Map`, adds `? COLLATE`
|
||||||
virtual const char *CollateNocase() const = 0;
|
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;
|
||||||
|
|
||||||
enum Status
|
enum Status
|
||||||
{
|
{
|
||||||
|
@ -67,8 +69,6 @@ public:
|
||||||
virtual void GetString(int Col, char *pBuffer, int BufferSize) const = 0;
|
virtual void GetString(int Col, char *pBuffer, int BufferSize) const = 0;
|
||||||
// returns number of bytes read into the buffer
|
// returns number of bytes read into the buffer
|
||||||
virtual int GetBlob(int Col, unsigned char *pBuffer, int BufferSize) const = 0;
|
virtual int GetBlob(int Col, unsigned char *pBuffer, int BufferSize) const = 0;
|
||||||
// syntax to insert a row into table or ignore if it already exists
|
|
||||||
virtual const char *GetInsertIgnore() const = 0;
|
|
||||||
|
|
||||||
// SQL statements, that can't be abstracted, has side effects to the result
|
// SQL statements, that can't be abstracted, has side effects to the result
|
||||||
virtual void AddPoints(const char *pPlayer, int Points) = 0;
|
virtual void AddPoints(const char *pPlayer, int Points) = 0;
|
||||||
|
|
|
@ -312,11 +312,6 @@ int CMysqlConnection::GetBlob(int Col, unsigned char *pBuffer, int BufferSize) c
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CMysqlConnection::GetInsertIgnore() const
|
|
||||||
{
|
|
||||||
return "INSERT IGNORE";
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMysqlConnection::AddPoints(const char *pPlayer, int Points)
|
void CMysqlConnection::AddPoints(const char *pPlayer, int Points)
|
||||||
{
|
{
|
||||||
char aBuf[512];
|
char aBuf[512];
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
virtual void ToUnixTimestamp(const char *pTimestamp, char *aBuf, unsigned int BufferSize);
|
virtual void ToUnixTimestamp(const char *pTimestamp, char *aBuf, unsigned int BufferSize);
|
||||||
virtual const char *InsertTimestampAsUtc() const { return "?"; }
|
virtual const char *InsertTimestampAsUtc() const { return "?"; }
|
||||||
virtual const char *CollateNocase() const { return "CONVERT(? USING utf8mb4) COLLATE utf8mb4_general_ci"; }
|
virtual const char *CollateNocase() const { return "CONVERT(? USING utf8mb4) COLLATE utf8mb4_general_ci"; }
|
||||||
|
virtual const char *InsertIgnore() const { return "INSERT IGNORE"; };
|
||||||
|
|
||||||
virtual Status Connect();
|
virtual Status Connect();
|
||||||
virtual void Disconnect();
|
virtual void Disconnect();
|
||||||
|
@ -54,7 +55,6 @@ public:
|
||||||
virtual int GetInt(int Col) const;
|
virtual int GetInt(int Col) const;
|
||||||
virtual void GetString(int Col, char *pBuffer, int BufferSize) const;
|
virtual void GetString(int Col, char *pBuffer, int BufferSize) const;
|
||||||
virtual int GetBlob(int Col, unsigned char *pBuffer, int BufferSize) const;
|
virtual int GetBlob(int Col, unsigned char *pBuffer, int BufferSize) const;
|
||||||
virtual const char *GetInsertIgnore() const;
|
|
||||||
|
|
||||||
virtual void AddPoints(const char *pPlayer, int Points);
|
virtual void AddPoints(const char *pPlayer, int Points);
|
||||||
|
|
||||||
|
|
|
@ -205,11 +205,6 @@ int CSqliteConnection::GetBlob(int Col, unsigned char *pBuffer, int BufferSize)
|
||||||
return Size;
|
return Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CSqliteConnection::GetInsertIgnore() const
|
|
||||||
{
|
|
||||||
return "INSERT OR IGNORE";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CSqliteConnection::Execute(const char *pQuery)
|
bool CSqliteConnection::Execute(const char *pQuery)
|
||||||
{
|
{
|
||||||
char *pErrorMsg;
|
char *pErrorMsg;
|
||||||
|
|
|
@ -20,6 +20,7 @@ public:
|
||||||
virtual void ToUnixTimestamp(const char *pTimestamp, char *aBuf, unsigned int BufferSize);
|
virtual void ToUnixTimestamp(const char *pTimestamp, char *aBuf, unsigned int BufferSize);
|
||||||
virtual const char *InsertTimestampAsUtc() const { return "DATETIME(?, 'utc')"; }
|
virtual const char *InsertTimestampAsUtc() const { return "DATETIME(?, 'utc')"; }
|
||||||
virtual const char *CollateNocase() const { return "? COLLATE NOCASE"; }
|
virtual const char *CollateNocase() const { return "? COLLATE NOCASE"; }
|
||||||
|
virtual const char *InsertIgnore() const { return "INSERT OR IGNORE"; };
|
||||||
|
|
||||||
virtual Status Connect();
|
virtual Status Connect();
|
||||||
virtual void Disconnect();
|
virtual void Disconnect();
|
||||||
|
@ -42,7 +43,6 @@ public:
|
||||||
virtual void GetString(int Col, char *pBuffer, int BufferSize) const;
|
virtual void GetString(int Col, char *pBuffer, int BufferSize) const;
|
||||||
// passing a negative buffer size is undefined behavior
|
// passing a negative buffer size is undefined behavior
|
||||||
virtual int GetBlob(int Col, unsigned char *pBuffer, int BufferSize) const;
|
virtual int GetBlob(int Col, unsigned char *pBuffer, int BufferSize) const;
|
||||||
virtual const char *GetInsertIgnore() const;
|
|
||||||
|
|
||||||
virtual void AddPoints(const char *pPlayer, int Points);
|
virtual void AddPoints(const char *pPlayer, int Points);
|
||||||
|
|
||||||
|
|
|
@ -518,7 +518,7 @@ bool CScore::SaveScoreThread(IDbConnection *pSqlServer, const ISqlData *pGameDat
|
||||||
"%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, "
|
"%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, "
|
||||||
"%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, "
|
"%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, "
|
||||||
"?, false);",
|
"?, false);",
|
||||||
pSqlServer->GetInsertIgnore(), pSqlServer->GetPrefix(),
|
pSqlServer->InsertIgnore(), pSqlServer->GetPrefix(),
|
||||||
pSqlServer->InsertTimestampAsUtc(), pData->m_Time,
|
pSqlServer->InsertTimestampAsUtc(), pData->m_Time,
|
||||||
pData->m_aCpCurrent[0], pData->m_aCpCurrent[1], pData->m_aCpCurrent[2],
|
pData->m_aCpCurrent[0], pData->m_aCpCurrent[1], pData->m_aCpCurrent[2],
|
||||||
pData->m_aCpCurrent[3], pData->m_aCpCurrent[4], pData->m_aCpCurrent[5],
|
pData->m_aCpCurrent[3], pData->m_aCpCurrent[4], pData->m_aCpCurrent[5],
|
||||||
|
@ -629,7 +629,7 @@ bool CScore::SaveTeamScoreThread(IDbConnection *pSqlServer, const ISqlData *pGam
|
||||||
str_format(aBuf, sizeof(aBuf),
|
str_format(aBuf, sizeof(aBuf),
|
||||||
"%s INTO %s_teamrace(Map, Name, Timestamp, Time, ID, GameID, DDNet7) "
|
"%s INTO %s_teamrace(Map, Name, Timestamp, Time, ID, GameID, DDNet7) "
|
||||||
"VALUES (?, ?, %s, %.2f, ?, ?, false);",
|
"VALUES (?, ?, %s, %.2f, ?, ?, false);",
|
||||||
pSqlServer->GetInsertIgnore(), pSqlServer->GetPrefix(),
|
pSqlServer->InsertIgnore(), pSqlServer->GetPrefix(),
|
||||||
pSqlServer->InsertTimestampAsUtc(), pData->m_Time);
|
pSqlServer->InsertTimestampAsUtc(), pData->m_Time);
|
||||||
pSqlServer->PrepareStatement(aBuf);
|
pSqlServer->PrepareStatement(aBuf);
|
||||||
pSqlServer->BindString(1, pData->m_Map);
|
pSqlServer->BindString(1, pData->m_Map);
|
||||||
|
@ -1317,7 +1317,7 @@ bool CScore::SaveTeamThread(IDbConnection *pSqlServer, const ISqlData *pGameData
|
||||||
str_format(aBuf, sizeof(aBuf),
|
str_format(aBuf, sizeof(aBuf),
|
||||||
"%s INTO %s_saves(Savegame, Map, Code, Timestamp, Server, SaveID, DDNet7) "
|
"%s INTO %s_saves(Savegame, Map, Code, Timestamp, Server, SaveID, DDNet7) "
|
||||||
"VALUES (?, ?, ?, CURRENT_TIMESTAMP, ?, ?, false)",
|
"VALUES (?, ?, ?, CURRENT_TIMESTAMP, ?, ?, false)",
|
||||||
pSqlServer->GetInsertIgnore(), pSqlServer->GetPrefix());
|
pSqlServer->InsertIgnore(), pSqlServer->GetPrefix());
|
||||||
pSqlServer->PrepareStatement(aBuf);
|
pSqlServer->PrepareStatement(aBuf);
|
||||||
pSqlServer->BindString(1, pSaveState);
|
pSqlServer->BindString(1, pSaveState);
|
||||||
pSqlServer->BindString(2, pData->m_Map);
|
pSqlServer->BindString(2, pData->m_Map);
|
||||||
|
|
Loading…
Reference in a new issue