20) PDB-File Structure -Vol.1-
"PDB" is the abbreviation of "Palm Database",But it is not difficult structure than "DATABASE" we call usually.
Therefore,if you know this structure,it is not difficult to make pdb files easily by VB or other tools.
In this topics,I'll explain the structure of the most simple case. If you understand this, you will be able to understand other cases easily.

----PREPARATIONS-----
The most simple case , it is Non-keyed database in NS Basic/Palm.
These database is what will be accessed by DbPut() and DbGet().
This program code can make a database file,it is sample for this topics:
    Dim Db as Database
    Dim res as Integer

    res=DbCreate(Db,"DB-CREATE-TEST",0,"Test")

    If res=0 then

        res=DbOpen(Db,"DB-CREATE-TEST",0)

        res=DbPosition(Db,1,0)
        res=DbPut(Db,"NS BASIC")

        res=DbPosition(Db,2,0)
        res=DbPut(Db,"mizuno-ami")

        res=DbPosition(Db,3,0)
        res=DbPut(Db,"Simple Sample")

        res=DbClose(Db)
    End if
And on the other hand,the reading database code is here:
(Field1008 shows the data which specified record at Field1006.)
    Dim Db as Database
    Dim res as Integer
    Dim intSet as Integer
    Dim strData as String

    intSet=Val(Field1006.Text)

    res=DbOpen(Db,"DB-CREATE-TEST",0)

    res=DbPosition(Db,intSet,0)
    res=DbGet(Db,strData)

    res=DbClose(Db)

    Field1008.text=strData
Please input these codes to NS Basic and make a sample program for test database.
Perhaps,this simple program will have a FORM with 2 BUTTONS and 2 FILEDS.
(Input name of these Fields as proper.)

After compiling,and do Hotsync and make a database.
And check the record data if the database was made.
If you input "1" and shows "NS Basic" ,it is OK.



After checking this,do Hotsync again.
Then you can find file of 'DB-CREATE-TEST.pdb' in your PC's backup folder of Palm-Desktop.
This is the database file that we want to analyze.

By the way, if you want to see this file , you will need a binary editor.
Please get a binary editor ,it can be tiny one.




----Database structure:Header----
With using real data,let's look at the structure in order.
(There are many explanation pages for this structure on the Web site,So it may not need to explain in detail.)
The outline of structure consists of these 3 parts.
  • Header(Database Header)
  • Location information(Record Header)
  • Real Record Data

If it need application infomation or others , it includes here. But the simple structure need not.

At first, look at Database header.
The size of this is 78bytes and this structure is following:
Offsetsize
(byte)
nameexplanation
+0000H32Database NameDatabase name on Palm(Not file name on PC)
+0020H2flagsattribute of this database
+0022H2versionversion number
+0024H4create timethe number of seconds since '1904-01-01 00:00:00'
+0028H4modified time
+002CH4backup time
+0030H4modified numberthe number of modified times
+0034H4application info sizeThe simplest database sets "00 00 00 00"
+0038H4sort info size
+003CH4typeFile type. database is "data"
+0040H4creatorIDcreator ID
+0044H4unique id seedUnique seed number(Don't mind!)
+0048H4next record listNext record number(Don't mind!)
+004CH2number of recordsnumber of records
There will be some data fields you had known already.
Let's look up these data in order.

The database name is 32 byte data. You can find the database name is included there.
But you can find strings like "ANL" that you did not write.
In fact,the end of data field is "00H" ,that is what you can find after database name.
Palm ignores data in the back of "00H".

Surely,there is "00H" after database name "DB-CREATE-TEST".
Therefore, the database name will be 31 bytes and "00H",even if the field is 32 bytes.



Next 2 bytes, you can find "00 08", this is attribute of database file.
This flag sets this files attribute.
If it sets "00 08", this file will be done backup to your PC at Hotsync.
Usually,you must set this flag "00 08".

Next 2 bytes, it is version number.
"00 00" is written here, so we may write only "00 00" to here.
B
The following data about date and time, it is seconds data as 4 bytes.
You must set the number of seconds since '1904-01-01 00:00:00'.
But can you count this data?
Don't mind, because at doing Hotsync,this data is written. So it is OK that you write "00 00 00 00" to here.



The next data 'modified number' will be counted up at correcting data.
When you will make a new PDB file, you can write "00 00 00 00" it.

Application info size and sort info size ,these data is "00 00 00 00".
It is meaning that these info data is not here.
The simplest database does not need these info.

Next 2 data may be familiar data for you.
The first 4 bytes is file type and next 4 bytes is creator ID.
At the database , the type will be usually "data".
And creator ID will be set by you when you create this database file by DbCreate().
In this case , "Test" which you set , you can find.



Next 8 bytes , I don't know in detail but I know these are nonsense data.

The last 2 bytes of header is number of records.
Records we wrote are 3 records, and so here is "00 03".
And this data is 2 bytes,it means that the maximum number of records is 65535 records.



These are a detail of header data of 78 bytes.
At least,the painted cells of the table will be necessary data.


----Database structure:Location info----
The following data at header is location info and read data.
Location info and real data should be a pair of data,so this test database includes 3 location infos and 3 real data.


Let's look at these location infos.

A location info data is 8 byte data as following:

offsetsize
(byte)
nameexplanation
+0000H4offsetlocation of this record from the head of file
+0004H1attribute
attribute
attribute of this record
+0005H3uniquie ID
uniqueID
count number of this record

It is helpful for you to understand that this is an index of record data.

The offset of 4 byte means the location of the record data from the head of file.
For example, you can find that the first record data 'NS BASIC' starts from the offset of 0068H.
And the offset of Location info is 0068H.
the 2nd data and the 3rd data ,too.


Next data ,it is an attribute of this record ,it is OK that only you know 40H.
PDB file has an attribute for whole of file and some attributes for records.
I think this structure will cut Hotsync time, because Hotsync program can find only updated records easily.

The last ,unique ID, this is for assigning a unique number to each record.
Surely, You'll find these data are unique and continue. i.e.'1E 90 01' , '1E 90 02' ...
But do you know what the data of '1E 90' is ?
To tell the truth, these number is what you don't have to make, because it is made automatically at Hotsync.
So it is no problem even if you know the only offset at the location data.


----Database structure:Real Data----
It is easy to image that the whole location info sizes can be calculated from the number of records.
One location info size is 8 byte, multiply the number of records by it , and you will know this size.
But what's mean for getting this size ?
In fact,this means the head of real data location.
For example in this case, the header is 78 byte and includes 3 data ,so 78 + 3 * 8 = 102 -> 066H, is the head of real data location.

However, in this case, the head of real data is 068H and there is a gap of 2 byte.
CPU decides the head of location at its convenience. And it calls "alignment".
Don't need to make this alignment when you make PDB files, because 2 byte of this case is nonsense space.
But it will be important that you know this possibility.

Although it is reckless test, let's cut the 2 byte of nonsense spaces.
After cutting this space and re-write these locaiton infos:

Before:


After:


Install this database to your palm and check this data. You will find this data is normal data.
It is enough for you to understand that PDB file consists by 3 continuous portions.


The head of real data can be read from its location info. But ,Where is the tail of real data ?
Let's look at the gap of 2 real data.
You'll find that "00 00" is written there.
One "00" means the end of data and the othere means the end of record.



But, in the future,it is possible that this structure will be change.
It is only necessary that you know that the location info means the head of real data.

These are the simplest PDB file structure's explanation and analysis.
This method that using binary editor will be helpful for you ,when you use numeric variables,or use keyed database.
And if you understand these things,you can make a PDB file converter easily.
Let's try !!