Java™-based development framework for PalmOS™ devices (PDAs) Copyright© 2000 by Bernd R. Fix. All Rights Reserved. |
|
DynaWorks TutorialHow to write applications with the DynaWorks framework |
DynaDb: Table Of Content |
||
DynaDb - creating database-aware applications easily |
||
The DynaWorks framework now includes DynaDb,
a set of classes to be used for database operations. DynaDb
not only helps you to use your custom databases, it also supports you in accessing
(limited to read access for the moment) the Palm build-in
databases (address, datetime, notes ...) as well. The DynaDb classes are ment to simplify the task of working with different databases. Instead of writing specific database methods for every database, you can use DynaDb abstract layer to handle your record layouts on the fly.
|
||
Defining your own recordset |
||
Databases (at least on the palm) are a ordered collection of variable-length
datastructures. Normally you devide each record (entry in the database) into
fields; the sequence of "fields" in a record is fixed, but the fields can have
(in case of Strings do have) variable length. You start by deriving from class Record to define your own record structure, that is the sequence (and eventually size) of each field:
|
||
BytesField | ||
a byte array of fixed length | ||
StringField | ||
a String of variable length | ||
ShortField | ||
a short value (2 Bytes) | ||
IntegerField | ||
an integer value (4 Bytes) | ||
Opening the database |
||
First you have to create a Palm database object. The constructor of the PalmDB class
requests a string arguments, that identifies the name of the database, the creator id and the type id:
// create a database object PalmDB db = new PalmDB ("MYAP:DATA:MyAppDatabase");This database object can then be opened for read/write by
// forced open on database if (!db.open()) { ...The database will be automatically created if it does not exist yet; only if a database could not be created nor opened, the call will fail.
|
||
Reading and writing records |
||
You can simply write a record to the database:
|
||
Closing the database |
||
To close a database simply call the 'close()' method of the DynaDB you want to close. | ||