Class Mem - Program Example

Class Mem allows to load selected rows into memory. Data stored in memory (doubly linked list) can be retrieved by moving forward or backward. A query condition can be set to retrieve specified memory records.

C++ program below shows use of Mem class, where fetched rows (using array fetch) are loaded into Mem object.
A query criteria for memory records are set, and retrieved records are displayed in default Line format (memory records are fetched by one).


// mem_example.cc
#include <orac_lib.h>

  int main()
  {
          Connect c;
          try {
              Database d = c.OpenDatabase("demo", "demo");
              Table t = d.GetTable("products");
              Select s(t);
              s >> "prod_type" == 3; // set query criteria

              s.Array(10); // set array fetch to 10 rows

              Mem m(s); // create Mem object based on Select 

              while (s.Row())
                  s << m; // load records into memory

              m.Begin(); // go to start of doubly linked list
              m >> "prod_id" == 100004; // set memory query criteria

              while (m.Next())
                  cout << m; // display memory records in Line format

              d.Close();
          }
          catch ( OException& e)  {
              cerr << e.Show() << endl;
          }
          catch ( ...)  {
              cerr << " Error ..." << endl;
          }
          return 0;
  }