home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / OOFILE / Buildable, limited OOFILE / samples / ooftst10.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-27  |  1.5 KB  |  61 lines  |  [TEXT/CWIE]

  1. // Copyright 1994 A.D. Software. All Rights Reserved
  2.  
  3. // OOFTEST10
  4.  
  5. // this sample uses stream operators to set records
  6.  
  7. // Simple stream I/O is used to interact with the user.
  8. #include "oofile.hpp"
  9.  
  10.  
  11. CLASS_TABLE(dbPeople)
  12.     dbChar        LastName, OtherNames;
  13. //    dbLong        Salary;
  14. //    dbText        Description;
  15.  
  16.     dbPeople() :
  17.                 dbTable("People"),
  18.                 LastName(39, "Last Name", kIndexed),
  19.                 OtherNames(79, "Other Names", kIndexed)  //,
  20. //                Salary("Salary", kIndexed),
  21. //                Description("Description")
  22.                 {};
  23. };
  24.  
  25. dbConnect_ctree theDB;
  26. dbPeople    People;
  27.  
  28. int main()
  29. {
  30.     cout << "OOFILE Validation Suite - Test 10\n"
  31.          << "Simple test to demonstrate creating records" << endl
  32.          << "using input streams" << endl;
  33.          
  34.     if (dbConnect::fileExists("ooftst10.db")) {
  35.         theDB.openConnection("ooftst10.db");
  36.         People.deleteAll();
  37.     }
  38.     else {
  39.         theDB.newConnection("ooftst10.db");
  40.     }
  41.  
  42. // fake setting up an input stream, with known quantities.
  43. // in normal life, we'd have an input stream straight from a file
  44. // but we want predictable input so we can use the output for regression testing
  45.  
  46.     ostrstream oss;
  47.     oss << "Dent" << '\t' << "Andy" << endl;
  48.     oss << "Dent" << '\t' << "Trissa" << endl;
  49.     
  50.     istream is(oss.rdbuf());  // normally something like ifstream is("filename");
  51.  
  52.     cout << "Entire database  - should be empty" << endl << theDB << endl;
  53.     
  54.     is >> People;  
  55.     
  56.     cout << "Entire database  - after importing from the stream" << endl << theDB << endl;
  57.     
  58.     cout << "done" << endl;
  59.  
  60.     return EXIT_SUCCESS;
  61. }