Dv::Sql::Table Class Reference
A Table object represents information about a database table or a query result table.
More...
#include <table.h>
List of all members.
Classes |
class | Column |
| A Column contains information about a column in a table. More...
|
Public Types |
typedef Dv::shared_ptr< Table > | Ref |
| Type of reference-counted pointer to a Table.
|
typedef std::set< Ref > | Set |
| Type of set of (reference-counted pointers) to tables.
|
Public Member Functions |
| ~Table () |
| Destructor.
|
std::string | name () const |
| The name of the table.
|
Db & | db () const |
| The database connection of the table.
|
const Column::List & | columns () const |
| The list of columns of this table.
|
const Column::List & | primary_key () const |
| The list of columns constituting the primary key of this table.
|
const Column & | find (const std::string &name) const throw (std::logic_error) |
| Return a reference to the column with a given name.
|
const Column & | column (size_t index) const throw (std::logic_error) |
| Return a reference to the column with a given index.
|
const Column & | column (const std::string &name) const throw (std::logic_error) |
| Return a reference to the column with a given name.
|
size_t | arity () const |
| The number of columns in this table.
|
std::string | select (bool distinct=true) const |
| Return "select" clause corresponding all the columns of this table.
|
Private Member Functions |
const Column * | push_back (const Table::Ref &table, const std::string &name, Column::Type type, bool auto_inc, bool in_primary_key, bool can_be_null) |
| Add a column to this table.
|
| Table (const Table &) |
| The copy ctor is forbidden.
|
| Table (const std::string &name, Db &db) |
| Constructor.
|
Private Attributes |
std::string | name_ |
| The name of the table.
|
Db & | db_ |
| A connection to the database of this table.
|
Column::List | columns_ |
| The columns of this table.
|
Column::List | pri_key_ |
| The columns constituting the primary key of this table.
|
Friends |
class | CommandImpl |
std::ostream & | operator<< (std::ostream &os, const Table &table) |
| Print information on a table to a stream.
|
Detailed Description
A Table object represents information about a database table or a query result table.
This information includes the name, the list of columns, the primary key (also a list of columns) and a reference to a connection to the database where the table is implemented (for query table, the database connection is the connection of the query command).
Since its constructors are private, tables can only be created by instance of its single friend class Dv::Sql::CommandImpl. Tables should not be used directly but only through reference counted pointers Table::Ref. Moreover, table information cannot be changed.
- See also:
- Dv::Sql::Table::Column
-
Dv::Sql::Table::Ref
Definition at line 36 of file table.h.
Member Typedef Documentation
Type of reference-counted pointer to a Table.
Definition at line 41 of file table.h.
Type of set of (reference-counted pointers) to tables.
Definition at line 44 of file table.h.
Constructor & Destructor Documentation
Dv::Sql::Table::~Table |
( |
|
) |
|
Dv::Sql::Table::Table |
( |
const Table & |
|
) |
[private] |
The copy ctor is forbidden.
Dv::Sql::Table::Table |
( |
const std::string & |
name, |
|
|
Db & |
db | |
|
) |
| | [inline, explicit, private] |
Constructor.
- Parameters:
-
| name | of the table |
| db | database connection of table |
Definition at line 219 of file table.h.
Member Function Documentation
std::string Dv::Sql::Table::name |
( |
|
) |
const [inline] |
The name of the table.
- Returns:
- the name of the table.
Definition at line 109 of file table.h.
References name_.
Referenced by column().
Db& Dv::Sql::Table::db |
( |
|
) |
const [inline] |
The database connection of the table.
For database tables, this returns a connection to the database containing the table. For query tables, this returns the database connection associated with the query command.
- Returns:
- the databsae connection of the table
- See also:
- Dv::Sql::Command
Definition at line 118 of file table.h.
References db_.
const Column::List& Dv::Sql::Table::columns |
( |
|
) |
const [inline] |
The list of columns of this table.
- Returns:
- the list of columns of this table.
Definition at line 122 of file table.h.
References columns_.
Referenced by arity().
const Column::List& Dv::Sql::Table::primary_key |
( |
|
) |
const [inline] |
The list of columns constituting the primary key of this table.
- Returns:
- the list of columns constituting the primary key of this table.
Definition at line 126 of file table.h.
References pri_key_.
const Column& Dv::Sql::Table::find |
( |
const std::string & |
name |
) |
const throw (std::logic_error) |
Return a reference to the column with a given name.
- Parameters:
-
| name | of the column to find |
- Returns:
- the column with the given name in this table
- Exceptions:
-
| std::logic_error | if the table does not have a column with the given name. |
Referenced by column().
const Column& Dv::Sql::Table::column |
( |
size_t |
index |
) |
const throw (std::logic_error) |
Return a reference to the column with a given index.
- Parameters:
-
| index | of the column to find |
- Returns:
- the column with the given index in this table
- Exceptions:
-
| std::logic_error | if index+1 exceeds the number of columns in this table. |
- See also:
- Dv::Sql::Table::arity
const Column& Dv::Sql::Table::column |
( |
const std::string & |
name |
) |
const throw (std::logic_error) [inline] |
Return a reference to the column with a given name.
- Parameters:
-
| name | of the column to find |
- Returns:
- the column with the given name in this table
- Exceptions:
-
| std::logic_error | if the table does not have a column with the given name. |
- See also:
- Dv::Sql::Table::find
Definition at line 151 of file table.h.
References find(), and name().
size_t Dv::Sql::Table::arity |
( |
|
) |
const [inline] |
The number of columns in this table.
- Returns:
- the number of columns in this table.
Definition at line 158 of file table.h.
References columns().
std::string Dv::Sql::Table::select |
( |
bool |
distinct = true |
) |
const |
Return "select" clause corresponding all the columns of this table.
- Parameters:
-
| distinct | if true, use "select distinct" instead of "select" |
- Returns:
- A string of the form
table for which to generate the clause
select table.column_1 , .. , table.column_n
or table for which to generate the clause
select distinct table.column_1 , .. , table.column_n
where column_1
, .. , column_n
are the names of all the columns of this table.
- See also:
- Dv::Sql::SelectExp::select
const Column* Dv::Sql::Table::push_back |
( |
const Table::Ref & |
table, |
|
|
const std::string & |
name, |
|
|
Column::Type |
type, |
|
|
bool |
auto_inc, |
|
|
bool |
in_primary_key, |
|
|
bool |
can_be_null | |
|
) |
| | [private] |
Add a column to this table.
The Column object will be dynamically allocated.
- Parameters:
-
| table | a reference-counted pointer to this table |
| name | of the new column |
| type | of the new column |
| auto_inc | true iff the new column is "auto increment" |
| in_primary_key | true iff the new column is part of the table's primary key |
| can_be_null | true iff the new column can have null value |
- Returns:
- a pointer to the newly created column
- Warning:
- this has no effect on the database, only on the description of a table.
- See also:
- Dv::Sql::Table::Column
Friends And Related Function Documentation
std::ostream& operator<< |
( |
std::ostream & |
os, |
|
|
const Table & |
table | |
|
) |
| | [friend] |
Print information on a table to a stream.
- Parameters:
-
| os | stream to print to |
| table | to print info on |
- Returns:
os
Member Data Documentation
The name of the table.
Definition at line 205 of file table.h.
Referenced by name().
A connection to the database of this table.
Definition at line 207 of file table.h.
Referenced by db().
The columns constituting the primary key of this table.
Definition at line 211 of file table.h.
Referenced by primary_key().
The documentation for this class was generated from the following file: