OOFILE | Downloads | Purchasing | Press | Services | Company Information | Soapbox | References | F.A.Q. | HOME |
This sample tests the database backend by creating a single table and storing and retrieving NON-indexed data.
#include "oofile.h" // the general oofile library #define demoNoIndexes // just fiddles with ooftst01.h definitions #include "ooftst01.h" // the declarations for the database classes we will be using in this test.
int main()
{
cout << "OOFILE Validation Suite - Test 13\n"
<< "Simple test to store some data and retrieve it\n"
<< "in a single-table database, with no relations and no indices !\n";
We first declare our database and table.
dbConnect_ctree theDB; dbPeople People;
Note: although using the same schema (Nearly) we can't use the files from ooftst01 & ooftst14 as they have indexes on several fields. This means we must create our own file (or open and clear the contents of the old one).
if (dbConnect::fileExists("ooftst13.db"))
theDB.openConnection("ooftst13.db");
else {
theDB.newConnection("ooftst13.db");
People.AddTestData();
}
First a simple test to try and retrieve a selection of records whose last name is Smith.
Testing: non-indexed selection using character field.
cout << "Retrieving Smith: " << People[People.LastName=="Smith"].LastName << endl;
We'll create a couple of dbViews which we will use over and over, unlike ooftst01 where we create the dbView temporarily in the cout.
dbView justNames(People); justNames << People.LastName << People.OtherNames; dbView NamesAndSalaries = justNames; NamesAndSalaries << People.Salary;
Now we use search() to test for retrieval of records with a lastName of Dent.
Testing: non-indexed search() testing string equality
People.search(People.LastName=="Dent"); cout << "Listing two Dent records: " << endl << justNames << endl;
And now we'll be testing comparisons to strings, I won't decrivbe each of them, the testing describes them adequately.
Testing: non-indexed search() testing string less than <GivenString>
People.search(People.OtherNames<"M"); cout << "Listing records with other names < M: " << endl << justNames << endl;
Testing: non-indexed search() testing string greater than or equal to <GivenString>
People.search(People.LastName>="Smith"); cout << "Listing records with surnames >= Smith: " << endl << justNames << endl;
Now, we'll do some numeric tests of a similar type
Testing: non-indexed search() testing numeric between()
People.search(People.Salary.between(5000,25000)); cout << "Listing records with salaries between 5000 and 25000 inclusive: " << endl << NamesAndSalaries << endl;
Testing: non-indexed search() testing numeric greater than <GivenNumber>
People.search(People.Salary>10000); cout << "Listing records with salaries greater than 10000: " << endl << NamesAndSalaries << endl;
We now use a previous selection and search it, refining our original search. In this way, we can combine two searches. This requires us to use the function searchSelection()
Testing: function searchSelection on non-indexed field
People.searchSelection(People.LastName=="Dent"); cout << "Refining this selection to the single Dent record: " << endl << justNames << endl;
cout << "Test Completed" << endl;
return EXIT_SUCCESS; }
(c) Copyright A.D. Software 1994-2000 (All Rights Reserved).
Last Updated: 9th September 2001