Promotic
WikipediaLinkedInYoutubeTwitterFacebook

DbExecute - method of object PmaAdo

Description:
Executes the statement entered in the syntax of the SQL language.
Syntax:
Object DbExecute(String sId, String sCommand, String sParams)
Calling:
oRecordset = oDb.DbExecute(sId, sCommand, sParams)
Parameters:
sId(String) Unique identifier that is used by the PmaAdo object to store the result data in the form of AdoRecordset.

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) Usualy, it is a SQL syntax statement (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 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 SQL language syntax query/statement (e.g. SELECT, INSERT, etc.).
text (default) - Specifies that the ADO Provider should evaluate the sSource parameter as a textual definition of a command. Corresponds to the ADO adCmdText value.
table - Specifies that the ADO Provider should generate an SQL query to return all records from the table named in the sSource parameter. Corresponds to the ADO adCmdTable value.
storedproc - Specifies that the ADO Provider should evaluate the sSource parameter as a stored procedure. 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. Corresponds to the ADO adCmdFile value.
tabledirect - Specifies that the ADO Provider should return all records from the table named in the sSource parameter. 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. 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, i.e. the method waits for the operation result.
async - Asynchronous query, i.e. the method does not wait for the operation result. 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 records should be fetched asynchronously. 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. 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 = value null for JavaScript or Nothing pro VBScript). Corresponds to the ADO adExecuteNoRecords value.
record - Specifies that the called query/statement returns a single row, that has the form of the AdoRecord object. Corresponds to the ADO adExecuteRecord value.
"return:xxx;" (optional) - Specifies whether the method returned 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) containing multiple returned values (new procedure) (e.g. Result, AffectedRows, ErrorCode, ErrorText).
Return Values:
New procedure: Returns PmMap object with values in following items:
- "Result": resulting data represented by AdoRecordset or error value (null for JavaScript or Nothing pro 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 signals successful method execution (no error)
- "ErrorText": error text description
 
Old procedure: Returns resulting data represented by AdoRecordset or error value (null for JavaScript or Nothing pro VBScript) (if the corresponding statement returns any data).
Note:
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). Není to ale typické pro nejběžněji užívané ADO Provider. 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 position of current record are not supported (e.g. MoveFirst). In order to keep the documntation 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
PROMOTIC 9.0.7 SCADA system documentation - MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice