#include <Wt/DboQuery>
Public Member Functions | |
~Query () | |
Destructor. | |
template<typename T> | |
Query< Result > & | bind (const T &value) |
Binds a value to the next positional marker. | |
Result | resultValue () const |
Returns a unique result value. | |
collection< Result > | resultList () const |
Returns a result list. | |
operator Result () const | |
Returns a unique result value. | |
operator collection< Result > () const | |
Returns a result list. |
A query will be used to fetch objects of class Result
.
Simple queries can be done using Session::find(), while more elaborate queries (with arbitrary result types) using Session::query().
You may insert positional holders for parameters using '?', using bind().
The query result may be fetched using resultValue() or resultList().
Usage example:
typedef dbo::collection<dbo::ptr<Account> > Accounts; Query query = session.find<Account>("where balance > ?").bind(100000); Accounts accounts = query.resultList(); for (Accounts::const_iterator i = accounts.begin(); i != accounts.end(); ++i) std::cerr << "Name: " << i->name << std::end;
Caveat warning!
A query object should be used transiently: a query can be used only once (one call to resultValue() or resultList()), after which it becomes unusable. You should not try to keep a query object around. This behavior was chosen because in this way, we do not need to store bound arguments and they are immediately passed on to the underlying prepared statement.
Query< Result > & Wt::Dbo::Query< Result >::bind | ( | const T & | value | ) | [inline] |
Binds a value to the next positional marker.
This binds the value
to the next positional marker. When this is the first bind() call, the statement is first prepared.
You should only bind arguments after the query is complete.
Result Wt::Dbo::Query< Result >::resultValue | ( | ) | const [inline] |
Returns a unique result value.
You can use this method if you are expecting the query to return at most one result. If the query returns more than one result a NoUniqueResultException is thrown.
After a result has been fetched, the query can no longer be used.
collection< Result > Wt::Dbo::Query< Result >::resultList | ( | ) | const [inline] |
Returns a result list.
This returns a collection which is backed by the underlying query. The query is not executed until this collection is traversed.
After a result has been fetched, the query can no longer be used.
Wt::Dbo::Query< Result >::operator Result | ( | ) | const [inline] |
Returns a unique result value.
This is a convenience conversion operator that calls resultValue().
Wt::Dbo::Query< Result >::operator collection< Result > | ( | ) | const [inline] |
Returns a result list.
This is a convenience conversion operator that calls resultList().