Execute a SELECT statement to retrieve information from an UltraLite database and handle the result set that is returned.
Prerequisites
There are no prerequisites for this task.
Declare the required variables using the following code:
ULPreparedStatement * prepStmt; ULResultSet * resultSet; |
Prepare a SQL statement for execution.
The following code prepares a SELECT statement for execution:
prepStmt = conn->PrepareStatement("SELECT MyColumn1 FROM MyTable"); |
Check for errors when preparing the statement.
For example, the following code is useful when checking for SQL syntax errors:
if( prepStmt == NULL ) { const ULError * ulerr; ulerr = conn->GetLastError(); // write code to handle the error return; } |
Execute the SQL and return a result set object that can be used to move the results of the query.
resultSet = prepStmt->ExecuteQuery(); if( resultSet == NULL ) { const ULError * ulerr; ulerr = conn->GetLastError(); // write code to handle the error prepStmt->Close(); return; } |
Traverse the rows by calling the Next method. Store the result as a string and store them in a buffer.
The Next method moves to the next row of the result set. The ULResultSet object is positioned on a row if the call returns true; otherwise, if the call returns false, all the rows have been traversed.
while( resultSet->Next() ) { char buffer[ 100 ]; resultSet->GetString( 1, buffer, 100 ); printf( "MyColumn = %s\n", buffer ); } |
Clean up the prepared statement and result set object resources.
The prepared statement object should not accessed after the Close method is called.
resultSet->Close(); prepStmt->Close(); |
![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2014, SAP AG or an SAP affiliate company. - SAP Sybase SQL Anywhere 16.0 |