ROSE
0.9.6a
|
Connection to a database. More...
#include <SqlDatabase.h>
Public Member Functions | |
TransactionPtr | transaction () |
Begins a new transaction for this connection. More... | |
Driver | driver () const |
Return the low-level driver being used. More... | |
std::string | openspec () const |
Returns the open specification used when the connection was established. More... | |
void | print (std::ostream &) const |
Print some basic info about this connection. More... | |
~Connection () | |
void | set_debug (FILE *f) |
Debugging property. More... | |
FILE * | get_debug () const |
Debugging property. More... | |
Static Public Member Functions | |
static ConnectionPtr | create (const std::string &open_spec, Driver driver=NO_DRIVER) |
Create a new database connection. More... | |
static Driver | guess_driver (const std::string &open_spec) |
Guess a driver based on a connection specification. More... | |
Protected Member Functions | |
Connection (const std::string &open_spec, Driver driver) | |
Private Member Functions | |
void | init (const std::string &open_spec, Driver driver) |
void | finish () |
Private Attributes | |
ConnectionImpl * | impl |
Friends | |
class | TransactionImpl |
class | Transaction |
class | StatementImpl |
Connection to a database.
Multiple connections may exist to a single database, and a connection may have multiple transactions in which statements are executed. The connection is automatically closed once all references to it have disappeared (both user references and references from transactions).
Connections should be closed around fork(). Most low-level drivers don't gracefully handle this situation. (FIXME: we might be able to work around this to some extent in the SqlDatabase implementation. [Robb P. Matzke 2013-05-31]
Definition at line 189 of file SqlDatabase.h.
|
inline |
Definition at line 233 of file SqlDatabase.h.
|
inlineprotected |
Definition at line 238 of file SqlDatabase.h.
References Dbg::init().
|
inlinestatic |
Create a new database connection.
All connection objects are bound to a database throughout their lifetime, although depending on the driver, the actual low-level connection may open and close. The open_spec
string describes how to connect to the database and its format varies depending on the underlying database driver. If no driver
is specified then a driver is chosen (if possible) based on the open_spec
. The underlying low-level connections are automatically closed when all transactions terminate.
Definition at line 199 of file SqlDatabase.h.
References SqlDatabase::Exception::Exception(), and SqlDatabase::NO_DRIVER.
TransactionPtr SqlDatabase::Connection::transaction | ( | ) |
Begins a new transaction for this connection.
A connection may have multiple transactions at one time; if the underlying database driver doesn't support multiple transactions, then multiple low-level connections are instantiated. All statements are executed within a transaction.
|
static |
Guess a driver based on a connection specification.
This will typically work only for drivers that use URLs that contain the driver name. Returns NO_DRIVER if a driver cannot be guessed.
Driver SqlDatabase::Connection::driver | ( | ) | const |
Return the low-level driver being used.
std::string SqlDatabase::Connection::openspec | ( | ) | const |
Returns the open specification used when the connection was established.
void SqlDatabase::Connection::set_debug | ( | FILE * | f) |
Debugging property.
If non-null, then debugging information is sent to that file. Transactions inherit the debugging property of their connection, and statements inherit the debugging property of their transaction.
FILE* SqlDatabase::Connection::get_debug | ( | ) | const |
Debugging property.
If non-null, then debugging information is sent to that file. Transactions inherit the debugging property of their connection, and statements inherit the debugging property of their transaction.
void SqlDatabase::Connection::print | ( | std::ostream & | ) | const |
Print some basic info about this connection.
|
private |
|
private |
|
friend |
Definition at line 190 of file SqlDatabase.h.
|
friend |
Definition at line 191 of file SqlDatabase.h.
|
friend |
Definition at line 192 of file SqlDatabase.h.
|
private |
Definition at line 245 of file SqlDatabase.h.