pQuery.doQuery¶
Signature: pQuery.doQuery(connection, 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 parameterized 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 | |
| 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 no rows still returns the column header row
var pQuery = qie.getParameterizedQuery("select name, last_seen from patient where patient_id = :patientId");
pQuery.setInt("patientId", 999);
var noMatch = pQuery.doQuery("EMR Database");
var rowCount = noMatch.getRowCount(); // 0
// an UPDATE produces no result set at all, so null is returned
var updatePQuery = qie.getParameterizedQuery("update patient set name = :name, last_seen = :birth where patient_id = 1");
updatePQuery.setString("name", "Mark Thompson");
updatePQuery.setTimestamp("birth", "2025-01-05 07:15");
var updated = updatePQuery.doQuery("EMR Database"); // null