company logo

Accessing databases with different dictionaries

When accessing databases referring to different dictionaries, the object model of the external database is not known to the expression. Instead of referring to data type properties, generic property access must be used instead.

In order to access data in a database, which dictionary is unknown in the scope of the expression, VOID or set<VOID> variables can be defined for extents in the external database (see main() function in the example below). Practically, it does not matter whether variables are defined as VOID or set<VOID>, but it is a matter of good style defining collection variables as set<VOID> always.

Since data structure of the externally referenced data is not known to the context of the expression, properties must be accessed by calling, the property() or value() function (see function ImportExtern() in the example below).

Complex variables accessed in the external database should be defined as VOID (or set<VOID>). Variables of elementary type should be defined with their type. In the last case, the defined type must correspond exactly to the type defined in the external database. Otherwise a type conflict is signaled.

DATASOURCE=SAMPLEDAT;

collection void Person::ImportExtern(set<VOID> &extern_persons) {

VARIABLES

set<VOID>      &adresses           = extern_persons.property('Adresses');

STRING         &ext_name           = extern_persons.value('name');

STRING         &ext_pid            = extern_persons.value('pid');

PROCESS

  while ( extern_persons.next ) {

    insert(ext_pid);  // create new person object with pid from external person object

    address.city = adresses(0).value('city'); // get city from first address

    name = ext_name;

  }

};

void main() {

VARIABLES

Dictionary    dict;

Database      db;

set<VOID>     extern_persons;   // source for importing persons

PROCESS

dict.open("e:/temp/extern.dev");

db.open(dict,"e:/temp/extern.dat",AccessModes::Read);

extern_persons.open(db,"Person",AccessModes::Read);

Person::Persons.ImportExtern(extern_persons); // import person data

extern_persons.close();

db.close();

dict.close();

};