To obtain the number of all records in a database, there is no need to read one by one and then determine how many records are successfully read.
EDB provides the cegetdbinformationbyhandle function, which can obtain a lot of corresponding information in the database.
This function requires two parameters. The first is the database handle, which is the handle returned when the database is opened through ceopendatabaseinsession, and the second parameter is
By_handle_db_information structure, which is defined:
Typedef struct by_handle_db_information {
WordWversion;
Word
Wreserved
;
CeguidGuidvol;
CeoidOiddbase;
CedbaseinfoexInfdatabase;
} By_handle_db_information;
Before using it, initialize several of its data. wversion is used to identify the struct version. In EDB, it must be set to 2 and 1 in CEDB. Guidvol is the unique identifier of the database volume, and oiddbase is the identifier of the database. After initializing the data, you can use this function to obtain the data.
The infdatabase in the by_handle_db_information structure contains various information about the database. It isThe cedbaseinfoex type is defined as follows:
Typedef struct cedbaseinfoex {
Word Wversion;
Word Wnumsortorder;
DWORD Dwflags;
Wchar Szdbasename[Cedb_maxdbasenamelen];
DWORD Dwdbasetype;
DWORD Dwnumrecords;
DWORD Dwsize;
Filetime Ftlastmodified;
Cesortorderspec Rgsortspecs[Cedb_maxsortorder];
} Cedbaseinfoex;
The following code retrieves the number of records:
- Ceoid dboid = 0;
- HDB = ceopendatabaseinsession (g_hsession,
- & G_volguid,
- & Dboid,
- Szdbname,
- Null,
- 0,
- Null );
- By_handle_db_information bhdi = {0 };
- Bhdi. wversion = 2;
- Bhdi. guidvol = g_volguid;
- Bhdi. oiddbase = dboid;
- If (! Cegetdbinformationbyhandle (HDB, & bhdi ))
- {
- DWORD dd = getlasterror ();
- Return false;
- }
After the above code is executed, the number of records stored in bhdi. infdatabase. dwnumrecords is