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. 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 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 the file, from which data will be loaded
    TextProvider.File := "c:\result.txt";
    // Specify the row with headers
    TextProvider.HeaderRow := 1;
    // Specify the character that delimits fields
    TextProvider.DelimitedColumnDelimiter := ";";
    // Set date format in file
    TextProvider.StringDataFormat.DateFormat := "YYYY";

    // Get fields from source file
    Fields := TextProvider.Fields;
    // Specify data type of fields
    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 that is used to create fields
    TCreator := New TableCreator.Create;
    // Specify data source for created table
    TCreator.Source := TextProvider;
    // Create information about created table
    CrInfo := MB.CreateCreateInfo;
    // Specify the 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 the database, which will store data table data
    TCreator.Database := Db;
    // Specify the row in data source, starting with which data will be loaded
    TCreator.DataRow := 0;
    // Specify the number  of rows to 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 the 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