Promotic

DbExecute - method of the PmaAdo object

Description:
Executes the statement entered in the SQL language syntax.
Syntax:
Object DbExecute(String sId, String sCommand, String sParams)
Parameters:
sId(String) Unique identifier that is used by the PmaAdo object to store the result data in the form of the AdoRecordset object.
If an empty string ("") is used, then the SQL statement is executed and the data is returned in the form of the AdoRecordset object, but the PmaAdo object will not store it. This is handy if it is necessary to execute some SQL query in the script and process the resulting data immediately, and release the AdoRecordset object right after that.
Empty string is also entered if entered statement does not return the resulting data.
sCommand(String) Usually, it is statement in the SQL language syntax (INSERT, UPDATE, DELETE, etc.), that does not return any data in the form of the AdoRecordset object.
It can also return the data in the form of the AdoRecordset object containing SQL query SELECT, table name, calling the saved procedure, name or URL address of the file containing the saved AdoRecordset object.
sParams(String) Additional parameters of the DbExecute method. Entries are in the KeyVal format, for example "command:text;execute:norecords;return:map;".
"command:xxx;" (optional) - Specifies how the corresponding ADO Provider evaluates the sSource parameter, especially if it contains something different than query/statement in the SQL language syntax (e.g. SELECT, INSERT, etc.).
text (default) - Specifies that the ADO Provider should evaluate the sSource parameter as a textual definition of a command.
It corresponds to the ADO adCmdText value.
table - Specifies that the ADO Provider should generate an SQL query to return all records of the database table named in the sSource parameter.
It corresponds to the ADO adCmdTable value.
storedproc - Specifies that the ADO Provider should evaluate the sSource parameter as a stored procedure.
It corresponds to the ADO adCmdStoredProc value.
file - Specifies that a persisted (saved) AdoRecordset object should be restored from the file named in the sSource parameter.
It corresponds to the ADO adCmdFile value.
tabledirect - Specifies that the ADO Provider should return all records of the database table named in the sSource parameter.
It corresponds to the ADO adCmdTableDirect value.
unknown - Specifies that the type of command in the sSource parameter is not known. The ADO Provider will try to evaluate it, but it will just consume more time.
It corresponds to the ADO adCmdUnknown value.
"execute:xxx;" (optional) - Specifies the corresponding ADO Provider how to execute the SQL query. The default mode is the synchronous query, it means that the method waits for the operation result.
async - Asynchronous query, it means that the method does not wait for the operation result.
It corresponds to the ADO adAsyncExecute value.
asyncfetch - Specifies that the rows defined by the ADO Recordset.CacheSize property are to be read synchronously and any remaining rows should be fetched asynchronously.
It corresponds to the ADO adAsyncFetch value.
asyncfetchnonblocking - Specifies that the main thread will never be blocked while reading is being processed. If the requested row is not read, then the cursor will be moved to the end.
It corresponds to the ADO adAsyncFetchNonBlocking value.
norecords - Specifies that the called query/statement does not return any data. If so, then the data will be discarded and not returned (no AdoRecordset object = value null for JavaScript or Nothing for VBScript).
It corresponds to the ADO adExecuteNoRecords value.
record - Specifies that the called query/statement returns a single row, that is in the form of the AdoRecord object.
It corresponds to the ADO adExecuteRecord value.
"return:xxx;" (optional) - Specifies whether the method return value is a map containing multiple values (new procedure) or a single value (old procedure).
If not set, then the old procedure is used.
map - Returns a map (PmMap object) containing multiple returned values (new procedure) (e.g. Result, AffectedRows, ErrorCode, ErrorText).
Return value:
New procedure: Returns PmMap object with values in following items:
- "Result": resulting data in the form of the AdoRecordset object or error value (null for JavaScript or Nothing for VBScript) (if the corresponding statement returns any data)
- "AffectedRows": Number of affected rows by the command (added, deleted, modified)
- "ErrorCode": numeric error code where the 0 value means successful method execution (no error)
- "ErrorText": error text description


Old procedure: Returns resulting data in the form of the AdoRecordset object or error value (null for JavaScript or Nothing for VBScript) (if the corresponding statement returns any data).
Note:
The ADO Record object:
Depending on the specific ADO Provider it is possible, that a single row SQL query result will not be returned in the form of the AdoRecordset object containing a single record, but in the form of the AdoRecord object (represents the single row). However, this is not typical of the most commonly used ADO Providers. The AdoRecord object is usually returned by explicit operations, when the specific AdoRecord is returned from the existing AdoRecordset object. The AdoRecord object consists of multiple AdoField objects, the same way as the AdoRecordset object. The difference is that the methods for moving the current record position are not supported (e.g. MoveFirst).
In order to keep the documentation PROMOTIC simple, it will be referred only to the commonly returned AdoRecordset object, although in some special cases the system may also return the AdoRecord object.
Example:
Adds new record into the table ("table1") in the PmaAdo object ("/TestAdoDb").
JavaScriptVBScriptSelect and copy to clipboard

var oDb = pMe.Pm("/TestAdoDb");
oDb.DbExecute("", "INSERT table1 (name, value) VALUES ('pi', 3.14)", "");

History:
Pm8.01.00: Created
Pm8.03.22: Returns the PmMap object with values in items "Result", "AffectedRows", "ErrorCode" and "ErrorText".
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.