Contents Index Scrolling through the rows of a table Searching for rows with find and lookup

UltraLite C++ User's Guide
  Understanding UltraLite Development
    Accessing and manipulating data with the Table API

Accessing the values of the current row


At any time, a Table object is positioned at one of the following positions:

If the Table object is positioned on a row, you can use one of a set of methods appropriate for the data type to access the value of each column. These methods take the column ID as argument. For example, the following code retrieves the value of the lname column, which is a character string:

ULValue val;
char lname[ MAX_NAME_LEN ];
val = t->Get( lname_col_id );
val.GetString( lname, MAX_NAME_LEN );

The following code retrieves the value of the cust_id column, which is an integer:

int id = (int)(t->Get( id_col_id );

In addition to the methods for retrieving values, there are methods for setting values. These take the column ID and the value as arguments. For example:

ULValue lname_col( "fname" );
ULValue v_lname( "Kaminski" );
t->Set( lname_col, v_lname );

By assigning values to these properties you do not alter the value of the data in the database. You can assign values to the properties even if you are before the first row or after the last row of the table, but it is an error to try to access data when the current row is at one of these positions, for example by assigning the property to a variable.

// This code is incorrect
t.BeforeFirst();
id = t.Get( cust_id );
Casting values 

The method you choose must match the data type you wish to assign. UltraLite automatically casts database data types where they are compatible, so that you could use the getString method to fetch an integer value into a string variable, and so on.


Contents Index Scrolling through the rows of a table Searching for rows with find and lookup