Make SQL_LastInsertId and SQL_GetAffectedRows work on query handles, allowing their use with threaded queries
This commit is contained in:
@@ -307,6 +307,8 @@ MyQuery::MyQuery(MyDatabase *db, MYSQL_RES *res)
|
||||
: m_pParent(db), m_rs(res)
|
||||
{
|
||||
m_pParent->IncReferenceCount();
|
||||
m_InsertID = m_pParent->GetInsertID();
|
||||
m_AffectedRows = m_pParent->GetAffectedRows();
|
||||
}
|
||||
|
||||
IResultSet *MyQuery::GetResultSet()
|
||||
@@ -319,6 +321,16 @@ IResultSet *MyQuery::GetResultSet()
|
||||
return &m_rs;
|
||||
}
|
||||
|
||||
unsigned int MyQuery::GetInsertID()
|
||||
{
|
||||
return m_InsertID;
|
||||
}
|
||||
|
||||
unsigned int MyQuery::GetAffectedRows()
|
||||
{
|
||||
return m_AffectedRows;
|
||||
}
|
||||
|
||||
bool MyQuery::FetchMoreResults()
|
||||
{
|
||||
if (m_rs.m_pRes == NULL)
|
||||
|
||||
@@ -87,9 +87,14 @@ public:
|
||||
IResultSet *GetResultSet();
|
||||
bool FetchMoreResults();
|
||||
void Destroy();
|
||||
public: // Used by the driver to implement GetInsertIDForQuery()/GetAffectedRowsForQuery()
|
||||
unsigned int GetInsertID();
|
||||
unsigned int GetAffectedRows();
|
||||
private:
|
||||
MyDatabase *m_pParent;
|
||||
MyBasicResults m_rs;
|
||||
unsigned int m_InsertID;
|
||||
unsigned int m_AffectedRows;
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_SM_MYSQL_BASIC_RESULTS_H_
|
||||
|
||||
@@ -257,6 +257,16 @@ IQuery *MyDatabase::DoQueryEx(const char *query, size_t len)
|
||||
return new MyQuery(this, res);
|
||||
}
|
||||
|
||||
unsigned int MyDatabase::GetAffectedRowsForQuery(IQuery *query)
|
||||
{
|
||||
return static_cast<MyQuery*>(query)->GetAffectedRows();
|
||||
}
|
||||
|
||||
unsigned int MyDatabase::GetInsertIDForQuery(IQuery *query)
|
||||
{
|
||||
return static_cast<MyQuery*>(query)->GetInsertID();
|
||||
}
|
||||
|
||||
IPreparedQuery *MyDatabase::PrepareQuery(const char *query, char *error, size_t maxlength, int *errCode)
|
||||
{
|
||||
MYSQL_STMT *stmt = mysql_stmt_init(m_mysql);
|
||||
|
||||
@@ -60,6 +60,8 @@ public: //IDatabase
|
||||
IDBDriver *GetDriver();
|
||||
bool DoSimpleQueryEx(const char *query, size_t len);
|
||||
IQuery *DoQueryEx(const char *query, size_t len);
|
||||
unsigned int GetAffectedRowsForQuery(IQuery *query);
|
||||
unsigned int GetInsertIDForQuery(IQuery *query);
|
||||
public:
|
||||
const DatabaseInfo &GetInfo();
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user