qie.doQuery¶
Signature: qie.doQuery(connection, query, readOnlyConnection*, quoteValues*, timestampFormat*, timeoutSeconds*)
Returns: CSV Message resultSet - a CSV Message representing the result set of the query, or null when the statement produces no result set. To see what methods can be used on a CSV Message, refer to the 'Source' functions.
Execute a database query and return the result set as a CSV message.
Note
This method uses the java.sql.PreparedStatement.execute() method.
Note
The CSV Message that is returned can be used like any Source message. To see what methods can be used on a CSV Message, refer to the 'Source' functions.
Note
When the query matches no rows, the CSV Message still holds the column header row, so getRowCount() returns 0. Test getRowCount() rather than comparing the result to null.
Note
A statement that produces no result set at all, such as an UPDATE, returns null.
Parameters¶
| Type | Name | Description | Default |
|---|---|---|---|
| String | connection | the name of the database connection | |
| String | query | the SQL query statement to execute (may contain node tags to be evaluated) | |
| Boolean | readOnlyConnection* | (optional) use a read-only database connection | false |
| Boolean | quoteValues* | (optional) true = individual values are surrounded with quotes | false |
| String | timestampFormat* | (optional) the format string to use for timestamp fields | yyyyMMddHHmmss |
| Integer | timeoutSeconds* | (optional) the SQL query timeout in seconds; 0 means no timeout | 0 |
Example¶
// a SELECT that matches rows returns them below the column header row
var response = qie.doQuery("EMR Database", "select name, date_of_birth as dob from patient where balance >= 0");
var firstDob = response.getNode("dob", 1);
// a SELECT that matches no rows still returns the column header row
var noMatch = qie.doQuery("EMR Database", "select name, date_of_birth as dob from patient where patient_id = 999");
var rowCount = noMatch.getRowCount(); // 0
// an UPDATE produces no result set at all, so null is returned
var updated = qie.doQuery("EMR Database", "update patient set name = 'john Smith' where patient_id = 1"); // null