How to bulk fetch a search result
Posted in 2000
Topics: Connectivity: ODBC / JDBC / .NET
Hello folks
Running Informix Dynamic Server 9.14 TC6 on NT 4.
Using Intersolv 3.11 32 bit Informix9 ODBC driver
Using CRecordset from the MFC library and Visual C++
Any idee about how to fetch only a part of a result from an sql statement?
Say that I have a sql statement that returns 1000 rows.
I want to fetch the result of that statement in bulks of 100.
And I do not want the server to transferr the data from 1-900 when I'm doing
the last call, I only want the last 100 rows.
(A paging mechanics as the one you see at the large search sites, as alta
vista)
The way I would like to solve this using C++ and MFC is:
CString OnUserRequest(int iFrom, int iTo)
{
CString strRet;
CMyRecordsSet rs("Select * from largetable where col1 = "blabla");
rs.Open();
rs.MoveTo(iFrom);
for(int counter = iFrom; counter < iTo && !rs.EOF(); counter++){
strRet += rs.GetRecord();
rs.MoveNext();
}
}
In theory this should work, the problem is that when using Informix, all the
records is transferred at the time you call rs.Open, and not when you
actually try to fetch data.
So to go around this I want to modify the sql statement, to something like
this
select * from largetable where col1 = "blabla" fetch [x to y]
where x is the value of iFrom and y is the value of iTo
Does anyone know if this is possible, and if it is, how can i do it?
Regars Trond-Eirik