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
<br /> <font color="#008080">Sub</font> UserProc;<br /> <font color="#008080">Var</font><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 color="#008080">Begin</font><br /> <font color="#008000">// Get current repository<br /> </font> MB := MetabaseClass.Active;<br /> <font color="#008000">// Create data source for table <br /> </font> TextProvider := <font color="#008080">New</font> DtTextProvider.Create;<br /> <font color="#008000">// Specify file, from which data is loaded<br /> </font> TextProvider.File := <font color="#800000">"c:\result.txt"</font>;<br /> <font color="#008000">// Specify row with titles<br /> </font> TextProvider.HeaderRow := <font color="#008000">1</font>;<br /> <font color="#008000">// Specify field delimiter<br /> </font> TextProvider.DelimitedColumnDelimiter := <font color="#800000">";"</font>;<br /> <font color="#008000">// Set date format in file<br /> </font> TextProvider.StringDataFormat.DateFormat := <font color="#800000">"YYYY"</font>;<br /> <font color="#008000">// Get fields from source file<br /> </font> Fields := TextProvider.Fields;<br /> <font color="#008000">// Specify field data type<br /> </font> Fields.Item(<font color="#008000">0</font>).DataType := DbDataType.String;<br /> Fields.Item(<font color="#008000">1</font>).DataType := DbDataType.String;<br /> Fields.Item(<font color="#008000">2</font>).DataType := DbDataType.String;<br /> Fields.Item(<font color="#008000">3</font>).DataType := DbDataType.DateTime;<br /> Fields.Item(<font color="#008000">4</font>).DataType := DbDataType.Float;<br /> <font color="#008000">// Create object used for creating fields<br /> </font> TCreator := <font color="#008080">New</font> TableCreator.Create;<br /> <font color="#008000">// Specify data source for created table<br /> </font> TCreator.Source := TextProvider;<br /> <font color="#008000">// Create information about created table<br /> </font> CrInfo := MB.CreateCreateInfo;<br /> <font color="#008000">// Specify folder, in which table is created<br /> </font> CrInfo.Parent := MB.ItemById(<font color="#800000">"FTable"</font>);<br /> <font color="#008000">// Specify information about created table<br /> </font> TCreator.ObjectCreateInfo := CrInfo;<br /> <font color="#008000">// Get database<br /> </font> Db := MB.ItemById(<font color="#800000">"DB"</font>).Bind <font color="#008080">As</font> IDatabase;<br /> <font color="#008000">// Specify database, in which table data is stored<br /> </font> TCreator.Database := Db;<br /> <font color="#008000">// Specify row in data source,<br /> </font> <font color="#008000">// starting with which data is loaded<br /> </font> TCreator.DataRow := <font color="#008000">0</font>;<br /> <font color="#008000">// Specify the number of rows, that is required to load<br /> </font> TCreator.RowCount := <font color="#008000">100</font>;<br /> <font color="#008000">// Specify that empty rows are skipped<br /> </font> TCreator.SkipEmptyRows := <font color="#008080">True</font>;<br /> <font color="#008000">// Create value transformer<br /> </font> Conv := <font color="#008080">New</font> Converter.Create;<br /> <font color="#008000">// Specify that values of the Value field must be transformed<br /> </font> TCreator.AddConverter(<font color="#800000">"Value"</font>, Conv);<br /> <font color="#008000">// Create table and load data to it<br /> </font> TmpTable := TCreator.Execute;<br /> <font color="#008000">// Save created table<br /> </font> (TmpTable <font color="#008080">As</font> IMetabaseObject).Save;<br /> <font color="#008080">End</font> <font color="#008080">Sub</font> 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 field are rounded.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
<font color="#008080">Imports</font> Prognoz.Platform.Interop.Cubes;<br /> <font color="#008080">Imports</font> Prognoz.Platform.Interop.Dal;<br /> <font color="#008080">Imports</font> Prognoz.Platform.Interop.Db;<br /> <font color="#008080">Imports</font> Prognoz.Platform.Interop.Dt;<br /> …<br /> <font color="#008080">Public</font> <font color="#008080">Shared</font> <font color="#008080">Sub</font> Main(Params: StartParams);<br /> <font color="#008080">Var</font><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 color="#008080">Begin</font><br /> <font color="#008000">// Get current repository<br /> </font> MB := Params.Metabase;<br /> <font color="#008000">// Create data source for table<br /> </font> TextProvider := <font color="#008080">New</font> DtTextProvider.Create();<br /> <font color="#008000">// Specify the file, from which data is loaded<br /> </font> TextProvider.File := <font color="#800000">"c:\result.txt"</font>;<br /> <font color="#008000">// Specify the row with headers<br /> </font> TextProvider.HeaderRow := <font color="#008000">1</font>;<br /> <font color="#008000">// Specify the character that separates fields<br /> </font> TextProvider.DelimitedColumnDelimiter := <font color="#800000">";"</font>;<br /> <font color="#008000">// Set date format in file<br /> </font> TextProvider.StringDataFormat.DateFormat := <font color="#800000">"YYYY"</font>;<br /> <font color="#008000">// Get fields from source file<br /> </font> Fields := TextProvider.Fields;<br /> <font color="#008000">// Specify type of field data<br /> </font> Fields.Item[<font color="#008000">0</font>].DataType := DbDataType.ddtString;<br /> Fields.Item[<font color="#008000">1</font>].DataType := DbDataType.ddtString;<br /> Fields.Item[<font color="#008000">2</font>].DataType := DbDataType.ddtString;<br /> Fields.Item[<font color="#008000">3</font>].DataType := DbDataType.ddtDateTime;<br /> Fields.Item[<font color="#008000">4</font>].DataType := DbDataType.ddtFloat;<br /> <font color="#008000">// Create an object used to create fields<br /> </font> TCreator := <font color="#008080">New</font> TableCreator.Create();<br /> <font color="#008000">// Specify the data source for created table<br /> </font> TCreator.Source := TextProvider;<br /> <font color="#008000">// Create information about created table<br /> </font> CrInfo := MB.CreateCreateInfo();<br /> <font color="#008000">// Specify the folder, in which table is created<br /> </font> CrInfo.Parent := MB.ItemById[<font color="#800000">"FTable"</font>];<br /> <font color="#008000">// Specify information about created table<br /> </font> TCreator.ObjectCreateInfo := CrInfo;<br /> <font color="#008000">// Get database<br /> </font> Db := MB.ItemById[<font color="#800000">"DB"</font>].Bind() <font color="#008080">As</font> IDatabase;<br /> <font color="#008000">// Specify the database, in which table data is stored<br /> </font> TCreator.Database := Db;<br /> <font color="#008000">// Specify the row in data source,<br /> </font> <font color="#008000">// starting from which data is loaded<br /> </font> TCreator.DataRow := <font color="#008000">0</font>;<br /> <font color="#008000">// Specify the number of rows, that must be loaded<br /> </font> TCreator.RowCount := <font color="#008000">100</font>;<br /> <font color="#008000">// Specify that empty rows are skipped<br /> </font> TCreator.SkipEmptyRows := <font color="#008080">True</font>;<br /> <font color="#008000">// Create value transformer<br /> </font> Conv := <font color="#008080">New</font> Converter.Create();<br /> <font color="#008000">// Specify that values of the Value field must be transformed<br /> </font> TCreator.AddConverter(<font color="#800000">"Value"</font>, Conv);<br /> <font color="#008000">// Create a table and load data to it<br /> </font> TmpTable := TCreator.Execute();<br /> <font color="#008000">// Save created table<br /> </font> (TmpTable <font color="#008080">As</font> IMetabaseObject).Save();<br /> <font color="#008080">End</font> <font color="#008080">Sub</font>;
See also: