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

OOFTST 24 - opening databases simultaneously

This sample tests opening two ctree-style databases at once. 


#include "oofile.h"	// the general oofile library
#include "ooftst01.h"	// the declarations for the database classes we will be using in this test.
  
int main()
{
	cout << "OOFILE Validation Suite - Test 24\n"
		 << "Simple test to store some data and retrieve it\n"
		 << "in 2 simultaneously open databases.\n";
	  

We declare our first database and its table.

	TEST_CONNECT    theDB;
	dbPeople     People;  

Test for platform and assign filename accordingly.

#ifdef TESTING_CTREE
	theDB.useSeparateFiles();  
	#ifdef _Macintosh
		const char* kExistsName =  ":ooftst01:People.dat";
		const char* kDatabaseName = ":ooftst01:";
	#else
		const char* kExistsName =   "People.dat"
		const char* kDatabaseName = "";
	#endif	  
#else
	#ifdef TESTING_DBASE
		#ifdef _Macintosh
			const char* kExistsName =  ":ooftst01:People.dbf";
			const char* kDatabaseName = ":ooftst01:";
		#else
			const char* kExistsName =   "People.dbf"
			const char* kDatabaseName = "";
		#endif	  
	#else
		// Persistent RAM, no option of single file
		#ifdef _Macintosh
			const char* kDatabaseName = ":ooftst01:ooftst01.db";
		#else
			const char* kDatabaseName = "ooftst01.db";
		#endif	
		const char* kExistsName = kDatabaseName;
	#endif
#endif  

Then we open or create the database.

	if (dbConnect::fileExists(kExistsName)) {
		theDB.openConnection(kDatabaseName);
		People.deleteAll();
	}
	else {
		theDB.newConnection(kDatabaseName);
	}

We add new test data and sort by last name. We print the database to show its initial condition.

	People.AddTestData();
	People.setSortOrder(People.LastName);
	cout << "Listing records\n" << People << endl;

Now we declare the second database and its table. Note that we are using the same structure database as the first one.

	TEST_CONNECT    theDB2;	// won't use separate files
	dbPeople     People2;

We now must set the name of this table to people2 to stop confusion of the two different tables (the other database's table is named People).

	People2.setName("People2");  

We test for what platform we are running on and assign the second filename accordingly.

	#ifdef TESTING_DBASE
		#ifdef _Macintosh
			kExistsName =  ":ooftst24:People2.dbf";
			kDatabaseName = ":oofts24:";
		#else
			kExistsName =   "People2.dbf"
			kDatabaseName = "";
		#endif	  
	#else
		kDatabaseName = "ooftst24.db";
		kExistsName = kDatabaseName;
	#endif
	  

We now open the second file. note, the other file should still be open.

	if (dbConnect::fileExists(kExistsName)) {
		cout << "Opening second database\n";
		theDB2.openConnection(kDatabaseName);
		People2.deleteAll();
	}
	else {
		cout << "Creating second database\n";
		theDB2.newConnection(kDatabaseName);
	}

We add new test data, then sort by othernames (remember, the first database is sorted by Last names).

	People2.AddTestData();
	People.setSortOrder(People.OtherNames);

We then print out the second database

	cout << "Listing records in 2nd database\n" << People2 << endl;  

Now we print out the first database again to show that it is atill active.

	cout << "Proving 1st database is still active\n" << People << endl;  
	cout << "Test Completed" << endl;
	  
	return EXIT_SUCCESS;
}  

 

Feature index

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