IDatasetDataArrayProvider.AttachArray

Syntax

AttachArray(Value: Array);

Parameters

Value. Array from which the data is loaded.

Description

The AttachArray method loads data from an array into a data source.

Comments

Dimension of array should correspond to quantity and the size of fields that are created in a data source.

Example

Executing the example requires that the repository contains a time series database with the FC identifier. The attribute referring to MDM dictionary with the COUNTRY identifier is created in the database. The dictionary is created in MDM repository with the RDS identifier. Additional integer attribute Code is created in MDM dictionary. The elements with following values of attributes are also created in MDM dictionary:

Element with a key 69 is created in dictionary of measure units. Annual frequency is used in the time series database.

Function OpenArrayProvider: IDatasetDataArrayProvider;
Var
    ArrayProvider: IDatasetDataArrayProvider;
    Arr: Array Of Variant;
    TField: ITableField;
    Row: Integer = 1000//Quantity of lines with data
Begin
    Arr := New Variant[Row, 5];
    Arr[00] := 1; Arr[01] := "Russia"; Arr[02] := 69; Arr[03] := "1997A1"; Arr[04] := 11.178;
    Arr [10: =1]  ;  Arr [11] : =  "Russia";  Arr [12: =69]  ;  Arr [13] : =  "1998A1";  Arr [14: =20]  .123;
    Arr [20: =1]  ;  Arr [21] := "Russia";  Arr [22: =69]  ;  Arr [23] : =  "1999A1";  Arr [24: =21]  .67;
    Arr [30: =1]  ;  Arr [31] := "Russia";  Arr [32: =69]  ;  Arr [33] : =  "2000A1";  Arr [34: =22]  .458;
    Arr [40: =1]  ;  Arr [41] := "Russia";  Arr [42: =69]  ;  Arr [43] : =  "2001A1";  Arr [44: =23]  .178;
    Arr [50: =2]  ;  Arr [51] := "USA";  Arr [52:=69]  ;  Arr [53] : =  "1997A1";  Arr [54:=22]  .167;
    Arr [60: =2]  ;  Arr [61] :=  "USA";  Arr [62:=69]  ;  Arr [63] :=  "1998A1";  Arr [64:=25]  .12;
    //Other data...
    ArrayProvider := New DatasetDataArrayProvider.Create;
    ArrayProvider.AddField("Code", DbDataType.Integer);
    ArrayProvider.AddField("Country", DbDataType.String);
    ArrayProvider.AddField("Units", DbDataType.Integer);
    ArrayProvider.AddField("Year", DbDataType.String);
    ArrayProvider.AddField("Value", DbDataType.Float);
    ArrayProvider.AttachArray(Arr);
    Return ArrayProvider;
End Function OpenArrayProvider;

Sub LoadDataFromArray;
Var
    Mb: IMetabase;
    RubDesc, NSIDesc: IMetabaseObjectDescriptor;
    CubeMetaLoader: ICubeMetaLoader;
    CrInfo: IMetabaseObjectCreateInfo;
    Obj: IMetabaseObject;
    ObjDesc: IMetabaseObjectDescriptor;
    Bindings: ICubeMetaLoaderBindings;
    Binding: ICubeMetaLoaderBinding;
Begin
    Mb := MetabaseClass.Active;
    RubDesc := Mb.ItemById("FC");
    NSIDesc := Mb.ItemById("RDS");

    // Object of import
    CrInfo := Mb.CreateCreateInfo;
    CrInfo.ClassId := MetabaseObjectClass.KE_CLASS_CUBEMETALOADER;
    CrInfo.Id := "CUBEMETALOADER";
    CrInfo.Permanent := False;
    CrInfo.Parent := RubDesc;
    ObjDesc := Mb.CreateObject(CrInfo);
    Obj := ObjDesc.Edit;
    CubeMetaLoader := Obj As ICubeMetaLoader;

    //Binding of attributes
    Bindings := CubeMetaLoader.Bindings;
    
    Binding := Bindings.Add;
    Binding.BindingType := CubeMetaLoaderBindingType.Attribute;
    Binding.Attribute := "COUNTRY";
    Binding.FieldType := CubeMetaLoaderFieldType.Index;
    Binding.Field := "0";
    Binding.CheckField := "1";
    Binding.Dimension := Mb.ItemByIdNamespace("COUNTRY", NsiDesc.Key).Bind As IDimensionModel;
    Binding.Index := "UNIQUEKEY";
    Binding.KeyAttribute := "KEY";
    Binding.NameAttribute := "NAME";
    
    Binding := Bindings.Add;
    Binding.BindingType := CubeMetaLoaderBindingType.Unit;
    Binding.FieldType := CubeMetaLoaderFieldType.Index;
    Binding.Field := "2";
    Binding.Dimension := Mb.ItemByIdNamespace("UNITS", NSIDesc.Key).Bind As IDimensionModel;
    Binding.Index := "PRIMARY_INDEX";
    Binding.KeyAttribute := "KEY";

    Binding := Bindings.Add;
    Binding.BindingType := CubeMetaLoaderBindingType.Calendar;
    Binding.CalendarOptions.Levels := DimCalendarLevelSet.Year;
    Binding.ByColumns := False;
    Binding.CalendarDateFormat := "$Year$A1";
    Binding.FieldType := CubeMetaLoaderFieldType.Index;
    Binding.Field := "3";
    
    Binding := Bindings.Add;
    Binding.BindingType := CubeMetaLoaderBindingType.Value;
    Binding.FieldType := CubeMetaLoaderFieldType.Index;
    Binding.Field := "4";

    Binding := Bindings.Add;
    Binding.BindingType := CubeMetaLoaderBindingType.Attribute;
    Binding.Attribute := "DL";
    Binding.FieldType := CubeMetaLoaderFieldType.ConstValue;
    Binding.FieldValue := DimCalendarLevel.Year;
    
    //Options of loader
    CubeMetaLoader.LoadType := CubeMetaLoaderLoadType.CreateAndUpdate;
    CubeMetaLoader.Rubricator := RubDesc.Bind As IRubricator;
    CubeMetaLoader.Data := OpenArrayProvider;
    CubeMetaLoader.LoadData;
End Sub LoadDataFromArray;

The OpenArrayProvider function implements the custom data source loading the data from array. At LoadDataFromArray procedure execution the loader of time series is created. Parameters of binding attributes are set up, and also the custom data source is specified as data source. After that data is loaded.

See also:

IDatasetDataArrayProvider