Print Thread
Pb initialising 2 CLOB columns with 1 TLobLocator
#49736 10/31/14 12:26 PM
Joined: Oct 2014
Posts: 3
France
J
jleg Offline OP
Member
OP Offline
Member
J
Joined: Oct 2014
Posts: 3
France
Hi all,

I've a problem to initialise 2 CLOB columns in 2 different tables with the same TLobLocator through PL/SQL procedure.
Take a look at this simplified scheme to view the problem.

I have 2 PL/SQL procedures defined like this.

SQL Query
Create or Replace procedure P1 (iID in PLS_INTEGER, ioLOB in out CLOB,...)
as
Begin
  Update MYTABLE1
     set COL2 = EMPTY_CLOB(),...
   where COL1 = iID
  returning COL2 into ioLOB;
  ...
  P2(iID, ioLOB);  
  ...
End;

Create or Replace procedure P2 (iNewID in PLS_INTEGER, ioNewLOB in out CLOB,...)
as
Begin
  ...
  Update MYTABLE2
     set COL2 = EMPTY_CLOB(),...
   where COL1 = iNewID
  returning COL2 into ioNewLOB;
  ...
End;

The corresponding Delphi code is:

Code
Var
  Lob: TLobLocator;
  ...
Begin
  ...//MyQuery calls P1
  Lob := TLobLocator.Create(MyQuery.Session, OtCLOB);
  MyQuery.SetComplexVariable('ioLOB', Lob);
  MyQuery.Execute;
  Lob.AsString := 'Blabla';
  MyQuery.Session.Commit;
  Lob.Free;
  ...
End;

In my database, the CLOB column in MYTABLE1 contains '' and the CLOB column in MYTABLE2 contains 'Blabla'.
But, i want 'Blabla' in MYTABLE1 too!

The only workaround i found is to have 2 lob parameters in my query (one for MYTABLE1 et one for MYTABLE2). But, duplicating the CLOB parameter is not good for memory (I have 2 other CLOB parameters in my parameters list of the PL procedure)

Is there any other solution ?

Thanks in advance for your responses.
jleg.

Re: Pb initialising 2 CLOB columns with 1 TLobLocator
jleg #49737 11/03/14 10:33 AM
Joined: Aug 1999
Posts: 22,200
Member
Offline
Member
Joined: Aug 1999
Posts: 22,200
You could call both procedures at once in the PL/SQL Block of your TOracleQuery instance, and pass the CLOB value to both procedures. This would minimize the number of calls, network traffic, and network roundtrips.

You would need to create the CLOB with the CreateTemporary constructor though, and write the CLOB data before calling the PL/SQL Block. The returning clause can be omitted from the update statement, and all columns can be written directly.


Marco Kalter
Allround Automations
Re: Pb initialising 2 CLOB columns with 1 TLobLocator
Marco Kalter #49750 11/04/14 04:59 PM
Joined: Oct 2014
Posts: 3
France
J
jleg Offline OP
Member
OP Offline
Member
J
Joined: Oct 2014
Posts: 3
France
Cool, it works fine. Thank's very much.

But, i would like to know what is the real difference between the both TLobLocator's constructors?

In the CreateTemporary constructor, the last parameter (cache) can be put to True (cache on client) or False (cache on server).
What is the best solution ? when should i use client or server?

If i choose False, what is the difference between CreateTemporary and Create?


jleg
Re: Pb initialising 2 CLOB columns with 1 TLobLocator
jleg #49754 11/05/14 09:58 AM
Joined: Aug 1999
Posts: 22,200
Member
Offline
Member
Joined: Aug 1999
Posts: 22,200
A TLOBLocator created with the Create constructor always needs to be associated with a single database column value. You cannot read or write data until this association is made, either by fetching the LOB value or by returning an empty LOB with the returning clause in an insert or update statement.

A TLOBLocator created with the CreateTemporary constructor can hold data regardless whether it is associated with a database column or not. It is called temporary, because if you free it without writing it to the database, the data is gone.

The temporary data can either be cached on the client or on the server. What is most efficient depends on how the application accesses the data.


Marco Kalter
Allround Automations
Re: Pb initialising 2 CLOB columns with 1 TLobLocator
Marco Kalter #49794 11/18/14 09:59 AM
Joined: Oct 2014
Posts: 3
France
J
jleg Offline OP
Member
OP Offline
Member
J
Joined: Oct 2014
Posts: 3
France
Clear explanation.
Thank you.


jleg

Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.026s Queries: 15 (0.007s) Memory: 2.5194 MB (Peak: 3.0393 MB) Data Comp: Off Server Time: 2024-04-19 12:26:14 UTC
Valid HTML 5 and Valid CSS