O'Reilly logo

Palm OS Programming, 2nd Edition by Neil Rhodes, Julie McKeehan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required