|
Boost : |
From: Andreas Pokorny (andreas.pokorny_at_[hidden])
Date: 2006-04-15 17:15:13
On Sat, Apr 15, 2006 at 10:19:30AM +0100, Reece Dunn <msclrhd_at_[hidden]> wrote:
> Steve Hutton wrote:
> > The idea is that to select all rows, you fetch within a loop. The
> > vector gets resized to contain the number of rows returned.
> >
> > const int BATCH_SIZE = 30;
> > std::vector<int> valsOut(BATCH_SIZE);
> > Statement st = (sql.prepare << "select value from numbers",
> > into(valsOut));
> > st.execute();
> > while (st.fetch())
> > {
> > std::vector<int>::iterator pos;
> > for(; pos != valsOut.end(); ++pos)
> > {
> > cout << *pos << '\n';
> > }
> > }
> >
> > http://soci.sourceforge.net/doc/statements.html
>
> How abouit something like:
>
> sql::statement query;
> query << "select value from numbers";
>
> sql::rowset< int > rows(query);
> cout << "found = " << rows.size() << endl;
>
> std::vector< int > values;
> std::copy( rows.begin(), rows.end(), values );
>
> Multi-item row searches could use tuple:
>
> sql::rowset< int, std::wstring, int > rows( query );
> std::tr1::tuple< int, std::wstring, int > value = rows.begin();
Slightly offtopic, but what about something like:
using std::sql::select;
using std::sql::from;
auto query = select >> value >> from >> numbers;
typedef decltype(query)::tuple_type tuple_type;
sql::rowset<tuple_type> rows(query,db);
...
or maybe a more generic reational syntax...
Regards
Andreas Pokorny
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk