ITableCreator.Execute

Syntax

Execute: ITable;

Description

The Execute method creates a table and loads data to it.

Comments

A table is created in the repository when executing the method according to the information specified in the ITableCreator.ObjectCreateInfo property. The corresponding physical table is created in the database specified in the ITableCreator.Database property. The table structure is determined automatically and corresponds to the structure of the data source specified in the ITableCreator.Source property. The data from the data source is loaded to the table after the table creation.

Example

Executing the example requires that the repository contains a database with the DB identifier and a folder with the FTable identifier. The file system must contain the C:\result.txt file with data.

The example uses the Converter custom class. Class implementation is given in the example for IValueConverter.Convert.

Add links to the Cubes, Dal, Db, Dt, MatFin, Metabase system assemblies.

Fragment of the C:\result.txt file

Sub UserProc;
Var
    MB: IMetabase;
    Db: IDatabase;
    CrInfo: IMetabaseObjectCreateInfo;
    TextProvider: IDtTextProvider;
    Fields: IDtFieldDefinitions;
    TCreator: ITableCreator;
    Conv: Converter;
    TmpTable: ITable;

Begin
    // Get the current repository
    MB := MetabaseClass.Active;
    // Create a data source for table
    TextProvider := New DtTextProvider.Create;
    // Specify file, from which data will be loaded
    TextProvider.File := "c:\result.txt";
    // Specify string with headers
    TextProvider.HeaderRow := 1;
    // Specify column delimiter
    TextProvider.DelimitedColumnDelimiter := ";";
    // Specify date format in file
    TextProvider.StringDataFormat.DateFormat := "YYYY";
    // Get fields from source file
    Fields := TextProvider.Fields;
    // Specify field data type
    Fields.Item(0).DataType := DbDataType.String;
    Fields.Item(1).DataType := DbDataType.String;
    Fields.Item(2).DataType := DbDataType.String;
    Fields.Item(3).DataType := DbDataType.DateTime;
    Fields.Item(4).DataType := DbDataType.Float;
    // Create an object used for creating fields
    TCreator := New TableCreator.Create;
    // Specify data source for created table
    TCreator.Source := TextProvider;
    // Create information about created table
    CrInfo := MB.CreateCreateInfo;
    // Specify folder, in which a table will be created
    CrInfo.Parent := MB.ItemById("FTable");
    // Specify information about created table
    TCreator.ObjectCreateInfo := CrInfo;

    // Get database
    Db := MB.ItemById("DB").Bind As IDatabase;
    
// Specify database, in which table data will be stored
    TCreator.Database := Db;
    
// Specify string in data source,
    // starting with which data will be loaded
    TCreator.DataRow := 0;
    
// Specify the number of rows that should be loaded
    TCreator.RowCount := 100;
    
// Specify that empty rows will be skipped
    TCreator.SkipEmptyRows := True;
    
// Create a value converter
    Conv := New Converter.Create;
    
// Specify that values of the Value field should be converted
    TCreator.AddConverter("Value", Conv);
    
// Create a table and load data to it
    TmpTable := TCreator.Execute;
    
// Save created table
    (TmpTable As IMetabaseObject).Save;
End Sub UserProc;

After executing the example a table is created in the FTable folder. Table structure is formed automatically based on data from the C:\result.txt file. The first 100 data rows are loaded to the table, empty rows are skipped. Values loaded from the Value value will be rounded.

See also:

ITableCreator