Creating, Opening, and Closing Databases

You handle these standard operations in a straightforward manner in Palm applications.

Creating a Database

To create a database, you normally use DmCreateDatabase :

Err DmCreateDatabase(UInt cardNo, CharPtr nameP, ULong creator, 
     ULong type, Boolean resDB)

The creator is the unique creator you’ve registered at the Palm developer web site (http://www.palm.com/devzone). You use the type to distinguish between multiple databases with different types of information in them. The nameP is the name of the database, and it must be unique.

Note

Until Palm Developer Support issues guidelines on how to use multiple card numbers, just use 0 as your card number when creating databases.

In order to guarantee that your database name is unique, you need to include your creator as part of your database name. Developer Support recommends that you name your database with two parts, the database name followed by a hyphen (-) and your creator code. An application with a creator of “Neil” that created two databases might name them:

Database1-Neil
Database2-Neil

Create your database in your StartApplication routine

You normally create your database from within your StartApplication routine. This is in cases where the database does not yet exist. Here is a typical code sequence to do that:

// Find the Customer database.  If it doesn't exist, create it.
gDB = DmOpenDatabaseByTypeCreator(kCustType, kSalesCreator, mode); if (! gDB) { err = DmCreateDatabase(0, kCustName, kSalesCreator, ...

Get Palm Programming: The Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.