Skip to content

pQuery.doSelectQuery

Signature: pQuery.doSelectQuery(connection, 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 parameterized 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
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

// Create the pQuery object with the query to be executed
var pQuery = qie.getParameterizedQuery("select name from patient where patient_id = :patientId");

// a query that matches rows reads like any Source message
pQuery.setInt("patientId", 1);
var queryResult = pQuery.doSelectQuery("EMR Database");
var name = queryResult.getNode("name", 1);

// a query that matches no rows returns null
pQuery.setInt("patientId", 999);
if (pQuery.doSelectQuery("EMR Database") == null) {
   // no patient found
}