Collection Contents Previous Next PDF

UltraLite C/C++ User's Guide

Developing Applications Using the UltraLite C++ Component

Accessing data using dynamic SQL

Data retrieval: SELECT


The SELECT statement allows you to retrieve information from the database. When you execute a SELECT statement, the PreparedStatement.ExecuteQuery method returns a ResultSet object.

For more information, see Class UltraLite_PreparedStatement_iface.

To execute a SELECT statement

  1. Create a new prepared statement and result set.

    PreparedStatement * prepStmt;
  2. Assign a prepared statement to your newly created PreparedStatement object.

    ULValue sqltext( "SELECT MyColumn FROM MyTable" );
    prepStmt = conn->PrepareStatement( sqltext );
  3. Execute the statement.

    In the following code, the result of the SELECT query contain a string, which is output to a command prompt.

    #define MAX_NAME_LEN     100
    ULValue mycol;
    ResultSet * rs = stmt->ExecuteQuery();
    rs->BeforeFirst();
    while( rs->Next() ){
       char mycol[ MAX_NAME_LEN ];
       val = rs->Get( 1 );
       val.GetString( mycol, MAX_NAME_LEN );
       printf( "mycol= %s\n", mycol );
    }

Collection Contents Previous Next PDF