Make SQL_LastInsertId and SQL_GetAffectedRows work on query handles, allowing their use with threaded queries

This commit is contained in:
John Schoenick
2011-05-14 20:21:37 -07:00
parent 5b45e29533
commit e8c141d775
9 changed files with 153 additions and 26 deletions
+12
View File
@@ -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)
+5
View File
@@ -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_
+10
View File
@@ -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);
+2
View File
@@ -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:
+9
View File
@@ -186,6 +186,15 @@ IQuery *SqDatabase::DoQueryEx(const char *query, size_t len)
return pQuery;
}
unsigned int SqDatabase::GetAffectedRowsForQuery(IQuery *query)
{
return static_cast<SqQuery*>(query)->GetAffectedRows();
}
unsigned int SqDatabase::GetInsertIDForQuery(IQuery *query)
{
return static_cast<SqQuery*>(query)->GetInsertID();
}
IPreparedQuery *SqDatabase::PrepareQuery(const char *query,
char *error,
size_t maxlength,
+2
View File
@@ -56,6 +56,8 @@ public:
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:
sqlite3 *GetDb();
private: