Boost logo

Boost :

Subject: Re: [boost] Boost.SQL?
From: Roland Bock (rbock_at_[hidden])
Date: 2010-09-14 10:54:19

On 09/14/2010 04:29 PM, Mathias Gaunard wrote:
> On 14/09/10 14:26, Roland Bock wrote:
>> std::vector<record> records =
> It probably should just return a range rather than a vector.

Yes, thanks for the hint :-)

>> sql::where(t::id() > 1000 && t::first_name() == name),
>> sql::order_by(t::priority()(sql::desc)),
>> sql::limit(17));
> Have you considered using Proto to define and check the grammar of
> that language?

Yes, but I would need support for that. I admit that (as of today) Proto
is too hard to understand for me.

>> // the values can be accessed by their name
>> // and are of the correct type, e.g.
>> records.front().first_name_; // is a string
>> records.front().middle_name_; // optional<string> because the table
>> definition says that it can be NULL
> How are first_name/middle_name/priority/id attached to the record type?

Via inheritance. The table struct contains a mpl::set of types
describing the columns, e.g.

// ---------------------------------------
struct Id: public sql::type<my_table, Id, sql::serial, sql:primary_key>
    Id(): id_(Id::get_default_value()) {}
    Id(const typename Id::value_type& value): id_(value) {}

    static const char* get_name() { return "id"; }

    typename Id::value_type id_;
// --------------------------------------

The record inherits from the columns of my_table and thus has id_ as a

Instead of getting ALL columns from my_table, you could also typedef a
record like this:

typedef sql::record<my_table, my_table::first_name, my_table::last_name>

In this case, trying to access record.id_ would lead to a compile error,
since it is simply not available.



Boost list run by bdawes at, gregod at, cpdaniel at, john at