after sqlite3_prepare_v2() of statement, need sqlite3_step() it.
for moment, let's ignore return values except sqlite3_row , sqlite3_done.
as long return value of sqlite3_step() sqlite3_row, need keep calling it, till results. last return value sqlite3_done.
i'm entering results std::vector using push_back().
from i've read, should have average complexity of o(log(n)) due resizing of internal array of vector. in order reduce complexity o(1), need use reserve() of vector, before doing push_back().
but sqlite3 api, can't see function returns total number of results get, before sqlite3_step() it.
how can sqlite3?
first of all: did benchmark it? bottleneck? if no, stop worrying efficiency , complexity now, , goto end of answer.
still here? ok, let me tell 1 more thing: resizing vector may of complexity, it's implementor of c++ standard library. may o(1), o(n), o(log n), etc. 1 thing sure: if have got n results database, you ain't no going retrieve data in o(n). because have... n results.
so think should still not worry - vector fast (assuming reasonably high-quality standard library implementation). go ahead , write while loop , push_back() elements 1 after , that's it.
but, if still being scared slowness of poor old vector, here's how find number of rows returned query - specific sqlite:
select count(*) the_table some_condition; also, there few more possibilities, described in answers this question.
Comments
Post a Comment