OOFILE | Downloads | Purchasing | Press | Services | Company Information | Soapbox | References | F.A.Q. | HOME

OOFTST 37 - copying databases

This sample tests copying from one database to another, eg: as if updating a schema.


#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. They have been wrapped into a class together. This is commonly used to have a document class to pass around a GUI interface. 

	class myDB {
	public:
		TEST_CONNECT    theDB;
		dbPatients    	Patients;
		dbVisits		Visits;  
		myDB();
	};

Here we declare the relationship as part of the class's constructor.

	myDB::myDB()
	{
		dbRelationship PatientVisits(Patients.Visits, Visits.Patient);
	}  

Now we declare two instances of the database class.

	myDB firstDB, secondDB;
		  
int main()
{
	cout << "OOFILE Validation Suite - Test 37\n"
		 << "Simple test to store some data and copy to another DB" << endl << endl;  

Here we create or open the first database.

	#ifdef TESTING_DBASE
		#ifdef _Macintosh
			const char* kExistsName =  ":ooftst37:Patients.dbf";
			const char* kDatabaseName = ":ooftst37:";
		#else
			const char* kExistsName =   "Patients.dbf"
			const char* kDatabaseName = "";
		#endif	  
	#else
		const char* kDatabaseName = "ooftst37.db";
		const char* kExistsName = kDatabaseName;
	#endif
	  
	if (dbConnect::fileExists(kExistsName)) {
		firstDB.theDB.openConnection(kDatabaseName);
	}
	else {
		firstDB.theDB.newConnection(kDatabaseName);
		firstDB.Patients.AddTestData();
	}  

Now we create or open the second database.

	#ifdef TESTING_DBASE
		#ifdef _Macintosh
			const char* kExistsName2 =  ":ooftsx37:Patients.dbf";
			const char* kDatabaseName2 = ":ooftsx37:";
		#else
			const char* kExistsName2 =   "Patients.dbf"
			const char* kDatabaseName2 = "";
		#endif	  
	#else
		const char* kDatabaseName2 = "ooftsx37.db";
		const char* kExistsName2 = kDatabaseName2;
	#endif
	  
	if (dbConnect::fileExists(kExistsName2)) {
		secondDB.theDB.openConnection(kDatabaseName2);
		secondDB.Patients.deleteAll();
	}
	else {
		secondDB.theDB.newConnection(kDatabaseName2);
	}  

We haven't added any test data to the second database,and to prove that this is the case, we print it out.

	cout << "Second DB is currently empty\n" << secondDB.theDB;  

Now we copy the first database to the second database. We use the function copyAllFrom(). Note that the database that calls this function is the one we are copying TO. The parameter passed to the function is the address of the database we are copying FROM.

Testing: function copyAllFrom()

	secondDB.theDB.copyAllFrom(&firstDB.theDB);		  

We now prove that the second is a copy of the first by printing it out.

	cout << "Second DB is now a copy of first\n" << secondDB.theDB;
	cout << "Test Completed" << endl;
	return EXIT_SUCCESS;
}        

 

Feature index

(c) Copyright A.D. Software 1994-2000 (All Rights Reserved).
Last Updated: 9th September 2001