[odb-users] Odd behavior with 'results not cached' exception with mysql

Boris Kolpackov boris at codesynthesis.com
Fri Sep 28 08:54:49 EDT 2012


Hi Sean,

Stroud, Sean T <ststrou at sandia.gov> writes:

>     odb::result<My_Class> r( db->query<My_Class>(false) );
>     r.cache();
>
>     if ( make_it_fail )
>       for ( odb::result<My_Class>::iterator iter(r.begin()); iter != r.end(); ++iter );
> 
>     // If the for-loop above is executed, then this line will throw a 
>     // "results not cached" exception. Otherwise no exception will be
>     // thrown.
>     cout << r.size() << endl;

That's a bug (you seem to be particularly good at uncovering them ;-)).

What happens is we try to release the underlying result set as soon as
possible in order not to hold on to database resources unnecessarily.
So in this case, once we hit the end during iteration, we release the
result set immediately but with that we also loose the size information.

I've committed a fix and can package you libodb-mysql-2.0.1 if you would
like. There is also an easy work-around: simply query the size before
iteration:

size_t n (r.size ());

for ( odb::result<My_Class>::iterator iter(r.begin()); iter != r.end(); ++iter );

cout << n << endl;

I guess it is somewhat unusual to query the result set size after the
iteration. That's probably why we haven't heard about anyone running
into this bug before.

Boris



More information about the odb-users mailing list