The following procedure retrieves rows from the table and prints them on the command line.
Listing rows in the table
Add the method below to customer.cpp. This method carries out the following tasks:
Any operations on a table are carried out at the current position. The position may be before the first row, on one of the rows of the table, or after the last row. By default, as in this case, the rows are ordered by their primary key value (cust_id). To order rows in a different way, you can add an index to an UltraLite database and open a table using that index.
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 ) { table->Release(); return false; } ul_column_num id_cid = schema->GetColumnID( UL_TEXT("cust_id") ); ul_column_num cname_cid = schema->GetColumnID( UL_TEXT("cust_name") ); schema->Release(); _tprintf( _TEXT("\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( _TEXT("id=%d, name=%s \n"), (int)table->Get(id_cid), cname); } table->Release(); return true; } |
Add the following line to the main method, immediately after the call to the insert method:
do_select(conn); |
Compile your application by running nmake.
Run your application by typing customer at the command prompt.
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |