Export and import schemes are child objects of a table MDM dictionary. The Fore 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 Export button with the ExpButton identifier.
The Import button with the ImpButton identifier.
Add links to the Metabase, Rds, and Dt system assemblies.
Clicking the Export 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 Import button imports data from the text file C:\Data_out.txt to the D_EXP_IMP dictionary.
Example execution order:
Click the Export button.
Click the Import button.
Result: after running export an import procedure the D_EXP_IMP dictionary will contain only first level elements.
This procedure is a handler of the OnClick event for the ExpButton button.
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 the 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 scheme
sExport := Dict.ExportSchemas.Add As IMetaRdsExportSchema;
// Bind dictionary attributes to the 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;
// Indicate, that the consumer must be 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 the dictionary
dictObj.Save;
// Export execution
dictInst := dictObj.Open(Null) As IRdsDictionaryInstance;
dictInst.ExportData(sExport);
End Sub ExpButtonOnClick;
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 a handler of the OnClick event for the ImpButton button.
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 the 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 scheme
sImport := Dict.ImportSchemas.Add As IMetaRdsImportSchema;
// Bind dictionary attributes to the 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 the dictionary
dictObj.Save;
// Run import
dictInst := dictObj.Open(Null) As IRdsDictionaryInstance;
dictInst.ImportData(sImport);
End Sub ImpButtonOnClick;
After executing the example data stored in the text file C:\Data_out.txt is imported to the D_EXP_IMP dictionary.
See also: