Size of data retrieved from SQL query via ODBC API
Does anyone know how I can get the number of items (* cols rows) returned after executing the SQL query? If this cannot be done, then is there something that is relatively consistent with the size of the data I am returning?
I'm trying to create a status bar that indicates how much of the returned data I've processed, so I want to be somewhere relatively close. Any ideas?
Note that SQLRowCount only returns the number of rows that are affected by an UPDATE, INSERT, or DELETE statement; not the number of rows returned from the SELECT statement (as far as I can tell). Therefore, I cannot multiply this directly by SQLColCount.
My last option is to have a status bar that goes back and forth indicating that the data is being processed.
source to share
This is often a problem when you want to reserve heap to store the entire result set.
One way is to return the score as part of the result set.
WITH
data AS
(
SELECT interesting-data
FROM interesting-table
WHERE some-condition
)
SELECT COUNT(*), data.*
from data
If you do not know in advance which columns you are choosing or use * as in the example above, then the number of columns can be selected from the USER_TAB_COLS table
SELECT COUNT(*)
FROM USER_TAB_COLS
WHERE TABLE_NAME = 'interesting-table'
source to share
SQLRowCount can return row count for SELECT queries if the driver supports it. However, many drivers do not work because it can be costly for the server to figure it out. If you want to ensure that you always have an account, you must use COUNT (*), forcing the server to do a potentially time-consuming calculation (or forcing it to delay returning any results until the entire result is known).
My suggestion is to try SQLRowCount so the server or driver can decide if the row count is easy to calculate. If it returns, then multiply the result by SQLNumResultCols. Otherwise, if it returns -1, use the back and forth status bar. Sometimes it's better because you can be more responsive to the user.
source to share