When you are creating a database, you can define up to four different sort orders. 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 or province, postal code, and telephone number. All name properties would have the same property identifier, all street addresses 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 that property. However, you cannot perform a sort on a binary property. The order in which the records are sorted affects the order in which the CeSeekDatabase database-seeking function finds records in the database.
You specify which of the four sort orders you want to use on a database when you call the CeOpenDatabase or CeOpenDatabaseEx function with the SORTORDERSPEC structure. SORTORDERSPEC contains the identifier of a single property on which the database properties are to be sorted. SORTORDERSPEC 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 specified property before or after all other records. By default, sorting is done in ascending order and is case-sensitive. Windows CE places all records not containing the specified property at the end of all other records. Although you can have only one sort order active for each handle, you can open multiple handles to a given database. Using multiple handles, you can use more than one sort order.
You can change these four sort orders or other database properties with a call to the CeSetDatabaseInfoEx function. CeSetDatabaseInfoEx lets you change the database name, type, or any of the four sort orders. When you change a sort order, Windows CE parses the database and changes each record. This process might take several minutes on a large database. It is more efficient to create the database with the necessary sort orders to begin with. If you must change the sort order, be sure that you inform the user of the projected time delay.