Searching rows

UltraLite has different modes of operation for working with data. You can use two of these modes, find and lookup, for searching. The Table object has methods corresponding to these modes for locating particular rows in a table.

Note

The columns you search with Find and Lookup methods must be in the index that is used to open the table.

  • Find methods   Move to the first row that exactly matches specified search values, under the sort order specified when the Table object was opened. If the search values cannot be found, the application is positioned before the first or after the last row.

  • Lookup methods   Move to the first row that matches or is greater than a specified search value, under the sort order specified when the Table object was opened.

To search for a row

  1. Enter find or lookup mode.

    Call a method on the table object to set the mode. For example, the following code enters find mode.

    tbl.FindBegin();
  2. Set the search values.

    Set the search values in the current row. Setting these values only affects the buffer holding the current row, not the database. For example, the following code fragment sets the value in the buffer to Kaminski.

    ULValue lname_col = t->GetSchema()->GetColumnID( UL_TEXT("lname") );
    ULValue v_lname( UL_TEXT("Kaminski") );
    tbl.Set( lname_col, v_lname );
  3. Search for the row.

    Call the appropriate method to carry out the search. For example, the following code looks for the first row that exactly matches the specified value in the current index.

    For multi-column indexes, a value for the first column is always used, but you can omit the other columns.

    tCustomer.FindFirst();
  4. Search for the next instance of the row.

    Call the appropriate method to carry out the search. For a find operation, FindNext locates the next instance of the parameters in the index. For a lookup, MoveNext locates the next instance.

See UltraLite_Table_iface class.