Sorting Records

When creating a new database, you can specify up to four sort order descriptions to associate with the database. A sort order description is a SORTORDERSPEC structure that contains the identifier of a property on which the database records are to be sorted. The structure also includes a combination of flags that indicate whether to sort the records in ascending or descending order, whether the sort is case-sensitive, and whether to place records that do not contain the given property before or after all other records. By default, sorting is done in descending order and is case-sensitive. Records not containing a given property are placed at the end of all other records.

Note Sorts on binary properties are not allowed.

Because sort orders increase the amount of time and system resources needed to perform each insertion or deletion, it is best to use the minimum number of sort orders for an application. However, do not use too few. While it is possible to use CeSetDataBaseInfo to reorder the database, this process is even more expensive in terms of time and system resources. It could take several minutes to reorder a large database.

Typically, each record in a database contains a similar set of properties, and each type of property shares the same property identifier. For example, each record in a Contacts database might contain a name, street address, city, state, zip code, and telephone number. Each name property would have the same property identifier, each street address property would have the same property identifier, and so on. You can select one of these properties and direct the system to sort the records based on it. The order in which the records are sorted affects the order in which the database-seeking function CeSeekDatabase finds records in the database.

You specify the sort order when you call the CeOpenDatabase function. Only one sort order can be active for each open handle. However, by opening multiple handles to the same database, you can use more than one sort order.

Note Multiple sort orders cannot be specified for a single property.