From bfe1ff6e154fec2f40513370e6ca277b4706213b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 24 Apr 2007 15:46:33 +0000 Subject: [PATCH] implemented amb27 (SQL_Rewind) fixed builds --- dlls/mysqlx/basic_sql.cpp | 23 +++++++++++++++++++++++ dlls/mysqlx/mysql/ISQLDriver.h | 4 ++++ dlls/mysqlx/mysql/MysqlResultSet.cpp | 6 ++++++ dlls/mysqlx/mysql/MysqlResultSet.h | 1 + dlls/mysqlx/threading.cpp | 4 ++++ dlls/mysqlx/threading.h | 1 + dlls/sqlite/basic_sql.cpp | 24 ++++++++++++++++++++++++ dlls/sqlite/msvc7/sqlite.vcproj | 4 ++-- dlls/sqlite/sqlitepp/ISQLDriver.h | 4 ++++ dlls/sqlite/sqlitepp/SqliteResultSet.cpp | 6 ++++++ dlls/sqlite/sqlitepp/SqliteResultSet.h | 1 + dlls/sqlite/threading.cpp | 4 ++++ dlls/sqlite/threading.h | 1 + 13 files changed, 81 insertions(+), 2 deletions(-) diff --git a/dlls/mysqlx/basic_sql.cpp b/dlls/mysqlx/basic_sql.cpp index 1bcf18e4..c41808a1 100644 --- a/dlls/mysqlx/basic_sql.cpp +++ b/dlls/mysqlx/basic_sql.cpp @@ -467,6 +467,28 @@ static cell AMX_NATIVE_CALL SQL_SetAffinity(AMX *amx, cell *params) return 0; } +static cell AMX_NATIVE_CALL SQL_Rewind(AMX *amx, cell *params) +{ + AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); + if (!qInfo) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]); + return 0; + } + + IResultSet *rs = qInfo->info.rs; + + if (!rs) + { + MF_LogError(amx, AMX_ERR_NATIVE, "No result set in this query!"); + return 0; + } + + rs->Rewind(); + + return 1; +} + AMX_NATIVE_INFO g_BaseSqlNatives[] = { {"SQL_MakeDbTuple", SQL_MakeDbTuple}, @@ -488,6 +510,7 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] = {"SQL_SetAffinity", SQL_SetAffinity}, {"SQL_GetInsertId", SQL_GetInsertId}, {"SQL_GetQueryString", SQL_GetQueryString}, + {"SQL_Rewind", SQL_Rewind}, {NULL, NULL}, }; diff --git a/dlls/mysqlx/mysql/ISQLDriver.h b/dlls/mysqlx/mysql/ISQLDriver.h index 80c325ad..d1a8144a 100644 --- a/dlls/mysqlx/mysql/ISQLDriver.h +++ b/dlls/mysqlx/mysql/ISQLDriver.h @@ -57,6 +57,10 @@ namespace SourceMod * call IsDone() after each call to NextRow(). */ virtual void NextRow() =0; + /** + * Rewinds to the first row. + */ + virtual void Rewind() =0; }; struct QueryInfo diff --git a/dlls/mysqlx/mysql/MysqlResultSet.cpp b/dlls/mysqlx/mysql/MysqlResultSet.cpp index 8327a431..d632ae13 100644 --- a/dlls/mysqlx/mysql/MysqlResultSet.cpp +++ b/dlls/mysqlx/mysql/MysqlResultSet.cpp @@ -147,3 +147,9 @@ void MysqlResultSet::NextRow() m_kRow.m_Lengths = lengths; } } + +void MysqlResultSet::Rewind() +{ + mysql_data_seek(m_pRes, 0); + NextRow(); +} diff --git a/dlls/mysqlx/mysql/MysqlResultSet.h b/dlls/mysqlx/mysql/MysqlResultSet.h index 0c65b53a..b4aa8da1 100644 --- a/dlls/mysqlx/mysql/MysqlResultSet.h +++ b/dlls/mysqlx/mysql/MysqlResultSet.h @@ -43,6 +43,7 @@ namespace SourceMod bool IsDone(); IResultRow *GetRow(); void NextRow(); + void Rewind(); private: MYSQL_RES *m_pRes; MysqlResultRow m_kRow; diff --git a/dlls/mysqlx/threading.cpp b/dlls/mysqlx/threading.cpp index cd4bce74..e3b77741 100644 --- a/dlls/mysqlx/threading.cpp +++ b/dlls/mysqlx/threading.cpp @@ -561,6 +561,10 @@ void AtomicResult::CopyFrom(IResultSet *rs) } } +void AtomicResult::Rewind() +{ + m_CurRow = 1; +} AMX_NATIVE_INFO g_ThreadSqlNatives[] = { diff --git a/dlls/mysqlx/threading.h b/dlls/mysqlx/threading.h index 11b1b32b..6a74f7af 100644 --- a/dlls/mysqlx/threading.h +++ b/dlls/mysqlx/threading.h @@ -33,6 +33,7 @@ public: virtual bool IsDone(); virtual IResultRow *GetRow(); virtual void NextRow(); + virtual void Rewind(); public: virtual const char *GetString(unsigned int columnId); virtual const char *GetStringSafe(unsigned int columnId); diff --git a/dlls/sqlite/basic_sql.cpp b/dlls/sqlite/basic_sql.cpp index b093f84f..c09f8bb8 100644 --- a/dlls/sqlite/basic_sql.cpp +++ b/dlls/sqlite/basic_sql.cpp @@ -467,6 +467,29 @@ static cell AMX_NATIVE_CALL SQL_SetAffinity(AMX *amx, cell *params) return 0; } +static cell AMX_NATIVE_CALL SQL_Rewind(AMX *amx, cell *params) +{ + AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); + if (!qInfo) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]); + return 0; + } + + IResultSet *rs = qInfo->info.rs; + + if (!rs) + { + MF_LogError(amx, AMX_ERR_NATIVE, "No result set in this query!"); + return 0; + } + + rs->Rewind(); + + return 1; +} + + AMX_NATIVE_INFO g_BaseSqlNatives[] = { {"SQL_MakeDbTuple", SQL_MakeDbTuple}, @@ -488,6 +511,7 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] = {"SQL_SetAffinity", SQL_SetAffinity}, {"SQL_GetInsertId", SQL_GetInsertId}, {"SQL_GetQueryString", SQL_GetQueryString}, + {"SQL_Rewind", SQL_Rewind}, {NULL, NULL}, }; diff --git a/dlls/sqlite/msvc7/sqlite.vcproj b/dlls/sqlite/msvc7/sqlite.vcproj index a5a65802..dd052abd 100644 --- a/dlls/sqlite/msvc7/sqlite.vcproj +++ b/dlls/sqlite/msvc7/sqlite.vcproj @@ -21,7 +21,7 @@ Name="VCCLCompilerTool" AdditionalOptions="/D "NO_TCL"" Optimization="0" - AdditionalIncludeDirectories=""..\sqlite-source";"..\sqlitepp";"..\thread";"..\sdk"" + AdditionalIncludeDirectories=""..\sqlite-source";"..\sqlitepp";"..\thread";"..\sdk";.." PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;sqlite_EXPORTS;SM_DEFAULT_THREADER" MinimalRebuild="TRUE" BasicRuntimeChecks="3" @@ -77,7 +77,7 @@ Optimization="2" InlineFunctionExpansion="1" OmitFramePointers="TRUE" - AdditionalIncludeDirectories=""..\sqlite-source";"..\sqlitepp";"..\thread";"..\sdk"" + AdditionalIncludeDirectories=""..\sqlite-source";"..\sqlitepp";"..\thread";"..\sdk";.." PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;sqlite_EXPORTS;SM_DEFAULT_THREADER" StringPooling="TRUE" RuntimeLibrary="0" diff --git a/dlls/sqlite/sqlitepp/ISQLDriver.h b/dlls/sqlite/sqlitepp/ISQLDriver.h index c3d6afb3..224feaf5 100644 --- a/dlls/sqlite/sqlitepp/ISQLDriver.h +++ b/dlls/sqlite/sqlitepp/ISQLDriver.h @@ -57,6 +57,10 @@ namespace SourceMod * call IsDone() after each call to NextRow(). */ virtual void NextRow() =0; + /** + * Resets back to the first row. + */ + virtual void Rewind() =0; }; struct QueryInfo diff --git a/dlls/sqlite/sqlitepp/SqliteResultSet.cpp b/dlls/sqlite/sqlitepp/SqliteResultSet.cpp index 41aef9de..abeea73a 100644 --- a/dlls/sqlite/sqlitepp/SqliteResultSet.cpp +++ b/dlls/sqlite/sqlitepp/SqliteResultSet.cpp @@ -158,3 +158,9 @@ void SqliteResultSet::NextRow() { m_CurIndex = (++m_CurRow * m_Columns); } + +void SqliteResultSet::Rewind() +{ + m_CurRow = 1; + m_CurIndex = (m_CurRow * m_Columns); +} diff --git a/dlls/sqlite/sqlitepp/SqliteResultSet.h b/dlls/sqlite/sqlitepp/SqliteResultSet.h index 5e8d928c..07935a7c 100644 --- a/dlls/sqlite/sqlitepp/SqliteResultSet.h +++ b/dlls/sqlite/sqlitepp/SqliteResultSet.h @@ -27,6 +27,7 @@ namespace SourceMod bool IsDone(); IResultRow *GetRow(); void NextRow(); + void Rewind(); public: /** * IResultRow diff --git a/dlls/sqlite/threading.cpp b/dlls/sqlite/threading.cpp index 6a06c690..672808d1 100644 --- a/dlls/sqlite/threading.cpp +++ b/dlls/sqlite/threading.cpp @@ -555,6 +555,10 @@ void AtomicResult::CopyFrom(IResultSet *rs) } } +void AtomicResult::Rewind() +{ + m_CurRow = 1; +} AMX_NATIVE_INFO g_ThreadSqlNatives[] = { diff --git a/dlls/sqlite/threading.h b/dlls/sqlite/threading.h index c8e198ab..f05a386a 100644 --- a/dlls/sqlite/threading.h +++ b/dlls/sqlite/threading.h @@ -33,6 +33,7 @@ public: virtual bool IsDone(); virtual IResultRow *GetRow(); virtual void NextRow(); + virtual void Rewind(); public: virtual const char *GetString(unsigned int columnId); virtual const char *GetStringSafe(unsigned int columnId);