Added SQL_GetInsertId()

This commit is contained in:
David Anderson
2006-08-28 19:17:26 +00:00
parent baf406cb6a
commit 9bd22661ff
13 changed files with 93 additions and 14 deletions

View File

@ -65,9 +65,10 @@ namespace SourceMod
unsigned long long affected_rows;
int errorcode;
bool success;
unsigned long long insert_id;
};
class IQuery
class IQuery
{
public:
virtual ~IQuery() { };
@ -94,6 +95,10 @@ namespace SourceMod
* Returns the query string.
*/
virtual const char *GetQueryString() =0;
/**
* Same as execute, but supports insert_id
*/
virtual bool Execute2(QueryInfo *info, char *error, size_t maxlength) =0;
};
class ISQLDriver;

View File

@ -46,6 +46,25 @@ bool MysqlQuery::Execute(QueryInfo *info, char *error, size_t maxlength)
return res;
}
bool MysqlQuery::Execute2(QueryInfo *info, char *error, size_t maxlength)
{
bool res = ExecuteR(info, error, maxlength);
if (m_LastRes)
m_LastRes->FreeHandle();
m_LastRes = (MysqlResultSet *)info->rs;
if (info->success)
{
info->insert_id = mysql_insert_id(m_pDatabase->m_pMysql);
} else {
info->insert_id = 0;
}
return res;
}
const char *MysqlQuery::GetQueryString()
{
return m_QueryString;
@ -91,10 +110,5 @@ bool MysqlQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength)
}
}
if (info->success && error && maxlength)
{
*error = '\0';
}
return info->success;
}

View File

@ -17,6 +17,7 @@ namespace SourceMod
void FreeHandle();
bool Execute(QueryInfo *info, char *error, size_t maxlength);
bool ExecuteR(QueryInfo *info, char *error, size_t maxlength);
bool Execute2(QueryInfo *info, char *error, size_t maxlength);
const char *GetQueryString();
private:
MysqlDatabase *m_pDatabase;