
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 :-)
db.select<record>( 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 member. 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> record; In this case, trying to access record.id_ would lead to a compile error, since it is simply not available. Regards, Roland