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.
at line 132
public
setName(string $name)
at line 140
public string
getName()
at line 148
public ConnectionInterface
getWrappedConnection()
at line 158
public integer
getNestedTransactionCount()
Gets the current transaction depth.
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.
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.
at line 199
public boolean
beginTransaction()
Overrides PDO::beginTransaction() to prevent errors due to already-in-progress transaction.
at line 220
public boolean
commit()
Overrides PDO::commit() to only commit the transaction if we are in the outermost transaction nesting level.
at line 249
public boolean
rollBack()
Overrides PDO::rollBack() to only rollback the transaction if we are in the outermost transaction nesting level
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.
at line 302
public boolean
inTransaction()
Checks if inside a transaction.
at line 316
public mixed
getAttribute(string $attribute)
Retrieve a database connection attribute.
at line 335
public boolean
setAttribute(string $attribute, mixed $value)
Set an attribute.
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.
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
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
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.
at line 453
public DataFetcherInterface
getSingleDataFetcher($data $data)
at line 461
public DataFetcherInterface
getDataFetcher($data $data)
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.
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.
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).
at line 526
public string
getLastExecutedQuery()
Get the SQL code for the latest query executed by Propel
at line 536
public
setLastExecutedQuery(string $query)
Set the SQL code for the latest query executed by Propel
at line 546
public
useDebug(boolean $value = true)
Enable or disable the query debug features
at line 560
public
setLogMethods(array $logMethods)
at line 568
public array
getLogMethods()
at line 581
public
setLogger(LoggerInterface $logger)
{@inheritDoc}
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.
at line 606
public
log(string $msg)
Logs the method call or the executed SQL statement.
at line 623
public
__call($method, $args)
Forward any call to a method not found to the wrapped connection.
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.