Database API in CE
CE provides a set of database API sets (under CE), which provides very effective support for some organized data. 1. Basic definition:
1. 9 data types allowed by Records:
Data Type Description IVal 2-byte signed integer UiVal 2-byte unsigned integer LVal 4-byte signed integer UlVal 4-byte unsigned integer FILETIME A time and date structure LPWSTR 0-terminated Unicode string CEBLOB A collection of bytes BOOL Boolean Double 8-byte Signed Value
// Ok, there is ceblob, a good index is established at the same time when the database is created, but it can be redefined later. The index is at the price, so please customize the index according to your needs. Briefly, CE provides basic database functions that can effectively help your application organize some simple data structures. Pocket PC uses the Database API to manage the Address Book, The Task List, and E-Mail Messages. 2. Design Database: Please carefully think about how the database will be used before you use CECREATEDATABASEEX. Do not imagine the database into large databases and cannot exceed the restrictions of the database structure. Although the limit is very loose: a single property cannot exceed CEDB_MAXPROPDataSize = 65, 471, and a single record cannot reach CEDB_MaxRecordsize = 131, 072. 3.
Database Volumes
: Database Volumes is stored in the external medium in the form of Volumes and is also directly in the Object Store. It is a specific format of a CE database energy to be positioned, which can be stored on a PC card or on a similar storage device. It is inconvenient that you have to first mount before using it, close before unmount. Volume is a file, in the file system, Volume is hidden, but can be deleted by standard file operation functions. So you can't stop some brave users from looking for everything when space is not enough and may delete a Volume. // Khan ING .....
Second, the database API: Plan the database, then start programming:
Mounting a Database Volume
If your database is on external devices, such as CompactFlash Card, you must mount a Database volume containing the database
Bool Cemountdbvol (Pceguid Pguid, LPWSTR LPSZVOL, DWORD DWFLAGS);
This function has two functions: Create a new Volume or open an existing Volume. The first parameter is a pointer to a GUID. Cemountdbvol returns a large database function to determine the address of the address of the database file. Don't confuse the GUID type in the OLE, -ceguid is just a handle to track the already opened database files. The second parameter is a Volume name to mount. Note: Not a database name. Because a Volume can contain multiple databases, it is also a file name. The standard extension should be .cdb. The third parameter is used to illustrate the action of the function: create_new, create_always, open_existing, open_always, truncate_existing. If the function is successful, return True, GUID is set, and will be used in other database functions. If you fail, call GetLastError and return an error. Database Volume can be opened by multiple processes at a time. The system will maintain a reference counter for this Volume, when the last process unmount this volume, the system is unmount this Volume. Enumerating Mounted Database Volumes Enumerates the database Volumes: Bool CeenumDbvolumes (Pceguid Pguid, LPWSTR LPBUF, DWORD DWSIZE);
CEENUMDBVOLUMES Returns True If a mounted Volume is discovered, then this Volume's GUID and NAME point to 2 parameters of PGUID and LPBuff. The third parameter is the size of the buffer pointed to which lpbuff is pointed. EX:
Ceguid Guid;
Tchar Szvolume [MAX_PATH];
INT NCNT = 0;
CREATE_INVALIDGUID (& GUID); // Set the GUID to INVALID
While (CeenumDbvolumes (& Guid, Szvolume, Sizeof (Szvolume))) {
// guid contains the guid of the mounted volume;
// Szvolume Contains the name of the volume.
NCNT ; // count the number of mounted volumes.
}
Unmounting a database volume
Bool CeunmountDbvol (Pceguid Pguid); as long as a mounted database Volume's GUID is available :)
Using The Object Store as a Database Volume
Although you can store a database in the form of Volume on the external device, but more commonly used, you have to store the database in the Object Store. because
Most database functions require a CEGUID to determine a database volume, you can use this macro: CREATE_SYSTEMGUID (Pceguid Pguid);
Creating a catabase:
Ceoid CecreatedTabaseEx2 (Pceguid Pguid, CedbaseinfoEx * Pinfo);
The first parameter is used to indicate the GUID of the database location. The second parameter is powerful, look at his structure:
Typedef struct _cedbaseinfoex {
Word wversion; // Structure ourselves, to be set to CEDBASEINFOEX_VERSIONWORD WNUMSORTORDER; / / Set to RgsortSpecsArray Sorting Sort Core Number, Maximum 4
DWORD dwflags; // Look at the introduction below
Wchar szdbasename [CEDB_MAXDBASENAMELEN]; // Database name, maximum 32 characters (including the last 0)
DWORD DWDBASETYPE;
DWORD DWNUMRECORDS; // ignored
DWORD DWSIZE; // ignored
Filetime fTlastModified; // ignored
SortorderSpecex RgsortSpecs [CEDB_MAXSORTORTER];
} CEDBASEINFOEX, * PCEDBASEINFOEX;
The dwFlags field has two uses. First, it contains flags indicating which fields in the structure are valid. The possible values for the dwFlags field are CEDB_VALIDNAME, CEDB_VALIDTYPE, CEDB_VALIDSORTSPEC, and CEDB_ VALIDDBFLAGS. When you're creating a database, it's easier to Set the dwflags field to CEDB_VALIDCREATE, WHICH IS A Combination of The Flags I Just Listed. An Additional Flag, CEDB_VALIDMODTIME, IS Used When CeoidgetInfo Uses this structure.
The other use for the dwFlags parameter is to specify the properties of the database. Two flags are currently defined. The first is CEDB_NOCOMPRESS, which can be specified if you do not want the database you're creating to be compressed. By default, all databases are compressed, which saves storage space at the expense of speed. By specifying the CEDB_NOCOMPRESS flag, the database will be larger but you will be able to read and write to the database faster. The second flag that can be defined is CEDB_SYSTEMDB. This flag indeicates That The Database Cannot Be deleted by An Untrusted Application. Trusted and UNTrusted Applications Are Part of The Windows CE Security Architecture and Will Be Discussed in Chapter 10.
Typedef struct _sortorderspecex {
Word wversion;
Word wnumprops;
Word WKEYFLAGS;
CEPROPID RGPROPID [CEDB_MAXSORTPROP];
DWORD RGDWFLAGS [CEDB_MAXSORTPROP];
} Sortorderspecex;
Note:. The function CeCreateDatabaseEx2 was added to Windows CE .NET 4.0 If an application needs to run on a Windows CE 3.0-based system, such as a Pocket PC 2000 or Pocket PC 2002, the application must use the function CeCreateDatabaseEx to create a . database The chief difference between the two functions is that CeCreateDatabaseEx2 allows multilevel sorting, whereas CeCreateDatabaseEx does not Opening a Database:. HANDLE CeOpenDatabaseEx2 (PCEGUID pguid, PCEOID poid, LPWSTR lpszName,
Sortorderspecex * psort,
DWORD DWFLAGS,
CenotifyRequest * prequest; seeking (or search for) A Record: Ceoid CeseekDatabaseEx (Handle HDatabase, DWORD DWSEEKTYPE, DWORD DWSEEKTYPE, DWORD DWVALUE,
Word Wnumvals, LPDWORD LPDWINDEX;
Changing The Sort ORDER: Bool CESetDatabaseInfoEx2 (Pceguid Pguid,
Ceoid Oiddbase,
CedbaseinfoEx * Pnewinfo; Reading a Record: Ceoid CereadRecordPropsex (Handle HDBase, DWORD DWFLAGS,
LPWORD LPCPROPID,
CEPROPID * RGPROPID, LPBYTE * LPLPBUFFER,
LPDWORD LPCBBBUFFER,
Handle hheap; Writing a replaord: Ceoid CEWRITERECORDPROPS (Handle HDBase, Ceoid OidRecord, Word CPropID,
CEPROPVAL * rgPropVal); Deleting Properties, Records, and Entire Databases: To delete an entire record in a database, call BOOL CeDeleteRecord (HANDLE hDatabase, CEOID oidRecord); You can delete an entire database using this function: BOOL CeDeleteDatabaseEx (PCEGUID pguid, Ceoid OID);
Enumerating Databases: HANDLE CeFindFirstDatabaseEx (PCEGUID pguid, DWORD dwDbaseType); CEOID CeFindNextDatabaseEx (HANDLE hEnum, PCEGUID pguid); Querying Object Information BOOL CeOidGetInfoEx2 (PCEGUID pguid, CEOID oid, CEOIDINFOEX * oidInfo); 2004 at 20:00 on November 3: 14 is so tired, write here today, have time to enrich