Boost logo

Boost :

From: Jonathan de Halleux (dehalleux_at_[hidden])
Date: 2003-09-11 06:55:44


Ok, the example was too trivial.

Suppose that I add a products struct and a product_id to the order struct:

struct order
{
      int id;
      int client_id; // foreign key to client
      int product_id; // foreign key to product
      bool operator<(const order& o)const{return id<o.id;}
};
struct product
{
     int id;
}

I define another set to products. How do I perform joins on those three
sets ? For example,

get all the order done by a client c and of a product p ? :)
I've seen in ex. 3 that you define some kind of intermediary view. Is there
a way to "automate" that ?

At 13:00 11/09/2003 +0200, you wrote:

>Jonathan de Halleux ha escrito:
>
> > [snipped]
> >
> > Very (very) interresting. I know you mention that "it is not intended to
> > provide a full-fledged relational database framework" but could it be
> > possible to support basic join operations.
> >
> > Suppose that we have:
> >
> > struct client
> > {
> > int id;
> > bool operator<(const client& e)const{return id<e.id;}
> > };
> >
> > struct order
> > {
> > int id;
> > int client_id; // foreign key to client
> > bool operator<(const order& o)const{return id<o.id;}
> > };
> >
> > Ok, so the indexed sets for these would be:
> > typedef indexed_set<
> > client,
> > index_list<
> > unique<identity<client>
> > >
> > > client_set;
> >
> > typedef indexed_set<
> > order,
> > index_list<
> > unique<identity<order> >,
> > non_unique< tag<client>, member<order,int,&employee::client_id> > >
> > > order_set;
> >
> > Now that I have my two sets, I would like to get all the orders done by a
> > particular client ?
> >
>
>There is no join going on here. Once you have the id for the client
>you only have to do something like:
>
>order_set os;
>...
>order_set::iterator_type<client>::type it0,it1;
>boost::tuples::tie(it0,it1)=os.equal_range(id);
>
>Take a look at example 3 in the docs for a more elaborate
>search using intermediate results. Maybe the kind of ops you're
>after can be coded with similar techniques.
>
>Joaquín M López Muñoz
>Telefónica, Investigación y Desarrollo
>
>_______________________________________________
>Unsubscribe & other changes:
>http://lists.boost.org/mailman/listinfo.cgi/boost

-----------------------------------------------------------------------------------
Jonathan de Halleux, Research Assistant
Center for Systems Engineering and Applied Mechanics (CESAME)
Universite catholique de Louvain
Batiment Euler , Av. Georges Lemaitre, 4 Tel : +32-10-47 2595
B-1348 Louvain-la-Neuve Belgium
E-mail : dehalleux_at_[hidden]
-----------------------------------------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk