Array DML and Timestamps leads to error

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jdorlon
Posts: 202
Joined: Fri 05 Jan 2007 22:07

Array DML and Timestamps leads to error

Post by jdorlon » Thu 06 Dec 2018 22:14

Hello,

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;

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Array DML and Timestamps leads to error

Post by MaximG » Mon 10 Dec 2018 16:14

Thank you for the information. We have reproduced the issue and will investigate its origin. We will inform you about the results shortly.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Array DML and Timestamps leads to error

Post by MaximG » Thu 13 Dec 2018 12:33

We reproduced the issue and fixed this error. The fix will be included in the next ODAC build. Currently, as a workaround, we can send you a night build with the required changes. For this, please specify the exact version of Delphi you are using via the e-support form ( https://www.devart.com/company/contactform.html )

jdorlon
Posts: 202
Joined: Fri 05 Jan 2007 22:07

Re: Array DML and Timestamps leads to error

Post by jdorlon » Thu 13 Dec 2018 16:59

Thank you Maxim.

Post Reply