company logo

Reading data from database

Reading data automatically happens, when selecting an instance in a property (handle). Thus, one may read instances by calling next() or previous() but also by requesting a specific instance calling get().

Instances are read automatically, when opening a property handle for an access path referring to exact one instance (see "Advanced property handles").

After an instance has been selected, one may access instance data by calling appropriate Value functions or get the serialized instance by calling the toInstance() function. toInstance() returns serialized data for the selected instance in OIF format. This is good for data exchange or for passing data to other systems, but it is difficult to access in detail, since it requires complex syntax analysis.

More appropriate for accessing data from a instance selected in a property handle is provided by calling different value functions.

From within OSI expressions instance properties can be accessed directly by name. Nevertheless, also OSI expressions sometimes require generic property access (e.g. when combining data from different databases in an expression).

// C++

  Property     persons(database,"Person::Persons",Read);

  while ( persons.next(true) ) {

    printf("Persons ID: %s\n",persons.value("pid").toString());

    printf("Persons data: %s\n",persons.value().toInstance());

  }

Serialize instance data

Usually, serializing data is not necessary, since all property handle functions refer to selected instances in property handles, which is more comfortable than dealing with serialized object instances. Moreover, serializing usually means loss of data or loss of performance.

Thus, serialization is more a mean of simplified data exchange, which also can be done more comfortable calling the export() function.

Nevertheless, one may extract instance data from a selected instance by calling toInstance(). The instance passed to the function usually contains the string type for the data (ESDF, XML or OIF). When no string type has been set by the application, OIF is assumed.

String SerializedData ( Property &person ) {

  Instance      result;

  result.stringType(OIFString);

  if ( person.selected() )

    person.value().toInstance(result);

  return result;

}