Using TOraRef as parameters
-
- Posts: 9
- Joined: Thu 29 Jun 2006 14:04
Using TOraRef as parameters
Hi All.
May I use out parameter of TOraRef type of TOraSQL as In parameter in another TOraSQL?
I have:
--------------------------------------------------
create type base_typ as object
(
name varchar2(32)
)not final;
create type property_typ as object
(
entity ref base_typ
val float
)not final;
create table base_t of base_typ;
create table property_t of property_typ;
--------------------------------------------------
OraSQL1: TOraSQL1
OraSQL1.SQL =
'insert into base_t t values(:nam) returning REF(t) into :res'
OraSQL2: TOraSQL2
OraSQL2.SQL =
'insert into property_t t values(:obj, :val)'
--------------------------------------------------
And following code:
...
t := TOraType.Create(Session.OCISvcCtx, 'base_t');
OraSQL1.ParamByName('Res').AsRef.ObjectType := t;
t.Free;
OraSQL1.ParamByName('Nam').AsString := 'String';
OraSQL1.Execute;
OraSQL2.ParamByName('obj').AsRef := OraSQL1.ParamByName('Res').AsRef;
OraSQL2.ParamByName('Val').AsFloat := 100;
OraSQL2.Execute;
...
I have no error, but in property_t table field entity is Null.
What's wrong?
Thanx
May I use out parameter of TOraRef type of TOraSQL as In parameter in another TOraSQL?
I have:
--------------------------------------------------
create type base_typ as object
(
name varchar2(32)
)not final;
create type property_typ as object
(
entity ref base_typ
val float
)not final;
create table base_t of base_typ;
create table property_t of property_typ;
--------------------------------------------------
OraSQL1: TOraSQL1
OraSQL1.SQL =
'insert into base_t t values(:nam) returning REF(t) into :res'
OraSQL2: TOraSQL2
OraSQL2.SQL =
'insert into property_t t values(:obj, :val)'
--------------------------------------------------
And following code:
...
t := TOraType.Create(Session.OCISvcCtx, 'base_t');
OraSQL1.ParamByName('Res').AsRef.ObjectType := t;
t.Free;
OraSQL1.ParamByName('Nam').AsString := 'String';
OraSQL1.Execute;
OraSQL2.ParamByName('obj').AsRef := OraSQL1.ParamByName('Res').AsRef;
OraSQL2.ParamByName('Val').AsFloat := 100;
OraSQL2.Execute;
...
I have no error, but in property_t table field entity is Null.
What's wrong?
Thanx
You should call Pin method of TOraRef after obtaining an object reference to pin the object in OCI object cache. After finishing work with this object you should call Unpin method.
Code: Select all
t := TOraType.Create(OraSession1.OCISvcCtx, 'base_typ');
OraSQL1.ParamByName('Res').AsRef.ObjectType := t;
t.Free;
OraSQL1.ParamByName('Nam').AsString := 'String';
OraSQL1.Execute;
ref := OraSQL1.ParamByName('Res').AsRef;
ref.Pin;
OraSQL2.ParamByName('obj').AsRef := ref;
OraSQL2.ParamByName('Val').AsFloat := 100;
OraSQL2.Execute;
ref.Unpin;
-
- Posts: 9
- Joined: Thu 29 Jun 2006 14:04
Thanks. It's work, but I got another trouble.
If I wrap thes code in cycle, I get Assertion in "OraObjects.pas, line 2522" on second pass on line of code
Can I use repeatedly same TOraSQL components to insert several rows with different params?
Thanks.
PS
I confused, that this approach read object in cache by call Pin, when I need only it's ref. May be there is another method?
If I wrap thes code in cycle, I get Assertion in "OraObjects.pas, line 2522" on second pass on line of code
Code: Select all
ref.Pin
Thanks.
PS
I confused, that this approach read object in cache by call Pin, when I need only it's ref. May be there is another method?
To repeatedly use same TOraRef object for parameter call FreeObject method of TOraRef after calling Unpin.
When using REF input parameter OCI requires referenced object to be in cache. If you don't want to pin objects you shouldn't use REF parameters. In your case you can combine two SQL statements in one PL/SQL block.
Code: Select all
ref.Unpin;
ref.FreeObject;
-
- Posts: 9
- Joined: Thu 29 Jun 2006 14:04
plash wrote:To repeatedly use same TOraRef object for parameter call FreeObject method of TOraRef after calling Unpin.When using REF input parameter OCI requires referenced object to be in cache. If you don't want to pin objects you shouldn't use REF parameters. In your case you can combine two SQL statements in one PL/SQL block.Code: Select all
ref.Unpin; ref.FreeObject;
There is no needs to call ref.FreeObject; now?5.70.1.34 07.07.06
------------------
....
- Unpin method of TOraRef corrected
....