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

SQL Anywhere 11.0.1 » UltraLite - C and C++ Programming » Application Development » Developing applications using the UltraLite C++ API » Accessing data with the table API


Navigating the rows of a table

The UltraLite C++ API provides you with several methods to navigate a table to perform a wide range of navigation tasks.

The table object provides you with the following methods to navigate a table:

  • AfterLast   Position immediately after the last row.

  • BeforeFirst   Position immediately before the first row.

  • First   Move to the first row.

  • Last   Move to the last row.

  • Next   Move to the next row.

  • Previous   Move to the previous row.

  • Relative(offset)   Move a specified number of rows relative to the current row, as specified by the signed offset value. Positive offset values move forward in the result set, relative to the current position of the cursor in the result set. Negative offset values move backward in the result set. An offset value of zero does not move the current location, but allows you to repopulate the row buffer.

See UltraLite_Table_iface class.


The following code opens the table named MyTable and displays the value of the column named MyColumn for each row.

Table * tbl = conn->openTable( "MyTable" );
ul_column_num colID = 
   tbl->GetSchema()->GetColumnID( "MyColumn" );

while ( tbl->Next() ){
   char buffer[ MAX_NAME_LEN ];
   ULValue colValue = tbl->Get(colID);
   colValue.GetString(buffer, MAX_NAME_LEN);
   printf( "%s\n", buffer );

You expose the rows of the table to the application when you open the table object. By default, the rows are ordered by primary key value, but you can specify an index when opening a table to access the rows in a particular order.


The following code fragment moves to the first row of the MyTable table as ordered by the ix_col index.

ULValue table_name( UL_TEXT("MyTable") )
ULValue index_name( UL_TEXT("ix_col") )
Table * tbl = 
   conn->OpenTableWithIndex( table_name, index_name );

See UltraLite_Table_iface class.