ITableCreator.Execute

Syntax

Execute: ITable;

Execute(): Prognoz.Platform.Interop.Db.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 ObjectCreateInfo property. The corresponding physical table is created in the database specified in the Database property. The table structure is determined automatically and corresponds to the structure of the data source specified in the 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, Metabase, MathFin system assemblies.

Fragment of the C:\result.txt file

<font color="#008080">Sub</font><font color="#000000">&nbsp;UserProc;<br /> </font><font color="#008080">Var</font><font color="#000000"><br /> &nbsp;&nbsp;&nbsp;&nbsp;MB:&nbsp;IMetabase;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Db:&nbsp;IDatabase;<br /> &nbsp;&nbsp;&nbsp;&nbsp;CrInfo:&nbsp;IMetabaseObjectCreateInfo;<br /> &nbsp;&nbsp;&nbsp;&nbsp;TextProvider:&nbsp;IDtTextProvider;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Fields:&nbsp;IDtFieldDefinitions;<br /> &nbsp;&nbsp;&nbsp;&nbsp;TCreator:&nbsp;ITableCreator;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Conv:&nbsp;Converter;<br /> &nbsp;&nbsp;&nbsp;&nbsp;TmpTable:&nbsp;ITable;<br /> </font><font color="#008080">Begin</font><font color="#000000"><br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Get&nbsp;current&nbsp;repository<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;MB&nbsp;:=&nbsp;MetabaseClass.Active;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Create&nbsp;data&nbsp;source&nbsp;for&nbsp;table<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TextProvider&nbsp;:=&nbsp;</font><font color="#008080">New</font><font color="#000000">&nbsp;DtTextProvider.Create;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Set&nbsp;file&nbsp;from&nbsp;which&nbsp;data&nbsp;will be&nbsp;loaded<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TextProvider.File&nbsp;:=&nbsp;</font><font color="#800000">&quot;c:\result.txt&quot;</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Set&nbsp;row&nbsp;with&nbsp;headers<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TextProvider.HeaderRow&nbsp;:=&nbsp;</font><font color="#008000">1</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;the character&nbsp;dividing&nbsp;fields<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TextProvider.DelimitedColumnDelimiter&nbsp;:=&nbsp;</font><font color="#800000">&quot;;&quot;</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Set&nbsp;date&nbsp;format&nbsp;in&nbsp;file<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TextProvider.StringDataFormat.DateFormat&nbsp;:=&nbsp;</font><font color="#800000">&quot;YYYY&quot;</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Get&nbsp;fields&nbsp;from&nbsp;source file<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;Fields&nbsp;:=&nbsp;TextProvider.Fields;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Set&nbsp;data&nbsp;type&nbsp;of fields<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;Fields.Item(</font><font color="#008000">0</font><font color="#000000">).DataType&nbsp;:=&nbsp;DbDataType.String;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Fields.Item(</font><font color="#008000">1</font><font color="#000000">).DataType&nbsp;:=&nbsp;DbDataType.String;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Fields.Item(</font><font color="#008000">2</font><font color="#000000">).DataType&nbsp;:=&nbsp;DbDataType.String;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Fields.Item(</font><font color="#008000">3</font><font color="#000000">).DataType&nbsp;:=&nbsp;DbDataType.DateTime;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Fields.Item(</font><font color="#008000">4</font><font color="#000000">).DataType&nbsp;:=&nbsp;DbDataType.Float;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Create&nbsp;an object&nbsp;that i used for&nbsp;field&nbsp;creation<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator&nbsp;:=&nbsp;</font><font color="#008080">New</font><font color="#000000">&nbsp;TableCreator.Create;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Set&nbsp;data&nbsp;source&nbsp;for&nbsp;created&nbsp;table<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.Source&nbsp;:=&nbsp;TextProvider;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Create&nbsp;information&nbsp;about&nbsp;created&nbsp;table<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;CrInfo&nbsp;:=&nbsp;MB.CreateCreateInfo;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Determine&nbsp;folder&nbsp;where&nbsp;the&nbsp;table&nbsp;will be&nbsp;created<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;CrInfo.Parent&nbsp;:=&nbsp;MB.ItemById(</font><font color="#800000">&quot;FTable&quot;</font><font color="#000000">);<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Set&nbsp;information&nbsp;about&nbsp;created&nbsp;table<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.ObjectCreateInfo&nbsp;:=&nbsp;CrInfo;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Get&nbsp;database<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;Db&nbsp;:=&nbsp;MB.ItemById(</font><font color="#800000">&quot;DB&quot;</font><font color="#000000">).Bind&nbsp;</font><font color="#008080">As</font><font color="#000000">&nbsp;IDatabase;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Set&nbsp;database&nbsp;where&nbsp;table&nbsp;data&nbsp;will be&nbsp;stored<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.Database&nbsp;:=&nbsp;Db;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Determine&nbsp;row&nbsp;in&nbsp;data&nbsp;source<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;starting&nbsp;from&nbsp;which&nbsp;data&nbsp;will be&nbsp;loaded<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.DataRow&nbsp;:=&nbsp;</font><font color="#008000">0</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Determine&nbsp;number&nbsp;of rows&nbsp;to be&nbsp;loaded<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.RowCount&nbsp;:=&nbsp;</font><font color="#008000">100</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Determine&nbsp;that&nbsp;empty&nbsp;rows&nbsp;will be&nbsp;skipped<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.SkipEmptyRows&nbsp;:=&nbsp;</font><font color="#008080">True</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Create&nbsp;a value&nbsp;converter<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;Conv&nbsp;:=&nbsp;</font><font color="#008080">New</font><font color="#000000">&nbsp;Converter.Create;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Determine&nbsp;that&nbsp;values&nbsp;of the&nbsp;Value&nbsp;filed must&nbsp;be&nbsp;converted<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.AddConverter(</font><font color="#800000">&quot;Value&quot;</font><font color="#000000">,&nbsp;Conv);<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Create&nbsp;a table&nbsp;and&nbsp;load&nbsp;data&nbsp;to&nbsp;it<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TmpTable&nbsp;:=&nbsp;TCreator.Execute;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Save&nbsp;created&nbsp;table<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;(TmpTable&nbsp;</font><font color="#008080">As</font><font color="#000000">&nbsp;IMetabaseObject).Save;<br /> </font><font color="#008080">End</font><font color="#000000">&nbsp;</font><font color="#008080">Sub</font><font color="#000000">&nbsp;UserProc;</font>

Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Db;
Imports Prognoz.Platform.Interop.Dt;
Imports Prognoz.Platform.Interop.Metabase;

