home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
compiler
/
doobject
/
relation.do
< prev
next >
Wrap
Text File
|
1991-06-10
|
1KB
|
62 lines
/*
demonstrate the dObject relation facility between two related
.DBF files, first, create a customer file with customer names
*/
custDb = createDbf("customer",[
["cId",'N',8,0],
["cName",'C',32,0],
["cAddress",'C',48,0],
["cCity",'C',16,0],
["cState",'C',2,0],
["cZip",'C',5,0]]);
/*
fill in some test customer names
*/
#define MAXCUST 5
for(i=0;i<MAXCUST;i=i+1) {
cId = i;
cName = "name"+asString(i);
cAddress = "";
cCity = "Chicago";
cState = "IL";
cZip = "60640";
? "writing record ",i;
write(custDb,0L);
}
close(custDb);
/*
create a database of customer purchases
*/
purchaseDb = createDbf("purchase",[
["cId",'N',8,0],
["pItem",'C',32,0],
["pDate",'D',0,0],
["pAmount",'N',8,2]]);
/*
create some test data
*/
for(i=0;i<MAXCUST;i=i+1)
for(j=0;j<2;j=j+1) {
cId = i;
pItem = "item"+asString(i);
pDate = date();
pAmount = 5.25;
write(purchaseDb,0L);
}
close(purchaseDb);
/*
find the purchases for customer #3
*/
custDb = new(Dbffile,"customer");
purchaseDb = new(Dbffile,"purchase");
ndx = createIndex(purchaseDb,"CID","cId",0,0);
setRelation(custDb,"cId",select(purchaseDb),select(ndx),0);
top(custDb);
locate(custDb,"cId",3);
? "record number for customer 3 is ",recno(custDb);
? "customer id field in purchase database is ",recno(purchaseDb);