[odb-users] Prepared statement feature

Stath, Paul pstath at axxcelera.com
Fri Sep 28 10:04:18 EDT 2012


I am interested, however I'm also not wild about the usage scenario from that previous email.

You state the two issues with caching queries is storing the query condition as well as any
by-reference parameters.

I'm imagining an abstract ODB prepared query class that can be extended by the programmer with
the query parameter fields.

The odb::pquery would provide an abstract base class that would have an init_query() method.
The init_query() method would be responsible for specifying the condition of the query, and would
be called during construction.

The odb::database would have a factory method for creating pquery objects, and the db->query() method
would be overloaded to take both odb::query and odb::pquery objects.
By creating the pquery object via a factory method, you can store the statement directly in the
pquery object and also save a pointer to the database so that when the deconstructor for the pquery
object is called, it can remove the prepared query from the database session.

The prepared query would typically be defined in the same translation unit as the object the
prepared query returns.  (i.e. person.hxx)

class age_pquery : public odb::pquery<person>
{
    public:
    unsigned short age_;

    private:
    init_query() {
        query (query::age < query::_ref(age_));
    }
}

In the program, I would create the prepared query as follows:

   age_pquery apq (odb::pquery<age_pquery>();

Later, I would execute the query by setting the parameter values and
passing the pquery to the db.

   apq.age = 34;
   result r (db->query<person> (age_pquery));

-- Paul

> -----Original Message-----
> From: Boris Kolpackov [mailto:boris at codesynthesis.com]
> Sent: Friday, September 28, 2012 6:57 AM
> To: Stath, Paul
> Cc: odb-users at codesynthesis.com
> Subject: Re: [odb-users] Prepared statement feature
> 
> Hi Paul,
> 
> Stath, Paul <pstath at axxcelera.com> writes:
> 
> > It there a timeline for when prepared statements as described in
> > http://www.codesynthesis.com/pipermail/odb-users/2012-
> January/000434.html
> > might be available/released?
> 
> It is on our TODO list but there is no definite timeline. Generally, we
> assign higher priority to features that someone is willing to start
> using
> immediately (i.e., test a pre-release, give feedback, etc). So if you
> are
> interested, we can implement something for you to try.
> 
> And speaking of feedback, what do you think about the usage scenario
> shown in that email? Will that fit with what you are trying to do? To
> me personally it feels a bit awkward.
> 
> Boris



More information about the odb-users mailing list