<font color="#008080">Public</font><font color="#000000">&nbsp;</font><font color="#008080">Shared</font><font color="#000000">&nbsp;</font><font color="#008080">Sub</font><font color="#000000">&nbsp;Main(Params:&nbsp;StartParams);<br /> </font><font color="#008080">Var</font><font color="#000000"><br /> &nbsp;&nbsp;&nbsp;&nbsp;MB:&nbsp;IMetabase;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Db:&nbsp;IDatabase;<br /> &nbsp;&nbsp;&nbsp;&nbsp;CrInfo:&nbsp;IMetabaseObjectCreateInfo;<br /> &nbsp;&nbsp;&nbsp;&nbsp;TextProvider:&nbsp;IDtTextProvider;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Fields:&nbsp;IDtFieldDefinitions;<br /> &nbsp;&nbsp;&nbsp;&nbsp;TCreator:&nbsp;ITableCreator;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Conv:&nbsp;Converter;<br /> &nbsp;&nbsp;&nbsp;&nbsp;TmpTable:&nbsp;ITable;<br /> </font><font color="#008080">Begin</font><font color="#000000"><br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Get&nbsp;current&nbsp;repository<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;MB&nbsp;:=&nbsp;Params.Metabase;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Create&nbsp;data&nbsp;source&nbsp;for&nbsp;table<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TextProvider&nbsp;:=&nbsp;</font><font color="#008080">New</font><font color="#000000">&nbsp;DtTextProvider.Create();<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;file&nbsp;from&nbsp;which&nbsp;data&nbsp;will be&nbsp;loaded<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TextProvider.File&nbsp;:=&nbsp;</font><font color="#800000">&quot;c:\result.txt&quot;</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;string&nbsp;with&nbsp;headers<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TextProvider.HeaderRow&nbsp;:=&nbsp;</font><font color="#008000">1</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;a character&nbsp;deviding&nbsp;fields<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TextProvider.DelimitedColumnDelimiter&nbsp;:=&nbsp;</font><font color="#800000">&quot;;&quot;</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Set&nbsp;date&nbsp;format&nbsp;in&nbsp;file<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TextProvider.StringDataFormat.DateFormat&nbsp;:=&nbsp;</font><font color="#800000">&quot;YYYY&quot;</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Get&nbsp;fields&nbsp;from&nbsp;source file<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;Fields&nbsp;:=&nbsp;TextProvider.Fields;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;data&nbsp;type&nbsp;of fields<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;Fields.Item[</font><font color="#008000">0</font><font color="#000000">].DataType&nbsp;:=&nbsp;DbDataType.ddtString;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Fields.Item[</font><font color="#008000">1</font><font color="#000000">].DataType&nbsp;:=&nbsp;DbDataType.ddtString;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Fields.Item[</font><font color="#008000">2</font><font color="#000000">].DataType&nbsp;:=&nbsp;DbDataType.ddtString;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Fields.Item[</font><font color="#008000">3</font><font color="#000000">].DataType&nbsp;:=&nbsp;DbDataType.ddtDateTime;<br /> &nbsp;&nbsp;&nbsp;&nbsp;Fields.Item[</font><font color="#008000">4</font><font color="#000000">].DataType&nbsp;:=&nbsp;DbDataType.ddtFloat;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Create&nbsp;an object&nbsp;used to&nbsp;create&nbsp;fields<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator&nbsp;:=&nbsp;</font><font color="#008080">New</font><font color="#000000">&nbsp;TableCreator.Create();<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;data&nbsp;source&nbsp;for&nbsp;created&nbsp;table<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.Source&nbsp;:=&nbsp;TextProvider;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Create&nbsp;information&nbsp;about&nbsp;created&nbsp;table<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;CrInfo&nbsp;:=&nbsp;MB.CreateCreateInfo();<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;folder&nbsp;where&nbsp;table&nbsp;will be&nbsp;created<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;CrInfo.Parent&nbsp;:=&nbsp;MB.ItemById[</font><font color="#800000">&quot;FTable&quot;</font><font color="#000000">];<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;information&nbsp;about&nbsp;created&nbsp;table<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.ObjectCreateInfo&nbsp;:=&nbsp;CrInfo;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Get&nbsp;database<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;Db&nbsp;:=&nbsp;MB.ItemById[</font><font color="#800000">&quot;DB&quot;</font><font color="#000000">].Bind()&nbsp;</font><font color="#008080">As</font><font color="#000000">&nbsp;IDatabase;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;database&nbsp;where&nbsp;table&nbsp;data&nbsp;will be&nbsp;stored<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.Database&nbsp;:=&nbsp;Db;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;a string&nbsp;in&nbsp;data&nbsp;source<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;starting&nbsp;from&nbsp;which&nbsp;data&nbsp;will be&nbsp;loaded<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.DataRow&nbsp;:=&nbsp;</font><font color="#008000">0</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;number&nbsp;of rows&nbsp;to&nbsp;be&nbsp;loaded<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.RowCount&nbsp;:=&nbsp;</font><font color="#008000">100</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;that&nbsp;empty&nbsp;rows&nbsp;will&nbsp;be skipped<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.SkipEmptyRows&nbsp;:=&nbsp;</font><font color="#008080">True</font><font color="#000000">;<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Create&nbsp;a data&nbsp;converter<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;Conv&nbsp;:=&nbsp;</font><font color="#008080">New</font><font color="#000000">&nbsp;Converter.Create();<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Specify&nbsp;that&nbsp;the Value field&nbsp;values&nbsp;must be&nbsp;converted<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TCreator.AddConverter(</font><font color="#800000">&quot;Value&quot;</font><font color="#000000">,&nbsp;Conv);<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Create&nbsp;a table&nbsp;and&nbsp;load&nbsp;data&nbsp;to&nbsp;it<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;TmpTable&nbsp;:=&nbsp;TCreator.Execute();<br /> &nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#008000">//&nbsp;Save&nbsp;created&nbsp;table<br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;(TmpTable&nbsp;</font><font color="#008080">As</font><font color="#000000">&nbsp;IMetabaseObject).Save();<br /> </font><font color="#008080">End</font><font color="#000000">&nbsp;</font><font color="#008080">Sub</font><font color="#000000">;</font>

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 field are rounded.

See also:

ITableCreator