gmazza
asked on
OCI8: Retrieving row count after OCIStmtFetch()
I'm using OCI8 with VC++.
As a memory saver, OCIStmtFetch() automatically frees the statement handle after all rows are fetched. (I've verified that behavior in my code, and the Oracle OCI8 documentation for OCIStmtExecute() says that this happens with that call.)
But I am bulk record fetching (100 at a time), and the last iteration I need to know how many (37? 80?) were in that last batch.
Since the statement handle is freed after the last batch, I can't call OCIAttrGet to get the OCI_ATTR_ROW_COUNT attribute of the statement handle. So I have no idea how many of the retrieved rows are valid in the last batch. (For batches prior to the last, I will correctly get row count = 100, 200, 300, etc. What I'm trying to get is a last value of, say, 337. This is easy in OCI7.3, where the "rc" attribute of the Cda_Def structure held the row count even after the fetch was finished.)
Question:
1) How do I get the total row count after last batch of records has been retrieved, given that the statement handle is freed?
or:
2) How do I stop OCI's default behavior of freeing the statement handle when all rows have been retrieved, so I can retrieve the OCI_ATTR_ROW_COUNT attribute of the statement handle?
Thanks,
Glen Mazza
As a memory saver, OCIStmtFetch() automatically frees the statement handle after all rows are fetched. (I've verified that behavior in my code, and the Oracle OCI8 documentation for OCIStmtExecute() says that this happens with that call.)
But I am bulk record fetching (100 at a time), and the last iteration I need to know how many (37? 80?) were in that last batch.
Since the statement handle is freed after the last batch, I can't call OCIAttrGet to get the OCI_ATTR_ROW_COUNT attribute of the statement handle. So I have no idea how many of the retrieved rows are valid in the last batch. (For batches prior to the last, I will correctly get row count = 100, 200, 300, etc. What I'm trying to get is a last value of, say, 337. This is easy in OCI7.3, where the "rc" attribute of the Cda_Def structure held the row count even after the fetch was finished.)
Question:
1) How do I get the total row count after last batch of records has been retrieved, given that the statement handle is freed?
or:
2) How do I stop OCI's default behavior of freeing the statement handle when all rows have been retrieved, so I can retrieve the OCI_ATTR_ROW_COUNT attribute of the statement handle?
Thanks,
Glen Mazza
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What happened is that I just had a single scalar variable (and not the necessary array) for the null indicator column in the define statement. So when I fetched several rows, it overwrote nearby variables--including the statement handle--declared in the class definition. Bug fixed.