Here is a simple Perl script that reads strings from a text file and creates
a Palm database on your desktop. The records in this case are the strings,
but you can modify the code to meet your needs.
NOTE: I use Mac OS X, so the Perl 'time' function returns the same time
value that the Palm OS uses: you'll need to modify the time according to
your platform. For example, on Windows, you need to add the number of
seconds between 1902 and 1970:
my $time = time + 0x383EC400;
I hope you find this useful,
JB @ PalmSource
<code>
#!/usr/bin/perl -w
use strict;
my @record; # list of record data
my $i; # record index
my $localID; # byte offset
my $uniqueID; # next unique ID
# Set creation time
my $time = time + 0x383EC400;
# Read data records
$i = 0;
while (<>) {
chomp; # remove line endings
next if (/^\s*$/); # skip blank lines
$record[$i] = $_ . "\x00"; # add null char
++$i;
}
# Write PDB
# Print database header
print pack("a32nnNNNNNNa4a4NNn",
"SampleDB-CrID", # database name
0x0008, # attributes (backup bit)
0, # version
$time, # creation date
$time, # modification date
0, # last backup date
0, # modification number
0, # AppInfo block
0, # SortInfo block
"DATA", # database type
"CrID", # creator ID
$#record + 2, # unique ID seed
0, # NextRecordList ID
$#record + 1 # number of records
);
# Print record list
# Header = 78 bytes; each list entry = 8 bytes.
# The record list is followed by a 2-byte pad.
$localID = 78 + (8 * ($#record + 1)) + 2;
$uniqueID = 1;
foreach $i (0..$#record) {
print pack("NN", $localID, $uniqueID);
$localID += length($record[$i]);
++$uniqueID;
}
# The record list must be followed by a 2-byte pad
print pack("n", 0);
# Print the data records
foreach $i (0..$#record) {
print $record[$i];
}
on 10/15/02 5:15 PM, Hugh Beyer at [EMAIL PROTECTED] wrote:
> "The Data Manager API of the Palm OS SDK allows Palm OS applications to
> create, delete, open, and close databases similar to creating, deleting,
> opening, and closing files on a desktop system...."
>
> Yes, but my question was really whether this could be done ahead of time, as
> part of putting together the app, rather than writing the database from an
> app at run time.
>
> Hugh
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/