Working with recordset
Previous  Index  Next

OraRecordset class covers most of data access related tasks in your applications. Its main purpose is to hold results after execution of any SQL or PL/SQL statements. If the statement, such as SELECT, returns a set of rows OraRecordset can receive and store them. This class provides the way to access to any record in resultset and to any of its fields.

OraRecordset object is constructed implicitly when OraRecordset.execute method is called. You may use a OraRecordset pointer to pass it to the execute method and get an instance of this class. For example:

  OraConnection connection("scott/tiger@ora");
  OraRecordset* record;
  OraCommand cmd(connection);
  . . .
  cmd.execute(&record);

Use a field member function to get access to the fields of current record. You have to provide either the field name or its index. For example, you can write this code to get the value of DNAME field:

  name = cmd.field("DNAME").getString();

or to get integer value of the first field:

  num = cmd.field(1).getInt();

OraRecordset has many functions to navigate through records such as next, prev, first, last and move. You should use isEOF, isBOF and recordNo member functions to check current record position.
For example, to process records from the first to the last you can write this loop:

  cmd.first();
  while (!cmd.isEOF()) {
    . . .
    cmd.next();
  }

By default OraRecordset stores in memory only the current record and prevents us from returning to the previous records. To circumvent this default behaviour we may instruct OraRecordset object to allocate buffers for all fetched records. Doing so OCL effectively provides local cache which may apart from allowing backward navigation also improve performance and reduce network traffic. Turn on cache as follows:

  cmd.setCached(true);

To release all allocated resources call close member function.

  cmd.close();

See Also

OraRecordset


OCL | Using OCL | Index