Hi
The optimal way is that you prepare the statement, fetch and count the results with sqlite3_step.
How would I "fetch and count" the results via sqlite3_step? Do you mean fetch all the records first? What if my result set is huge, and I would only like to show the first few records but still know how many there are? For exmaple, Lets say I run a SQL statement (its a very heavy statement consiting of joins and subqueries). It returns 5000 rows. For speed I dont want to retrieve 5000 rows, I want to setup a list which shows that there are 5000 rows on the scroll bar, but only retrieves the first say 20 for display. Is this possible? I know I can do a "select count(*) from (SQL)" but its a heavy query and then I would be running it twice? Any solution to this? S On 10/6/06, He Shiming <[EMAIL PROTECTED]> wrote:
> Hi List, > If I use sqlite3_exec to query a database, > How can I know that the results in the data base got over. For example If > I am expecting a 10 results in some for loop and actually there are only > five results , How can I get a notification or return value that the > results completed or Is there any way I can get SQLITE_DONE through > sqlite3_Exec. What return value I will get If I query an empty table. > > > Thanks and Regards, > Vivek R > SQLite didn't provide a "get number of rows" function for the result set. It is mentioned in the document that sqlite3_exec is actually a wrapper for sqlite3_prepare and sqlite3_step. It is in my opinion that sqlite3_exec should only be used when the result of the query isn't that important. For instance, a pragma query. For the record, sqlite3_exec did provide a callback function in which you can count and get the number of rows in a resultset. The optimal way is that you prepare the statement, fetch and count the results with sqlite3_step. Another thing I noticed from your question is that you might not want to "expect 10 results". It's not very wise to design a hard loop such as for(i=0;i<10;i++) when comes to a database query resultset. A better way would be to use an array to store the result set they way you could understand, and process them later. Then you'll have for(i=0;i<array.size()<10?array.size():10;i++). Best regards, He Shiming ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------