Reference 158251 158256 158257
Ok i understand that the database in PALM is not structured like the
database in say Access
However I am still some what confused on how to add a record to this binary
type of data storage file
So here is some code riped form the tutorial to assist in explanations
#define kCreator 'ErrD'
#define kDBType 'DATA'
#define kDBName "ListErrD"
DmOpenRef gDB = 0;
error = DmCreateDatabase(0, kDBName, kCreator, kDBType, false);
// this creates a database file not a resource file
gDB = DmOpenDatabaseByTypeCreator(kDBType, kCreator, dmModeReadWrite);
// this opens that file
Next this adds a record to that database
Err AddToDatabase(ErrandDBPtr record)
{
Err error = errNone;
UInt16 recIndex = dmMaxRecordIndex;
MemHandle recH;
MemPtr recP;
UInt16 index;
recP = MemPtrNew(sizeof(ErrandDB));
((ErrandDBPtr)recP)->day = record->day;
index = GetFromDatabase((ErrandDBPtr)recP);
MemPtrFree(recP);
if (index == -1)
{
recH = DmNewRecord(gDB, &recIndex,
sizeof(Weekday)+StrLen(record->errands)+1);
if (recH)
{
recP = MemHandleLock(recH);
DmWrite(recP, 0, &(record->day), sizeof(Weekday));
DmWrite(recP, sizeof(Weekday), record->errands,
StrLen(record->errands)+1);
error = DmReleaseRecord(gDB, recIndex, true);
MemHandleUnlock(recH);
}
}
else
{
UInt16 newSize = sizeof(record) + StrLen(record->errands) + 1;
recH = DmResizeRecord(gDB, index, newSize);
if (recH)
{
recP = MemHandleLock(recH);
DmWrite(recP, sizeof(Weekday), record->errands,
StrLen(record->errands)+1);
DmReleaseRecord(gDB, index, true);
MemHandleUnlock(recH);
}
}
if (error == errNone)
return 0;
else
return DmGetLastErr();
}
The only thing I can see here as to a reference to a field name might be in
these statements
// recH = DmNewRecord(gDB, &recIndex,
sizeof(Weekday)+StrLen(record->errands)+1);
// DmWrite(recP, sizeof(Weekday), record->errands,
StrLen(record->errands)+1);
could someone help me out here
I did print out the section 27 Data and Resource Manager from the API docs
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/