OOFILE | Downloads | Purchasing | Press | Services | Company Information | Soapbox | References | F.A.Q. | HOME |
This header is included in ooftst16.
This sample is almost a copy of ooftst02.h but without the PatientNo fields for the join relationships
Here we declare the fact that each visit will have one reference of a patient whereas each patient will have a set of visits. This is explained more fully in ooftst02.h
DECLARE_REF(dbPatients) DECLARE_SET(dbVisits)
Declaring a pointer relationship
Now we declare the class for the patient records. Note the 'dbVisitsSet' field called 'Visits'. This is how we will refer to the related records using pointers. Note also that we do not declare a join field and do not even include a patient number in the table. Compare this with ooftst02.h's declaration.
DECLARE_CLASS(dbPatients) dbChar LastName, Othernames; dbVisitsSet Visits; dbLong Salary;
We then give the basic information about our fields, without giving any to the visits field.
dbPatients() :
LastName(40, "Last Name", kIndexed),
Othernames(80, "Other names", kIndexed),
Salary("Salary", kIndexed)
{};
These procedures will be for adding data to the table. Note that we have a procedure for adding data to the other table -> through this one.
void Add(const char *lname, const char *oname, const long salary); void AddVisit(const char* visitDate, const char* why); void AddTestData();
};
Now we declare the class for the other table. Note that we don't have a set of records to relate to this one, just a single record stored as "Patient". Again we do not give any information about this field.
DECLARE_CLASS(dbVisits)
dbPatientsRef Patient;
dbDate VisitDate;
dbChar Why;
dbVisits() :
VisitDate("VisitDate", kIndexed),
Why(200, "Reason for Visit", kIndexCompress)
{};
};
This is the procedure for adding a single record to the patients table. It simply accepts a value for each field (apart from the relationship field) and assigns the value to it, then saves the record.
void dbPatients::Add(const char *lname, const char *oname, const long salary)
{
newRecord();
LastName = lname;
Othernames = oname;
Salary = salary;
saveRecord();
}
This is the procedure that adds a record to the visits table. Remember that it was declared as a method of the patients class, so each value it is passed must be assigned through the relatiionship to its related record. It also does not save the record so that must be done after it has been called.
void dbPatients::AddVisit(const char* visitDate, const char* why)
{
Visits->newRecord();
Visits->VisitDate = visitDate;
Visits->Why = why;
}
This procedure is used to add a lump of test data to the database for use in ooftst16.
void dbPatients::AddTestData()
{
Apparently, if you are using SmartHeap debugging the following can take long enough to make folks wonder. There are a *lot* of places where OOFILE calls SmartHeap to check memory.
The first patient has multiple visits.
cout << "Generating new test records..." << flush;
Add("Smith", "John", 20000);
AddVisit("1/10/1994", "Sore Knee");
AddVisit("14/10/1994", "Measles");
saveRecord();
The second has only one, but has a large number for a salary to be used for tests for overflow errors.
Add("DENT", "Trissa", 99999);
AddVisit("23-11-1994", "Flu");
saveRecord();
This is a relatively normal record.
Add("Dent", "Andy", 50000);
AddVisit("4.10.1994", "Flu");
saveRecord();
This record has no related records to test zero conditions.
Add("Taylor", "Ken", 75000);
cout << endl << endl;
}
(c) Copyright A.D. Software 1994-2000 (All Rights Reserved).
Last Updated: 9th September 2001