Add BindBlob and BindFloat function to IDbConnection interface

This commit is contained in:
Zwelf 2020-07-15 00:12:08 +02:00
parent 26a2c91235
commit e3a78a7a31
5 changed files with 40 additions and 0 deletions

View file

@ -41,7 +41,9 @@ public:
// PrepareStatement has to be called beforehand, // PrepareStatement has to be called beforehand,
virtual void BindString(int Idx, const char *pString) = 0; 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 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 // executes the query and returns if a result row exists and selects it
// when called multiple times the next row is selected // when called multiple times the next row is selected

View file

@ -4,6 +4,8 @@
#include <cppconn/driver.h> #include <cppconn/driver.h>
#endif #endif
#include <string>
lock CMysqlConnection::m_SqlDriverLock; lock CMysqlConnection::m_SqlDriverLock;
CMysqlConnection::CMysqlConnection( CMysqlConnection::CMysqlConnection(
@ -205,6 +207,16 @@ void CMysqlConnection::BindString(int Idx, const char *pString)
#endif #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) void CMysqlConnection::BindInt(int Idx, int Value)
{ {
#if defined(CONF_SQL) #if defined(CONF_SQL)
@ -213,6 +225,14 @@ void CMysqlConnection::BindInt(int Idx, int Value)
#endif #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() bool CMysqlConnection::Step()
{ {
#if defined(CONF_SQL) #if defined(CONF_SQL)

View file

@ -39,7 +39,9 @@ public:
virtual void PrepareStatement(const char *pStmt); virtual void PrepareStatement(const char *pStmt);
virtual void BindString(int Idx, const char *pString); 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 BindInt(int Idx, int Value);
virtual void BindFloat(int Idx, float Value);
virtual bool Step(); virtual bool Step();

View file

@ -118,6 +118,13 @@ void CSqliteConnection::BindString(int Idx, const char *pString)
m_Done = false; 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) void CSqliteConnection::BindInt(int Idx, int Value)
{ {
int Result = sqlite3_bind_int(m_pStmt, Idx, Value); int Result = sqlite3_bind_int(m_pStmt, Idx, Value);
@ -125,6 +132,13 @@ void CSqliteConnection::BindInt(int Idx, int Value)
m_Done = false; 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() bool CSqliteConnection::Step()
{ {
if(m_Done) if(m_Done)

View file

@ -26,7 +26,9 @@ public:
virtual void PrepareStatement(const char *pStmt); virtual void PrepareStatement(const char *pStmt);
virtual void BindString(int Idx, const char *pString); 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 BindInt(int Idx, int Value);
virtual void BindFloat(int Idx, float Value);
virtual bool Step(); virtual bool Step();