Does ODAC support cursor field type?

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
dados
Posts: 82
Joined: Thu 18 Aug 2005 14:06

Does ODAC support cursor field type?

Post by dados » Fri 14 Sep 2012 10:19

Hi,

This query returns one row and one field of type cursor.
Can ODAC read the data from that field?

select cursor(select 1,2,'Test' X from dual) TestCursorField from dual

bork
Devart Team
Posts: 649
Joined: Fri 12 Mar 2010 07:55

Re: Does ODAC support cursor field type?

Post by bork » Fri 14 Sep 2012 12:54

Hello

Yes, you can. Here is an example:

Code: Select all

begin
  OraQuery1.SQL.Text := 'select cursor(select 1,2,''Test'' X from dual) TestCursorField from dual';
  OraQuery1.Open;

  OraQuery2.Cursor := TCursorField(OraQuery1.Fields[0]).AsCursor;
  OraQuery2.Open;
end;

dados
Posts: 82
Joined: Thu 18 Aug 2005 14:06

Re: Does ODAC support cursor field type?

Post by dados » Fri 14 Sep 2012 13:33

Well, that was simple. Thanks :)

dados
Posts: 82
Joined: Thu 18 Aug 2005 14:06

Re: Does ODAC support cursor field type?

Post by dados » Fri 14 Sep 2012 14:19

If I open the cursor for the first time it will work. But when I try to open the cursor for the second time it will generate access violation. Is there a proper way to close it before the second open or some other refetch trick that will allow the second opening?

*EDIT* Calling OraQuery1.Refresh; will work for the second opening. I find this way rather brutal. Is there another more lightweight method to do this?

Code: Select all

begin
  OraQuery1.SQL.Text := 'select cursor(select 1,2,''Test'' X from dual) TestCursorField from dual';
  OraQuery1.Open;

  OraQuery2.Cursor := TCursorField(OraQuery1.Fields[0]).AsCursor;
  // Here the cursor is fetched
  OraQuery2.Open;

  //Does not matter if I close this
  OraQuery2.Close;

  // If I open the cursor for the second time I will get access violation
  OraQuery3.Cursor := TCursorField(OraQuery1.Fields[0]).AsCursor;
  OraQuery3.Open;

end;

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Does ODAC support cursor field type?

Post by AlexP » Mon 17 Sep 2012 08:56

Hello,

We cannot reproduce the error when re-opening the cursor on the latest ODAC version, please specify your ODAC version.
In addition, if you are trying to re-open the cursor not having closed it, you won't retrieve data in this case, as the cursor is already open and data is retrieved. Therefore, for retrieving data from the cursor again, you should preliminarily close it.
Closing and opening of DataSet takes place within the Refresh method, therefore calling the Refresh method is similar to calling the Open/Close methods, the only difference is that, when calling the Refresh method after opening DataSet, there occurs the positioning to the record, where the cursor was.

Post Reply