If I put a TOraSession, a TOraSQL, and a TSmartQuery on a form, and put the below code the FormCreate event handler, I get the following error: TOraTimeStamp.Free RefCount = 0 (C:\.....MemData.pas, line 8811).
Rad Studio 10.1. Berlin
ODAC version 10.3.8
Oracle client version 12.2 but I don't think it matters
Oracle server 12.1 but I don't think it matters
Code: Select all
var
i: Integer;
ArrayLength: Integer;
begin
// Connect to Server
OraSession1.Username := 'JDORLON';
OraSession1.Password := 'jdorlon';
OraSession1.Server := 'azure_12c_plug';
OraSession1.LoginPrompt := False;
OraSession1.Connect;
// Drop tables if they exist
SmartQuery1.sql.add('drop table ts_test');
try
SmartQuery1.execute;
except
end;
SmartQuery1.sql.clear;
SmartQuery1.sql.add('drop table ts_test2');
try
SmartQuery1.execute;
except
end;
// create tables again.
SmartQuery1.sql.clear;
SmartQuery1.sql.add('create table ts_test (a_ts timestamp(9))');
SmartQuery1.execute;
SmartQuery1.sql.clear;
SmartQuery1.sql.add('create table ts_test2 (a_ts timestamp(9))');
SmartQuery1.execute;
// insert 100 rows into one of the tables
OraSQL1.sql.add('insert into ts_test (a_ts) values (:Param1)');
ArrayLength := 100;
OraSQL1.ArrayLength := ArrayLength;
OraSQL1.ParamByName('Param1').DataType := ftOraTimestamp;
OraSQL1.ParamByName('Param1').ParamType := ptInput;
for i := 1 to ArrayLength do // y m d h m s fs
OraSQL1.ParamByName('Param1').ItemAsTimeStamp[i].Construct(2016, 2, 8, 9, 46, 30, i, '');
OraSQL1.execute(ArrayLength);
OraSQL1.Session.Commit;
// select the rows just inserted
SmartQuery1.sql.clear;
smartQuery1.SQL.Add('select * from ts_test');
SmartQuery1.Execute;
// try to insert them into the other table.
OraSQL1.SQL.Clear;
ArrayLength := 10;
OraSQL1.ArrayLength := ArrayLength;
OraSQL1.sql.add('insert into ts_test2 (a_ts) values (:Param1)');
OraSQL1.ParamByName('Param1').DataType := ftOraTimestamp;
OraSQL1.ParamByName('Param1').ParamType := ptInput;
// The second time through this loop, an error is thrown.
i := 1;
while not smartquery1.eof do
begin
OraSQL1.ParamByName('Param1').ItemAsTimeStamp[i] := SmartQuery1.GetTimeStamp('A_TS');
if i < ArrayLength then
i := i + 1
else
begin
OraSQL1.Execute(ArrayLength);
i := 1;
end;
SmartQuery1.Next;
end;
OraSQL1.Session.Commit;
end;