Hi all,
I have been reading a lot of EDB reference, but still can't figure our how to work on EDB, can someone post a sample it here
(PS. I cannot find any EDB samples in WM5 SDK)
Hi all,
I have been reading a lot of EDB reference, but still can't figure our how to work on EDB, can someone post a sample it here
(PS. I cannot find any EDB samples in WM5 SDK)
Request EDB samples for WM5
Dani
Hi,
Here is a sample EDB application that is self-explanatory. Hope this helps.
/*
* Program to demonstrate a particular usage of EDB APIs.
* The program creates a database volume and
* writes couple of records into it and
* then closes the volume. This is done in the 'WriteRecords'
* routine.
* After that in the 'ReadRecord' routine we remount the volume
* and search for a record, whose contents has "Tera" as a prefix.
* Sure enough we find the record as we had written the string
* "Terabyte" in our 'WriteRecords' routine.
* Once we find the record we unmount the volume.
*
* Compilation: Remember to compile the program with the flag /DEDB
* and make a debug build for the same.
*
*/
#include <windows.h>
#include <winbase.h>
#include <windbase.h>
static bool WriteRecords(void)
{
CEOID oid = NULL;
CEGUID guidVol = {0,};
BOOL fOK = true;
HANDLE h = INVALID_HANDLE_VALUE;
SORTORDERSPECEX s =
{
2, // wVersion should be 2 for EDB
1, // wNumProps
0, // wKeyFlags
0, // wReserved
0, //rgPropID,
{ 0 } //rgdwFlags
};
CEDBASEINFOEX info =
{
2, // wVersion must be 2 for EDB
0, // wNumSortOrder
(CEDB_VALIDNAME | CEDB_VALIDTYPE | CEDB_VALIDSORTSPEC), // dwFlags
L"Table1", // szDbaseName
0x777, // dwDbaseType
NULL, // dwNumRecords
NULL, // dwSize (Not used by EDB)
{0,}, //ftLastModified (Not used by EDB)
};
CEPROPVAL val =
{
0, // propid
NULL, // wLenData - can be garbage on entry
NULL, // wFlags
0
};
s.rgPropID[0] = CEVT_LPWSTR;
val.propid = CEVT_LPWSTR;
if (!CeMountDBVolEx(&guidVol, L"volume.db", NULL, CREATE_ALWAYS))
{
fOK = false;
goto exit;
}
if ((oid = CeCreateDatabaseWithProps(&guidVol, &info, 0, NULL)) == NULL)
{
fOK = false;
goto exit;
}
if ((h = CeOpenDatabaseInSession(NULL, &guidVol, &oid, NULL, NULL,
0, NULL)) == INVALID_HANDLE_VALUE)
{
fOK = false;
goto exit;
}
//Write 2 records.
val.val.lpwstr = L"Gigabyte";
if (!CeWriteRecordProps(h, 0, 1, &val))
{
fOK = false;
goto exit;
}
val.val.lpwstr = L"Terabyte";
if (!CeWriteRecordProps(h, 0, 1, &val))
{
fOK = false;
goto exit;
}
CeFlushDBVol(&guidVol); // Just being paranoid!
CloseHandle(h);
exit:
CeUnmountDBVol(&guidVol);
return fOK;
}
static bool ReadRecord(void)
{
bool fOK = true;
CEOID oid = NULL, oidRow = NULL;
CEGUID guidVol = {0,};
HANDLE h = INVALID_HANDLE_VALUE;
CEDBASEINFOEX info =
{
2, // wVersion must be 2 for EDB
1, // wNumSortOrder
CEDB_VALIDSORTSPEC, // dwFlags
L"Table1", // szDbaseName
0x777, // dwDbaseType
NULL, // dwNumRecords
NULL, // dwSize (Not used by EDB)
{0,}, //ftLastModified (Not used by EDB)
};
SORTORDERSPECEX s =
{
2, // wVersion should be 2 for EDB
1, // wNumProps
0, // wKeyFlags
0, // wReserved
0, //rgPropID,
0, //rgdwFlags
};
CEPROPVAL val =
{
0, // propid
NULL, // wLenData - can be garbage on entry
NULL, // wFlags
0
};
s.rgPropID[0] = CEVT_LPWSTR;
info.rgSortSpecs[0] = s;
val.propid = CEVT_LPWSTR;
if (!CeMountDBVolEx(&guidVol, L"volume.db", NULL, OPEN_EXISTING))
{
fOK = false;
}
// Open Database by Name to get its oid.
if ((h = CeOpenDatabaseInSession(NULL, &guidVol, &oid, L"Table1", NULL,
0, NULL)) == INVALID_HANDLE_VALUE)
{
fOK = false;
goto exit;
}
CloseHandle(h);
if (CeSetDatabaseInfoEx2(&guidVol, oid, &info) == false)
{
fOK = false;
goto exit;
}
if ((h = CeOpenDatabaseInSession(NULL, &guidVol, &oid, L"Table1", &s, 0, NULL)) == NULL)
{
fOK = false;
goto exit;
}
val.val.lpwstr = L"Tera";
// Seeking the prefix "Tera".
if ((oidRow = CeSeekDatabaseEx(h, CEDB_SEEK_VALUEFIRSTEQUAL | CEDB_SEEK_PREFIX, (DWORD) &val, 1, 0)) == NULL)
{
fOK = false;
}
if (oidRow == NULL)
{
MessageBox(NULL,
_T("CeSeekDatabase failed."),
_T("Error"),
MB_OK);
}
exit:
CeUnmountDBVol(&guidVol);
return fOK;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nShowCmd)
{
if (WriteRecords() == false)
{
return 1;
}
if (ReadRecord() == false)
{
return 1;
}
return 0;
}