On 02/16/2012 06:01 PM, Neil Morgenstern wrote: > The issue is that when you bind the result you are actually binding a > pointer to a contiguous buffer, not a C++ object. > So actually it's &vec[0] that is being bound. If a vector is resized > upward then &vec[0] would change > and the pointers would no longer be valid. > > Once the results are read in the vectors can be resized down for you > just to inform you how many were actually returned. > The fact that you get fewer results than your buffer size doesn't mean > there aren't more results, just that there are no > more results ready at present. Remember the database doesn't necessarily > return all its results at once. Therefore > you can resize your vectors at this point but when a vector does a > resize down it doesn't reduce the capacity therefore > if you resize it back up again the pointers won't actually change. The > size is a logical size, i.e. indicates the number of > rows populated. > > Note that a vector must be resized even to write into the memory > directly. You can't rely on reserve. > >
Hi Neil, thanks for explaining that. I thought perhaps SOCI was doing a push_back or similar - expensive I guess... So perhaps I would need to create any of my queries that return a set to only return a certain sized result set. I think I can figure out how to write the SQL for that, but I was thinking perhaps SOCI already has that functionality. I guess that would require some kind of DAL. Seeing as it does abstract away certain things like 'prepare', it seems that SOCI does have at least some of this functionality. Is SOCI able to abstract away reading rowsets and provide some kind of interface for that? Or must I craft the SQL and keep reading results until I get back a result set smaller than what I initialized the vector to? Are there any other best practices? Many thanks, Simon -- simonsmicrophone.com ------------------------------------------------------------------------------ Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ _______________________________________________ Soci-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/soci-users
