Skip to content

Commit

Permalink
Limit number of rows per extended INSERT to 1000 in CSV import dialog.
Browse files Browse the repository at this point in the history
…Closes #326
  • Loading branch information
ansgarbecker committed Jul 19, 2020
1 parent 435d47a commit 6c8c6a0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions source/loaddata.pas
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,16 @@ procedure Tloaddataform.ClientParse(Sender: TObject);
var
P, ContentLen, ProgressCharsPerStep, ProgressChars: Integer;
IgnoreLines, ValueCount, PacketSize: Integer;
RowCountInChunk: Int64;
EnclLen, TermLen, LineTermLen: Integer;
Contents: String;
EnclTest, TermTest, LineTermTest: String;
Value, SQL: String;
IsEncl, IsTerm, IsLineTerm, IsEof: Boolean;
InEncl: Boolean;
OutStream: TMemoryStream;
const
MaxRowCountPerChunk = 1000;

procedure NextChar;
begin
Expand Down Expand Up @@ -527,16 +530,18 @@ procedure Tloaddataform.ClientParse(Sender: TObject);
Delete(SQL, Length(SQL)-1, 2);
StreamWrite(OutStream, SQL + ')');
SQL := '';
if (OutStream.Size < PacketSize) and (P < ContentLen) then
SQL := SQL + ', ('
else begin
Inc(RowCountInChunk);
if (OutStream.Size < PacketSize) and (P < ContentLen) and (RowCountInChunk < MaxRowCountPerChunk) then begin
SQL := SQL + ', (';
end else begin
OutStream.Position := 0;
ChunkSize := OutStream.Size;
SetLength(SA, ChunkSize div SizeOf(AnsiChar));
OutStream.Read(PAnsiChar(SA)^, ChunkSize);
OutStream.Size := 0;
FConnection.Query(UTF8ToString(SA), False, lcScript);
SQL := '';
RowCountInChunk := 0;
end;
end else
SQL := '';
Expand Down Expand Up @@ -566,6 +571,7 @@ procedure Tloaddataform.ClientParse(Sender: TObject);
ProgressCharsPerStep := ContentLen div ProgressBarSteps;
ProgressChars := 0;
RowCount := 0;
RowCountInChunk := 0;
IgnoreLines := UpDownIgnoreLines.Position;
ValueCount := 0;
PacketSize := SIZE_MB div 2;
Expand Down

0 comments on commit 6c8c6a0

Please sign in to comment.