Personal Portable System Manager
Programmer’s Manual
Database Management 7-3
database.
7.3 Creating and Editing a Database
Whenever a record is created, PPSM will pass back a unique record identifier.
Application will need to use this identifier as the key for subsequent access of that
particular record.
The following example illustrates a routine build database and its associated
memory variables which create a database, add new record and initialize four
formatted data field in a record.
Note that user must have already declared the variable gAddBkDBaseID before
calling DBAdd(). It is important that the database ID must remain intact since
access to the database need this as the key.
Note also that in the example, recID is used as a temporary variable only, the
creation of the next record will overwrite the former recID. This is permissible
because of the linked list structure of the record list, we can traverse the list to
retrieve the record that we need without needing you keep track of every record
ID. However, for those frequently called record, it would be better to allocate a
memory variable to keep its record ID for speedy access.
Example 7-1 Create a database, add record, write data to record, and read
number of records in database
/* Database identifier *
U32 gAddBkDBaseID;
/* Data to be written in RECORD 1 */
TEXT grec1LName[5]={’A’,’d’,’a’,’m’,0};
TEXT grec1FName[4]={’K’,’e’,’n’,0};
TEXT grec1Phone[9]={’2’,’2’,’2’,’-’,’6’,’7’,’8’,’9’,0};
TEXT grec1Add[17]={’1’,’0’,’ ’,’M’,’a’,’v’,’e’,’n’,’ ’,’A’,’v’,’e’,0};
/* Data to be written in RECORD 2 */
TEXT grec2LName[8]={’A’,’p’,’p’,’l’,’e’,0};
TEXT grec2FName[4]={’J’,’o’,’e’,0};
TEXT grec2Phone[9]={’6’,’6’,’6’,’-’,’1’,’3’,’3’,’1’,0};
TEXT grec2Add[17]={’1’,’2’,’ ’,’M’,’a’,’i’,’n’,’ ’,’S’,’t’,’r’,’e’,’e’,’t’,0};
STATUS buildDBase(void)
{
STATUS ret;
U32 recID;
S32 numRec;
ret = DBAdd(&gAddBkDBaseID);
if(ret != PPSM_OK) return(-1);
/* Add Record 1 */
DBAddRecord(gAddBkDBaseID,&recID, 0);
DBChangeStdData(gAddBkDBaseID,recID, DB_LAST,grec1LName);
DBChangeStdData(gAddBkDBaseID,recID, DB_FIRST,grec1FName);
DBChangeStdData(gAddBkDBaseID,recID, DB_HOME,grec1Phone);
DBChangeStdData(gAddBkDBaseID,recID, DB_ADDRESS,grec1Add);
/* Add Record 2 */
DBAddRecord(gAddBkDBaseID,&recID, 0);
DBChangeStdData(gAddBkDBaseID,recID, DB_LAST,grec2LName);
DBChangeStdData(gAddBkDBaseID,recID, DB_FIRST,grec2FName);
DBChangeStdData(gAddBkDBaseID,recID, DB_HOME,grec2Phone);
DBChangeStdData(gAddBkDBaseID,recID, DB_ADDRESS,grec2Add);
/* Read back no of record in the database, should be 2*/