A reference represents a semantic connection between tables. More...
#include <reference.h>
Public Types | |
typedef std::vector< const Reference * > | List |
Public Member Functions | |
Reference (const Table::Ref &from_table, std::vector< const Dv::Sql::Column * > from_columns, const Table::Ref &to_table, std::vector< const Dv::Sql::Column * > to_columns) throw (std::logic_error) | |
Constructor. | |
~Reference () | |
Destructor. | |
size_t | to (size_t i) const |
The index of the i'th column in the list of target table columns. | |
size_t | from (size_t i) const |
The index of the i'th column in the list of source table columns. | |
size_t | size () const |
The number of columns in each list. | |
const SelectExp & | match () const |
Return an SQL "where" condition expressing that corresponding column values should match. | |
operator SelectExp () const | |
SelectExp | match_source (const Object &source) const throw (std::logic_error) |
Return an SQL "where" condition expressing that the source column values of the source table should match those of the parameter object. | |
SelectExp | match_target (const Object &target) const throw (std::logic_error) |
Return an SQL "where" condition expressing that the target column values of the target table should match those of the parameter object. | |
Public Attributes | |
const Table::Ref & | from_table |
The source table of the reference. | |
const Table::Ref & | to_table |
The target table of the reference. | |
Private Attributes | |
std::vector< const Dv::Sql::Column * > | from_ |
The columns in the source table of the reference. | |
std::vector< const Dv::Sql::Column * > | to_ |
The columns in the target table of the reference. | |
SelectExp * | select_exp |
A reference represents a semantic connection between tables.
It consists of two tables, a source and target table and a list of columns in each table. Both lists should have equal length and the corresponding data types of the columns in both lists should agree.
A reference can be followed, e.g. if an object corresponds to a row in the source table, then an object(s) in the target table may be obtained by copying the column values from the source object to a target object and then find all objects in the target table matching the target object. Similarly, a reference can be followed in the "reverse" direction. Note that there is no requirement that a reference is single valued, e.g. there may be many target table rows corresponding to a single source table row.
References are supported by Object and Row as well as by the Object::Set and Row::Set classes.
const Dv::Sql::Reference acct_cust( Database::account, (cols = &Account::customer_id), Database::customer, (cols = &Customer::id) ); Object cust(..); // all accounts of this customer Object::Set::Ref accounts = cust.references(acct_cust);
In addition, reference can be used to generate Dv::Sql::SelectExp objects and queries using the member functions Dv::Sql::Reference::match Dv::Sql::Reference::match_source and Dv::Sql::Reference::match_target .
const Dv::Sql::Reference acct_cust( Database::account, (cols = &Account::customer_id), Database::customer, (cols = &Customer::id) ); const Dv::Sql::Reference trans_acct( Database::transaction, (cols = &Transaction::account_code), Database::account, (cols = &Account::code) ); Dv::Sql::SelectExp e = acct_cust.match_target(cust) && acct_cust.match() && trans_acct.match(); // transs contains all transactions associated with accounts from customer @p cust Transaction::Set transs(e);
Definition at line 73 of file reference.h.
typedef std::vector<const Reference*> Dv::Sql::Reference::List |
Definition at line 75 of file reference.h.
Dv::Sql::Reference::Reference | ( | const Table::Ref & | from_table, | |
std::vector< const Dv::Sql::Column * > | from_columns, | |||
const Table::Ref & | to_table, | |||
std::vector< const Dv::Sql::Column * > | to_columns | |||
) | throw (std::logic_error) |
Constructor.
from_table | source table of the reference | |
from_columns | list of columns in from_table | |
to_table | target table of the reference | |
to_columns | list of columns in the target table |
std::logic_error | if from_columns has a different size from to_columns | |
std::logic_error | if from_columns has size 0 |
In the example below: the constructor will succeed even before Database::account and Account::customer_id have been initialized, but the resulting acct_cust
should not be used until they have been initialized.
const Dv::Sql::Reference acct_cust( Database::account, (cols = &Account::customer_id), Database::customer, (cols = &Customer::id) );
Dv::Sql::Reference::~Reference | ( | ) |
Destructor.
size_t Dv::Sql::Reference::to | ( | size_t | i | ) | const [inline] |
The index of the i'th column in the list of target table columns.
i | the position in the list of target table columns. |
Definition at line 124 of file reference.h.
References to_.
Referenced by Dv::Sql::Set< Row< database_table > >::Set().
size_t Dv::Sql::Reference::from | ( | size_t | i | ) | const [inline] |
The index of the i'th column in the list of source table columns.
i | the position in the list of source table columns. |
Definition at line 130 of file reference.h.
References from_.
Referenced by Dv::Sql::Set< Row< database_table > >::Set().
size_t Dv::Sql::Reference::size | ( | ) | const [inline] |
The number of columns in each list.
Definition at line 135 of file reference.h.
References from_.
Referenced by Dv::Sql::Set< Row< database_table > >::Set().
const SelectExp& Dv::Sql::Reference::match | ( | ) | const |
Return an SQL "where" condition expressing that corresponding column values should match.
const Dv::Sql::Reference acct_cust( Database::account, (cols = &Account::customer_id), Database::customer, (cols = &Customer::id) ); const Dv::Sql::Reference trans_acct( Database::transaction, (cols = &Transaction::account_code), Database::account, (cols = &Account::code) ); Dv::Sql::SelectExp e = acct_cust.match_target(cust) && acct_cust.match() && trans_acct.match(); // transs contains all transactions associated with accounts from customer @p cust Transaction::Set transs(e);
Referenced by operator SelectExp().
Dv::Sql::Reference::operator SelectExp | ( | ) | const [inline] |
Definition at line 158 of file reference.h.
References match().
Return an SQL "where" condition expressing that the source column values of the source table should match those of the parameter object.
source | object whose column values will be used to restrict the column values of source table objects. This object should represent a row in the source table. |
std::logic_error | if the source object's arity does not match the from_table's. |
Return an SQL "where" condition expressing that the target column values of the target table should match those of the parameter object.
target | object whose column values will be used to restrict the column values of target table objects. This object should represent a row in the target table. |
std::logic_error | iff the target object's arity does not match the to_table's. |
The source table of the reference.
Definition at line 115 of file reference.h.
The target table of the reference.
Definition at line 117 of file reference.h.
std::vector<const Dv::Sql::Column*> Dv::Sql::Reference::from_ [private] |
The columns in the source table of the reference.
Definition at line 189 of file reference.h.
std::vector<const Dv::Sql::Column*> Dv::Sql::Reference::to_ [private] |
The columns in the target table of the reference.
Definition at line 191 of file reference.h.
Referenced by to().
SelectExp* Dv::Sql::Reference::select_exp [private] |
Definition at line 192 of file reference.h.
dvmysql-1.0.3 | [17 November, 2010] |