MATLAB: How to determine whether all records in the database have been retrieved using the Database Toolbox

cursordatabaseDatabase Toolboxexecfetchnumberrecordsterminate

I am using FETCH from the Database Toolbox and including the RowLimit argument so that only a certain number of records are returned, as follows:
cur = fetch(cur,5);
However, I would like to be able to first check the cursor object to see if all the records have been returned. For example, I might place FETCH within a WHILE loop to be sure that I retrieve all the records. I need to know how to condition this loop.

Best Answer

This change has been incorporated into the documentation in Release 14 Service Pack 3 (R14SP3). For previous releases, read below for any additional information:
When all of the records associated with a cursor object have been retrieved, the cursor object's "Data" field is set to 'No Data'. Use this condition to terminate a processing loop after all records of a query have been processed, as illustrated in this example:
function data = dbtest()
% The "test" database has one table (Table1) with one numeric field
conn = database('test','username','password')
cur = exec(conn, 'select * from Table1');
% number of records to retrieve on each FETCH
fetchSize = 3;
i = 1;
cur = fetch(cur,fetchSize);
while ~strcmp(cur.Data, 'No Data')
disp(['Fetch number ' num2str(i)])
i = i+1;
cur.Data{:}
cur = fetch(cur,fetchSize);
end
close(cur)
close(conn)