implemented amb27 (SQL_Rewind)

fixed builds
This commit is contained in:
David Anderson 2007-04-24 15:46:33 +00:00
parent adfc2ab451
commit bfe1ff6e15
13 changed files with 81 additions and 2 deletions

View File

@ -467,6 +467,28 @@ static cell AMX_NATIVE_CALL SQL_SetAffinity(AMX *amx, cell *params)
return 0; 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[] = AMX_NATIVE_INFO g_BaseSqlNatives[] =
{ {
{"SQL_MakeDbTuple", SQL_MakeDbTuple}, {"SQL_MakeDbTuple", SQL_MakeDbTuple},
@ -488,6 +510,7 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] =
{"SQL_SetAffinity", SQL_SetAffinity}, {"SQL_SetAffinity", SQL_SetAffinity},
{"SQL_GetInsertId", SQL_GetInsertId}, {"SQL_GetInsertId", SQL_GetInsertId},
{"SQL_GetQueryString", SQL_GetQueryString}, {"SQL_GetQueryString", SQL_GetQueryString},
{"SQL_Rewind", SQL_Rewind},
{NULL, NULL}, {NULL, NULL},
}; };

View File

@ -57,6 +57,10 @@ namespace SourceMod
* call IsDone() after each call to NextRow(). * call IsDone() after each call to NextRow().
*/ */
virtual void NextRow() =0; virtual void NextRow() =0;
/**
* Rewinds to the first row.
*/
virtual void Rewind() =0;
}; };
struct QueryInfo struct QueryInfo

View File

@ -147,3 +147,9 @@ void MysqlResultSet::NextRow()
m_kRow.m_Lengths = lengths; m_kRow.m_Lengths = lengths;
} }
} }
void MysqlResultSet::Rewind()
{
mysql_data_seek(m_pRes, 0);
NextRow();
}

View File

@ -43,6 +43,7 @@ namespace SourceMod
bool IsDone(); bool IsDone();
IResultRow *GetRow(); IResultRow *GetRow();
void NextRow(); void NextRow();
void Rewind();
private: private:
MYSQL_RES *m_pRes; MYSQL_RES *m_pRes;
MysqlResultRow m_kRow; MysqlResultRow m_kRow;

View File

@ -561,6 +561,10 @@ void AtomicResult::CopyFrom(IResultSet *rs)
} }
} }
void AtomicResult::Rewind()
{
m_CurRow = 1;
}
AMX_NATIVE_INFO g_ThreadSqlNatives[] = AMX_NATIVE_INFO g_ThreadSqlNatives[] =
{ {

View File

@ -33,6 +33,7 @@ public:
virtual bool IsDone(); virtual bool IsDone();
virtual IResultRow *GetRow(); virtual IResultRow *GetRow();
virtual void NextRow(); virtual void NextRow();
virtual void Rewind();
public: public:
virtual const char *GetString(unsigned int columnId); virtual const char *GetString(unsigned int columnId);
virtual const char *GetStringSafe(unsigned int columnId); virtual const char *GetStringSafe(unsigned int columnId);

View File

@ -467,6 +467,29 @@ static cell AMX_NATIVE_CALL SQL_SetAffinity(AMX *amx, cell *params)
return 0; 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[] = AMX_NATIVE_INFO g_BaseSqlNatives[] =
{ {
{"SQL_MakeDbTuple", SQL_MakeDbTuple}, {"SQL_MakeDbTuple", SQL_MakeDbTuple},
@ -488,6 +511,7 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] =
{"SQL_SetAffinity", SQL_SetAffinity}, {"SQL_SetAffinity", SQL_SetAffinity},
{"SQL_GetInsertId", SQL_GetInsertId}, {"SQL_GetInsertId", SQL_GetInsertId},
{"SQL_GetQueryString", SQL_GetQueryString}, {"SQL_GetQueryString", SQL_GetQueryString},
{"SQL_Rewind", SQL_Rewind},
{NULL, NULL}, {NULL, NULL},
}; };

View File

@ -21,7 +21,7 @@
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
AdditionalOptions="/D "NO_TCL"" AdditionalOptions="/D "NO_TCL""
Optimization="0" Optimization="0"
AdditionalIncludeDirectories=""..\sqlite-source";"..\sqlitepp";"..\thread";"..\sdk"" AdditionalIncludeDirectories=""..\sqlite-source";"..\sqlitepp";"..\thread";"..\sdk";.."
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;sqlite_EXPORTS;SM_DEFAULT_THREADER" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;sqlite_EXPORTS;SM_DEFAULT_THREADER"
MinimalRebuild="TRUE" MinimalRebuild="TRUE"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
@ -77,7 +77,7 @@
Optimization="2" Optimization="2"
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
OmitFramePointers="TRUE" OmitFramePointers="TRUE"
AdditionalIncludeDirectories=""..\sqlite-source";"..\sqlitepp";"..\thread";"..\sdk"" AdditionalIncludeDirectories=""..\sqlite-source";"..\sqlitepp";"..\thread";"..\sdk";.."
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;sqlite_EXPORTS;SM_DEFAULT_THREADER" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;sqlite_EXPORTS;SM_DEFAULT_THREADER"
StringPooling="TRUE" StringPooling="TRUE"
RuntimeLibrary="0" RuntimeLibrary="0"

View File

@ -57,6 +57,10 @@ namespace SourceMod
* call IsDone() after each call to NextRow(). * call IsDone() after each call to NextRow().
*/ */
virtual void NextRow() =0; virtual void NextRow() =0;
/**
* Resets back to the first row.
*/
virtual void Rewind() =0;
}; };
struct QueryInfo struct QueryInfo

View File

@ -158,3 +158,9 @@ void SqliteResultSet::NextRow()
{ {
m_CurIndex = (++m_CurRow * m_Columns); m_CurIndex = (++m_CurRow * m_Columns);
} }
void SqliteResultSet::Rewind()
{
m_CurRow = 1;
m_CurIndex = (m_CurRow * m_Columns);
}

View File

@ -27,6 +27,7 @@ namespace SourceMod
bool IsDone(); bool IsDone();
IResultRow *GetRow(); IResultRow *GetRow();
void NextRow(); void NextRow();
void Rewind();
public: public:
/** /**
* IResultRow * IResultRow

View File

@ -555,6 +555,10 @@ void AtomicResult::CopyFrom(IResultSet *rs)
} }
} }
void AtomicResult::Rewind()
{
m_CurRow = 1;
}
AMX_NATIVE_INFO g_ThreadSqlNatives[] = AMX_NATIVE_INFO g_ThreadSqlNatives[] =
{ {

View File

@ -33,6 +33,7 @@ public:
virtual bool IsDone(); virtual bool IsDone();
virtual IResultRow *GetRow(); virtual IResultRow *GetRow();
virtual void NextRow(); virtual void NextRow();
virtual void Rewind();
public: public:
virtual const char *GetString(unsigned int columnId); virtual const char *GetString(unsigned int columnId);
virtual const char *GetStringSafe(unsigned int columnId); virtual const char *GetStringSafe(unsigned int columnId);