When creating a database using the CeCreateDatabaseEx you take certain decisions on how the database will be created. For example, you can specify up to four sort orders, and whether the database will be compressed or not. The CeSetDatabaseInfoEx function allows these attributes to be changed on existing databases. The function is passed a CEDBASEINFO structure that is used to specify the attributes that are to be changed. You should avoid changing databases from compressed to uncompressed, or changing the sort orders, as this can be time-consuming.
Listing 4.19 shows using CeSetDatabaseInfoEx to rename an existing database. First, the database is opened using CeOpenDatabaseEx to find the database's object identifier, and then is closed (a database cannot be renamed while it is opened). Then, the CEDBASEINFO structure is initialized, setting the dwFlags member to CEDB_VALIDNAME to indicate that the szDbaseName contains a new database name. Finally, CeSetDatabaseInfoEx is called to perform the rename.
Listing 4.19 Changes database attributes
void Listing4_19() { CEOID ceOidDB = 0; CEGUID ceObjStore; HANDLE hDB; CEDBASEINFO cdbInfo; // find oid of database CREATE_SYSTEMGUID(&ceObjStore); hDB = CeOpenDatabaseEx(&ceObjStore, &ceOidDB, _T("Company"), 0, 0, NULL); if(hDB != INVALID_HANDLE_VALUE) { CloseHandle(hDB); cdbInfo.dwSize = sizeof(CEDBASEINFO); cdbInfo.dwFlags = CEDB_VALIDNAME; wcscpy(cdbInfo.szDbaseName, _T("Company_new")); if(CeSetDatabaseInfoEx(&ceObjStore, ceOidDB, &cdbInfo)) cout _T("Database renamed") endl; else cout _T("Could not rename database") endl; } else cout _T("Could not open database") endl; }
Table 4.22. CeSetDatabaseInfoEx Changes database attributes
CeSetDatabaseInfoEx | |
PCEGUID pceguid | CEGUID of mounted database volume |
CEOID oidDbase | Object identifier of database to change |
CEDBASEINFO * pNewInfo | CEDBASEINFO structure containing details of changes to be made |
BOOL Return Value | Returns TRUE on success |