How to use the TPgLoader component?

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Ole Ekerhovd
Posts: 8
Joined: Sat 07 Feb 2009 07:43

How to use the TPgLoader component?

Post by Ole Ekerhovd » Sat 26 Feb 2011 12:41

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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 28 Feb 2011 08:23

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.

Ole Ekerhovd
Posts: 8
Joined: Sat 07 Feb 2009 07:43

Post by Ole Ekerhovd » Mon 28 Feb 2011 08:38

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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 28 Feb 2011 12:06

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.

Post Reply