Error while reading a blob field

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mile
Posts: 6
Joined: Tue 05 May 2009 14:57

Error while reading a blob field

Post by mile » Wed 15 Jul 2009 08:31

I have this table in postgresql :
CREATE TABLE sif_pictogrami
(
id serial NOT NULL,
picture oid,
naziv character varying(100)
)
WITH (OIDS=FALSE);
ALTER TABLE sif_pictogrami OWNER TO postgres;

I use this UniQuery "select * from sif_pictogrami" to open a table and give me error active trasaction is required for operation for large objects. to insert a picture i use
'INSERT INTO sif_pictogrami (picture) VALUES(lo_import(' + '''' + FileName + '''' + '));'
this query and i have no problem. I also try the example from C:\Program Files\Devart\UniDac for Delphi 7\Demos\UniDacDemo\Pictures but that example does not store the picture in the data base only load from the file and when i try to POST give me the same error.
Any help how can i store, view data in oid field from Delphi 7.

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

Post by Plash » Thu 16 Jul 2009 07:16

You should call the StartTransaction method of TPgConnection before opening the query.

mile
Posts: 6
Joined: Tue 05 May 2009 14:57

Post by mile » Mon 20 Jul 2009 09:02

I use table to store the picture. First i call StartTransaction what need to do after Post. If i call Commit and again call the StartTransaction when a close the table it gives me error invalid large object descriptor : 0.

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

Post by dschuch » Mon 20 Jul 2009 09:26

how do you insert the picture?

tpglargeobject param?
tfield.loadfromfile?

daniel.

mile
Posts: 6
Joined: Tue 05 May 2009 14:57

Post by mile » Mon 20 Jul 2009 09:54

You can do it like this :
t_pictogramipicture.LoadFromFile(FileName);
t_pictogrami.Post;
Edit FileName before use LoadFromFile :
FileName := StringReplace(FileName,'\,'/', [rfReplaceAll]);

mile
Posts: 6
Joined: Tue 05 May 2009 14:57

Post by mile » Tue 21 Jul 2009 07:20

When i open the table i call starttransaction after that
t_pictogrami.Insert, i load a picture from a file and i use this.
t_pictogramipicture.LoadFromFile(FileName);
t_pictogrami.Post;
When i try to insert another picture give me an error

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

Post by Challenger » Tue 21 Jul 2009 10:48

The large object handle is valid only in the context of current transaction. When you commit/rollback transaction, all opened objects are closed. PgDAC tries to close the object on freeing of TPgSqlLargeObject. If the handle is already closed, it raises an exception. That's why you get the mentioned exception. But this exception is internally catched and is visible in the debug mode only.

mile
Posts: 6
Joined: Tue 05 May 2009 14:57

Post by mile » Thu 23 Jul 2009 10:22

Can you give me an example for this table
table (
id integer,
picture oid
)
how to start transaction and end transaction bloc.
Thanks

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

Post by Plash » Tue 04 Aug 2009 08:42

First time you need transaction when you open the table to read large objects:

Code: Select all

PgConnection.StartTransaction;
PgTable.Open;
PgConnection.Rollback;
When you add a row, you also need to start transaction:

Code: Select all

PgConnection.StartTransaction;
PgTable.Insert;
PgRow := PgTable.GetPgRow('picture');
PgRow.LoadFromFile(FileName);
PgTable.Post;
PgRow.CloseObject; // make sure object is closed before the transaction is commited
PgConnection.Commit;

Post Reply