Programming for Palm OS/C/Databases

to open a database

edit
 UInt16  cardNo = 0;
 LocalID  databaseId = DmFindDatabase( cardNo, "YourAppDB");
 if ( databaseId)
 {
   UInt16     mode = dmModeReadOnly;
   DmOpenRef  database = DmOpenDatabase( cardNo, databaseId, mode);
 }


to close a database

edit
 if ( database)
 {
   Err  e = DmCloseDatabase( database);
 }


to walk the records of a database

edit
 UInt16  numRecords = DmNumRecords( database);
 UInt16  recordIndex;
 for ( recordIndex = 0;  recordIndex < numRecords;  ++ recordIndex)
 {
   MemHandle  record = DmQueryRecord( database, recordIndex);
   if ( record)
   {
     UInt32  recordSize = MemHandleSize( record);
     char    *data = MemHandleLock( record);
     Err     e = MemHandleUnlock( record);
   }
 }


to create databases on your workstation

edit
 sudo apt-get install  ruby  rubygems
 sudo gem install --include-dependencies --no-rdoc --no-ri  palm
#!/usr/bin/env ruby
#

require 'rubygems'
require 'palm'

pdb = Palm::PDB.new
pdb.name    = 'YourAppDB'
pdb.creator = 'Anon'
pdb.type    = 'DATA'
pdb.version = 1
  
pdb.data << Palm::RawRecord.new( 'Hello')
pdb.data << Palm::RawRecord.new( 'World') 
    
pdb.write_file 'YourAppDB.pdb'