diff --git a/extensions/sqlite/driver/SqQuery.cpp b/extensions/sqlite/driver/SqQuery.cpp index 11525213..bf77e7ff 100644 --- a/extensions/sqlite/driver/SqQuery.cpp +++ b/extensions/sqlite/driver/SqQuery.cpp @@ -27,6 +27,7 @@ SqQuery::SqQuery(SqDatabase *parent, sqlite3_stmt *stmt) : m_pParent(parent), m_pStmt(stmt), m_pResults(NULL), m_AffectedRows(0), m_InsertID(0) { m_ParamCount = sqlite3_bind_parameter_count(m_pStmt); + m_ColCount = sqlite3_column_count(m_pStmt); m_pParent->IncReferenceCount(); } @@ -127,15 +128,25 @@ bool SqQuery::Execute() { int rc; + /* If we don't have a result set and we have a column count, + * create a result set pre-emptively. This is in case there + * are no rows in the upcoming result set. + */ + if (!m_pResults && m_ColCount) + { + m_pResults = new SqResults(this); + } + /* If we've got results, throw them away */ if (m_pResults) { m_pResults->ResetResultCount(); } + /* Fetch each row, if any */ while ((rc = sqlite3_step(m_pStmt)) == SQLITE_ROW) { - /* Delay creation as long as possible... */ + /* This should NEVER happen but we're being safe. */ if (!m_pResults) { m_pResults = new SqResults(this); diff --git a/extensions/sqlite/driver/SqQuery.h b/extensions/sqlite/driver/SqQuery.h index 73f11f26..5f3a1f5e 100644 --- a/extensions/sqlite/driver/SqQuery.h +++ b/extensions/sqlite/driver/SqQuery.h @@ -81,6 +81,7 @@ private: int m_LastErrorCode; unsigned int m_AffectedRows; unsigned int m_InsertID; + unsigned int m_ColCount; }; #endif //_INCLUDE_SQLITE_SOURCEMOD_QUERY_H_