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

OOFTST 40 - indexed vs non-indexed query

This sample uses generated data to create a reasonable sized database for testing with c-tree to compare indexed vs non-indexed recordNumber(query)  


#include "oofile.h"	// the general oofile library
#include "ooftest.h"

We start by declaring the class to use. As we specifically declare it as a child of dbTable, we must also declare OOFILE_METHODS(dbTest).

class dbTest : public dbTable {
	OOFILE_METHODS(dbTest)
	dbChar		IndexedChar;
	dbChar		PlainChar;
	dbUlong		IndexedLong;
	dbUlong		PlainLong;

We have two pairs of fields, one indexed the other not for the dbChars and the same for the dbLongs.

	dbTest() :
		IndexedChar(60, "IndexedChar", kIndexCompress),
		PlainChar(60, "Plain Char"),
		IndexedLong("Indexed Long", kIndexNoDups),
		PlainLong("Plain Long")
	{};  
};

Here we have our global variables, connecting up our ctree style table.

dbConnect_ctree theDB;
dbTest	Test;  
int main()
{  
	cout << "OOFILE Validation Suite - Test 40\n"
		 << "Simple test to demonstrate recordNumber(query) on various selections" << endl
		 << "using the inbuilt test data generator to generate a decent size DB" << endl << endl;

We open or create our database, generating many records for it.

	if (dbConnect::fileExists("ooftst40.db")) {
		theDB.openConnection("ooftst40.db");
	}
	else {
		theDB.newConnection("ooftst40.db");
		Test.generateTestData(10000, false);
	}

We have the option of printing out our database, but it is currently commented out as 10000 records is a lot!

//	cout << theDB << endl;  

We declare a variable to store a found record number.

	unsigned long recNo;

This searches the indexed long field, looking for record number 211. It is here to test a traditional search if we wish to, but is commented out for now.

//	Test.search(Test.IndexedLong==211);
//	cout << Test << endl;

The searches the indexed character field, looking for record number 211. Note that we are using the funciton recordNumber(query). This will return the actual record number fitting the description given. If the expression is likely to return more than one record, recordNumber() will return the first matching record found.

Testing: function recordNumber(<selection>)

	recNo = Test.recordNumber(Test.IndexedChar>="two-one-one");
	cout << "tried to get rec 211: recNo = "	<< recNo << endl << endl;
	cout << "done" << endl;  
	return EXIT_SUCCESS;
}        

 

Feature index

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