Databases

Postby Corzar on Mon Apr 23, 2001 11:20 pm

The use of dbrecs is a very useful function to create quick loading programs. By "chinking" files, you can load each individual piece when it is needed.

Here is a sample program that creates a chunked database:

// Complete Level DB Compiler
string ddata;
string data[5184];
int ndata, a;

// Declare Palm OS information
@cid "cor1";
@name "comp";
@ver "1.0.1";
@dbname "Level Compiler";

// Declare Icons
@licon1 "TheDeadArmy1.bmp";
@licon2 "TheDeadArmy2.bmp";
@licon4 "TheDeadArmy2.bmp";
@licon8 "TheDeadArmy8.bmp";
@sicon1 "DeadArmy1.bmp";
@sicon2 "DeadArmy2.bmp";
@sicon4 "DeadArmy2.bmp";
@sicon8 "DeadArmy8.bmp";

write(){
int a, b, c; string e;
dbdelete();

dbcreatex("TDA_LEV", "Corz", "lev");

for (a = 0; a < 4; a++)
{
resetaot();

if (a == 0) {mmfind("TDA"); dbrec(a); puts("TDA");}
if (a == 1) {mmfind("Box Layout"); dbrec(a); puts("\nBox Layout");}
if (a == 2) {mmfind("Door Layout"); dbrec(a); puts("\nDoor Layout");}
if (a == 3) {mmfind("Story"); dbrec(a); puts("\nStory");}

mmgetl();

// get values
while (data[ndata] = mmgetl()) {

// write data
dbwrite(data[ndata]);

if (data[ndata] == -1) { break;}

ndata++;}}

mmfind("Tda Layout"); puts("\nTDA Layout");
ddata=mmgetl();

for (a = 0; a < 100; a++){

dbrec(a + 4);

resetaot();
ddata=mmgetl();

if (ddata == -1) {dbwrite(ddata); break;}

for (b=1; b<7; b++){
ddata=mmgetl();

if (ddata=="skip")
{puts("skip"); dbwrite(-2); break;}

for (c=0; c<30; c=c+5){
e = substr(ddata,c,3);
dbwrite (e);}}}

dbbackup(1);}

main() {

title("Complete DB compiler");
clear();
puts("Opening DB 'TDA_LEV'\n");
dbopen("TDA_LEV");
write();
}

As you can see, everytime dbrec() is called to a higher number then exists in the db, the opened db will create a new record.

To call a particular saved record, dbrec() is also called, and to call the first record, do this:

dbrec(0);

dbrec() sets the position to the begining of the record. using dbread() will read a portion of the record starting from the start. :)



Edited by - Corzar on 04/25/2001 18:48:29
Xavier Smork

*Trying to make something important*

Love my Sony PDA!

http://www.geocities.com/xaviersmork
Corzar
 
Posts: 53
Joined: Mon Apr 23, 2001 11:19 pm
Location: USA

Return to PocketC for Palm OS KB

Who is online

Users browsing this forum: No registered users and 2 guests

cron