A Dv::Sql::Set<T> represents a set of T-objects retrieved from the database. More...
#include <set.h>
Public Types | |
typedef Dv::shared_ptr< Set< T > > | Ref |
Type of a reference-counted pointer to a set. | |
typedef std::vector < Dv::shared_ptr< T > > | Container |
The underlying container type, which contains reference counted pointers to T-objects. | |
typedef Container::const_iterator | const_iterator |
typedef Container::const_reverse_iterator | const_reverse_iterator |
typedef Container::iterator | iterator |
typedef Container::reverse_iterator | reverse_iterator |
Public Member Functions | |
Set (Dv::Sql::Command &q) throw (std::logic_error) | |
Initialize a set using the result of a query. | |
Set (Dv::Sql::Db &db, const std::string &prefix, SelectExp select_exp=SelectExp(new Dv::Sql::true_boolexp()), const std::string &rest="") throw (std::logic_error) | |
Initialize a set using the result of a query. | |
Set (const Dv::Sql::Table::Ref &table, SelectExp select_exp=SelectExp(new Dv::Sql::true_boolexp()), const std::string &rest="") throw (std::logic_error) | |
Initialize a set using the result of a query. | |
Set (const T &t, const std::string &rest="") throw (std::logic_error) | |
Initialize the set with all objects that match the dirty column values in t . | |
template<typename Source > | |
Set (const Source &target, const Dv::Sql::Reference &reference, const std::string &rest="") throw (std::logic_error) | |
Initialize a set to contain all source objects that are linked via a Reference to a given target object. | |
size_t | set (Dv::Sql::Command &q) throw (std::logic_error) |
Append the result of a query to this set. | |
const_reverse_iterator | rbegin () const |
const_reverse_iterator | rend () const |
const_iterator | begin () const |
const_iterator | end () const |
size_t | size () const |
template<typename C > | |
void | get (size_t i, C &container, const_iterator i0, const_iterator i1) const throw (std::logic_error) |
Retrieve a column value for all objects in this set. | |
template<typename C > | |
void | get_insert (size_t i, C &container, const_iterator i0, const_iterator i1) const throw (std::logic_error) |
Retrieve a column value for all objects in this set. | |
template<typename C > | |
void | get (size_t i, C &container) const throw (std::logic_error) |
template<typename C > | |
void | get (const Table::Column &c, C &container) const throw (std::logic_error) |
template<typename C > | |
void | get (const std::string &col_name, C &container) const throw (std::logic_error) |
void | append (const Set< T > &source) |
Private Attributes | |
Container | objects_ |
A Dv::Sql::Set<T> represents a set of T-objects retrieved from the database.
Normally, the template parameter is derived from Dv::Sql::Object.
Definition at line 24 of file set.h.
typedef Dv::shared_ptr<Set<T> > Dv::Sql::Set< T >::Ref |
typedef std::vector<Dv::shared_ptr<T> > Dv::Sql::Set< T >::Container |
typedef Container::const_iterator Dv::Sql::Set< T >::const_iterator |
typedef Container::const_reverse_iterator Dv::Sql::Set< T >::const_reverse_iterator |
typedef Container::iterator Dv::Sql::Set< T >::iterator |
typedef Container::reverse_iterator Dv::Sql::Set< T >::reverse_iterator |
Dv::Sql::Set< T >::Set | ( | Dv::Sql::Command & | q | ) | throw (std::logic_error) [inline] |
Dv::Sql::Set< T >::Set | ( | Dv::Sql::Db & | db, | |
const std::string & | prefix, | |||
SelectExp | select_exp = SelectExp(new Dv::Sql::true_boolexp()) , |
|||
const std::string & | rest = "" | |||
) | throw (std::logic_error) [inline] |
Initialize a set using the result of a query.
The query is built using a prefix, usually of the form
select * from tablename where select_exp rest
std::string zip; // retrieve sorted list of ages of customers in a certain area, Dv::Sql::Set<Object> ages(db, "select age from customer where ", Customer::zip = zip and age > 10, "order by age");
db | database connection to use | |
prefix | of the query text | |
select_exp | condition to be used in the query text | |
rest | suffix of the query text |
std::logic_error | if executing the query fails |
Dv::Sql::Set< T >::Set | ( | const Dv::Sql::Table::Ref & | table, | |
SelectExp | select_exp = SelectExp(new Dv::Sql::true_boolexp()) , |
|||
const std::string & | rest = "" | |||
) | throw (std::logic_error) [inline] |
Initialize a set using the result of a query.
The query has the following form.
select table.c1, table.c2, .. , table.cn from table where select_exp rest
where (c1 .. cn) are all columns of table
.
Dv::Sql::Table::Ref customer; std::string zip; // list of customers in area ordered by age Dv::Sql::Set<Object> customers(customer, Customer::zip = zip and age > 10, "order by age");
table | database table to select from | |
select_exp | condition to be used in the query text | |
rest | suffix of the query text, may be 0 |
std::logic_error | if executing the query fails |
Dv::Sql::Set< T >::Set | ( | const T & | t, | |
const std::string & | rest = "" | |||
) | throw (std::logic_error) [inline] |
Dv::Sql::Set< T >::Set | ( | const Source & | target, | |
const Dv::Sql::Reference & | reference, | |||
const std::string & | rest = "" | |||
) | throw (std::logic_error) [inline] |
Initialize a set to contain all source objects that are linked via a Reference to a given target object.
Thus, this constructor follows the reference in the "reverse" direction (from target to source). Since, usually, references are (in the normal direction) many-to-one, the reverse mapping is one-to-many.
const Dv::Sql::Reference acct_cust( Database::account, (cols = &Account::customer_id), Database::customer, (cols = &Customer::id) ); Dv::Sql::Row<Database::customer> cust; cust.set(Customer::id, 1000); Dv::Sql::Set<Dv::Sql::Row<Database::account> > accounts(cust, acct_cust); // Now accounts contains all accounts for the given customer @p cust.
target | object whose column values will be copied to a source object, according to ref | |
reference | object describing ma |
std::logic_error | if the query fails. |
size_t Dv::Sql::Set< T >::set | ( | Dv::Sql::Command & | q | ) | throw (std::logic_error) [inline] |
const_reverse_iterator Dv::Sql::Set< T >::rbegin | ( | ) | const [inline] |
const_reverse_iterator Dv::Sql::Set< T >::rend | ( | ) | const [inline] |
const_iterator Dv::Sql::Set< T >::begin | ( | ) | const [inline] |
Definition at line 176 of file set.h.
Referenced by Dv::Sql::Set< Row< database_table > >::append(), and Dv::Sql::Set< Row< database_table > >::get().
const_iterator Dv::Sql::Set< T >::end | ( | ) | const [inline] |
Definition at line 177 of file set.h.
Referenced by Dv::Sql::Set< Row< database_table > >::append(), and Dv::Sql::Set< Row< database_table > >::get().
size_t Dv::Sql::Set< T >::size | ( | ) | const [inline] |
Definition at line 178 of file set.h.
Referenced by Dv::Sql::Set< Row< database_table > >::get(), and Dv::Sql::Set< Row< database_table > >::set().
void Dv::Sql::Set< T >::get | ( | size_t | i, | |
C & | container, | |||
const_iterator | i0, | |||
const_iterator | i1 | |||
) | const throw (std::logic_error) [inline] |
Retrieve a column value for all objects in this set.
i | index (0-based) of the column value to retrieve |
std::logic_error | if i exceeds the object's arity | |
std::logic_error | if the conversion from a string fails |
void Dv::Sql::Set< T >::get_insert | ( | size_t | i, | |
C & | container, | |||
const_iterator | i0, | |||
const_iterator | i1 | |||
) | const throw (std::logic_error) [inline] |
Retrieve a column value for all objects in this set.
i | index (0-based) of the column value to retrieve |
std::logic_error | if i exceeds the object's arity | |
std::logic_error | if the conversion from a string fails |
void Dv::Sql::Set< T >::get | ( | size_t | i, | |
C & | container | |||
) | const throw (std::logic_error) [inline] |
void Dv::Sql::Set< T >::get | ( | const Table::Column & | c, | |
C & | container | |||
) | const throw (std::logic_error) [inline] |
void Dv::Sql::Set< T >::get | ( | const std::string & | col_name, | |
C & | container | |||
) | const throw (std::logic_error) [inline] |
void Dv::Sql::Set< T >::append | ( | const Set< T > & | source | ) | [inline] |
Container Dv::Sql::Set< T >::objects_ [private] |
Definition at line 231 of file set.h.
Referenced by Dv::Sql::Set< Row< database_table > >::append(), Dv::Sql::Set< Row< database_table > >::begin(), Dv::Sql::Set< Row< database_table > >::end(), Dv::Sql::Set< Row< database_table > >::rbegin(), Dv::Sql::Set< Row< database_table > >::rend(), Dv::Sql::Set< Row< database_table > >::set(), and Dv::Sql::Set< Row< database_table > >::size().
dvmysql-1.0.3 | [17 November, 2010] |