With CPDB, it's very simple to search on any field of the database. Search a string value on a 7000 records database take less than 4 seconds* !
* test done with a Zip code database on a Palm IIIxe device : search of the last record
The first method consist with a generic search, a string value is used. You must convert to a string if the value is a numeric value.
Use the following example :
Err err; Boolean bFound;
err = CPDB_Search(mydbHandle, "FIELDNAME", "1234", CPDB_SEARCH_FROMCURRENT); err = CPDB_IsFound(mydbHandle, &bFound); |
The bFound boolean contain true if the search succed.
Please note the CPDB_SEARCH_FROMCURRENT parameter. You can also use :
- CPDB_SEARCH_REVERSE
- CPDB_SEARCH_FROMCURRENT
- CPDB_SEARCH_WITHIN
- CPDB_SEARCH_CASELESS
This permit to search all the records with a specific value. Just use CPDB_SEARCH_FROMBEGIN for the first search operation then loop on CPDB_SEARCH_FORMCURRENT to search the next record. This is an exemple :
Err err; Boolean bFound;
err = CPDB_Search(mydbHandle, "FIELDNAME", "1234", 0); err = CPDB_IsFound(mydbHandle, &bFound);
while ( bFound == true && err == 0 ) { // your code here // ... // Next record err = CPDB_Search(mydbHandle, "FIELDNAME", "1234", CPDB_SEARCH_FROMCURRENT); if (err == 0) err = CPDB_IsFound(mydbHandle, &bFound); } |
For a typed search, simply use :
- CPDB_SearchNumeric : search in the database with a numeric value
Note : the size of the value is Int32, so please take care if you search on a SHORTINT or INT field, a conversion is done internaly.
To improve search performance and to browse you database in a correct order, it is usefull to sort the database on a specific field.
Use the following example :
err = CPDB_Sort(mydbHandle, "FIELDNAME", CPDB_SORT_ASC);
You can use CPDB_SORT_DESC for an inverse sort.
Warning : for a big database, this operation can take time. Display a waiting message is usefull. Example for a Zipcode database with 7000 records : less than 10 seconds with a Palm IIIxe.
CPDB_Search
CPDB_SearchNumeric
CPDB_IsFound
CPDB_Sort
Creation date : 01/10/2003 @ 06:49
Last update : 01/10/2003 @ 07:36
Category : CPDB library
Page read 9359 times
|