omron — DBCursorOpenSQL

Appendix: Built-in Scripting Language DBCursorOpenSQL Selects a set of rows and columns in a database table, initializes the cursor at the first row of the result set, copies that row's values to mapped tags, and then returns a cursor handle that can be referenced by other DB/ERP functions. (This function is equivalent to a SQL SELECT statement.) Syntax DBCursorOpenSQL( strDBConn , strSQL , optStrTags , " optStrErrorTag " ) strDBConn strSQL The name of the database connection. Connections are configured in the Database/ERP folder. A string that gives a complete, syntactically correct SQL SELECT statement. Note:

In SQL, curly brackets ( {} ) are typically used to enclose an expression that must be evaluated before the entire SQL statement is executed. For example: SELECT * INTO inmates FROM OPENROWSET ('MSDASQL','Driver={Microsoft Text Driver (*.txt; *.csv)};DEFAULTDIR=C:\;Extensions=CSV;','SELECT * FROM flat.csv') In IWS, however, curly brackets are used to reference tags in text fields that are not normally evaluated (e.g., in the caption of a Button object). If you pass a SQL statement that includes such an expression to DBCursorOpenSQL , then the project will try to evaluate the expression as a tag reference and the function will fail.

To pass the SQL statement so that the project can correctly evaluate the expression, create a new String tag that contains the text of the expression and then reference the tag in the SQL statement. For example: $AuxTag = "{Microsoft Text Driver (*.txt; *.csv)}" $DBCursorOpenSQL( "inmates", "SELECT * INTO inmates FROM OPENROWSET ('MSDASQL','Driver={AuxTag};DEFAULTDIR=C: \;Extensions=CSV;','SELECT * FROM flat.csv')") optStrTags A string that lists the project tags to which the columns will be mapped. This list of tag names should be comma-delimited and in the same order as the columns specified by the WHERE clause of strSQL .

As the cursor is moved through the result set, the values in the current row are copied to these tags. This is an optional parameter. If no tags are specified, then no values will be copied. optStrErrorTag The name of a String tag that will receive detailed error messages, if errors occur during runtime. Note: The tag name must be enclosed in quotes, as shown in the syntax diagram, or else the project will try to get the value of the named tag. InduSoft Web Studio Page 627 Tag Name Expression selects all rows where Column1 has a value greater than 3. Column1 is mapped to Tag1, and Column2 is mapped to Tag2. Rows are ordered first by Column1, then by Column2, in descending order.

Error messages are written to TagError. Function Group Execution Windows Embedded Thin Client DBCursorOpenS QLDatabase/ERP Synchronous Supported Supported Supported Note: This feature emulates SQL (Structured Query Language) database operations. You should be familiar with how SQL commands are formed and executed before you use this feature.