The functions CeFindFirstDatabaseEx and CeFindNextDatabaseEx can be used to list all databases in a mounted database volume. You can filter for particular database types based on the dwDbaseType values specified when the database is created. CeFindFirstDatabaseEx sets up the database enumeration and is passed the handle to the mounted database volume to be enumerated, and the dwDbaseType value specifying the type of database to filter. This value can be zero to enumerate all databases. The function returns a handle which is used when calling CeFindNextDatabaseEx, and this handle must be closed when finished by calling CloseHandle. Listing 4.17 shows calls to CeFindFirstDatabaseEx and CeFindNextDatabaseEx to list all databases in the object store. The function Listing4_18 lists database information and is described later in this section. Listing 4.17 Lists databasesvoid Listing4_17() { HANDLE hDBFind; CEGUID ceObjStore; CEOID ceDBOid; CREATE_SYSTEMGUID(&ceObjStore); hDBFind = CeFindFirstDatabaseEx(&ceObjStore, 0); if(hDBFind != INVALID_HANDLE_VALUE) { while((ceDBOid = CeFindNextDatabaseEx( hDBFind, &ceObjStore)) != 0) { Listing4_18(&ceObjStore, ceDBOid); } CloseHandle(hDBFind); } else cout _T("Could not enumerate databases") endl; }
CeFindNextDatabaseEx is called repeatedly to get information on the first and subsequent databases. This function is passed the handle returned by CeFindFirstDatabaseEx, and the handle to the mounted database volume. CeFindNextDatabaseEx returns the database's object identifier.
CeFindNextDatabaseEx returns the object identifier for the database, which can then be passed to CeOidGetInfoEx to get information (such as the database name, number of records, and size) about the database. CeOidGetInfoEx can return information on any object type in the object store including files, directories, databases, and records. Listing 4.18 shows database information given a database object identifier. Listing 4.18 Lists database informationvoid Listing4_18(CEGUID* pceObjStore, CEOID ceDBOid) { CEOIDINFO cdbInfo; if(CeOidGetInfoEx(pceObjStore, ceDBOid, &cdbInfo)) { if(cdbInfo.wObjType == OBJTYPE_DATABASE) { cout _T("DB: ") cdbInfo.infDatabase.szDbaseName; cout _T(" Size: ") cdbInfo.infDatabase.dwSize; cout _T(" Recs: ") cdbInfo.infDatabase.wNumRecords endl; } else cout _T("Not a database!") endl; } else cout _T("Could not get database information") endl; } The CEOIDINFO structure contains the wObjType member containing a constant value indicating what type of object information has been returned on, and can be one of the following values shown in Table 4.21.
The CEOIDINFO also contains a union of structures, with one union member for each object type. The members are CEFILEINFO, CEDIRINFO, CEDBASEINFO, and CERECORDINFO. In Listing 4.18 the CEDBASEINFO structure is used to list the database's name, size in bytes, and number of records. The same structure also contains information on the sort orders, the date of last modification, whether the database is compressed, and the database type.
|