Align InsertIgnore with other SQL query related functions

This commit is contained in:
Zwelf 2020-09-06 23:21:49 +02:00
parent d1aa014357
commit 46b0ff354e
6 changed files with 7 additions and 17 deletions

View file

@ -31,6 +31,8 @@ public:
virtual const char *InsertTimestampAsUtc() const = 0;
// can be used in the context of `LIKE Map`, adds `? COLLATE`
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
{
@ -67,8 +69,6 @@ public:
virtual void GetString(int Col, char *pBuffer, int BufferSize) const = 0;
// returns number of bytes read into the buffer
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
virtual void AddPoints(const char *pPlayer, int Points) = 0;

View file

@ -312,11 +312,6 @@ int CMysqlConnection::GetBlob(int Col, unsigned char *pBuffer, int BufferSize) c
#endif
}
const char *CMysqlConnection::GetInsertIgnore() const
{
return "INSERT IGNORE";
}
void CMysqlConnection::AddPoints(const char *pPlayer, int Points)
{
char aBuf[512];

View file

@ -33,6 +33,7 @@ public:
virtual void ToUnixTimestamp(const char *pTimestamp, char *aBuf, unsigned int BufferSize);
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 Status Connect();
virtual void Disconnect();
@ -54,7 +55,6 @@ public:
virtual int GetInt(int Col) const;
virtual void GetString(int Col, 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);

View file

@ -205,11 +205,6 @@ int CSqliteConnection::GetBlob(int Col, unsigned char *pBuffer, int BufferSize)
return Size;
}
const char *CSqliteConnection::GetInsertIgnore() const
{
return "INSERT OR IGNORE";
}
bool CSqliteConnection::Execute(const char *pQuery)
{
char *pErrorMsg;

View file

@ -20,6 +20,7 @@ public:
virtual void ToUnixTimestamp(const char *pTimestamp, char *aBuf, unsigned int BufferSize);
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 Status Connect();
virtual void Disconnect();
@ -42,7 +43,6 @@ public:
virtual void GetString(int Col, char *pBuffer, int BufferSize) const;
// passing a negative buffer size is undefined behavior
virtual int GetBlob(int Col, unsigned char *pBuffer, int BufferSize) const;
virtual const char *GetInsertIgnore() const;
virtual void AddPoints(const char *pPlayer, int Points);

View file

@ -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, "
"?, false);",
pSqlServer->GetInsertIgnore(), pSqlServer->GetPrefix(),
pSqlServer->InsertIgnore(), pSqlServer->GetPrefix(),
pSqlServer->InsertTimestampAsUtc(), pData->m_Time,
pData->m_aCpCurrent[0], pData->m_aCpCurrent[1], pData->m_aCpCurrent[2],
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),
"%s INTO %s_teamrace(Map, Name, Timestamp, Time, ID, GameID, DDNet7) "
"VALUES (?, ?, %s, %.2f, ?, ?, false);",
pSqlServer->GetInsertIgnore(), pSqlServer->GetPrefix(),
pSqlServer->InsertIgnore(), pSqlServer->GetPrefix(),
pSqlServer->InsertTimestampAsUtc(), pData->m_Time);
pSqlServer->PrepareStatement(aBuf);
pSqlServer->BindString(1, pData->m_Map);
@ -1317,7 +1317,7 @@ bool CScore::SaveTeamThread(IDbConnection *pSqlServer, const ISqlData *pGameData
str_format(aBuf, sizeof(aBuf),
"%s INTO %s_saves(Savegame, Map, Code, Timestamp, Server, SaveID, DDNet7) "
"VALUES (?, ?, ?, CURRENT_TIMESTAMP, ?, ?, false)",
pSqlServer->GetInsertIgnore(), pSqlServer->GetPrefix());
pSqlServer->InsertIgnore(), pSqlServer->GetPrefix());
pSqlServer->PrepareStatement(aBuf);
pSqlServer->BindString(1, pSaveState);
pSqlServer->BindString(2, pData->m_Map);