Page 1 of 1

How to use the TPgLoader component?

Posted: Sat 26 Feb 2011 12:41
by Ole Ekerhovd
I have a comma delimited text file with more than 200' lines (records) I need to insert into a table. I have tried "For i:=1 to 200000 .... insert into.." but closed the connection after 15 minutes.

I have looked at the demos, but it's to complicated to me.

Delphi XE Postgresql 8.4 and PostgreSql Access.

The text file is on the client computer.

Help please :)

Regards, Ole

Posted: Mon 28 Feb 2011 08:23
by AlexP
Hello,

I cannot reproduce the problem.

Please specify the following information:
- the exact version of PgDAC;
- the error you are getting.
- the errors in the Postges log file;
- the piece of code where you insert a record.

Also try to set the ConnectionTimeout property to false.

Posted: Mon 28 Feb 2011 08:38
by Ole Ekerhovd
Hi

There is no error, I just want to use the TPgLoader and not the TPgQuery component.

I don't understand how to load a text file into the TPgLoader component and thereafter save the contens to a Postgresql table.

The reason is that "ordinary inserts" using TPgQuery took hours to finish and as I understand the TPgLoader is much faster?

Regards,
Ole

Posted: Mon 28 Feb 2011 12:06
by AlexP
Hello,

PgLoader can't load data from a file.
To load data from a text file using PgLoader you should write the OnPutData or the OnGetColumnData event.

For example:

Code: Select all

procedure TForm1.PutData(Sender: TDALoader);
var
  F: TextFile;
  S: String;
  i: Integer;
begin
  i:= 1;
  AssignFile(F,'d:\test.txt');
  Reset(F);
  while not eof(F) do
  begin
    Readln(F, S);
    Sender.PutColumnData(0,i,S);
    inc(i);
  end;
  CloseFile(F);
end;
For more information, please see TDALoader.Load Method, TDALoader.OnPutData Event, DALoader.OnGetColumnData Event topics in the PgDAC help.