Posted By: Stephen CLOBs using C++ Builder - 08/11/23 04:11 AM
I see lots of examples using Delphi but non for C++ Builder with the temporary LOB (CreateTemporary) calls.

I don't even know if that's what I need to do....

I have an Oracle function inside a package:
SQL Query
function my_func(pJSON in clob) returning clob is
  cRetval clob := empty_clob();
begin
  cRetval := 'some long text value in JSON format';
  return cRetval;
end;

I use the Package Wizard to create components for each of my packages.

I want to call this function from C++ Builder, passing in a CLOB and receiving a CLOB in return.

Code that was working (but not with 11.3):
Code

TLOBLocator *inp = new TLOBLocator(OraSession, otCLOB, true);
inp->AsString = "some JSON input string";

TLOBLocator *outp = MyPackage->MyFunc(inp);      // <<- crash here
ShowMessage(outp->AsString);

delete outp;
delete inp;

Any help (with examples) would be greatly appreciated!
Posted By: Marco Kalter Re: CLOBs using C++ Builder - 08/11/23 08:59 AM
Can you show me the pascal source of the MyPackage.MyFunc function?
Posted By: Stephen Re: CLOBs using C++ Builder - 08/11/23 12:26 PM
SQL Query
function TMyPackage.my_func(Pjson: TLOBLocator): TLOBLocator;
begin
  Result := TLOBLocator.Create(Session, otCLOB);
  ThreadAcquire;
  try
    GetQuery;
    OCPQuery.DeclareVariable('function_result', otCLOB);
    OCPQuery.SetComplexVariable('function_result', Result);
    OCPQuery.DeclareVariable('PJSON', otCLOB);
    OCPQuery.SetComplexVariable('PJSON', Pjson);
    OCPQuery.SQL.Add('begin');
    OCPQuery.SQL.Add('  :function_result := "MYPACKAGE_PAKG"."MY_FUNC"(PJSON => :PJSON);');
    OCPQuery.SQL.Add('end;');
    OCPQuery.Execute;
  except
    ThreadRelease;
    Result.Free;
    raise;
  end;
  ThreadRelease;
end;

I can replicated this function by creating the query and declaring the parameters without a problem. The issue is when I try to call it from within the component that is created by the wizard.

Interestingly enough, if I modify the call (from the initial post) where I'm not even looking at the return value such as:
Code
MyPackage->MyFunc(inp);      // <<- crash here

I still receiver the error ORA-03120: two-task conversion routine: integer overflow. When I look up this error, I get the response that it is usually generated from the calling program. I can run the stored procedure all day long using the CLOB I'm passing in to the function and I've verified that it indeed has a value when I'm passing it in.

Also, it works just fine when I replicate the code above where I create the query, the 2 TLOBLocators and declare and set everything.
Posted By: Marco Kalter Re: CLOBs using C++ Builder - 08/14/23 08:37 AM
Can you change

Result := TLOBLocator.Create(Session, otCLOB);

to

Result := TLOBLocator.CreateTemporary(Session, otCLOB, True);

and try again?
© Allround Automations forums