[odb-users] Prepared statement feature

Stath, Paul pstath at axxcelera.com
Tue Oct 2 08:07:26 EDT 2012


Boris --

Thanks for explaining the connection/multi-threading issue more fully.
The ODB library does a really good job of handling connections and
multi-threading issues, and not passing these issues up to 
be handled by the developer.

My thinking was that the prepared_query<> class would work like a
factory class, creating the prepared query statement in each database
connection as necessary.  Thus hiding the connection/multi-threading aspects
of the connection, much like odb::<db>::connection_factory hides how
connection objects are obtained.

The prepared_query<> class would hold the query condition, and when
the execute method is called, would look up the prepared statement
in the current database connection, and if not present would prepare
and cache it in the connection, and finally execute it.
The next time that connection is used to execute the prepared query,
the prepared statement would already be in the cache, and the query
could be executed, skipping the prepare/cache steps.

It seems to me that there is no need to expose the lookup and cache
methods to the user, instead hide them inside the execute method of
the prepared query.

In the end, either method will work, and will allow the prepared
query statement to be cached, eliminating the expensive parse of
the query statement for every query.

Thanks for taking the time to discuss.

-- Paul



More information about the odb-users mailing list