Added SQL_GetInsertId()
This commit is contained in:
@ -65,6 +65,7 @@ namespace SourceMod
|
||||
unsigned long long affected_rows;
|
||||
int errorcode;
|
||||
bool success;
|
||||
unsigned long long insert_id;
|
||||
};
|
||||
|
||||
class 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;
|
||||
|
@ -47,6 +47,25 @@ bool SqliteQuery::Execute(QueryInfo *info, char *error, size_t maxlength)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool SqliteQuery::Execute2(QueryInfo *info, char *error, size_t maxlength)
|
||||
{
|
||||
bool res = ExecuteR(info, error, maxlength);
|
||||
|
||||
if (m_LastRes)
|
||||
m_LastRes->FreeHandle();
|
||||
|
||||
m_LastRes = (SqliteResultSet *)info->rs;
|
||||
|
||||
if (info->success)
|
||||
{
|
||||
info->insert_id = sqlite3_last_insert_rowid(m_pDatabase->m_pSql);
|
||||
} else {
|
||||
info->insert_id = 0;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
const char *SqliteQuery::GetQueryString()
|
||||
{
|
||||
return m_QueryString;
|
||||
|
@ -24,6 +24,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:
|
||||
SqliteDatabase *m_pDatabase;
|
||||
|
Reference in New Issue
Block a user