AnyDAC
ContentsIndexHome
PreviousUpNext
TADAdaptedDataSet.NextRecordSet Method

Go to the next cursor, returned by the SQL command.

Group
Links

The NextRecordSet method closes current cursor, forwards it to the next accessible cursor and opens dataset. If there is no more accessible cursors, then after call dataset is closed. See "Command Batches" chapter for more details. 

The Close method closes current cursor. The CloseAll method call discards all associated cursors. So, to get all cursors, you should set FetchOptions.AutoClose to False before opening dataset. 

For AnyDAC the Oracle and PostgreSQL REF CURSOR is a command cursors, and a NextRecordSet call will select the next REF CURSOR parameter. For SQL Server, Sybase SQL Anywhere, MySQL, etc a NextRecordSet call will select next result set, produced by batch, stored procedure or how else. 

In design time, you can forward dataset to the next cursor, by right clicking component and choosing the "Next record set" popup menu item. See the "Executing Command" chapter for more details.

procedure NextRecordSet;
ADQuery1.FetchOptions.AutoClose := False;
ADQuery1.SQL.Text := 'select 1 as i; select ''qwe'' as s';
ADQuery1.Open;
ShowMessage(ADQuery1.Fields[0].FieldName + ' ' + ADQuery1.Fields[0].AsString); // output "i 1"
ADQuery1.NextRecordSet;
ShowMessage(ADQuery1.Fields[0].FieldName + ' ' + ADQuery1.Fields[0].AsString); // output "s qwe"
ADQuery1.Close;

See AnyDAC\Samples\Comp Layer\TADStoredProc\Oracl_NextRecordSet demo for details of how to work with Oracle stored procedure, returning multiple REF CURSOR's.

What do you think about this topic? Send feedback!