Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » UltraLite - C and C++ Programming » Tutorial: Build an Application Using the C++ API

Lesson 2: Insert data into the database Next Page

Lesson 3: Select and list rows from the table

The following procedure retrieves rows from the table and prints them on the command line.

Listing rows in the table
  1. Add the method below to customer.cpp. This method carries out the following tasks:

    bool do_select( Connection * conn ) {
      Table * table = conn->OpenTable( _TEXT("ULCustomer") );
      if( table == UL_NULL ) {
        return false;
      TableSchema * schema = table->GetSchema();
      if( schema == UL_NULL ) {
        return false;
      ul_column_num id_cid = 
         schema->GetColumnID( UL_TEXT("cust_id") );
      ul_column_num cname_cid = 
         schema->GetColumnID( UL_TEXT("cust_name") );
      _tprintf( "\n\nTable 'ULCustomer' row contents:\n");
      while( table->Next() ) {
        ul_char cname[ MAX_NAME_LEN ];
        table->Get( cname_cid ).GetString(
                    cname, MAX_NAME_LEN );
        _tprintf( "id=%d, name=%s \n", 
                  (int)table->Get(id_cid), cname);
      return true;
  2. Add the following line to the main method, immediately after the call to the insert method:

  3. Compile your application by running nmake.

  4. Run your application by typing customer at the command prompt.