I need to a allocate a 2D string array to return the results of the query to the caller. The query might be something like
Select * from files where size > x
The 2D array that I need to allocated is something like
std::string [x][y];
I know the number of columns but ofcourse I do not know how many rows will match the query. I have to allocated the memory before hand to put the result set.
I know I can execute a seperate query like, but that’s an overkill and there should be no need to execute a seperate query.
select count(*) from files where size > x
Perhaps a I can rethink a more dynamic 2D data structure to push the results ? I am not sure any ideas ?
Why not use a
std::vector < std::vector < std::string > >? That one can grow dynamically and the number of rows can be easily inspected viavector.size().Depending on how you’re executing your queries, sqlite does tell you the number of rows returned. For example, see here for
sqlite_get_table(): http://www.sqlite.org/c3ref/free_table.html . It returns the number of rows in*pnRow.