I am writing a small application server for DB2(AS/400) on C/CLI.
Is there any way to get a number of rows in result after select but before the whole circle of fetch operations?
If you mean the number of rows in a cursor, then I think you would have to submit two queries. First query (not in a cursor) that only selects count(*), but has same predicates. Second query would be the normal cursor that is fetched one row at a time.
The reason is that DB2 does not always know the entire number of rows in the cursor until you fetch them (unless cursor materialization is necessary to return the first row). In some cases, depending on the isolation level, the answer set could change between the first fetch and the last fetch.