跳至内容

Palm OS/C/数据库编程

来自维基教科书,自由的教科书

打开数据库

[编辑 | 编辑源代码]
 UInt16  cardNo = 0;
 LocalID  databaseId = DmFindDatabase( cardNo, "YourAppDB");
 if ( databaseId)
 {
   UInt16     mode = dmModeReadOnly;
   DmOpenRef  database = DmOpenDatabase( cardNo, databaseId, mode);
 }


关闭数据库

[编辑 | 编辑源代码]
 if ( database)
 {
   Err  e = DmCloseDatabase( database);
 }


遍历数据库记录

[编辑 | 编辑源代码]
 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);
   }
 }


在工作站上创建数据库

[编辑 | 编辑源代码]
 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'
华夏公益教科书