ROSE  0.9.10.89
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SqlDatabase::Connection Class Reference

Description

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 193 of file SqlDatabase.h.

#include <SqlDatabase.h>

Inheritance diagram for SqlDatabase::Connection:
Inheritance graph
[legend]
Collaboration diagram for SqlDatabase::Connection:
Collaboration graph
[legend]

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...
 
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...
 
static std::string connectionSpecification (const std::string &uri, Driver driver=NO_DRIVER)
 Converts a uniform resource locator to a driver specific string. More...
 

Protected Member Functions

 Connection (const std::string &open_spec, Driver driver)
 

Member Function Documentation

static ConnectionPtr SqlDatabase::Connection::create ( const std::string &  open_spec,
Driver  driver = NO_DRIVER 
)
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 203 of file SqlDatabase.h.

References driver(), guess_driver(), 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 Driver SqlDatabase::Connection::guess_driver ( const std::string &  open_spec)
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.

Referenced by create().

Driver SqlDatabase::Connection::driver ( ) const

Return the low-level driver being used.

Referenced by create().

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.

static std::string SqlDatabase::Connection::connectionSpecification ( const std::string &  uri,
Driver  driver = NO_DRIVER 
)
static

Converts a uniform resource locator to a driver specific string.


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