Dv::Sql::Row< database_table > Class Template Reference

A class template of which each instantiation class represents the rows of a relational table. More...

#include <row.h>

Inheritance diagram for Dv::Sql::Row< database_table >:
Inheritance graph
[legend]
Collaboration diagram for Dv::Sql::Row< database_table >:
Collaboration graph
[legend]

List of all members.

Classes

struct  Column
 A Row<T>::Column object should be considered as a reference to a Table::Column object. More...
class  Set
 A set of rows of this table. More...

Public Member Functions

 Row ()
 An empty row.
 Row (SelectExp select_exp, const std::string &rest="") throw (std::logic_error, std::runtime_error)
 Initialize a row object with data matching the first result in an SQL select statement defined by select_exp followed by rest.
 Row (Dv::Sql::Command &q, unsigned int r) throw (std::logic_error, std::runtime_error)
 Initialize a row object with data from the r'th row in the answer of a query q.
 Row (const Dv::Sql::Object &source, const Dv::Sql::Reference &reference) throw (std::runtime_error, std::logic_error)
 Initialize a row using data from a row that is obtained by "following a reference".
bool is_null (const Column &column) const
 Is the column value null?
template<typename T >
operator() (const Column &column, const T &default_value) const
 Obtain column value for a row.

Static Public Member Functions

static Dv::Sql::Table::Ref table ()
static Dv::Sql::Dbdb ()
static void erase_all (SelectExp select_exp)

Detailed Description

template<Dv::Sql::Table::Ref & database_table>
class Dv::Sql::Row< database_table >

A class template of which each instantiation class represents the rows of a relational table.

The template parameter is a (reference to) a Dv::Sql::Table object, for which the class instances represent rows. A Row object is essentially a Dv::Sql::Object with a fixed associated database table (note that the association between an object and a database table cannot be changed: see Dv::Sql::Object::set_table).

See also:
Dv::Sql::Table
Dv::Sql::Object
Examples:

example-database.C, and example-row.C.

Definition at line 25 of file row.h.


Constructor & Destructor Documentation

template<Dv::Sql::Table::Ref & database_table>
Dv::Sql::Row< database_table >::Row (  )  [inline]

An empty row.

See also:
Dv::Sql::Object::Object(Dv::Sql::Table::Ref)

Definition at line 34 of file row.h.

template<Dv::Sql::Table::Ref & database_table>
Dv::Sql::Row< database_table >::Row ( SelectExp  select_exp,
const std::string &  rest = "" 
) throw (std::logic_error, std::runtime_error) [inline]

Initialize a row object with data matching the first result in an SQL select statement defined by select_exp followed by rest.

Example:
 std::string n("Jones"0;
 Row<customer> customer(name == n, "order by age"); 
will retrieve the youngest customer called "Jones".
Parameters:
select_exp boolean condition that is translated to the "where" clause in the SQL select statement.
rest optional part of the SQL select statement follwing the "where" clause.
Exceptions:
std::runtime_error if the query returns no anwers
std::logic_error if the query caused an SQL error

Definition at line 55 of file row.h.

template<Dv::Sql::Table::Ref & database_table>
Dv::Sql::Row< database_table >::Row ( Dv::Sql::Command q,
unsigned int  r 
) throw (std::logic_error, std::runtime_error) [inline]

Initialize a row object with data from the r'th row in the answer of a query q.

Example
 Db::Sql::Command q(db, "select * from customer where",
    age < 21 && name ^ "A%", "order by age");
 Row<customer> customer(q, 2);
Parameters:
q the query for which the answer will supply the data to initialize the row object
r the number of the row in the query answer from which the data will be used to initialize this row object.
Exceptions:
std::runtime_error if the query returns less than r answers
std::logic_error if the query caused an SQL error or if the number of columns in the query answer is not equal to the number of columns in table_ref (the template parameter).

Definition at line 78 of file row.h.

template<Dv::Sql::Table::Ref & database_table>
Dv::Sql::Row< database_table >::Row ( const Dv::Sql::Object source,
const Dv::Sql::Reference reference 
) throw (std::runtime_error, std::logic_error) [inline]

Initialize a row using data from a row that is obtained by "following a reference".

The data are obtained from the first row of the result of a query that selects the rows of the target table that match data from the source object in the colums indicated by the reference object.

Example
 // Define reference from account(customer_id) to customer(id)
 const Dv::Sql::Reference acct_cust(
           Database::account, (cols = &Account::customer_id), 
           Database::customer, (cols = &Customer::id)
           );
 Row<account> acct;
 // Cust will be initialized using data from the first
 // (only) customer with id acct.cust_id
 Row<customer> cust(acct, acct_cust);
Parameters:
source object from which the reference will be followed. It should be a row from reference.from_table.
reference that will be followed. Its to_table should match database_table (the template parameter) of this object.
Exceptions:
std::runtime_error if the resulting query returns no answers
std::logic_error if the query caused an SQL error or if the number of columns in the query answer is not equal to the number of columns in table_ref (the template parameter) or if the number of columns in the source object does not equal the number of columns in reference.from_table.

Definition at line 113 of file row.h.


Member Function Documentation

template<Dv::Sql::Table::Ref & database_table>
static Dv::Sql::Table::Ref Dv::Sql::Row< database_table >::table (  )  [inline, static]

Definition at line 28 of file row.h.

Referenced by Dv::Sql::Row< database_table >::erase_all().

template<Dv::Sql::Table::Ref & database_table>
static Dv::Sql::Db& Dv::Sql::Row< database_table >::db (  )  [inline, static]

Definition at line 29 of file row.h.

Referenced by Dv::Sql::Row< database_table >::erase_all().

template<Dv::Sql::Table::Ref & database_table>
static void Dv::Sql::Row< database_table >::erase_all ( SelectExp  select_exp  )  [inline, static]
template<Dv::Sql::Table::Ref & database_table>
bool Dv::Sql::Row< database_table >::is_null ( const Column column  )  const [inline]

Is the column value null?

Parameters:
column as generated by db2cpp
Returns:
true iff the column value is null

Definition at line 166 of file row.h.

References Dv::Sql::Column::index().

template<Dv::Sql::Table::Ref & database_table>
template<typename T >
T Dv::Sql::Row< database_table >::operator() ( const Column column,
const T &  default_value 
) const [inline]

Obtain column value for a row.

Parameters:
column as generated by db2cpp
default_value returned if the 'real' value of the column is null, should enable automatic deduction of T
Returns:
the value of the column for this row

Definition at line 177 of file row.h.

References Dv::Sql::Column::index().


The documentation for this class was generated from the following file:

dvmysql-1.0.3 [17 November, 2010]