CPDB.Net

https://cpdb.ppcompiler.org/

6- Sort and search operations (CPDB library)



Introduction

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


 

Generic search

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 :



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);
}

Typed search


For a typed search, simply use :



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.


 


Sort your database


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.


 


More information


CPDB_Search


CPDB_SearchNumeric


CPDB_IsFound


CPDB_Sort