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

Declaring fields

Basic field information

The class dbPeople is the class that defines each record. It contains a number of different types of the basic fields: a character field, a numeric field, a text field, and a date field. This will allow us to test a wide range of the basic functions on this database.

Testing: definition of table class

DECLARE_CLASS(dbPeople)
	dbChar		LastName, OtherNames;
	dbLong		Salary;
	dbText		Description;
	dbDate		LastPaid;  

Declaring indices

Here, we check if we wish to test indices. If not, we must declare the fields without them.
Each field is given some important desciptive data, such as the field's size (odd sizes are provided in this database on purpose to catch out any alignment errors). They are given a name and an index type (where applicable). The indexed tests are donein ooftst01, the non-indexed tests in ooftst13.

Testing: passing required information to fields -> size, name and index

#ifndef demoNoIndexes
	dbPeople() :
				dbTable("People"),
				LastName(39, "Last Name", kIndexCompress),
				OtherNames(79, "Other Names", kIndexCompress),
				Salary("Salary", kIndexed),
				Description("Description"),
				LastPaid("Last Paid", kIndexed)
				{};
#else
	dbPeople() :
				dbTable("People"),
				LastName(39, "Last Name"),
				OtherNames(79, "Other Names"),
				Salary("Salary"),
				Description("Description"),
				LastPaid("Last Paid", kIndexed)
				{};
#endif
	  

These data entry procedures are provided below.

	void Add(const char *lname, const char *oname, const long salary);
	void AddTestData();
};  

Adding a single record

This procedure is to test how we can add a new record to the database during runtime. It simply takes in a parameter for each field and assigns that value to it. You will note that we must first create a new record using newRecord() then, after adding the data, we must save the record using saveRecord(). If we don't do this the record only goes into cache and so doesn't save to file. The cache is explored in ooftst06.

Note: the date field is initialised by finding the current date using the setDateToCurrentDate() function.

Testing: function newRecord()
Testing: function setDateToCurrentDate()
Testing: function saveRecord()

void dbPeople::Add(const char *lname, const char *oname, const long salary)
{
	newRecord();
	LastName = lname;
	OtherNames = oname;
	Salary = salary;
	LastPaid.setDateToCurrentDate();
	saveRecord();
} 

Adding many records at once

The procedure below serves to add several test records at once to the database. This provides a working base for us to explore with later tests. Adding the records consists of merely calling the above add() function repeatedly with different values for each of the fields.

We add zero to this numeric field so we can later test boundary conditions on a number of numeric operations. We add a very large character field to test for overflow errors.

void dbPeople::AddTestData()
{
	Add("Smith", "John", 0);  // specifically to test zero searches
	Description = "John is a plain sort of bloke, not the kind to stand-out in a crowd\n";
	Description += "and in fact you'd probably say he's the classic Mr Average. However ";
	Description += "he harbours secret dreams of being a brain surgeon and a bloke 'wot ";
	Description += "goes down the sewers in big rubber boots'\n";
	LastPaid -= 21;  // 3 weeks ago
	saveRecord();  

We add a record whose fields are not all given values

	Add("Dent", "Trissa", 5000);
	Description = "Trissa is married to Andy and mother of Tanith and Ryan";
	saveRecord();  

We add a somewhat standard record

	Add("Dent", "Andy", 25000);
	Description = "Andy has a Don Quixote complex but his Sancho ";
	Description += "Panza stops him tilting at too many software windmills";
	LastPaid -= 7;  // 1 week ago
	saveRecord();  

We add a record that has very few fields with values.

	Add("Taylor", "Ken", 75000);
} 

 

Feature index

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