Listing Database Information

< BACK  NEXT >
[oR]

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 databases
 void 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; } 

Table 4.18. CeFindFirstDatabaseEx Initializes database enumeration
CeFindFirstDatabaseEx
PCEGUID pceguid CEGUID of mounted database volume
DWORD dwDbaseType Database type to filter, or 0 for all databases
HANDLE Return Value Returns HANDLE to the enumeration or INVALID_ HANDLE_VALUE on failure

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.

Table 4.19. CeFindNextDatabaseEx Finds next database in enumeration
CeFindNextDatabaseEx
HANDLE hEnum Handle returned by CeFindFirstDatabaseEx
PCEGUID pceguid Handle to mounted database volume
CEOID Return Value Returns Object Identifier of database, or 0 if no more databases

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 information
 void 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.

Table 4.20. CeOidGetInfoEx Returns information on an object identifer
CeOidGetInfoEx
PCEGUID pceguid CEGUID of a mounted database volume
CEOID oid Object identifier, such as a database object identifier returned from CeFindNextDatabaseEx
CEOIDINFO * poidInfo Pointer to CEOIDINFO structure in which object information is returned
BOOL Return Value Returns TRUE on success

Table 4.21. wObjType constant value meanings
Constant Meaning
OBJTYPE_INVALID Invalid object identifier.
OBJTYPE_FILE Object is a file.
OBJTYPE_DIRECTORY Object is a directory.
OBJTYPE_DATABASE Object is a database.
OBJTYPE_RECORD Object is a record.

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.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net