4366: Add sql BindInt64 r=def- a=ChillerDragon

Comes in handy for my downstream

Follow up to https://github.com/ddnet/ddnet/pull/4334

Tested with sqlite3

## Checklist

- [x] Tested the change ingame
- [ ] 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
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] 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: ChillerDragon <ChillerDragon@gmail.com>
This commit is contained in:
bors[bot] 2021-11-19 12:40:05 +00:00 committed by GitHub
commit 6df701a34a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View file

@ -54,6 +54,7 @@ public:
virtual void BindString(int Idx, const char *pString) = 0;
virtual void BindBlob(int Idx, unsigned char *pBlob, int Size) = 0;
virtual void BindInt(int Idx, int Value) = 0;
virtual void BindInt64(int Idx, int64_t Value) = 0;
virtual void BindFloat(int Idx, float Value) = 0;
// Print expanded sql statement

View file

@ -82,6 +82,7 @@ public:
virtual void BindString(int Idx, const char *pString);
virtual void BindBlob(int Idx, unsigned char *pBlob, int Size);
virtual void BindInt(int Idx, int Value);
virtual void BindInt64(int Idx, int64_t Value);
virtual void BindFloat(int Idx, float Value);
virtual void Print() {}
@ -400,6 +401,23 @@ void CMysqlConnection::BindInt(int Idx, int Value)
pParam->error = nullptr;
}
void CMysqlConnection::BindInt64(int Idx, int64_t Value)
{
m_NewQuery = true;
Idx -= 1;
dbg_assert(0 <= Idx && Idx < (int)m_aStmtParameters.size(), "index out of bounds");
m_aStmtParameterExtras[Idx].i = Value;
MYSQL_BIND *pParam = &m_aStmtParameters[Idx];
pParam->buffer_type = MYSQL_TYPE_LONGLONG;
pParam->buffer = &m_aStmtParameterExtras[Idx].i;
pParam->buffer_length = sizeof(m_aStmtParameterExtras[Idx].i);
pParam->length = nullptr;
pParam->is_null = nullptr;
pParam->is_unsigned = false;
pParam->error = nullptr;
}
void CMysqlConnection::BindFloat(int Idx, float Value)
{
m_NewQuery = true;

View file

@ -32,6 +32,7 @@ public:
virtual void BindString(int Idx, const char *pString);
virtual void BindBlob(int Idx, unsigned char *pBlob, int Size);
virtual void BindInt(int Idx, int Value);
virtual void BindInt64(int Idx, int64_t Value);
virtual void BindFloat(int Idx, float Value);
virtual void Print();
@ -197,6 +198,13 @@ void CSqliteConnection::BindInt(int Idx, int Value)
m_Done = false;
}
void CSqliteConnection::BindInt64(int Idx, int64_t Value)
{
int Result = sqlite3_bind_int64(m_pStmt, Idx, Value);
AssertNoError(Result);
m_Done = false;
}
void CSqliteConnection::BindFloat(int Idx, float Value)
{
int Result = sqlite3_bind_double(m_pStmt, Idx, (double)Value);