Creating a Property Database

< BACK  NEXT >
[oR]

Property databases are created using the CeCreateDatabaseEx function. The database can be created in the Object Store, or in a mounted database volume. Listing 4.3 creates a database in the Object Store. The CREATE_SYSTEMGUID macro is used to retrieve the database GUID for the Object Store. Databases can be created in mounted database volumes by passing the CEGUID returned when calling CEMountDBVol.

Listing 4.3 Creates a database
 const CEPROPID propCompany = MAKELONG(CEVT_LPWSTR, 100); const CEPROPID propCompanyID = MAKELONG(CEVT_I4, 101); void Listing4_3() {   CEOID ceDB;   CEGUID ceObjStore;   CEDBASEINFO ceDBInfo;   // initialize structure   ceDBInfo.dwFlags =     CEDB_VALIDNAME |     CEDB_VALIDSORTSPEC |     CEDB_VALIDTYPE;   wcscpy(ceDBInfo.szDbaseName, _T("Company"));   // arbitary database type identifier   ceDBInfo.dwDbaseType = 19500;   // number of sort orders   ceDBInfo.wNumSortOrder = 2;   // setup two sort orders   ceDBInfo.rgSortSpecs[0].propid = propCompany;   ceDBInfo.rgSortSpecs[0].dwFlags = 0;   ceDBInfo.rgSortSpecs[1].propid = propCompanyID;   ceDBInfo.rgSortSpecs[1].dwFlags = 0;   CREATE_SYSTEMGUID(&ceObjStore);   ceDB = CeCreateDatabaseEx(&ceObjStore, &ceDBInfo);   if(ceDB == NULL)      cout   _T("Could not create database");   else      cout   _T("Database created"); } 

Table 4.7. CeCreateDatabaseEx Creates a property database
CeCreateDatabaseEx
PCEGUID pceguid Pointer to a CEGUID specifying the database volume
CEDBASEINFO * lpCEDBInfo Pointer to the CEDBASEINFO structure defining the database
CEOID Return Value Returns NULL for failure, or a CEOID representing the new database

The CEDBASEINFO structure contains members that define the characteristics of the database:

 typedef struct _CEDBASEINFO {   DWORD dwFlags;   WCHAR szDbaseName[CEDB_MAXDBASENAMELEN];   DWORD dwDbaseType;   WORD wNumRecords;   WORD wNumSortOrder;   DWORD dwSize;   FILETIME ftLastModified;   SORTORDERSPEC rgSortSpecs[CEDB_MAXSORTORDER]; } CEDBASEINFO; 

The structure is also used when opening databases and changing the database using CeSetDatabaseInfoEx. The members are shown in Table 4.8.

Table 4.8. CEDBASEINFO structure members
Member Description
dwFlags Flags indicating which members have valid values:
CEDB_VALIDMODTIME
The ftLastModified member is valid.
CEDB_VALIDNAME
The szDbaseName member is valid.
CEDB_VALIDTYPE
The dwDbaseType member is valid.
CEDB_VALIDSORTSPEC
The rgSortSpecs member is valid.
szDBaseName Name of the database to create. Maximum length is CEDB_MAXDBASENAMELEN, currently 32.
dwDbaseType Type identifier for database. Each type of database you create should have a different identifier.
wNumRecords Returns the number of records in the database. Not used when creating the database.
wNumSortOrder Number of sort orders to be created.
dwSize Size, in bytes, of the database. Not used when creating the database.
ftLast Modified Time when database was last modified.
rgSortSpecs Array of sort order specifications.

In Listing 4.3 three flags (CEDB_VALIDNAME, CEDB_VALIDSORTSPEC, and CEDB_VALIDTYPE) are used to specify the members being used to define the new database. Since you do not need to specify sort orders when the database is created, you could omit CEDB_VALIDSORTSPEC. However, it is best to create sort orders at the time the database is created.

The new database will be called "Company", and will have the database type identifier "19500". This value is arbitrary, and is used to indicate the purpose of the database. In effect, this states that all databases with the type identifier "19500" will contain Company information and will contain the same properties. You are not guaranteed uniqueness, since another programmer may choose the same value. Note that the database is created, but not opened.


< 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