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

Stroud, Sean T ststrou at sandia.gov
Fri Sep 28 10:25:59 EDT 2012


Hi Boris,

Thanks for the explanation - makes sense.  No need for a special package, the workaround you suggested is good enough for what I'm doing.

Thanks!

Sean

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Friday, September 28, 2012 6:55 AM
To: Stroud, Sean T
Cc: odb-users at codesynthesis.com
Subject: [EXTERNAL] Re: [odb-users] Odd behavior with 'results not cached' exception with mysql

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