Fix crash when scanning CSV file with more values in data than in header line. Closes #1698

This commit is contained in:
Ansgar Becker
2022-11-14 20:07:37 +01:00
parent 9339304356
commit 28e34b9942

View File

@@ -5,7 +5,8 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, SynEdit, SynMemo, extra_controls, apphelpers,
loaddata, dbconnection, Vcl.ExtCtrls, gnugettext, dbstructures, System.Math, SynRegExpr, System.IOUtils;
loaddata, dbconnection, Vcl.ExtCtrls, gnugettext, dbstructures, System.Math, SynRegExpr, System.IOUtils,
System.StrUtils;
type
TfrmCsvDetector = class(TExtForm)
@@ -208,7 +209,7 @@ function TfrmCsvDetector.DetectColumnAttributes(Rows: TGridRows; IgnoreLines: In
var
Row: TGridRow;
Value: TGridValue;
Col: TTableColumn;
Col, UnknownColumn: TTableColumn;
i, j, k: Integer;
UnknownTypeYet, IsInteger, IsFloat, IsDate, IsDatetime, IsText: Boolean;
ValueSize, TypeSize: Int64;
@@ -237,11 +238,15 @@ begin
Break;
end;
UnknownColumn := TTableColumn.Create(FConnection);
for i:=IgnoreLines to Rows.Count-1 do begin
MainForm.ProgressStep;
for j:=0 to Rows[i].Count-1 do begin
Value := Rows[i][j];
Col := Result[j];
if j >= Result.Count then
Col := UnknownColumn
else
Col := Result[j];
// Detect data type of current value