Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Getting the results of a query

To read data from a table, a query should be formed using an SQL "SELECT" statement and executing the statement with the ExecuteQuery function. In this example, a typical user will be queried for messages. The ExecuteQuery function returns a dbc_ResultSet object that represents the results of the query. Each row of the ResultSet object can be accessed by calling the GetNext function. Individual columns of the ResultSet row can be accessed via the GetXXX commands, depending on the type affinity of the particular column.

stmt = “SELECT msgText FROM messages table WHERE userId = ?”;

/* Assume statement is created and parameters bound */
/* Execute a query, results are returned in ResultSet */

dbc_IResultSet* piResultSet = NULL;
dbc_IPreparedStatement_ExecuteQuery(piStatement, &piResultSet);

/* Loop over the result set */
while (1) {
   nResult = dbc_IResultSet_GetNext(piResultSet);
   if (dbc_ROW != nResult) break;
   nResult = dbc_IResultSet_GetText(piResultSet, 0, buffer, bufferLen, &nLenReq);
}