home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1994 A.D. Software. All Rights Reserved
-
- // OOFTEST7
-
- // this sample demonstrates searching and sorting by
- // different types of fields, and how to parameterize
- // calls, passing in table and field references
-
- // Simple stream I/O is used to interact with the user.
- #include "oofile.hpp"
-
-
- CLASS_TABLE(dbPeople)
- dbChar LastName, Othernames;
- dbLong Salary, SalaryNoDup;
- dbShort SalaryShort, SalaryShortNoDup;
- dbReal SalaryReal, SalaryRealNoDup;
- dbDate LastVisit, LastVisitNoDup;
- dbUshort ShortUnsigned;
- dbUlong LongUnsigned;
-
- dbPeople() :
- dbTable("People"),
- LastName(40, "Last Name", kIndexed),
- Othernames(80, "Other names", kIndexNoDups),
- Salary("Salary", kIndexed),
- SalaryNoDup("Salary NoDup", kIndexNoDups),
- SalaryShort("SalaryShort", kIndexed),
- SalaryShortNoDup("SalaryShortNoDup", kIndexNoDups),
- SalaryReal("SalaryReal", kIndexed),
- SalaryRealNoDup("SalaryRealNoDup", kIndexNoDups),
- LastVisit("LastVisit", kIndexed),
- LastVisitNoDup("LastVisitNoDup", kIndexNoDups),
- ShortUnsigned("ShortUnsigned", kIndexed),
- LongUnsigned("LongUnsigned", kIndexed)
- {};
-
- // my own data entry procedure
- void Add(const char *lname, const char *oname, const long salary, const char* visitDate);
- };
-
-
- void dbPeople::Add(const char *lname, const char *oname, const long salary, const char* visitDate)
- {
- newRecord();
- LastName = lname;
- Othernames = oname;
- Salary = salary;
- SalaryNoDup = salary;
- SalaryReal = salary;
- SalaryRealNoDup = salary;
- SalaryShort = salary;
- SalaryShortNoDup = salary;
- LastVisit = visitDate;
- LastVisitNoDup = visitDate;
-
- ShortUnsigned = salary*5; // numbers 10,000 to 49,999
- LongUnsigned = ULONG_MAX - salary;
-
- saveRecord();
- }
-
- void testField(dbPeople& searchTable, dbNumericField& searchBy);
- void testField(dbPeople& searchTable, dbChar& searchBy, const char* searchAgainst, const char* searchUpto, const char* searchAgainstPartial);
- void testField(dbPeople& searchTable, dbDate& searchBy, const char* searchAgainst, const char* searchUpto);
-
-
- int main()
- {
- cout << "OOFILE Validation Suite - Test 7\n"
- << "Simple test to demonstrate comparative searches" << endl
- << "using a database similar to ooftest2 but with lots of indexed fields" << endl;
-
- dbConnect_ctree theDB;
- dbPeople People;
-
- if (dbConnect::fileExists("ooftst07.db"))
- theDB.openConnection("ooftst07.db");
- else {
- theDB.newConnection("ooftst07.db");
- People.Add("Smith", "John", 2000, "23/11/94");
- People.Add("DENT", "Trissa", 9999, "22/11/94");
- People.Add("Denton", "Andy", 5000, "23-1-95");
- People.Add("Taylor", "Ken", 7500, "16,11,95");
- }
- // simple numeric test first, then use the parameterized versions
- People.selectAll();
-
- People.sortBy(People.LongUnsigned);
- cout << "Dumping database in key order by LongUnsigned (reverse of Salary)" << endl
- << People << endl << endl;
-
- cout << "Retrieving Andy Dent by ShortUnsigned == 25,000: " << endl;
- People[People.ShortUnsigned==25000];
- cout << People << endl << endl;
-
- cout << "Finding LongUnsigned between " << ULONG_MAX-5001 << " and " << ULONG_MAX << endl;
- People[People.LongUnsigned.between(ULONG_MAX-5001, ULONG_MAX)];
- cout << People << endl << endl;
-
-
- // test char searches
- testField(People, People.LastName, "Dent", "Denton", "DE");
- testField(People, People.Othernames, "Andy", "Kell", "J");
-
- // test numeric searches
- testField(People, People.SalaryShort);
- testField(People, People.SalaryShortNoDup);
- testField(People, People.Salary);
- testField(People, People.SalaryNoDup);
- testField(People, People.SalaryReal);
- testField(People, People.SalaryRealNoDup);
-
- // test date searches
- testField(People, People.LastVisit, "23/11/94", "23-1-95");
- testField(People, People.LastVisitNoDup, "23/11/94", "22-1-95");
-
- cout << "done" << endl;
-
- return EXIT_SUCCESS;
- }
-
- void testField(dbPeople& searchTable, dbNumericField& searchBy)
- {
- searchTable.selectAll();
-
- searchTable.sortBy(searchBy);
- cout << "Dumping database in key order by " << searchBy.fieldName() << endl
- << searchTable << endl << endl;
-
- cout << "Retrieving Andy Dent by " << searchBy.fieldName() << " = 5000: " << endl;
- searchTable[searchBy==5000];
- cout << searchTable << endl << endl;
-
- cout << "Retrieving John Smith by " << searchBy.fieldName() << " < 5000: " << endl;
- searchTable[searchBy<5000];
- cout << searchTable << endl << endl;
-
- cout << "Retrieving Smith & Andy Dent by " << searchBy.fieldName() << " <= 5000: " << endl;
- searchTable[searchBy<=5000];
- cout << searchTable << endl << endl;
-
- cout << "Retrieving Taylor & Trissa Dent by " << searchBy.fieldName() << " > 5000: " << endl;
- searchTable[searchBy>5000];
- cout << searchTable << endl << endl;
-
- cout << "Same search with >=5000 (should also get Andy Dent): " << endl;
- searchTable[searchBy>=5000];
- cout << searchTable << endl << endl;
-
- cout << "Finding " << searchBy.fieldName() << " between 5000 and 7500 " << endl;
- searchTable[searchBy.between(5000,7500)];
- cout << searchTable << endl << endl;
-
- cout << "Finding " << searchBy.fieldName() << " outside 5000 to 7500 " << endl;
- searchTable[sea