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 databaseconst 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"); }
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.
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.
|