MediaWiki master
Wikimedia\Rdbms\IDatabaseForOwner Interface Reference

Internal interface for relational database handles exposed to their owner. More...

Inherits Wikimedia\Rdbms\IDatabase.

Inherited by Wikimedia\Rdbms\DBConnRef, and Wikimedia\Rdbms\Database.

Collaboration diagram for Wikimedia\Rdbms\IDatabaseForOwner:

Public Member Functions

 flushSession ( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
 Release important session-level state (named lock, table locks) as post-rollback cleanup.
 
 getPrimaryPos ()
 Get the replication position of this primary DB server.
 
 lastDoneWrites ()
 Get the last time that the connection was used to commit a write.
 
 pendingWriteCallers ()
 Get the list of method names that did write queries for this transaction.
 
 pendingWriteQueryDuration ( $type=self::ESTIMATE_TOTAL)
 Get the time spend running write queries for this transaction.
 
 primaryPosWait (DBPrimaryPos $pos, $timeout)
 Wait for the replica server to catch up to a given primary server position.
 
 serverIsReadOnly ()
 
 setLBInfo ( $nameOrArray, $value=null)
 Set the entire array or a particular key of the managing load balancer info array.
 
 setTransactionListener ( $name, ?callable $callback=null)
 Run a callback after each time any transaction commits or rolls back.
 
 writesOrCallbacksPending ()
 Whether there is a transaction open with either possible write queries or unresolved pre-commit/commit/resolution callbacks pending.
 
 writesPending ()
 
- Public Member Functions inherited from Wikimedia\Rdbms\IDatabase
 affectedRows ()
 Get the number of rows affected by the last query method call.
 
 begin ( $fname=__METHOD__, $mode=self::TRANSACTION_EXPLICIT)
 Begin a transaction.
 
 cancelAtomic ( $fname=__METHOD__, ?AtomicSectionIdentifier $sectionId=null)
 Cancel an atomic section of SQL statements.
 
 commit ( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
 Commits a transaction previously started using begin()
 
 delete ( $table, $conds, $fname=__METHOD__)
 Delete all rows in a table that match a condition.
 
 deleteJoin ( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__)
 Delete all rows in a table that match a condition which includes a join.
 
 doAtomicSection ( $fname, callable $callback, $cancelable=self::ATOMIC_NOT_CANCELABLE)
 Perform an atomic section of reversible SQL statements from a callback.
 
 endAtomic ( $fname=__METHOD__)
 Ends an atomic section of SQL statements.
 
 explicitTrxActive ()
 Check whether there is a transaction open at the specific request of a caller.
 
 flushSnapshot ( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
 Commit any transaction but error out if writes or callbacks are pending.
 
 getLBInfo ( $name=null)
 Get properties passed down from the server info array of the load balancer.
 
 getScopedLockAndFlush ( $lockKey, $fname, $timeout)
 Acquire a named lock, flush any transaction, and return an RAII style unlocker object.
 
 insert ( $table, $rows, $fname=__METHOD__, $options=[])
 Insert row(s) into a table, in the provided order.
 
 insertId ()
 Get the sequence-based ID assigned by the last query method call.
 
 insertSelect ( $destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[], $selectJoinConds=[])
 INSERT SELECT wrapper.
 
 isReadOnly ()
 Check if this DB server is marked as read-only according to load balancer info.
 
 lock ( $lockName, $method, $timeout=5, $flags=0)
 Acquire a named lock.
 
 lockForUpdate ( $table, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Lock all rows meeting the given conditions/options FOR UPDATE.
 
 lockIsFree ( $lockName, $method)
 Check to see if a named lock is not locked by any thread (non-blocking)
 
 newDeleteQueryBuilder ()
 Get an DeleteQueryBuilder bound to this connection.
 
 newInsertQueryBuilder ()
 Get an InsertQueryBuilder bound to this connection.
 
 newReplaceQueryBuilder ()
 Get an ReplaceQueryBuilder bound to this connection.
 
 newUpdateQueryBuilder ()
 Get an UpdateQueryBuilder bound to this connection.
 
 onAtomicSectionCancel (callable $callback, $fname=__METHOD__)
 Run a callback when the atomic section is cancelled.
 
 onTransactionCommitOrIdle (callable $callback, $fname=__METHOD__)
 Run a callback when the current transaction commits or now if there is none.
 
 onTransactionPreCommitOrIdle (callable $callback, $fname=__METHOD__)
 Run a callback before the current transaction commits or now if there is none.
 
 onTransactionResolution (callable $callback, $fname=__METHOD__)
 Run a callback when the current transaction commits or rolls back.
 
 query ( $sql, $fname=__METHOD__, $flags=0)
 Run an SQL query statement and return the result.
 
 replace ( $table, $uniqueKeys, $rows, $fname=__METHOD__)
 Insert row(s) into a table, in the provided order, while deleting conflicting rows.
 
 rollback ( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
 Rollback a transaction previously started using begin()
 
 setSessionOptions (array $options)
 Override database's default behavior.
 
 startAtomic ( $fname=__METHOD__, $cancelable=self::ATOMIC_NOT_CANCELABLE)
 Begin an atomic section of SQL statements.
 
 trxLevel ()
 Gets the current transaction level.
 
 trxTimestamp ()
 Get the UNIX timestamp of the time that the transaction was established.
 
 unlock ( $lockName, $method)
 Release a lock.
 
 update ( $table, $set, $conds, $fname=__METHOD__, $options=[])
 Update all rows in a table that match a given condition.
 
 upsert ( $table, array $rows, $uniqueKeys, array $set, $fname=__METHOD__)
 Upsert row(s) into a table, in the provided order, while updating conflicting rows.
 
- Public Member Functions inherited from Wikimedia\Rdbms\IReadableDatabase
 __toString ()
 Get a debugging string that mentions the database type, the ID of this instance, and the ID of any underlying connection resource or driver object if one is present.
 
 andExpr (array $conds)
 See Expression::__construct()
 
 close ( $fname=__METHOD__)
 Close the database connection.
 
 databasesAreIndependent ()
 Returns true if DBs are assumed to be on potentially different servers.
 
 dbSchema ( $schema=null)
 Get/set the db schema.
 
 decodeBlob ( $b)
 Some DBMSs return a special placeholder object representing blob fields in result objects.
 
 encodeBlob ( $b)
 Some DBMSs have a special format for inserting into blob fields, they don't allow simple quoted strings to be inserted.
 
 estimateRowCount ( $tables, $var=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Estimate the number of rows in dataset.
 
 expr (string $field, string $op, $value)
 See Expression::__construct()
 
 getDBname ()
 Get the current database name; null if there isn't one.
 
 getDomainID ()
 Return the currently selected domain ID.
 
 getLag ()
 Get the seconds of replication lag on this database server.
 
 getServer ()
 Get the hostname or IP address of the server.
 
 getServerInfo ()
 Get a human-readable string describing the current software version.
 
 getServerName ()
 Get the readable name for the server.
 
 getServerVersion ()
 A string describing the current software version.
 
 getSessionLagStatus ()
 Get a cached estimate of the seconds of replication lag on this database server, using the estimate obtained at the start of the current transaction if one is active.
 
 getSoftwareLink ()
 Returns a wikitext style link to the DB's website (e.g.
 
 getType ()
 Get the RDBMS type of the server (e.g.
 
 isOpen ()
 
 lastErrno ()
 Get the RDBMS-specific error code from the last attempted query statement.
 
 lastError ()
 Get the RDBMS-specific error description from the last attempted query statement.
 
 newSelectQueryBuilder ()
 Create an empty SelectQueryBuilder which can be used to run queries against this connection.
 
 newUnionQueryBuilder ()
 Create an empty UnionQueryBuilder which can be used to run queries against this connection.
 
 orExpr (array $conds)
 See Expression::__construct()
 
 ping ()
 Ping the server and try to reconnect if it there is no connection.
 
 select ( $tables, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Execute a SELECT query constructed using the various parameters provided.
 
 selectDomain ( $domain)
 Set the current domain (database, schema, and table prefix)
 
 selectField ( $tables, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[])
 A SELECT wrapper which returns a single field from a single result row.
 
 selectFieldValues ( $tables, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[])
 A SELECT wrapper which returns a list of single field values from result rows.
 
 selectRow ( $tables, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
 Wrapper to IDatabase::select() that only fetches one row (via LIMIT)
 
 selectRowCount ( $tables, $var=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Get the number of rows in dataset.
 
 tablePrefix ( $prefix=null)
 Get/set the table prefix.
 
- Public Member Functions inherited from Wikimedia\Rdbms\Platform\ISQLPlatform
 addIdentifierQuotes ( $s)
 Escape a SQL identifier (e.g.
 
 anyChar ()
 Returns a token for buildLike() that denotes a '_' to be used in a LIKE query.
 
 anyString ()
 Returns a token for buildLike() that denotes a '' to be used in a LIKE query.
 
 bitAnd ( $fieldLeft, $fieldRight)
 
 bitNot ( $field)
 
 bitOr ( $fieldLeft, $fieldRight)
 
 buildComparison (string $op, array $conds)
 Build a condition comparing multiple values, for use with indexes that cover multiple fields, common when e.g.
 
 buildConcat ( $stringList)
 Build a concatenation list to feed into a SQL query.
 
 buildExcludedValue ( $column)
 Build a reference to a column value from the conflicting proposed upsert() row.
 
 buildGreatest ( $fields, $values)
 Build a GREATEST function statement comparing columns/values.
 
 buildGroupConcatField ( $delim, $tables, $field, $conds='', $join_conds=[])
 Build a GROUP_CONCAT or equivalent statement for a query.
 
 buildIntegerCast ( $field)
 
 buildLeast ( $fields, $values)
 Build a LEAST function statement comparing columns/values.
 
 buildLike ( $param,... $params)
 LIKE statement wrapper.
 
 buildSelectSubquery ( $tables, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery.
 
 buildStringCast ( $field)
 
 buildSubString ( $input, $startPosition, $length=null)
 Build a SUBSTRING function.
 
 conditional ( $cond, $caseTrueExpression, $caseFalseExpression)
 Returns an SQL expression for a simple conditional.
 
 decodeExpiry ( $expiry, $format=TS_MW)
 Decode an expiry time into a DBMS independent format.
 
 encodeExpiry ( $expiry)
 Encode an expiry time into the DBMS dependent format.
 
 factorConds ( $condsArray)
 Given an array of condition arrays representing an OR list of AND lists, for example:
 
 getInfinity ()
 Find out when 'infinity' is.
 
 getTableAliases ()
 Return current table aliases.
 
 implicitOrderby ()
 Returns true if this database does an implicit order by when the column has an index For example: SELECT page_title FROM page LIMIT 1.
 
 limitResult ( $sql, $limit, $offset=false)
 Construct a LIMIT query with optional offset.
 
 makeList (array $a, $mode=self::LIST_COMMA)
 Makes an encoded list of strings from an array.
 
 makeWhereFrom2d ( $data, $baseKey, $subKey)
 Build a "OR" condition with pairs from a two-dimensional array.
 
 selectSQLText ( $tables, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
 Take the same arguments as IDatabase::select() and return the SQL it would use.
 
 setIndexAliases (array $aliases)
 Convert certain index names to alternative names before querying the DB.
 
 setSchemaVars ( $vars)
 Set schema variables to be used when streaming commands from SQL files or stdin.
 
 setTableAliases (array $aliases)
 Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name.
 
 strreplace ( $orig, $old, $new)
 Returns a SQL expression for simple string replacement (e.g.
 
 tableName (string $name, $format='quoted')
 Format a table name ready for use in constructing an SQL query.
 
 tableNames (... $tables)
 Fetch a number of table names into an associative array.
 
 tableNamesN (... $tables)
 Fetch a number of table names into a zero-indexed numerical array.
 
 timestamp ( $ts=0)
 Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS.
 
 timestampOrNull ( $ts=null)
 Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS.
 
 unionQueries ( $sqls, $all, $options=[])
 Construct a UNION query.
 
 unionSupportsOrderAndLimit ()
 Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION.
 
- Public Member Functions inherited from Wikimedia\Rdbms\Database\DbQuoter
 addQuotes ( $s)
 Escape and quote a raw value string for use in a SQL query.
 
- Public Member Functions inherited from Wikimedia\Rdbms\Database\IDatabaseFlags
 clearFlag ( $flag, $remember=self::REMEMBER_NOTHING)
 Clear a flag for this connection.
 
 getFlag ( $flag)
 Returns a boolean whether the flag $flag is set for this connection.
 
 restoreFlags ( $state=self::RESTORE_PRIOR)
 Restore the flags to their prior state before the last setFlag/clearFlag call.
 
 setFlag ( $flag, $remember=self::REMEMBER_NOTHING)
 Set a flag for this connection.
 

Additional Inherited Members

- Public Attributes inherited from Wikimedia\Rdbms\IDatabase
const ATOMIC_CANCELABLE = 'cancelable'
 Atomic section is cancelable.
 
const ATOMIC_NOT_CANCELABLE = ''
 Atomic section is not cancelable.
 
const ESTIMATE_DB_APPLY = 'apply'
 Estimate time to apply (scanning, applying)
 
const ESTIMATE_TOTAL = 'total'
 Estimate total time (RTT, scanning, waiting on locks, applying)
 
const FLUSHING_ALL_PEERS = 'flush'
 Commit/rollback is from the owning connection manager for the IDatabase handle.
 
const FLUSHING_INTERNAL = 'flush-internal'
 Commit/rollback is from the IDatabase handle internally.
 
const FLUSHING_ONE = ''
 Commit/rollback is from outside the IDatabase handle and connection manager.
 
const LB_READ_ONLY_REASON = 'readOnlyReason'
 Field for getLBInfo()/setLBInfo()
 
const LB_TRX_ROUND_ID = 'trxRoundId'
 Field for getLBInfo()/setLBInfo()
 
const LOCK_TIMESTAMP = 1
 Flag to return the lock acquisition timestamp (null if not acquired)
 
const ROLE_STATIC_CLONE = 'static-clone'
 Replica server within a static dataset.
 
const ROLE_STREAMING_MASTER = 'streaming-master'
 Primary server than can stream writes to replica servers.
 
const ROLE_STREAMING_REPLICA = 'streaming-replica'
 Replica server that receives writes from a primary server.
 
const ROLE_UNKNOWN = 'unknown'
 Server with unknown topology role.
 
const TRANSACTION_EXPLICIT = ''
 Transaction is requested by regular caller outside of the DB layer.
 
const TRANSACTION_INTERNAL = 'implicit'
 Transaction is requested internally via DBO_TRX/startAtomic()
 
const TRIGGER_CANCEL = 4
 Callback triggered by atomic section cancel (ROLLBACK TO SAVEPOINT)
 
const TRIGGER_COMMIT = 2
 Callback triggered by COMMIT.
 
const TRIGGER_IDLE = 1
 Callback triggered immediately due to no active transaction.
 
const TRIGGER_ROLLBACK = 3
 Callback triggered by ROLLBACK.
 
- Public Attributes inherited from Wikimedia\Rdbms\IReadableDatabase
const UNION_ALL = true
 Parameter to unionQueries() for UNION ALL.
 
const UNION_DISTINCT = false
 Parameter to unionQueries() for UNION DISTINCT.
 
- Public Attributes inherited from Wikimedia\Rdbms\Platform\ISQLPlatform
const ALL_ROWS = '*'
 Unconditional update/delete of whole table.
 
const CALLER_SUBQUERY = 'subquery'
 Special value for ->caller() / $fname parameter used when providing a caller is not expected, because we're formatting a subquery that won't be executed directly.
 
const CALLER_UNKNOWN = 'unknown'
 Special value for ->caller() / $fname parameter used when a caller is not provided.
 
const LIST_AND = 1
 Combine list with AND clauses.
 
const LIST_COMMA = 0
 Combine list with comma delimiters.
 
const LIST_NAMES = 3
 Treat as field name and do not apply value escaping.
 
const LIST_OR = 4
 Combine list with OR clauses.
 
const LIST_SET = 2
 Convert map into a SET clause.
 
const QUERY_CHANGE_LOCKS = 512
 Query is a command for advisory locks.
 
const QUERY_CHANGE_NONE = 32
 Query is a read-only Data Query Language query.
 
const QUERY_CHANGE_ROWS = 128
 Query is a Data Manipulation Language command (INSERT, DELETE, LOCK, ...)
 
const QUERY_CHANGE_SCHEMA = 256
 Query is a Data Definition Language command.
 
const QUERY_CHANGE_TRX = 64
 Query is a Transaction Control Language command (BEGIN, USE, SET, ...)
 
const QUERY_IGNORE_DBO_TRX = 8
 Ignore the current presence of any DBO_TRX flag.
 
const QUERY_NO_RETRY = 16
 Do not try to retry the query if the connection was lost.
 
const QUERY_NORMAL = 0
 Idiom for "no special flags".
 
const QUERY_PSEUDO_PERMANENT = 2
 Track a TEMPORARY table CREATE as if it was for a permanent table (for testing)
 
const QUERY_REPLICA_ROLE = 4
 Enforce that a query does not make effective writes.
 
const QUERY_SILENCE_ERRORS = 1
 Ignore query errors and return false when they happen.
 
- Public Attributes inherited from Wikimedia\Rdbms\Database\IDatabaseFlags
const DBO_COMPRESS = 512
 Enable compression in connection protocol.
 
const DBO_DDLMODE = 128
 Schema file mode; was used by Oracle.
 
const DBO_DEBUG = 1
 Enable debug logging of all SQL queries.
 
const DBO_DEFAULT = 16
 Join load balancer transaction rounds (which control DBO_TRX) in non-CLI mode.
 
const DBO_GAUGE = 1024
 Optimize connection for guaging server state (e.g.
 
const DBO_IGNORE = 4
 Unused since 1.31.
 
const DBO_NOBUFFER = 2
 Unused since 1.34.
 
const DBO_PERSISTENT = 32
 Use DB persistent connections if possible.
 
const DBO_SSL = 256
 Enable SSL/TLS in connection protocol.
 
const DBO_SYSDBA = 64
 DBA session mode; was used by Oracle.
 
const DBO_TRX = 8
 Automatically start a transaction before running a query if none is active.
 
const REMEMBER_NOTHING = ''
 Do not remember the prior flags.
 
const REMEMBER_PRIOR = 'remember'
 Remember the prior flags.
 
const RESTORE_INITIAL = 'initial'
 Restore to the initial flag state.
 
const RESTORE_PRIOR = 'prior'
 Restore to the prior flag state.
 

Detailed Description

Internal interface for relational database handles exposed to their owner.

Instances are either owned by a LoadBalancer object or owned by the caller that created the instance using a constructor/factory function such as DatabaseFactory::create().

Access: internal
Only for use within the rdbms library

Definition at line 31 of file IDatabaseForOwner.php.

Member Function Documentation

◆ flushSession()

Wikimedia\Rdbms\IDatabaseForOwner::flushSession ( $fname = __METHOD__,
$flush = self::FLUSHING_ONE )

Release important session-level state (named lock, table locks) as post-rollback cleanup.

This should only be called by a load balancer or if the handle is not attached to one. Also, there must be no chance that a future caller will still be expecting some of the lost session state.

Connection and query errors will be suppressed and logged

Parameters
string$fnameCalling function name
string$flushFlush flag, set to a situationally valid IDatabase::FLUSHING_* constant to disable warnings about explicitly rolling back implicit transactions. This will silently break any ongoing explicit transaction. Only set the flush flag if you are sure that it is safe to ignore these warnings in your context.
Exceptions
DBErrorIf an error occurs, {
See also
query}
Since
1.38

Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.

◆ getPrimaryPos()

Wikimedia\Rdbms\IDatabaseForOwner::getPrimaryPos ( )

Get the replication position of this primary DB server.

Returns
DBPrimaryPos|false Position; false if this is not a primary DB
Exceptions
DBErrorIf an error occurs, {
See also
query}
Since
1.37

Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.

◆ lastDoneWrites()

Wikimedia\Rdbms\IDatabaseForOwner::lastDoneWrites ( )

Get the last time that the connection was used to commit a write.

Access: internal
Should only be called from the rdbms library.
Returns
float|null UNIX timestamp; null if no writes were committed
Since
1.24

Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.

◆ pendingWriteCallers()

Wikimedia\Rdbms\IDatabaseForOwner::pendingWriteCallers ( )

Get the list of method names that did write queries for this transaction.

Returns
array
Since
1.27

Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.

◆ pendingWriteQueryDuration()

Wikimedia\Rdbms\IDatabaseForOwner::pendingWriteQueryDuration ( $type = self::ESTIMATE_TOTAL)

Get the time spend running write queries for this transaction.

High values could be due to scanning, updates, locking, and such.

Parameters
string$typeIDatabase::ESTIMATE_* constant [default: ESTIMATE_ALL]
Returns
float|false Returns false if not transaction is active
Since
1.26

Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.

◆ primaryPosWait()

Wikimedia\Rdbms\IDatabaseForOwner::primaryPosWait ( DBPrimaryPos $pos,
$timeout )

Wait for the replica server to catch up to a given primary server position.

Note that this does not start any new transactions.

Callers might want to flush any existing transaction before invoking this method. Upon success, this assures that replica server queries will reflect all changes up to the given position, without interference from prior REPEATABLE-READ snapshots.

Parameters
DBPrimaryPos$pos
int$timeoutThe maximum number of seconds to wait for synchronisation
Returns
int|null Zero if the replica DB server was past that position already, greater than zero if we waited for some period of time, less than zero if it timed out, and null on error
Exceptions
DBErrorIf an error occurs, {
See also
query}
Since
1.37

Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.

◆ serverIsReadOnly()

Wikimedia\Rdbms\IDatabaseForOwner::serverIsReadOnly ( )
Returns
bool Whether this DB server is running in server-side read-only mode
Exceptions
DBErrorIf an error occurs, {
See also
query}
Since
1.28

Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMySQL, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.

◆ setLBInfo()

Wikimedia\Rdbms\IDatabaseForOwner::setLBInfo ( $nameOrArray,
$value = null )

Set the entire array or a particular key of the managing load balancer info array.

Keys matching the IDatabase::LB_* constants are also used internally by subclasses

Access: internal
should not be called outside of rdbms library.
Parameters
array | string$nameOrArrayThe new array or the name of a key to set
array | mixed | null$valueIf $nameOrArray is a string, the new key value (null to unset)

Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.

◆ setTransactionListener()

Wikimedia\Rdbms\IDatabaseForOwner::setTransactionListener ( $name,
?callable $callback = null )

Run a callback after each time any transaction commits or rolls back.

The callback takes two arguments:

  • IDatabase::TRIGGER_COMMIT or IDatabase::TRIGGER_ROLLBACK
  • This IDatabase object Callbacks must commit any transactions that they begin.

Registering a callback here will not affect writesOrCallbacks() pending.

Since callbacks from this or onTransactionCommitOrIdle() can start and end transactions, a single call to IDatabase::commit might trigger multiple runs of the listener callbacks.

Parameters
string$nameCallback name
callable | null$callbackUse null to unset a listener
Since
1.28

Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.

◆ writesOrCallbacksPending()

Wikimedia\Rdbms\IDatabaseForOwner::writesOrCallbacksPending ( )

Whether there is a transaction open with either possible write queries or unresolved pre-commit/commit/resolution callbacks pending.

This does not count recurring callbacks, e.g. from setTransactionListener().

Returns
bool

Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.

Referenced by Wikimedia\Rdbms\TransactionManager\trxCheckBeforeClose().

◆ writesPending()

Wikimedia\Rdbms\IDatabaseForOwner::writesPending ( )
Returns
bool Whether there is a transaction open with possible write queries
Since
1.27

Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.


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