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


Accessing the current row

A Table object is always located 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 retrieve or modify the value of the columns in that row.

Retrieving column values

The Table object provides a set of methods for retrieving column values. These methods take the column ID as the argument.

The following code fragment retrieves the value of the lname column, which is a character string.

ULValue val;
char lname[ MAX_NAME_LEN ];
val = tbl->Get( UL_TEXT("lname") );
val.GetString( lname, MAX_NAME_LEN );

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

int id = tbl->Get( UL_TEXT("cust_id") );
Modifying column values

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

For example, the following code sets the value of the lname column to Kaminski.

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

By setting column values, you do not directly alter 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. Do not attempt to access data when the current row is undefined. For example, attempting to fetch the column value in the following example is incorrect:

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

The method you choose should match the data type you want to assign. UltraLite automatically casts database data types where they are compatible, so that you can use the GetString method to fetch an integer value into a string variable, and so on. See Converting data types explicitly.