@MySQLQuery
Syntax
@MySQLQuery(MySQLHandle;QueryStr);
@MySQLQuery(MySQLHandle;QueryStr;MySQLResultHandle);
@MySQLQuery(MySQLHandle;QueryStr;MySQLResultHandle;AutoIncrementIDRet);
Description
Executes a MySQL query.
If the query returns a result, it can be stored in the VSPECMYSQLRES MySQLResultHandle.
If the query contains an INSERT statement and it affects an AUTOINCREMENT ID column, the generated ID is returned in AutoIncrementIDRet.
The VSPECMYSQL MySQLHandle is provided by @MySQLInit.
Return:
On success TRUE, otherwise @Error;
Example: @MySQLQuery(MySQLHandle;QueryStr;MySQLResultHandle);
MySQLh:=@MySQLInit;
MySQLError:=1;
IF(@IsError(MySQLh)){
@LogReport(MySQLh;3);
}ELSE{
@MySQLOptions(MySQLh);
MySQLUser:="MySQLConnectorUser";
MySQLPassword:="ConnectorPassword";
MySQLDefaultDatabase:="testdb";
MySQLHost:="mysql.intranet";
Ret:=@MySQLConnect(MySQLh;MySQLHost;MySQLUser;MySQLPassword;MySQLDefaultDatabase);
IF(@IsError(Ret)){
@LogReport(Ret);
}ELSE{
MySQLError:=0;}
IF(!MySQLError){
QueryStr:="SELECT ID,Name,Amount,UID FROM testdb.amounts WHERE Name=\"Test User\";";
Ret:=@MySQLQuery(MySQLh;QueryStr;MySQLResH);
NumRows:=@MySQLGetNumRows(MySQLResH);
IF(NumRows=1){
Ret:=@MySQLFetchRow(MySQLResH;1;ThisQueryID;ThisQueryName;ThisQueryAmount;ThisQueryUID);
}ELSE{
ThisQueryID:=-1;
ThisQueryAmount:=0;
ThisQueryName:=ThisQueryUID:="";
}
MySQLResH:=@MySQLFreeResult(MySQLResH);
@LogReport("ThisQueryID :"+@Text(ThisQueryID);3);
@LogReport("ThisQueryName :"+ThisQueryName;3);
@LogReport("ThisQueryAmount:"+@Text(ThisQueryAmount);3);
@LogReport("ThisQueryUID :"+ThisQueryUID;3);
}
MySQLh:=@MySQLClose(MySQLh);
}
@MySQLThreadEnd;
MySQL DB for this example:
INSERT INTO testdb.amount (Name,Amount,UID,ModTime) VALUES ("Test User",123.45,"1234567890ABCDEFABCD1234567890AB",NOW());
Output in APILOG for this example:
NumRows:1
ThisQueryID :1
ThisQueryName :Test User
ThisQueryAmount:123.45
ThisQueryUID :1234567890ABCDEFABCD1234567890AB
A MySQL connection is established and a query is submitted; the result is then output to APILOG.
Note : This text was machine-translated and may contain inaccuracies.
