Export and import schemas are child objects of a table MDM dictionary. The Fore and Fore.NET language can be used to set up:
Import from the following sources:
Microsoft OLEDB Provider for Oracle.
Microsoft OLEDB Provider for SQL Server.
Microsoft Excel (*.xls, *.xlsx).
Microsoft Access (*.mdb).
Microsoft XML (*.xml).
Text file (*.txt).
Clipboard.
Export to the following consumers:
Microsoft OLEDB Provider for Oracle.
Microsoft OLEDB Provider for SQL Server.
Microsoft Excel (*.xls, *.xlsx).
Microsoft Access (*.mdb).
Microsoft XML (*.xml).
Text file (*.txt).
Executing the example requires that the repository contains an MDM repository with the RDS identifier. This repository must contain a table MDM dictionary with the D_EXP_IMP identifier.
The example also requires a form that contains:
The ExpButton button for export.
The ImpButton button for import.
Add links to the Metabase, Rds, Dt system assemblies.
Clicking the ExpButton button exports elements of the D_EXP_IMP dictionary to the text file C:\Data_out.txt. Export options are defined as follows:
Only elements of the first dictionary level are exported.
The exported elements are sorted by value of the NAME attribute.
Clicking the ImpButton button imports data from the text file C:\Data_out.txt to the D_EXP_IMP dictionary.
Example execution order:
Click the ExpButton button.
Click the ImpButton button.
After executing the example, the D_EXP_IMP dictionary will contain only first level elements after executing export and import.
This procedure is an event handler for the ExpButton button:
In the Fore example for the OnClick event.
In the Fore.NET example for the Click event.
Sub ExpButtonOnClick(Sender: Object; Args: IMouseEventArgs);
Var
mb: IMetabase;
rdsKey: Integer;
dictObj: IMetabaseObject;
Dict: IRdsDictionary;
sExport: IMetaRdsExportSchema;
i: Integer;
dictAts: IRdsAttributes;
Attr: IRdsAttribute;
attrMap: IRdsExportSchemaAttribute;
dictSort: IRdsSortAttributes;
dictFilter: IRdsDictionaryFilterConditions;
Cond: IRdsDictionaryFilterCondition;
textCons: IDtTextConsumer;
dictInst: IRdsDictionaryInstance;
Begin
mb := MetabaseClass.Active;
// Get key of MDM repository
rdsKey := mb.GetObjectKeyById("RDS");
// Get table MDM dictionary
dictObj := mb.ItemByIdNamespace("D_EXP_IMP", rdsKey).Edit;
Dict := dictObj As IRdsDictionary;
// Create a new export schema
sExport := Dict.ExportSchemas.Add As IMetaRdsExportSchema;
// Bind dictionary attributes to consumer fields
dictAts := Dict.Attributes;
For i := 0 To dictAts.Count - 1 Do
Attr := dictAts.Item(i);
attrMap := sExport.AddMapping;
attrMap.Attribute := Attr;
attrMap.FieldName := Attr.Id;
End For;
// Specify that consumer must cleared before export
sExport.ClearBeforeExport := True;
// Set sorting by the NAME attribute
dictSort := sExport.SortAttributes;
Attr := dictAts.FindById("NAME");
dictSort.Add(Attr, True);
// Add a filter: only first level elements are exported
dictFilter := sExport.Filter;
Attr := dictAts.FindById("PARENT_KEY");
Cond := dictFilter.Add(Attr);
Cond.Value := Null;
Cond.Operation := RdsConditionOperation.Equal;
// Set up data consumer: text file
textCons := New DtTextConsumer.Create;
textCons.File := "c:\Data_out.txt";
textCons.WriteHeader := True;
textCons.RowDelimiter := #13 + #10;
textCons.DelimitedColumnDelimiter := #9;
textCons.DelimitedTextQualifier := "'";
sExport.Consumer := textCons;
// Save dictionary
dictObj.Save;
// Execute export
dictInst := dictObj.Open(Null) As IRdsDictionaryInstance;
dictInst.ExportData(sExport);
End Sub ExpButtonOnClick;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Dt;
Imports Prognoz.Platform.Interop.Rds;
…
Private Sub ExpButton_Click(sender: System.Object; e: System.EventArgs);
Var
mb: IMetabase;
rdsKey: uinteger;
dictObj: IMetabaseObject;
Dict: IRdsDictionary;
sExport: IMetaRdsExportSchema;
i: Integer;
dictAts: IRdsAttributes;
Attr: IRdsAttribute;
attrMap: IRdsExportSchemaAttribute;
dictSort: IRdsSortAttributes;
dictFilter: IRdsDictionaryFilterConditions;
Cond: IRdsDictionaryFilterCondition;
textCons: IDtTextConsumer;
dictInst: IRdsDictionaryInstance;
Begin
mb := self.Metabase;
// Get key of MDM repository
rdsKey := mb.GetObjectKeyById("RDS_70");
// Get table MDM dictionary
dictObj := mb.ItemByIdNamespace["D_EXP_IMP", rdsKey].Edit();
Dict := dictObj As IRdsDictionary;
// Create a new export schema
sExport := Dict.ExportSchemas.Add() As IMetaRdsExportSchema;
// Bind dictionary attributes to consumer fields
dictAts := Dict.Attributes;
For i := 0 To dictAts.Count - 1 Do
Attr := dictAts.Item[i];
attrMap := sExport.AddMapping();
attrMap.Attribute := Attr;
attrMap.FieldName := Attr.Id;
End For;
// Specify that consumer must cleared before export
sExport.ClearBeforeExport := True;
// Set sorting by the NAME attribute
dictSort := sExport.SortAttributes;
Attr := dictAts.FindById("NAME");
dictSort.Add(Attr, True);
// Add a filter: only first level elements are exported
dictFilter := sExport.Filter;
Attr := dictAts.FindById("PARENT_KEY");
Cond := dictFilter.Add(Attr);
Cond.Value := Null;
Cond.Operation := RdsConditionOperation.rcoEqual;
// Set up data consumer: text file
textCons := New DtTextConsumer.Create();
textCons.File := "c:\Data_out.txt";
textCons.WriteHeader := True;
textCons.DelimitedTextQualifier := "'";
sExport.Consumer := textCons;
// Save dictionary
dictObj.Save();
// Execute export
dictInst := dictObj.Open(Null) As IRdsDictionaryInstance;
dictInst.ExportData(sExport);
End Sub;
After executing the procedure, the text file C:\Data_out.txt contains first level elements of the D_EXP_IMP dictionary sorted by value of the NAME attribute.
This procedure is an event handler for the ImpButton button:
In the Fore example for the OnClick event.
In the Fore.NET example for the Click event.
Sub ImpButtonOnClick(Sender: Object; Args: IMouseEventArgs);
Var
mb: IMetabase;
rdsKey: Integer;
dictObj: IMetabaseObject;
Dict: IRdsDictionary;
sImport: IMetaRdsImportSchema;
i: Integer;
dictAts: IRdsAttributes;
Attr: IRdsAttribute;
attrMap: IRdsImportSchemaAttribute;
textProv: IDtTextProvider;
dictInst: IRdsDictionaryInstance;
Begin
mb := MetabaseClass.Active;
// Get key of MDM repository
rdsKey := mb.GetObjectKeyById("RDS");
// Get table MDM dictionary
dictObj := mb.ItemByIdNamespace("D_EXP_IMP", rdsKey).Edit;
Dict := dictObj As IRdsDictionary;
// Create a new import schema
sImport := Dict.ImportSchemas.Add As IMetaRdsImportSchema;
// Bind dictionary attributes to provider fields
dictAts := Dict.Attributes;
For i := 0 To dictAts.Count - 1 Do
Attr := dictAts.Item(i);
attrMap := sImport.Mappings(Attr);
attrMap.Attribute := Attr;
attrMap.FieldName := Attr.Id;
End For;
// Specify import mode
sImport.Mode := UpdateLoadMode.Replace;
// Set up data provider: text file
textProv := New DtTextProvider.Create;
textProv.File := "c:\Data_out.txt";
textProv.RangeHasHeader := True;
textProv.HeaderRow := 0;
textProv.RowDelimiter := #13 + #10;
textProv.DelimitedColumnDelimiter := #9;
textProv.DelimitedTextQualifier := "'";
sImport.Source := textProv;
// Save dictionary
dictObj.Save;
// Execute import
dictInst := dictObj.Open(Null) As IRdsDictionaryInstance;
dictInst.ImportData(sImport);
End Sub ImpButtonOnClick;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Dt;
Imports Prognoz.Platform.Interop.Rds;
…
Private Sub ImpButton_Click(sender: System.Object; e: System.EventArgs);
Var
mb: IMetabase;
rdsKey: uinteger;
dictObj: IMetabaseObject;
Dict: IRdsDictionary;
sImport: IMetaRdsImportSchema;
i: Integer;
dictAts: IRdsAttributes;
Attr: IRdsAttribute;
attrMap: IRdsImportSchemaAttribute;
textProv: IDtTextProvider;
dictInst: IRdsDictionaryInstance;
Begin
mb := self.Metabase;
// Get key of MDM repository
rdsKey := mb.GetObjectKeyById("RDS_70");
// Get table MDM dictionary
dictObj := mb.ItemByIdNamespace["D_EXP_IMP", rdsKey].Edit();
Dict := dictObj As IRdsDictionary;
// Create a new import schema
sImport := Dict.ImportSchemas.Add() As IMetaRdsImportSchema;
// Bind dictionary attributes to provider fields
dictAts := Dict.Attributes;
For i := 0 To dictAts.Count - 1 Do
Attr := dictAts.Item[i];
attrMap := sImport.Mappings[Attr];
attrMap.Attribute := Attr;
attrMap.FieldName := Attr.Id;
End For;
// Specify import mode
sImport.Mode := UpdateLoadMode.ulmReplace;
// Set up data provider: text file
textProv := New DtTextProvider.Create();
textProv.File := "c:\Data_out.txt";
textProv.RangeHasHeader := True;
textProv.HeaderRow := 0;
//textProv.RowDelimiter := "\r" + "\n";
//textProv.DelimitedColumnDelimiter := "\t";
textProv.DelimitedTextQualifier := "'";
sImport.Source := textProv;
// Save dictionary
dictObj.Save();
// Execute import
dictInst := dictObj.Open(Null) As IRdsDictionaryInstance;
dictInst.ImportData(sImport);
End Sub;
After executing the example data stored in the text file C:\Data_out.txt is imported to the D_EXP_IMP dictionary.
See also: