Skip to content

qie.doSelectQuery

Signature: qie.doSelectQuery(connection, query, readOnlyConnection*, quoteValues*, timestampFormat*, timeoutSeconds*)

Returns: CSV Message resultSet - a CSV Message representing the result set of the query, or null when the query matched no rows. 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.executeQuery() method. You will usually use the qie.doQuery() and qie.doConditionQuery() methods. Some JDBC drivers will require you to use this java.sql.PreparedStatement.executeQuery() method instead.

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, null is returned. Check the result for null before reading it.

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 query that matches rows reads like any Source message
var response = qie.doSelectQuery("EMR Database", "select name, date_of_birth as dob from patient where balance >= 0");
var dobOfTheFirstPatientInTheResultSet = response.getNode("dob", 1);

// a query that matches no rows returns null
var noMatch = qie.doSelectQuery("EMR Database", "select name, date_of_birth as dob from patient where patient_id = 999");
if (noMatch == null) {
   // no patient found
}