Working with Records

Now that you know how to set up databases, you need to populate them with records.

Each application defines the structure of the records in its database. For example, the Memo Pad stores null-terminated C strings as the contents of its records. Thus, if the user creates two memos—a short one and a long one—there will be two records, one short and one long.

We’ll look first at how to read an existing record, then how to modify one. Next, we’ll look at creating records, and then sorting and searching for records.

Reading from a Record

Reading from a record is very simple. Although records are write protected, they are still in RAM; thus, you can just get a record from a database, lock it, and then read from it. You obtain a record using DmQueryRecord :

MemHandle DmQueryRecord(DmOpenRef dbP, UInt16 index)

It requires an open database, along with a record number (also called record index): record numbers always start at 0. This routine is very simple and fast; it goes to the specified array entry in the database and returns the handle of that record.

Example 10-8 shows using DmQueryRecord to retrieve the first memo from the Memo Pad database, which it then displays in an alert (the definition for the alert isn’t shown here).

Example 10-8. Retrieving the first memo from the memo database and displaying it
Err DisplayFirstMemo(DmOpenRef memoDB) { Err err = 0; MemHandle myRecord = DmQueryRecord(memoDB, 0); if (!myRecord) err = DmGetLastErr( ); else { Char *s = (Char ...

Get Palm OS Programming, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.