Page 1 of 1

Error while reading a blob field

Posted: Wed 15 Jul 2009 08:31
by mile
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.

Posted: Thu 16 Jul 2009 07:16
by Plash
You should call the StartTransaction method of TPgConnection before opening the query.

Posted: Mon 20 Jul 2009 09:02
by mile
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.

Posted: Mon 20 Jul 2009 09:26
by dschuch
how do you insert the picture?

tpglargeobject param?
tfield.loadfromfile?

daniel.

Posted: Mon 20 Jul 2009 09:54
by mile
You can do it like this :
t_pictogramipicture.LoadFromFile(FileName);
t_pictogrami.Post;
Edit FileName before use LoadFromFile :
FileName := StringReplace(FileName,'\,'/', [rfReplaceAll]);

Posted: Tue 21 Jul 2009 07:20
by mile
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

Posted: Tue 21 Jul 2009 10:48
by Challenger
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.

Posted: Thu 23 Jul 2009 10:22
by mile
Can you give me an example for this table
table (
id integer,
picture oid
)
how to start transaction and end transaction bloc.
Thanks

Posted: Tue 04 Aug 2009 08:42
by Plash
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;