sqlite3_step and number of results sqlite3_step and number of results sqlite sqlite

sqlite3_step and number of results


First of all: did you benchmark it? Is this the bottleneck? If no, then just stop worrying about efficiency and complexity now, and goto end of answer.

Still here? OK, so let me tell you one more thing: resizing the vector may be of any complexity, it's up to the implementor of the C++ standard library. It may be O(1), O(n), O(log n), etc. But one thing is sure: if you have got N results from the database, you ain't no going to retrieve the data in O(n). Simply because you have... N results.

So I think that you should still not worry about this - vector is fast (assuming a reasonably high-quality standard library implementation). So go ahead and write that while loop and push_back() the elements one after another and that's it.

But, if you are still being scared by the slowness of poor old vector, then here's how you find the number of rows returned from a query - this is specific to SQLite:

SELECT COUNT(*) FROM the_table WHERE some_condition;

Also, there are a few more possibilities, as described in answers to this question.