Problems with "TPgLargeObjectField"

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Problems with "TPgLargeObjectField"

Post by dschuch » Thu 05 Feb 2009 15:45

Hi,

i have some trouble with BLOB Fields.

1) Delphi does not know the class TPgLargeObjectField, so each time i open a form delphi says "unkown class". it seems that this fieldtype isn't registered? (RegisterClass)
If i call Registerclass everything works fine.

2) if i set the Blobtype to ftBlob i always get
"Type mismatch for field 'mm_picture', expecting: TBlobField actual: TPgLargeObjectField".
FieldType in Database is oid.

The reason seems to be the BlobType property of the TPgLargeObjectField. It seems that Blobtype is not set correct. If i try to compile i get "unsupported 16 bit resource in file X". If i look into the dfm:

object MainMenumm_picture: TPgLargeObjectField
FieldName = 'mm_picture'
BlobType =
end

if setting the blobtype on ftBlob error 2) is raised.

can anyone give a tip

Using PostgreSQL 8.1

Challenger
Devart Team
Posts: 925
Joined: Thu 17 Nov 2005 10:53

Post by Challenger » Mon 09 Feb 2009 11:47

1) We will fix this problem in the next build of PgDAC.
2) If you want to insert or update a record you should use ftPgLargeObject as parameter datatype.

Challenger
Devart Team
Posts: 925
Joined: Thu 17 Nov 2005 10:53

Post by Challenger » Mon 09 Feb 2009 12:00

Please note that all operations with Large Object data type should be performed in transaction. Please take a look at BYTEA data type. You can also refer to the PgDAC help, "Working with Large Objects" article.

dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Post by dschuch » Mon 09 Feb 2009 17:31

Hi Challanger,

Please note that all operations with Large Object data type should be performed in transaction. Please take a look at BYTEA data type. You can also refer to the PgDAC help, "Working with Large Objects" article.
thats clear. and done already. but currently all fields are of type oid, not bytea in database. Also i have some trouble with the example in the documentation too, but i will research it more. currently i'm unable to get my oid data.

Problem #2

Please Try:
Create a Table with a oid column.
Create a Query in Delphi, Create Fields at DesignTime with the "CerateAllFields" Popup. Now you can see my Problem #2:
It is the "TPgLargeObjectField"s property BlobType wich makes trouble.

I have a new small issue for you:

SELECT a+b AS calc_c FROM x;

Now PgDac maps c as a normal (Data)Field and if you Update this field you get an error because the update statement looks like "UPDATE x SET calc_c=..."

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 10 Feb 2009 10:42

We have fixed the problems with registering field classes and with the BlobType property. The fixes will be included in the next PgDAC build.

By default PgDAC sets the ReadOnly flag for fields that are based on expressions. So you cannot edit this field. If you change the SetFieldsReadOnly option of TPgQuery to False, you can edit such field, but it is not included in UPDATE statement anyway.
We cannot reproduce the problem with editing the field. Please send to pgdac*devart*com a small sample that demonstrates the problem, including the script for creating database objects.

dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Post by dschuch » Tue 10 Feb 2009 19:33

By default PgDAC sets the ReadOnly flag for fields that are based on expressions. So you cannot edit this field. If you change the SetFieldsReadOnly option of TPgQuery to False, you can edit such field, but it is not included in UPDATE statement anyway.
We cannot reproduce the problem with editing the field. Please send to pgdac*devart*com a small sample that demonstrates the problem, including the script for creating database objects.
yes, your right, so problem seems to be more complicated, i send a demo.

dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

BLOB OID

Post by dschuch » Tue 10 Feb 2009 20:02

the Blob Problem is very simple:

ReadBlob and WriteBlob is required. thats not clear in the documentation.


ReadBlob

Code: Select all

 Assert(OpenDialog1.Execute());
 PgConnection1.StartTransaction;
 LargeObject := TPgLargeObject.Create(PgConnection1);
 LargeObject.OID:=PGQuery1.FieldByName('picture').AsInteger;
 LargeObject.OpenObject;
 LargeObject.ReadBlob;
 LargeObject.SaveToFile(OpenDialog1.FileName);
 LargeObject.CloseObject;
WriteBlob

Code: Select all

 Assert(OpenDialog1.Execute());
 LargeObject := TPgLargeObject.Create(PgConnection1);
 PgConnection1.StartTransaction;
 PGQuery1.Insert;
 LargeObject.CreateObject;
 LargeObject.LoadFromFile(OpenDialog1.FileName);
 LargeObject.WriteBlob;
 LargeObject.CloseObject;
 PGQuery1.FieldByName('picture').AsInteger:=LargeObject.OID;
 PgQuery1.Post;
 PgConnection1.Commit;

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 17 Feb 2009 12:23

The 'Using PgDAC \ Working with Large Objects' topic of the PgDAC help contains information about using ReadBlob and WriteBlob methods. There is also an example with the call of WriteBlob method.

Post Reply