Peter Hamilton-Scott wrote:

I'm trying to get the database functions to work, and after a lot of playing around I'm not finding this very intuitive, what with the sheer number of Dm... routines there are and that you have to do A before B before C and woe betide you if call E before B - you probably know the feeling! :-)

In short, does anyone know if there is a freeware library that simplifies database access? My app needs (or at least I think it needs) an app info block as I'd like to keep some database state external to the records it refers to. From what I find and see, app info blocks and control records are not well described though the database records is a little more easier to use.

To that end, I'm looking at using the first record as my control record and then having to union the data records. This is counter-productive. If there is a reliable library you know of I'd appreciate that, or failing that, a link to a good onlite site that does a walk-through of Palm database I/O?

Thanks.

Peter, it's certainly not all that hard to use the Dm functions to get to your goal. I think you are reading too much into it. Even if you could find a library to do it, getting that to work would be just as complicated. Below are some samples that creates a database if it doesn't already exist, then add a record. I edited them a little to protect the innocent, so I hope I didn't add any bugs. Bob.

Boolean CreateDatabase(Char *dbName, UInt16 dbType, UInt16 dbAppId){
 LocalID       dbID;
 UInt16        attr;
 DmOpenRef     db = DmOpenDatabaseByTypeCreator(dbType, , dmModeReadWrite);

//if it wasn't able to open then create it
if (!db) {
//if it can't create then bail out
if (DmCreateDatabase(0, dbName, dbAppID, dbType, false)) return 1;
//get the default attributes and add the db backup bit
dbID=DmFindDatabase(0,dbName);
DmDatabaseInfo(0,dbID,NULL, &attr, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
attr=attr | dmHdrAttrBackup;
DmSetDatabaseInfo(0,dbID,NULL, &attr, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
else DmCloseDatabase(db);
return 0;
}


And this sample will open your db and write a string into it as a new record...

UInt16 WriteString(Char *st, UInt16 dbType, UInt16 dbAppId){
   MemHandle  recH=NULL;
   UInt8      *recP=NULL;
   UInt16     record=-1; //-1 puts new record at end
   DmOpenRef  db;

db=DmOpenDatabaseByTypeCreator(dbType, dbAppId, dmModeReadWrite);
if (db){
recH=DmNewRecord(db,&record,StrLen(header)+3); //+3 is some padding at end
recP=MemHandleLock(recH);
DmSet(recP,0,MemHandleSize(recH),0);
DmWrite(recP,0,header,StrLen(header));
DmSet(recP,StrLen(header),1,10);
MemHandleUnlock(recH);
DmCloseDatabase(db);
}
}




--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to