working with large objects

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Lemmy
Posts: 5
Joined: Wed 08 Oct 2014 07:40

working with large objects

Post by Lemmy » Fri 17 Jun 2022 20:27

Hello,
I have this table:

Code: Select all

CREATE TABLE IF NOT EXISTS fdmandant14.postausgang (
  id BigSerial NOT NULL,
  empfaengermail VarChar(100),
  absendermail VarChar(100),
  emailtext Text,
  datum Timestamp,
  gesendet Boolean DEFAULT false,
  beleg Bytea,
  xmlbeleg Bytea,
  patpass Bytea,
  konfi Bytea
);
I use this SQL to insert data:

Code: Select all

qryPOstAusgang.Connection.StartTransaction;
              qryPostAusgang.sql.Text := 'Insert into postausgang Values (:Empfaenger, :Absender, :Emailtext, :Datum, :Gensendet, '
                                       + ':Beleg, :XMLBeleg, :PatPass, :Konfi)';
To set the parameters :beleg, :XMLBeleg,... I use this method:

Code: Select all

procedure CreateLargeObject(const ALargeObject: TPgLargeObject; const AStream: TStream);
  begin
    ALargeObject.Connection := dataPG.PgConnectionFD;
    ALargeObject.ReadBlob;
    ALargeObject.Clear;
    ALargeObject.Truncate(0);
    ALargeObject.LoadFromStream(AStream);
    ALargeObject.WriteBlob;
    ALargeObject.CloseObject;
  end;
and so I execute the method:

Code: Select all

var fs: TFileStream;
fs := TFileStream.Create(PDFPath + AnhangBezeichnung, fmOpenRead, fmShareDenyNone);
try
  CreateLargeObject(qryPOstAusgang.ParamByName('Beleg').AsPgLargeObject, fs);
finally
 fs.Free;
end;
And then I get the error:
EPgError: "Large Object 0 existiert nicht"

What do I wrong?
Best regards
Wolfgang

p.s: I use your contact form (twice) and get a 404, maybe someone can fix this...

evgeniym
Devart Team
Posts: 103
Joined: Thu 13 May 2021 07:08

Re: working with large objects

Post by evgeniym » Mon 20 Jun 2022 11:49

Hi Wolfgang,
Thanks for your request!

The TPgLargeObject class is not designed to work with the type bytea, but rather to work with the type PostgreSQL large objects.
The bytea type is not equivalent to PostgreSQL large object.
With the bytea type you can work as with TBlobField.

You can find more information about the TPgLargeObject class at the following link:
https://docs.devart.com/pgdac/devart.pg ... object.htm

You can find more info about PostgreSQL large objects at the following link:
https://www.postgresql.org/docs/14/largeobjects.html

An example of how the TPgLargeObject class works with PostgreSQL large objects can be found at the link:
https://docs.devart.com/pgdac/work_large_objects.htm

More info about the bytea type you can find at the provided link:
https://www.postgresql.org/docs/current ... inary.html

Could you please clarify the 404 error appeared when using the https://www.devart.com/company/contactform.html contact form?

Regards,
Evgeniy

Post Reply