Access functions
External files can be accessed in different ways.
- openExtern - Read or write external files via property handle
- loadData - Load data to external file
- storeData - Store data to database
Depending on the required functionality, a file schema and a data exchange schema should be provided.
The fileExtent() operation allows accessing an external file structure, which is defined by an explicit or implicit file schema. External files can be read or written, but depending on the file structure, there are several restrictions. Most external file formats do support appending data to the file, only.
External data sources can be accessed in OSI script files or access path via the File() operation, but also via property handle.
// OSI version (OQL operation)
{
VARIABLES
set< xml::Person > &extFile;
set<VOID> &extFile = File( Path='c:/temp/my_persons.xml', FileType='xml',
Definition='c:/temp/my_persons.def', Headline = false);
PROCESS
Option("Persons").assign('c:/temp/my_persons.xml'); // xml root element
extFile &= fileExtent( PathOption="Persons", FileType='xml',
Definition='xml::Person', Headline = false);
while ( extFile.next )
// ... do some processing;
}
// C++ property handle
Property extFile:
extFile.openExtern(os,"c:/temp/my_persons.xml",
"xml::Person",odaba::Read,false);
while ( extFile.next() )
// ... processing;
The fromFile() operation supports importing data from external files into a database. Importing files requires a (usually explicit) data exchange schema (extended file schema), which provides a mapping to database locations in addition to the structure definition of the import file.
Data can be imported in an OSI script, but also directly in an application program via ODABA API functions. Calling import() with the property handle requires a self-contained import file, i.e. the data exchange schema must be part of the import file. In order to import data for files with a separate exchange schema, an operation path can be used, which is more flexible, since it allows defining different locations for the exchange schema.
// Import external data to extent Persons
// OSI version (OQL operation)
Option("Persons").assign('c:/temp/my_persons.xml'); // xml root element
Persons.fromFile( PathOption="Persons", FileType='xml', Source="imp1",
Definition='xml::Person', Headline = false);
// C++ version
Property persons(os,"Persons",Update);
Property extPers:
extPers.openExtern(os,"c:/temp/my_persons.xml",
"xml::Person",odaba::Read);
extPers.storeData(person,"imp1");
The toFile() operation supports exporting data from a database to an external file format. As well as the fromFile() operation, toFile() requires a data exchange schema (Source parameter).
Data can be exported in an OSI script, but also directly in an application program via ODABA API functions. Calling export() with the property handle requires a self-contained export file, i.e. the data exchange schema must be part of the export file. In order to export data for files with a separate exchange schema, an operation path can be used, which is more flexible, since it allows defining different locations for the exchange schema.
// Import external data to extent Persons
// OSI version
Persons.toFile( Path='c:/temp/my_persons.xml', FileType='xml', Source='exp1',
Definition='xml::Person', Headline = false);
// C++ version: export Persons to an OIF file
Property persons(os,"Persons",Update);
Property extPers:
extPers.openExtern(os,"c:/temp/my_persons.xml",
"xml::Person",odaba::Update);
extPers.loadData(person,"exp1");