FetchRows(Count: Integer; Var Values: Array): Integer;
Count. The number of entries, data of which should be read.
Values. Two-dimensional array, in which read values will be placed.
The FetchRows method reads data of the specified number of entries from the data provider and returns the number of actually read entries.
Data is read into the array passed by the link in the Values parameter.
If the volume of loaded data is known (the number of records and columns, in which each record data is located is known), the array, which size is larger or equal to the volume of the data, can be specified as value of the Values parameter.
If the volume of loaded data is unknown, specify the variable corresponding to the empty dynamic array as value of the Values parameter. On executing the FetchRows method the array is automatically initialized according to the calculated volume of loaded data.
NOTE. On numerous reading of data for repeated use of the same variable-array before calling the FetchRows method, the variable must be reset to zero, or a new array of required size must be initialized.
After reading the cursor in the provider moves to the next record.
Executing the example requires that the file system contains the file D:\Work\Data.xlsx file.
The repository must contain a table with the T_DATA identifier. Table structure should contain the KEY field, and the structure should also correspond to the Microsoft Excel file data.
Add links to the Db, Dt, and Metabase system assemblies.
Sub LoadData;
Var
Mb: IMetabase;
ExcelProviderEx: IDtExcelProviderEx;
MbConsumer: IDtMetabaseConsumer;
v: Array;
Sub ShowArray(Data: Array);
Var
i, j: Integer;
Begin
For j := Data.GetLowerBound(2) To Data.GetUpperBound(2) Do
For i := Data.GetLowerBound(1) To Data.GetUpperBound(1) Do
Debug.Write(Data[i, j] + " ");
End For;
Debug.WriteLine("");
End For;
End Sub ShowArray;
Begin
Mb := MetabaseClass.Active;
// Data provider
ExcelProviderEx := New DtExcelProviderEx.Create;
ExcelProviderEx.File := "D:\Work\Data.xlsx";
ExcelProviderEx.Sheet := "Sheet1";
ExcelProviderEx.HasHeader := False;
ExcelProviderEx.HeaderRow := 0;
ExcelProviderEx.Format := "XLSX";
ExcelProviderEx.DataRow := 1;
ExcelProviderEx.Open;
// Read the first data block
Debug.WriteLine("First data array:");
ExcelProviderEx.FetchRows(5, v);
ShowArray(v);
// Data consumer
MBConsumer := New DtMetabaseConsumer.Create;
MBConsumer.Dataset := Mb.ItemById("T_DATA").Bind As IDatasetModel;
MBConsumer.Open;
MBConsumer.KeyFieldNames := "KEY";
// Record the first data block to consumer
MBConsumer.Put(v);
MBConsumer.Close;
// Read the second data block
v := Null;
Debug.WriteLine("Second data array:");
ExcelProviderEx.FetchRows(10, v);
ShowArray(v);
ExcelProviderEx.Close;
End Sub LoadData;
After executing the example a new data provider that imports data from Microsoft Excel file is created. Data is read from the file in two iterations, the first data block is recorded to the repository table. All read data is displayed in the development environment console.
See also: