home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1995 A.D. Software. All Rights Reserved
-
- // OOFTEST12
-
- // This sample tests the compound indexes by creating a single table
- // and storing and retrieving indexed data.
-
- // Simple stream I/O is used to interact with the user.
-
- #include "oofile.hpp"
-
- CLASS_TABLE(dbPeople)
- dbChar LastName, OtherNames, DepartmentCode, ProjectCode;
- dbLong Salary;
- dbCompoundField CombinedNames, NameAndSalary, JobCode;
- dbUshort StartedYear;
-
-
- dbPeople() :
- dbTable("People"),
- LastName(39, "Last Name"),
- OtherNames(79, "Other Names", kIndexCompress),
- DepartmentCode(3, "Dept. Code"),
- ProjectCode(4, "Proj. Code"),
- Salary("Salary")
-
- {
- CombinedNames << LastName << OtherNames;
- CombinedNames.index(kIndexCompress); // order of these two lines is not significant
-
- NameAndSalary << LastName << Salary;
- NameAndSalary.index(kIndexCompress);
-
- JobCode << DepartmentCode << ProjectCode << StartedYear;
- JobCode.index(kIndexed);
- };
-
- // my own data entry procedures
- void Add(const char *lname, const char *oname, const long salary, const char *dept, const char *proj, const unsigned short year);
- };
-
- void dbPeople::Add(const char *lname, const char *oname, const long salary, const char *dept, const char *proj, const unsigned short year)
- {
- newRecord();
- LastName = lname;
- OtherNames = oname;
- Salary = salary;
- DepartmentCode = dept;
- ProjectCode = proj;
- StartedYear = year;
- saveRecord();
- }
-
-
-
- int main()
- {
- cout << "OOFILE Validation Suite - Test 12\n"
- << "Simple test to build compound indexes\n"
- << "and demonstrate sorting and searching by them and their components\n";
-
- dbConnect_ctree theDB;
- dbPeople People;
-
- if (dbConnect::fileExists("ooftst12.db"))
- theDB.openConnection("ooftst12.db");
- else {
- theDB.newConnection("ooftst12.db");
- People.Add("Smith", "John", 0, "Acc", "XXX", 1970); // specifically to test zero searches
- People.Add("DENT", "Trissa", 5000, "Acc", "Rec", 1985);
- People.Add("Dent", "Andy", 25000, "Acc", "XXX", 1992);
- People.Add("Dent", "Andrew", 40000, "MIS", "Boss", 1982); // should sort before Andy on CombinedNames but after on Salary
- People.Add("Denton", "Andrew", 39000, "Pur", "XXX", 1994);
- People.Add("Taylor", "Ken", 75000, "MIS", "Cntr", 1994);
- }
- People.sortBy(People.CombinedNames);
- cout << "Listing records by combined names\n" << People << endl;
-
- People.sortBy(People.OtherNames);
- cout << "Listing records in OtherNames order\n" << People << endl;
-
- People.search(People.LastName=="Dent"); // uses compound index
- cout << "Listing three Dent records: " << endl << People << endl;
-
- People.search(People.JobCode.startsWith("AccXXX")); // uses compound index in direct query
- cout << "Listing two AccXXX records: " << endl << People << endl;
-
- People[People.LastName=="Dent" && People.Salary==25000];
- cout << "Listing Andy Dent by compound key search: " << endl << People << endl;
-
- People[People.LastName=="Dent" && People.OtherNames=="Andrew"];
- cout << "Listing Andrew Dent by compound key search: " << endl << People << endl;
-
- // combinatorial search
- People[ (People.LastName=="Dent" && People.OtherNames=="Andrew") | People.OtherNames=="Andrew"];
- cout << "Listing Andrew Dent & Denton: " << endl << People << endl;
-
- cout << "Test Getting copy from read-only compound field" << endl;
- People.start();
- char* str = People.JobCode.copyAsChars();
- cout << "JobCode is: " << str << endl;
- delete[] str;
-
- cout << endl << "Test Completed" << endl;
-
- return EXIT_SUCCESS;
- }