mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 06:28:19 +00:00
Add BindBlob and BindFloat function to IDbConnection interface
This commit is contained in:
parent
26a2c91235
commit
e3a78a7a31
|
@ -41,7 +41,9 @@ public:
|
|||
|
||||
// PrepareStatement has to be called beforehand,
|
||||
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 BindFloat(int Idx, float Value) = 0;
|
||||
|
||||
// executes the query and returns if a result row exists and selects it
|
||||
// when called multiple times the next row is selected
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <cppconn/driver.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
lock CMysqlConnection::m_SqlDriverLock;
|
||||
|
||||
CMysqlConnection::CMysqlConnection(
|
||||
|
@ -205,6 +207,16 @@ void CMysqlConnection::BindString(int Idx, const char *pString)
|
|||
#endif
|
||||
}
|
||||
|
||||
void CMysqlConnection::BindBlob(int Idx, unsigned char *pBlob, int Size)
|
||||
{
|
||||
#if defined(CONF_SQL)
|
||||
// copy blob into string
|
||||
auto Blob = std::string(pBlob, pBlob+Size);
|
||||
m_pPreparedStmt->setString(Idx, Blob);
|
||||
m_NewQuery = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CMysqlConnection::BindInt(int Idx, int Value)
|
||||
{
|
||||
#if defined(CONF_SQL)
|
||||
|
@ -213,6 +225,14 @@ void CMysqlConnection::BindInt(int Idx, int Value)
|
|||
#endif
|
||||
}
|
||||
|
||||
void CMysqlConnection::BindFloat(int Idx, float Value)
|
||||
{
|
||||
#if defined(CONF_SQL)
|
||||
m_pPreparedStmt->setDouble(Idx, (double)Value);
|
||||
m_NewQuery = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CMysqlConnection::Step()
|
||||
{
|
||||
#if defined(CONF_SQL)
|
||||
|
|
|
@ -39,7 +39,9 @@ public:
|
|||
virtual void PrepareStatement(const char *pStmt);
|
||||
|
||||
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 BindFloat(int Idx, float Value);
|
||||
|
||||
virtual bool Step();
|
||||
|
||||
|
|
|
@ -118,6 +118,13 @@ void CSqliteConnection::BindString(int Idx, const char *pString)
|
|||
m_Done = false;
|
||||
}
|
||||
|
||||
void CSqliteConnection::BindBlob(int Idx, unsigned char *pBlob, int Size)
|
||||
{
|
||||
int Result = sqlite3_bind_blob(m_pStmt, Idx, pBlob, Size, NULL);
|
||||
ExceptionOnError(Result);
|
||||
m_Done = false;
|
||||
}
|
||||
|
||||
void CSqliteConnection::BindInt(int Idx, int Value)
|
||||
{
|
||||
int Result = sqlite3_bind_int(m_pStmt, Idx, Value);
|
||||
|
@ -125,6 +132,13 @@ void CSqliteConnection::BindInt(int Idx, int Value)
|
|||
m_Done = false;
|
||||
}
|
||||
|
||||
void CSqliteConnection::BindFloat(int Idx, float Value)
|
||||
{
|
||||
int Result = sqlite3_bind_double(m_pStmt, Idx, (double)Value);
|
||||
ExceptionOnError(Result);
|
||||
m_Done = false;
|
||||
}
|
||||
|
||||
bool CSqliteConnection::Step()
|
||||
{
|
||||
if(m_Done)
|
||||
|
|
|
@ -26,7 +26,9 @@ public:
|
|||
virtual void PrepareStatement(const char *pStmt);
|
||||
|
||||
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 BindFloat(int Idx, float Value);
|
||||
|
||||
virtual bool Step();
|
||||
|
||||
|
|
Loading…
Reference in a new issue