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