OOFILE | Downloads | Purchasing | Press | Services | Company Information | Soapbox | References | F.A.Q. | HOME |
This sample tests searching by related files.
#include "oofile.h" // the general oofile library #include "ooftst02.h" // the declarations for the database classes we will be using in this test.
These are the global variables that define the database using the ooftst02 classes
TEST_CONNECT theDB; dbPatients Patients; dbVisits Visits; dbRelationship PatientVisits(Patients.Visits, Visits.Patient);
int main()
{
cout << "OOFILE Validation Suite - Test 26\n"
<< "Simple test of counting related data" << endl
<< "and intersecting related data" << endl
<< "as is often used in producing reports or graphs" << endl << endl;
We test for the current platform and assign a filename accordingly.
#ifdef TESTING_DBASE #ifdef _Macintosh const char* kExistsName = ":ooftst02:Patients.dbf"; const char* kDatabaseName = ":ooftst02:"; #else const char* kExistsName = "Patients.dbf" const char* kDatabaseName = ""; #endif
#else const char* kDatabaseName = "ooftst02.db"; const char* kExistsName = kDatabaseName; #endif
Now we open or create a new file and add test data.
if (dbConnect::fileExists(kExistsName)) {
theDB.openConnection(kDatabaseName);
}
else {
theDB.newConnection(kDatabaseName);
Patients.AddTestData();
}
We print out the database so we can get an idea of its initial condition.
cout << theDB << endl;
Now we create a simple search on the main table.
Patients.search(Patients.LastName == "Dent");
We print out the results of our search, counting the number of records found, using the function count().
cout << "Number of 'Dent' Patients = " << Patients.count() << endl;
Now we try a search on the other table, testing for records whose VisitDate is earlier than the one given.
Visits.search(Visits.VisitDate < "1-11-1994");
We again print the number of records found.
cout << "Number of Visits prior 1-11-1994 = " << Visits.count() << endl
Now we print the number of visits related to the selected patients. We do this using the function countAllRelated().
cout << "Number of Visits related to selected Patients = " << Patients.Visits.countAllRelated() << endl;
Now we print the number of vistis that are related to patients in our search, but only those within the parameters of our other search. This is like a refinement of the search. We do this using the function countAllRelatedIn().
cout << "Number of Visits related to selected Patients prior 1-11-1994 = " << Patients.Visits.countAllRelatedIn(Visits) << endl;
cout << "Test Completed" << endl;
return EXIT_SUCCESS; }
(c) Copyright A.D. Software 1994-2000 (All Rights Reserved).
Last Updated: 9th September 2001