Propel 2 API
Class

Propel\Runtime\Connection\ConnectionWrapper

class ConnectionWrapper implements ConnectionInterface, LoggerAwareInterface

Wraps a Connection class, providing nested transactions, statement cache, and logging.

This class was designed to work around the limitation in PDO where attempting to begin
a transaction when one has already been begun will trigger a PDOException. Propel
relies on the ability to create nested transactions, even if the underlying layer
simply ignores these (because it doesn't support nested transactions).

The changes that this class makes to the underlying API include the addition of the
getNestedTransactionDepth() and isInTransaction() and the fact that beginTransaction()
will no longer throw a PDOException (or trigger an error) if a transaction is already
in-progress.

Constants

PROPEL_ATTR_CACHE_PREPARES

Attribute to use to set whether to cache prepared statements.

Properties

boolean $useDebug Whether or not the debug is enabled

Methods

__construct(ConnectionInterface $connection)

Creates a Connection instance.

setName(string $name)

string getName()

ConnectionInterface getWrappedConnection()

integer getNestedTransactionCount()

Gets the current transaction depth.

boolean isInTransaction()

Is this PDO connection currently in-transaction? This is equivalent to asking whether the current nested transaction count is greater than 0.

boolean isCommitable()

Check whether the connection contains a transaction that can be committed.

boolean beginTransaction()

Overrides PDO::beginTransaction() to prevent errors due to already-in-progress transaction.

boolean commit()

Overrides PDO::commit() to only commit the transaction if we are in the outermost transaction nesting level.

boolean rollBack()

Overrides PDO::rollBack() to only rollback the transaction if we are in the outermost transaction nesting level

boolean forceRollBack()

Rollback the whole transaction, even if this is a nested rollback and reset the nested transaction count to 0.

boolean inTransaction()

Checks if inside a transaction.

mixed getAttribute(string $attribute)

Retrieve a database connection attribute.

boolean setAttribute(string $attribute, mixed $value)

Set an attribute.

StatementInterface prepare(string $sql, array $driver_options = array())

Prepares a statement for execution and returns a statement object.

integer exec(string $sql)

Execute an SQL statement and return the number of affected rows.

StatementInterface query()

Executes an SQL statement, returning a result set as a PDOStatement object.

string quote(string $string, int $parameter_type = 2)

Quotes a string for use in a query.

DataFetcherInterface getSingleDataFetcher($data $data)

DataFetcherInterface getDataFetcher($data $data)

string lastInsertId(string $name = null)

Returns the ID of the last inserted row or sequence value.

clearStatementCache()

Clears any stored prepared statements for this connection.

integer getQueryCount()

Returns the number of queries this DebugPDO instance has performed on the database connection.

integer incrementQueryCount()

Increments the number of queries performed by this DebugPDO instance.

string getLastExecutedQuery()

Get the SQL code for the latest query executed by Propel

setLastExecutedQuery(string $query)

Set the SQL code for the latest query executed by Propel

useDebug(boolean $value = true)

Enable or disable the query debug features

setLogMethods(array $logMethods)

array getLogMethods()

setLogger(LoggerInterface $logger)

{@inheritDoc}

LoggerInterface getLogger()

Gets the logger to use for this connection.

log(string $msg)

Logs the method call or the executed SQL statement.

__call($method, $args)

Forward any call to a method not found to the wrapped connection.

__destruct()

If so configured, makes an entry to the log of the state of this object just prior to its destruction.

Details

at line 121
public __construct(ConnectionInterface $connection)

Creates a Connection instance.

Parameters

ConnectionInterface $connection

at line 132
public setName(string $name)

Parameters

string $name The datasource name associated to this connection

at line 140
public string getName()

Return Value

string The datasource name associated to this connection

at line 148
public ConnectionInterface getWrappedConnection()

Return Value

ConnectionInterface

at line 158
public integer getNestedTransactionCount()

Gets the current transaction depth.

Return Value

integer

at line 178
public boolean isInTransaction()

Is this PDO connection currently in-transaction? This is equivalent to asking whether the current nested transaction count is greater than 0.

Return Value

boolean

at line 189
public boolean isCommitable()

Check whether the connection contains a transaction that can be committed.

To be used in an environment where Propelexceptions are caught.

Return Value

boolean True if the connection is in a committable transaction

at line 199
public boolean beginTransaction()

Overrides PDO::beginTransaction() to prevent errors due to already-in-progress transaction.

Return Value

boolean TRUE on success or FALSE on failure.

at line 220
public boolean commit()

Overrides PDO::commit() to only commit the transaction if we are in the outermost transaction nesting level.

Return Value

boolean TRUE on success or FALSE on failure.

at line 249
public boolean rollBack()

Overrides PDO::rollBack() to only rollback the transaction if we are in the outermost transaction nesting level

Return Value

boolean Whether operation was successful.

at line 276
public boolean forceRollBack()

Rollback the whole transaction, even if this is a nested rollback and reset the nested transaction count to 0.

Return Value

boolean Whether operation was successful.

at line 302
public boolean inTransaction()

Checks if inside a transaction.

Return Value

boolean TRUE if a transaction is currently active, and FALSE if not.

at line 316
public mixed getAttribute(string $attribute)

Retrieve a database connection attribute.

Parameters

string $attribute The name of the attribute to retrieve, e.g. PDO::ATTR_AUTOCOMMIT

Return Value

mixed A successful call returns the value of the requested attribute. An unsuccessful call returns null.

at line 335
public boolean setAttribute(string $attribute, mixed $value)

Set an attribute.

Parameters

string $attribute The attribute name, or the constant name containing the attribute name (e.g. 'PDO::ATTR_CASE')
mixed $value

Return Value

boolean TRUE on success or FALSE on failure.

at line 365
public StatementInterface prepare(string $sql, array $driver_options = array())

Prepares a statement for execution and returns a statement object.

Overrides PDO::prepare() in order to:
- Add logging and query counting if logging is true.
- Add query caching support if the PropelPDO::PROPEL_ATTR_CACHE_PREPARES was set to true.

Parameters

string $sql This must be a valid SQL statement for the target database server.
array $driver_options One $array or more key => value pairs to set attribute values for the PDOStatement object that this method returns.

Return Value

StatementInterface

at line 392
public integer exec(string $sql)

Execute an SQL statement and return the number of affected rows.

Overrides PDO::exec() to log queries when required

Parameters

string $sql

Return Value

integer

at line 415
public StatementInterface query()

Executes an SQL statement, returning a result set as a PDOStatement object.

Despite its signature here, this method takes a variety of parameters.

Overrides PDO::query() to log queries when required

Return Value

StatementInterface

See also

http://php.net/manual/en/pdo.query.php for a description of the possible parameters.

at line 445
public string quote(string $string, int $parameter_type = 2)

Quotes a string for use in a query.

Places quotes around the input string (if required) and escapes special
characters within the input string, using a quoting style appropriate to
the underlying driver.

Parameters

string $string The string to be quoted.
int $parameter_type Provides a data type hint for drivers that have alternate quoting styles.

Return Value

string A quoted string that is theoretically safe to pass into an SQL statement. Returns FALSE if the driver does not support quoting in this way.

at line 453
public DataFetcherInterface getSingleDataFetcher($data $data)

Parameters

$data $data

Return Value

DataFetcherInterface

at line 461
public DataFetcherInterface getDataFetcher($data $data)

Parameters

$data $data

Return Value

DataFetcherInterface

at line 483
public string lastInsertId(string $name = null)

Returns the ID of the last inserted row or sequence value.

Returns the ID of the last inserted row, or the last value from a sequence
object, depending on the underlying driver. For example, PDO_PGSQL()
requires you to specify the name of a sequence object for the name parameter.

Parameters

string $name Name of the sequence object from which the ID should be returned.

Return Value

string If a sequence name was not specified for the name parameter, returns a string representing the row ID of the last row that was inserted into the database. If a sequence name was specified for the name parameter, returns a string representing the last value retrieved from the specified sequence object.

at line 491
public clearStatementCache()

Clears any stored prepared statements for this connection.

at line 504
public integer getQueryCount()

Returns the number of queries this DebugPDO instance has performed on the database connection.

When using DebugPDOStatement as the statement class, any queries by DebugPDOStatement instances
are counted as well.

Return Value

integer

at line 516
public integer incrementQueryCount()

Increments the number of queries performed by this DebugPDO instance.

Returns the original number of queries (ie the value of $this->queryCount before calling this method).

Return Value

integer

at line 526
public string getLastExecutedQuery()

Get the SQL code for the latest query executed by Propel

Return Value

string Executable SQL code

at line 536
public setLastExecutedQuery(string $query)

Set the SQL code for the latest query executed by Propel

Parameters

string $query Executable SQL code

at line 546
public useDebug(boolean $value = true)

Enable or disable the query debug features

Parameters

boolean $value True to enable debug (default), false to disable it

at line 560
public setLogMethods(array $logMethods)

Parameters

array $logMethods

at line 568
public array getLogMethods()

Return Value

array

at line 581
public setLogger(LoggerInterface $logger)

{@inheritDoc}

Parameters

LoggerInterface $logger

at line 592
public LoggerInterface getLogger()

Gets the logger to use for this connection.

If no logger was set, returns the default logger from the Service Container.

Return Value

LoggerInterface A logger.

at line 606
public log(string $msg)

Logs the method call or the executed SQL statement.

Parameters

string $msg Message to log.

at line 623
public __call($method, $args)

Forward any call to a method not found to the wrapped connection.

Parameters

$method
$args

at line 633
public __destruct()

If so configured, makes an entry to the log of the state of this object just prior to its destruction.

See also

self::log()