Add ExecuteUpdate to database interface reporting affected rows

This commit is contained in:
Zwelf 2021-01-20 14:22:42 +01:00
parent aebe11568a
commit bad2d71d77
5 changed files with 24 additions and 1 deletions

View file

@ -67,6 +67,9 @@ public:
// executes the query and returns if a result row exists and selects it
// when called multiple times the next row is selected
virtual bool Step() = 0;
// executes the query and returns the number of rows affected by the update/insert/delete
// FIXME(2020-01-20): change function to AffectedRows() when moved to c-api of MySQL
virtual int ExecuteUpdate() = 0;
virtual bool IsNull(int Col) const = 0;
virtual float GetFloat(int Col) const = 0;

View file

@ -261,6 +261,18 @@ bool CMysqlConnection::Step()
#endif
}
int CMysqlConnection::ExecuteUpdate()
{
#if defined(CONF_SQL)
if(m_NewQuery)
{
m_NewQuery = false;
return m_pPreparedStmt->executeUpdate();
}
#endif
return -1;
}
bool CMysqlConnection::IsNull(int Col) const
{
#if defined(CONF_SQL)

View file

@ -52,6 +52,7 @@ public:
virtual void Print() {}
virtual bool Step();
virtual int ExecuteUpdate();
virtual bool IsNull(int Col) const;
virtual float GetFloat(int Col) const;

View file

@ -190,6 +190,12 @@ bool CSqliteConnection::Step()
return false;
}
int CSqliteConnection::ExecuteUpdate()
{
Step();
return sqlite3_changes(m_pDb);
}
bool CSqliteConnection::IsNull(int Col) const
{
return sqlite3_column_type(m_pStmt, Col - 1) == SQLITE_NULL;

View file

@ -39,6 +39,7 @@ public:
virtual void Print();
virtual bool Step();
virtual int ExecuteUpdate();
virtual bool IsNull(int Col) const;
virtual float GetFloat(int Col) const;
@ -58,7 +59,7 @@ private:
sqlite3_stmt *m_pStmt;
bool m_Done; // no more rows available for Step
bool m_Locked;
// returns true, if the query succeded
// returns true, if the query succeeded
bool Execute(const char *pQuery);
void ExceptionOnError(int Result);