Hi,
I'm trying to export data to a *.csv file using a TSQLQuery (connected to a postgres database). Everything works fine for a small results. When the result is bigger (for example 80k rows, each with 6 fields of varchar 255 - which isn't of course huge amount of data), my program exhausts all possible memory (more than 1,5GB). I'm wondering what's wrong. During search in google and this forum I found some similar problems but none resolved.
Did anyone met with this problem?
I made tests on Windows 7 64b, Win 8.1.
Application was compiled on Lazarus (stable) 1.0.10.
Please find below a part of code:
try
AssignFile(plik, Utf8ToAnsi(SaveDialog.FileName));
Rewrite(plik);
Form1.QueryReports.First;
Count := Form1.QueryReports.FieldCount - 1;
pg.Max := Form1.QueryReports.RowsAffected;
pg.Position := 0;
Form1.Datasource1.Enabled := False;
Form1.Datasource1.DataSet := nil;
//nagłówek
for i := 0 to Count do
begin
if i = Count then
Writeln(plik, '"' + Form1.QueryReports.FieldDefs[i].DisplayName + '"')
else
Write(plik, '"' + Form1.QueryReports.FieldDefs[i].DisplayName + '"' + ',');
end;
//zawartość pliku
while not Form1.QueryReports.EOF do
begin
for i := 0 to Count do
begin
if i = Count then
begin
tmp_string:= '"' + StringReplace(Form1.QueryReports.Fields[i].AsString, '"', '^', [rfIgnoreCase, rfReplaceAll]) + '"';
tmp_string:= StringReplace(tmp_string, #13, ' ', [rfIgnoreCase, rfReplaceAll]);
tmp_string:= StringReplace(tmp_string, #10, ' ', [rfIgnoreCase, rfReplaceAll]);
Writeln(plik, tmp_string);
end
else
begin
tmp_string:= '"' + StringReplace(Form1.QueryReports.Fields[i].AsString, '"', '^', [rfIgnoreCase, rfReplaceAll]) + '"' + ',';
tmp_string:= StringReplace(tmp_string, #13, ' ', [rfIgnoreCase, rfReplaceAll]);
tmp_string:= StringReplace(tmp_string, #10, ' ', [rfIgnoreCase, rfReplaceAll]);
Write(plik, tmp_string);
end;
end;
Form1.QueryReports.Next;
pg.Position := pg.Position + 1;
end;
CloseFile(plik);
ShowMessage(Form1.GetLanText('Eksport zakończony!'));
pg.Position := 0;
Form1.Datasource1.DataSet := Form1.QueryReports;
except
on E: Exception do
Form1.Log('ERROR >> ' + E.Message + ' ' + IntToStr(E.HelpContext));
end;
Thanks in advance