Page 1 of 1

[solved] Directly using LargeObjects-examples needed!

Posted: 12.06.2012, 21:07
by bulba

I've have few science applications written in Python which are gathering medical data (X-Rays) and inserts them into PostgresQL 9.1 database using LargeObject interface for further processing, and they are working fine :)
I'd like to use lo_create/lo_import/lo_export with ZEOS (svn version) and Delphi XE to access and modify this data. I've took a look at the ZEOS' forum and I've found information regarding "direct call interface", the GetPlainDriver function and I've found in the ZEOS' sources functions: OpenLargeObject, TellLargeObject and so on. Great! :)

But how can I use them? There is no examples at all and I'm little bit lost :( Could you please be so nice and provide me with small example of using LargeFile interface with TZQuery, svn's ZEOS and Delphi?
Thank you in advance! :)

Bulba Nakcharashi, MD

Posted: 12.06.2012, 21:26
by EgonHugeist

very spezial request!

What i know is that Zeos supports that large objects if you add 'oidasblob=true' to the TZConnecton.Properties. Then Zeos is able to read thes blobs and you can access them like (TZQuery.FieldByName('x-Ray') as TBlobField).SaveToStrem/LoadFromStream.

The exact answer should be:
(TZConnection.DbcConnection.GetIZPlainDriver as IZPostgreSQLPlainDriver).OpenLargeObject(Handle: PZPostgreSQLConnect; ObjId: Oid;
Mode: Integer);

But here you need some more Parameters... which you can't get so easy like this call.


Posted: 13.06.2012, 09:20
by bulba
Well, ZEOS i really clever software! :) However as always a little bit o black magick has to be involved ;)

So here is the receipe:
1) create example table like: create table x_breast_cancer(id serial, xray oid);
2) add oidasblob=true to the ZConnection properties
3) set TransactionIsolationLevel to tiReadCommitted - VERY IMPORTANT! While playing with LargeObject Zeos in fact creates squence of commands which MUST be done in transaction, in other case it'll fail with 'unknown OID 0' message!
4) add your binary data to the OID field (in my example: 'xray') as usuall ftBlob, you'll notice then in the table in the OID field there will be a number - kind of pointer to the binary date on server
5) if you like to retrieve data just read this OID field and you'll receive binary data :)

Well, it's the easiest way to play with LargeFiles, however it's not possible to play with Seek or Tell methods this way, I'll research it further.

Michael, thank you very much for your help! :)

Bulba Nakcharashi, MD

Posted: 13.06.2012, 09:49
by EgonHugeist

Yes that's not supported actually. And i think that was well done. If you publish these funtions either on the PGPlainDriver or on the DbcPostgreConnection interfaces then it should be possible to have this support directly. Then you can call them with a cast like i proposed before. Example: (ZConnection.DbcConnection as IZDbcPostgeConnection).Tell/Seek(Oid: integer)..

Attach a patch and we'll add it to our repositories...