
On Sat, Apr 15, 2006 at 10:19:30AM +0100, Reece Dunn <msclrhd@hotmail.com> 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'; } }
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