DB Query Results are formatted as CSV messages. A DB query result message will always contain a header row populated with the column alias names returned by the database query.
Examples of using the query results
Querying the table
var queryResult = qie.doQuery(dbName, ‘SELECT firstName, lastName, patientId FROM person’);
Verifying if any results were returned
If (queryResult.getRowCount() > 0) {
//additional code to perform
};
Determining how many records were returned
var count = queryResult.getRowCount();
Referencing a column value or the column header from the query
queryResult.getNode(‘columnName’, instance)
The column name is the database table column name used in the select statement. Also note that the column name should be quoted as shown in the example.
In the case where the query returns multiple results the instance tells QIE which result record to reference. The instance can be any number greater than 1 up to the number of results returned by the query to reference the data values. An instance number of 0 will return the column header value.
Looping through the query results
for (var i=0 ; i < queryResult.getRowCount() ; i++) {
var value = queryResult.getNode(‘columnName’, i+1);
}
In the above example we did a math operation to add 1 to the “i” counter so that we do not return the column header value in our loop.