@MySQLSeekResult
Syntax
@MySQLSeekResult(MySQLResultHandle;Position);
Description
Sets the current position, respectively row, in a stored result of an @MySQLQuery request.
WARNING: Counting starts at 0!
Return:
TRUE on success, otherwise @Error.
Example: @MySQLSeekResult(MySQLResultHandle;Position);
/* Example: Simple MySQL query from the Engine.
The script establishes a connection to a MySQL database,
reads all records from the table testdb.amount,
stores the result values in variables, and writes them to the log. */
/* Initialize the MySQL handle. */
MySQLh:=@MySQLInit;
/* Initialize the error status: 1 means error or no successful connection yet. */
MySQLError:=1;
/* Check whether the MySQL handle was initialized successfully. */
IF(@IsError(MySQLh)){
@LogReport(MySQLh;3);
}ELSE{
/* Set or initialize MySQL options. */
@MySQLOptions(MySQLh);
/* Define the connection data for the MySQL server. */
MySQLUser:="MySQLConnector";
MySQLPassword:="ConnectorPassword";
MySQLDefaultDatabase:="testdb";
MySQLHost:="172.16.1.215";
/* Establish the connection to the MySQL database. */
Ret:=@MySQLConnect(MySQLh;MySQLHost;MySQLUser;MySQLPassword;MySQLDefaultDatabase);
/* If the connection fails, log the error. */
IF(@IsError(Ret)){
@LogReport(Ret);
}ELSE{
/* The connection was successful; reset the error status. */
MySQLError:=0;}
/* Execute the query only if the connection was established successfully. */
IF(!MySQLError){
/* Select all records in testdb.amount. */
QueryStr:="SELECT ID,Name,Amount,UID FROM testdb.amount;";
/* Execute the query and return the result handle in MySQLResH. */
Ret:=@MySQLQuery(MySQLh;QueryStr;MySQLResH);
IF(@IsError(Ret)){
@LogReport(Ret;3);}
/* Determine the number of rows returned by the query. */
NumRows:=@MySQLGetNumRows(MySQLResH);
@LogReport("NumRows:"+@Text(NumRows);3);
/* Iterate over all rows of the result */
Rows_Index:=1;
WHILE(Rows_Index<=NumRows){
/* Read the current row and store the column values in variables. */
Ret:=@MySQLFetchRow(MySQLResH;1;ThisQueryID;ThisQueryName;ThisQueryAmount;ThisQueryUID);
IF(@IsError(Ret)){
@LogReport(Ret;3);
Rows_Index:=NumRows;
}
ELSE{
/* Output the retrieved result values. */
@LogReport("ThisQueryID :"+@Text(ThisQueryID);3);
@LogReport("ThisQueryName :"+ThisQueryName;3);
@LogReport("ThisQueryAmount:"+@Text(ThisQueryAmount);3);
@LogReport("ThisQueryUID :"+ThisQueryUID;3);
}
/* Increment RowIndex */
@Increment(Rows_Index);
}
@LogReport("Setting the position to row #2 in result";3);
/* Setting Position to row #2 */
@MySQLSeekResult(MySQLResH;1);
/* Reading row #2 again */
Ret:=@MySQLFetchRow(MySQLResH;1;ThisQueryID;ThisQueryName;ThisQueryAmount;ThisQueryUID);
IF(@IsError(Ret)){
@LogReport(Ret;3);
Rows_Index:=NumRows;
}
ELSE{
/* Output the retrieved result values. */
@LogReport("ThisQueryID :"+@Text(ThisQueryID);3);
@LogReport("ThisQueryName :"+ThisQueryName;3);
@LogReport("ThisQueryAmount:"+@Text(ThisQueryAmount);3);
@LogReport("ThisQueryUID :"+ThisQueryUID;3);
}
/* Free the result handle. */
MySQLResH:=@MySQLFreeResult(MySQLResH);
}
/* Close the MySQL connection. */
MySQLh:=@MySQLClose(MySQLh);
}
/* End or clean up the MySQL thread context. */
@MySQLThreadEnd;
Note : This text was machine-translated and may contain inaccuracies.
