squeak.org
[*]  Links

[*]  Syntax Coloring

[*]  Cream Font

[*]  Units

[*]  XML Parser

[*]  PalmOS® tools

PalmOS® Database import/export for Squeak 2.8 and 2.9

A fileIn to enable Squeak to read, write and create PDB and PRC databases as used on
  • 3com® Palm®s
  • USR® Pilot®s
  • IBM® Workpad®s
  • Handspring® Visor®s
(All these are trademarks of their respective owners.)

Two classes, PDB and PilotRecord provide everything needed, and more. PDB holds the contents of a *.PDB or *.PRC in memory, where the individiual records or resources are PilotRecords. These double as both plain database records (in which case they have attributes and a uniqueID) and as resources (in which case they have a type and an id). I tried having database records and resource records as two separate classes, but these abstractions didn't seem to carry their own weight... Just make sure you don't mix records and resources in the same PDB, as it won't export properly.
You can enumerate records, access and manipulate their data contents, flip their attributes etc., all from within Squeak. Import loads a PDB/PRC, export writes one.

Download

Download File Size
FileIn PalmOS-Databases-hh.st 23 KB
Same fileIn, zipped PalmOS-Databases-hh.zip 6 KB
Examples, as shown below (are contained in the code)  

For more in-depth information on the PDB and PRC formats, see the official documentation (zipped PDF), or peruse the links on this tech note page at nsbasic.com.

License

The code is made available under the Squeak license.

Examples

The following example code can be found in class PDB's examples category:
"You must supply real PDB and PRC files. Adjust the filenames accordingly."

"Import the Memo database and examine the records. Provided you use a real MemoDB,
you can see the memo's text in the Inspector by selecting a record and printing 'self data
asString' in the lower pane. Note that all records end in '0 asCharacter'..."

	(PDB new importFromFileNamed: 'MemoDB.pdb') explore.

"Import a PalmOS(R) application and examine its resources"

	(PDB new importFromFileNamed: 'Year.prc') explore.

"Create a very simple PDB. Note the 'false' parameter to resource:..."

	(PDB named: 'My first PDB' type: 'HELL' creator: 'WORL' resource: false)
		addRecord: (PilotRecord new data: 'Hello, world.'; attributes: 0);
		exportToNewFileNamed: 'MyPDB.pdb'.

"Reopen it and examine its contents."

	(PDB new importFromFileNamed: 'MyPDB.pdb') explore.

"Create a very simple PRC. Do not sync that one to a real Pilot."

	(PDB named: 'My first PRC' type: 'HELL' creator: 'WORL' resource: true)
		addRecord: (PilotRecord new type: 'NONS'; id: 101; data: 'Hello, world.');
		exportToNewFileNamed: 'MyPRC.prc'.

"Reopen it and examine its contents."

	(PDB new importFromFileNamed: 'MyPRC.prc') explore.

"Copy a PDB. Note that uniqueIDs will be cleared on export, as recommended
by the PDB spec."

	(PDB new importFromFileNamed: 'MemoDB.pdb')
		exportToNewFileNamed: 'Copied', 'MemoDB.pdb'.

"Copy a PRC. PRCs don't have uniqueIDs, so the result should be bit-identical."

	(PDB new importFromFileNamed: 'Year.prc')
		exportToNewFileNamed: 'Copied', 'Year.prc'.

"Copy a PDB verbatim, preserving the uniqueIDs. Included for completeness to
show bit-identicalness is possible. Remember that uniqueIDs *should* be cleared
on export, as recommended by the PDB spec. Don't confuse your Pilot. ;-)"

	(PDB new importFromFileNamed: 'MemoDB.pdb')
		exportUniqueIDs: true;
		exportToNewFileNamed: 'VerbatimCopied', 'MemoDB.pdb'

Copyright © 1999-2000 by Helge Horch. All rights reserved.
LAST AWK RUN: hh 03oct00, contact: heho@gmx.de