Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
22.58% covered (danger)
22.58%
49 / 217
7.59% covered (danger)
7.59%
11 / 145
CRAP
0.00% covered (danger)
0.00%
0 / 1
DBConnRef
22.58% covered (danger)
22.58%
49 / 217
7.59% covered (danger)
7.59%
11 / 145
13264.86
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 ensureConnection
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
6
 __call
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getReferenceRole
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getServerInfo
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 trxLevel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 trxTimestamp
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 explicitTrxActive
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 tablePrefix
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 dbSchema
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 getLBInfo
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setLBInfo
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 implicitOrderby
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 lastDoneWrites
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 writesPending
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 writesOrCallbacksPending
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 pendingWriteQueryDuration
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 pendingWriteCallers
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isOpen
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setFlag
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 clearFlag
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 restoreFlags
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFlag
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getProperty
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDomainID
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 getType
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 insertId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 lastErrno
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 lastError
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 affectedRows
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSoftwareLink
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getServerVersion
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 close
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 query
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 newSelectQueryBuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 newUnionQueryBuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 newUpdateQueryBuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 newDeleteQueryBuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 newInsertQueryBuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 newReplaceQueryBuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 selectField
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 selectFieldValues
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 select
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 selectSQLText
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 limitResult
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 selectRow
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 estimateRowCount
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 selectRowCount
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 lockForUpdate
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 fieldExists
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 indexExists
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPrimaryKeyColumns
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 tableExists
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 insert
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
1.12
 update
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
1.12
 buildComparison
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 makeList
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 makeWhereFrom2d
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 factorConds
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 bitNot
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 bitAnd
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 bitOr
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildConcat
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildGroupConcat
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildGroupConcatField
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildGreatest
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildLeast
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildSubstring
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildStringCast
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildIntegerCast
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildExcludedValue
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildSelectSubquery
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 databasesAreIndependent
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 selectDomain
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDBname
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getServer
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getServerName
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 addQuotes
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 expr
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 andExpr
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 orExpr
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addIdentifierQuotes
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildLike
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 anyChar
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 anyString
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 replace
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
1.12
 upsert
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
1.12
 deleteJoin
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 delete
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
1.12
 insertSelect
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 unionSupportsOrderAndLimit
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 unionQueries
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 conditional
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 strreplace
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 primaryPosWait
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPrimaryPos
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 serverIsReadOnly
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 onTransactionResolution
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 onTransactionCommitOrIdle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 onTransactionPreCommitOrIdle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setTransactionListener
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 startAtomic
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 endAtomic
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 cancelAtomic
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doAtomicSection
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 begin
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 commit
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 rollback
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 flushSession
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 flushSnapshot
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 timestamp
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 timestampOrNull
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 ping
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getLag
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSessionLagStatus
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 encodeBlob
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 decodeBlob
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setSessionOptions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setSchemaVars
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 lockIsFree
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 lock
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
1.12
 unlock
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
1.12
 getScopedLockAndFlush
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
1.12
 getInfinity
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 encodeExpiry
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 decodeExpiry
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isReadOnly
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setTableAliases
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTableAliases
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 tableName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 tableNames
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 tableNamesN
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 sourceFile
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 sourceStream
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 dropTable
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 truncateTable
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 streamStatementEnd
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 duplicateTableStructure
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 indexUnique
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 listTables
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 fieldInfo
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __toString
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 assertRoleAllowsWrites
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getDomainChangeException
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 normalizeServerIndex
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use InvalidArgumentException;
6use Stringable;
7use Wikimedia\ScopedCallback;
8use Wikimedia\Timestamp\TimestampFormat as TS;
9
10/**
11 * Helper class used for automatically re-using IDatabase connections and lazily
12 * establishing the actual network connection to a database host.
13 *
14 * It does this by deferring to ILoadBalancer::getConnectionInternal, which in
15 * turn ensures we share and re-use a single connection for a given database
16 * wherever possible.
17 *
18 * This class previously used an RAII-style pattern where connections would be
19 * claimed from a pool, and then added back to the pool for re-use only after
20 * the calling code's variable for this object went out of scope (a __destruct
21 * got called when the calling function returns or throws). This is no longer
22 * needed today as LoadBalancer now permits re-use internally even for
23 * overlapping callers, where two pieces of code may both obtain their own
24 * DBConnRef object and where both are used alternatingly, and yet still share
25 * the same connection.
26 *
27 * @par Example:
28 * @code
29 *     function getRowData() {
30 *         $conn = $this->lb->getConnection( DB_REPLICA );
31 *         $row = $conn->select( ... );
32 *         return $row ? (array)$row : false;
33 *     }
34 * @endcode
35 *
36 * @ingroup Database
37 * @since 1.22
38 */
39class DBConnRef implements Stringable, IMaintainableDatabase, IDatabaseForOwner {
40    /** @var ILoadBalancer */
41    private $lb;
42    /** @var IDatabase|null Live connection handle */
43    private $conn;
44    /**
45     * @var array Map of (DBConnRef::FLD_* constant => connection parameter)
46     * @phan-var array{0:int,1:array|string|false,2:DatabaseDomain,3:int}
47     */
48    private $params;
49    /** @var int One of DB_PRIMARY/DB_REPLICA */
50    private $role;
51
52    /**
53     * @var int Reference to the $modcount passed to the constructor.
54     *      $conn is valid if $modCountRef and $modCountFix are the same.
55     */
56    private $modCountRef;
57
58    /**
59     * @var int Last known good value of $modCountRef
60     *      $conn is valid if $modCountRef and $modCountFix are the same.
61     */
62    private $modCountFix;
63
64    private const FLD_INDEX = 0;
65    private const FLD_GROUPS = 1;
66    private const FLD_DOMAIN = 2;
67    private const FLD_FLAGS = 3;
68
69    /**
70     * @internal May not be used outside Rdbms LoadBalancer
71     * @param ILoadBalancer $lb Connection manager for $conn
72     * @param array $params [server index, query groups, domain, flags]
73     * @param int $role The type of connection asked for; one of DB_PRIMARY/DB_REPLICA
74     * @param null|int &$modcount Reference to a modification counter. This is for
75     *  LoadBalancer::reconfigure to indicate that a new connection should be acquired.
76     */
77    public function __construct( ILoadBalancer $lb, $params, $role, &$modcount = 0 ) {
78        if ( !is_array( $params ) || count( $params ) < 4 || $params[self::FLD_DOMAIN] === false ) {
79            throw new InvalidArgumentException( "Missing lazy connection arguments." );
80        }
81
82        $params[self::FLD_DOMAIN] = DatabaseDomain::newFromId( $params[self::FLD_DOMAIN] );
83
84        $this->lb = $lb;
85        $this->params = $params;
86        $this->role = $role;
87
88        // $this->conn is valid as long as $this->modCountRef and $this->modCountFix are the same.
89        $this->modCountRef = &$modcount; // remember reference
90        $this->modCountFix = $modcount;  // remember current value
91    }
92
93    /**
94     * Connect to the database if we are not already connected.
95     */
96    public function ensureConnection() {
97        if ( $this->modCountFix !== $this->modCountRef ) {
98            // Discard existing connection, unless we are in an ongoing transaction.
99            // This is triggered by LoadBalancer::reconfigure(), to allow changed settings
100            // to take effect. The primary use case are replica servers being taken out of
101            // rotation, or the primary database changing.
102            if ( $this->conn && !$this->conn->trxLevel() ) {
103                $this->conn->close( wfGetCaller() );
104                $this->conn = null;
105            }
106        }
107
108        if ( $this->conn === null ) {
109            $this->conn = $this->lb->getConnectionInternal(
110                $this->params[self::FLD_INDEX],
111                $this->params[self::FLD_GROUPS],
112                $this->params[self::FLD_DOMAIN]->getId(),
113                $this->params[self::FLD_FLAGS]
114            );
115            $this->modCountFix = $this->modCountRef;
116        }
117
118        if ( !$this->params[self::FLD_DOMAIN]->equals( $this->conn->getDomainID() ) ) {
119            // The underlying connection handle is likely being shared by other DBConnRef
120            // instances in a load balancer. Make sure that each one routes queries by their
121            // owner function to the domain that the owner expects.
122            $this->conn->selectDomain( $this->params[self::FLD_DOMAIN] );
123        }
124    }
125
126    public function __call( $name, array $arguments ) {
127        $this->ensureConnection();
128
129        return $this->conn->$name( ...$arguments );
130    }
131
132    /**
133     * @return int DB_PRIMARY when this *requires* the primary DB, otherwise DB_REPLICA
134     * @since 1.33
135     */
136    public function getReferenceRole() {
137        return $this->role;
138    }
139
140    /** @inheritDoc */
141    public function getServerInfo() {
142        return $this->__call( __FUNCTION__, func_get_args() );
143    }
144
145    /** @inheritDoc */
146    public function trxLevel() {
147        return $this->__call( __FUNCTION__, func_get_args() );
148    }
149
150    /** @inheritDoc */
151    public function trxTimestamp() {
152        return $this->__call( __FUNCTION__, func_get_args() );
153    }
154
155    /** @inheritDoc */
156    public function explicitTrxActive() {
157        return $this->__call( __FUNCTION__, func_get_args() );
158    }
159
160    /** @inheritDoc */
161    public function tablePrefix( $prefix = null ) {
162        if ( $prefix !== null ) {
163            // Disallow things that might confuse the LoadBalancer tracking
164            throw $this->getDomainChangeException();
165        }
166
167        if ( $this->conn === null ) {
168            // Avoid triggering a database connection
169            $prefix = $this->params[self::FLD_DOMAIN]->getTablePrefix();
170        } else {
171            // This will just return the prefix
172            $prefix = $this->__call( __FUNCTION__, func_get_args() );
173        }
174
175        return $prefix;
176    }
177
178    /** @inheritDoc */
179    public function dbSchema( $schema = null ) {
180        if ( $schema !== null ) {
181            // Disallow things that might confuse the LoadBalancer tracking
182            throw $this->getDomainChangeException();
183        }
184
185        if ( $this->conn === null ) {
186            // Avoid triggering a database connection
187            $schema = (string)( $this->params[self::FLD_DOMAIN]->getSchema() );
188        } else {
189            // This will just return the schema
190            $schema = $this->__call( __FUNCTION__, func_get_args() );
191        }
192
193        return $schema;
194    }
195
196    /** @inheritDoc */
197    public function getLBInfo( $name = null ) {
198        return $this->__call( __FUNCTION__, func_get_args() );
199    }
200
201    /** @inheritDoc */
202    public function setLBInfo( $nameOrArray, $value = null ) {
203        // @phan-suppress-previous-line PhanPluginNeverReturnMethod
204        // Disallow things that might confuse the LoadBalancer tracking
205        throw $this->getDomainChangeException();
206    }
207
208    /** @inheritDoc */
209    public function implicitOrderby() {
210        return $this->__call( __FUNCTION__, func_get_args() );
211    }
212
213    /** @inheritDoc */
214    public function lastDoneWrites() {
215        return $this->__call( __FUNCTION__, func_get_args() );
216    }
217
218    /** @inheritDoc */
219    public function writesPending() {
220        return $this->__call( __FUNCTION__, func_get_args() );
221    }
222
223    /** @inheritDoc */
224    public function writesOrCallbacksPending() {
225        return $this->__call( __FUNCTION__, func_get_args() );
226    }
227
228    /** @inheritDoc */
229    public function pendingWriteQueryDuration( $type = self::ESTIMATE_TOTAL ) {
230        return $this->__call( __FUNCTION__, func_get_args() );
231    }
232
233    /** @inheritDoc */
234    public function pendingWriteCallers() {
235        return $this->__call( __FUNCTION__, func_get_args() );
236    }
237
238    /** @inheritDoc */
239    public function isOpen() {
240        return $this->__call( __FUNCTION__, func_get_args() );
241    }
242
243    /** @inheritDoc */
244    public function setFlag( $flag, $remember = self::REMEMBER_NOTHING ) {
245        return $this->__call( __FUNCTION__, func_get_args() );
246    }
247
248    /** @inheritDoc */
249    public function clearFlag( $flag, $remember = self::REMEMBER_NOTHING ) {
250        return $this->__call( __FUNCTION__, func_get_args() );
251    }
252
253    /** @inheritDoc */
254    public function restoreFlags( $state = self::RESTORE_PRIOR ) {
255        return $this->__call( __FUNCTION__, func_get_args() );
256    }
257
258    /** @inheritDoc */
259    public function getFlag( $flag ) {
260        return $this->__call( __FUNCTION__, func_get_args() );
261    }
262
263    /** @inheritDoc */
264    public function getProperty( $name ) {
265        return $this->__call( __FUNCTION__, func_get_args() );
266    }
267
268    /** @inheritDoc */
269    public function getDomainID() {
270        if ( $this->conn === null ) {
271            // Avoid triggering a database connection
272            return $this->params[self::FLD_DOMAIN]->getId();
273        }
274
275        return $this->__call( __FUNCTION__, func_get_args() );
276    }
277
278    /** @inheritDoc */
279    public function getType() {
280        if ( $this->conn === null ) {
281            // Avoid triggering a database connection
282            $index = $this->normalizeServerIndex( $this->params[self::FLD_INDEX] );
283            if ( $index >= 0 ) {
284                // In theory, if $index is DB_REPLICA, the type could vary
285                return $this->lb->getServerType( $index );
286            }
287        }
288
289        return $this->__call( __FUNCTION__, func_get_args() );
290    }
291
292    /** @inheritDoc */
293    public function insertId() {
294        return $this->__call( __FUNCTION__, func_get_args() );
295    }
296
297    /** @inheritDoc */
298    public function lastErrno() {
299        return $this->__call( __FUNCTION__, func_get_args() );
300    }
301
302    /** @inheritDoc */
303    public function lastError() {
304        return $this->__call( __FUNCTION__, func_get_args() );
305    }
306
307    /** @inheritDoc */
308    public function affectedRows() {
309        return $this->__call( __FUNCTION__, func_get_args() );
310    }
311
312    /** @inheritDoc */
313    public function getSoftwareLink() {
314        return $this->__call( __FUNCTION__, func_get_args() );
315    }
316
317    /** @inheritDoc */
318    public function getServerVersion() {
319        return $this->__call( __FUNCTION__, func_get_args() );
320    }
321
322    /** @inheritDoc */
323    public function close( $fname = __METHOD__ ) {
324        // @phan-suppress-previous-line PhanPluginNeverReturnMethod
325        throw new DBUnexpectedError( $this->conn, 'Cannot close shared connection.' );
326    }
327
328    /** @inheritDoc */
329    public function query( $sql, $fname = __METHOD__, $flags = 0 ) {
330        if ( $this->role !== ILoadBalancer::DB_PRIMARY ) {
331            $flags |= IDatabase::QUERY_REPLICA_ROLE;
332        }
333
334        return $this->__call( __FUNCTION__, [ $sql, $fname, $flags ] );
335    }
336
337    public function newSelectQueryBuilder(): SelectQueryBuilder {
338        // Use $this not $this->conn so that the domain is preserved (T326377)
339        return new SelectQueryBuilder( $this );
340    }
341
342    public function newUnionQueryBuilder(): UnionQueryBuilder {
343        // Use $this not $this->conn so that the domain is preserved (T326377)
344        return new UnionQueryBuilder( $this );
345    }
346
347    public function newUpdateQueryBuilder(): UpdateQueryBuilder {
348        // Use $this not $this->conn so that the domain is preserved (T326377)
349        return new UpdateQueryBuilder( $this );
350    }
351
352    public function newDeleteQueryBuilder(): DeleteQueryBuilder {
353        // Use $this not $this->conn so that the domain is preserved (T326377)
354        return new DeleteQueryBuilder( $this );
355    }
356
357    public function newInsertQueryBuilder(): InsertQueryBuilder {
358        // Use $this not $this->conn so that the domain is preserved (T326377)
359        return new InsertQueryBuilder( $this );
360    }
361
362    public function newReplaceQueryBuilder(): ReplaceQueryBuilder {
363        // Use $this not $this->conn so that the domain is preserved (T326377)
364        return new ReplaceQueryBuilder( $this );
365    }
366
367    /** @inheritDoc */
368    public function selectField(
369        $tables, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = []
370    ) {
371        return $this->__call( __FUNCTION__, func_get_args() );
372    }
373
374    /** @inheritDoc */
375    public function selectFieldValues(
376        $tables, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = []
377    ): array {
378        return $this->__call( __FUNCTION__, func_get_args() );
379    }
380
381    /** @inheritDoc */
382    public function select(
383        $tables, $vars, $conds = '', $fname = __METHOD__,
384        $options = [], $join_conds = []
385    ) {
386        return $this->__call( __FUNCTION__, func_get_args() );
387    }
388
389    /** @inheritDoc */
390    public function selectSQLText(
391        $tables, $vars, $conds = '', $fname = __METHOD__,
392        $options = [], $join_conds = []
393    ) {
394        return $this->__call( __FUNCTION__, func_get_args() );
395    }
396
397    /** @inheritDoc */
398    public function limitResult( $sql, $limit, $offset = false ) {
399        return $this->__call( __FUNCTION__, func_get_args() );
400    }
401
402    /** @inheritDoc */
403    public function selectRow(
404        $tables, $vars, $conds, $fname = __METHOD__,
405        $options = [], $join_conds = []
406    ) {
407        return $this->__call( __FUNCTION__, func_get_args() );
408    }
409
410    /** @inheritDoc */
411    public function estimateRowCount(
412        $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
413    ): int {
414        return $this->__call( __FUNCTION__, func_get_args() );
415    }
416
417    /** @inheritDoc */
418    public function selectRowCount(
419        $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
420    ): int {
421        return $this->__call( __FUNCTION__, func_get_args() );
422    }
423
424    /** @inheritDoc */
425    public function lockForUpdate(
426        $table, $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
427    ) {
428        $this->assertRoleAllowsWrites();
429
430        return $this->__call( __FUNCTION__, func_get_args() );
431    }
432
433    /** @inheritDoc */
434    public function fieldExists( $table, $field, $fname = __METHOD__ ) {
435        return $this->__call( __FUNCTION__, func_get_args() );
436    }
437
438    /** @inheritDoc */
439    public function indexExists( $table, $index, $fname = __METHOD__ ) {
440        return $this->__call( __FUNCTION__, func_get_args() );
441    }
442
443    /** @inheritDoc */
444    public function getPrimaryKeyColumns( $table, $fname = __METHOD__ ) {
445        return $this->__call( __FUNCTION__, func_get_args() );
446    }
447
448    /** @inheritDoc */
449    public function tableExists( $table, $fname = __METHOD__ ) {
450        return $this->__call( __FUNCTION__, func_get_args() );
451    }
452
453    /** @inheritDoc */
454    public function insert( $table, $rows, $fname = __METHOD__, $options = [] ) {
455        $this->assertRoleAllowsWrites();
456
457        return $this->__call( __FUNCTION__, func_get_args() );
458    }
459
460    /** @inheritDoc */
461    public function update( $table, $set, $conds, $fname = __METHOD__, $options = [] ) {
462        $this->assertRoleAllowsWrites();
463
464        return $this->__call( __FUNCTION__, func_get_args() );
465    }
466
467    /** @inheritDoc */
468    public function buildComparison( string $op, array $conds ): string {
469        return $this->__call( __FUNCTION__, func_get_args() );
470    }
471
472    /** @inheritDoc */
473    public function makeList( array $a, $mode = self::LIST_COMMA ) {
474        return $this->__call( __FUNCTION__, func_get_args() );
475    }
476
477    /** @inheritDoc */
478    public function makeWhereFrom2d( $data, $baseKey, $subKey ) {
479        return $this->__call( __FUNCTION__, func_get_args() );
480    }
481
482    /** @inheritDoc */
483    public function factorConds( $condsArray ) {
484        return $this->__call( __FUNCTION__, func_get_args() );
485    }
486
487    /** @inheritDoc */
488    public function bitNot( $field ) {
489        return $this->__call( __FUNCTION__, func_get_args() );
490    }
491
492    /** @inheritDoc */
493    public function bitAnd( $fieldLeft, $fieldRight ) {
494        return $this->__call( __FUNCTION__, func_get_args() );
495    }
496
497    /** @inheritDoc */
498    public function bitOr( $fieldLeft, $fieldRight ) {
499        return $this->__call( __FUNCTION__, func_get_args() );
500    }
501
502    /** @inheritDoc */
503    public function buildConcat( $stringList ) {
504        return $this->__call( __FUNCTION__, func_get_args() );
505    }
506
507    /** @inheritDoc */
508    public function buildGroupConcat( $field, $delim ): string {
509        return $this->__call( __FUNCTION__, func_get_args() );
510    }
511
512    /** @inheritDoc */
513    public function buildGroupConcatField(
514        $delim, $tables, $field, $conds = '', $join_conds = []
515    ) {
516        return $this->__call( __FUNCTION__, func_get_args() );
517    }
518
519    /** @inheritDoc */
520    public function buildGreatest( $fields, $values ) {
521        return $this->__call( __FUNCTION__, func_get_args() );
522    }
523
524    /** @inheritDoc */
525    public function buildLeast( $fields, $values ) {
526        return $this->__call( __FUNCTION__, func_get_args() );
527    }
528
529    /** @inheritDoc */
530    public function buildSubstring( $input, $startPosition, $length = null ) {
531        return $this->__call( __FUNCTION__, func_get_args() );
532    }
533
534    /** @inheritDoc */
535    public function buildStringCast( $field ) {
536        return $this->__call( __FUNCTION__, func_get_args() );
537    }
538
539    /** @inheritDoc */
540    public function buildIntegerCast( $field ) {
541        return $this->__call( __FUNCTION__, func_get_args() );
542    }
543
544    /** @inheritDoc */
545    public function buildExcludedValue( $column ) {
546        return $this->__call( __FUNCTION__, func_get_args() );
547    }
548
549    /** @inheritDoc */
550    public function buildSelectSubquery(
551        $tables, $vars, $conds = '', $fname = __METHOD__,
552        $options = [], $join_conds = []
553    ) {
554        return $this->__call( __FUNCTION__, func_get_args() );
555    }
556
557    /** @inheritDoc */
558    public function databasesAreIndependent() {
559        return $this->__call( __FUNCTION__, func_get_args() );
560    }
561
562    /** @inheritDoc */
563    public function selectDomain( $domain ) {
564        // @phan-suppress-previous-line PhanPluginNeverReturnMethod
565        // Disallow things that might confuse the LoadBalancer tracking
566        throw $this->getDomainChangeException();
567    }
568
569    /** @inheritDoc */
570    public function getDBname() {
571        if ( $this->conn === null ) {
572            // Avoid triggering a database connection
573            return $this->params[self::FLD_DOMAIN]->getDatabase();
574        }
575
576        return $this->__call( __FUNCTION__, func_get_args() );
577    }
578
579    /** @inheritDoc */
580    public function getServer() {
581        return $this->__call( __FUNCTION__, func_get_args() );
582    }
583
584    /** @inheritDoc */
585    public function getServerName() {
586        if ( $this->conn === null ) {
587            // Avoid triggering a database connection
588            $index = $this->normalizeServerIndex( $this->params[self::FLD_INDEX] );
589            if ( $index >= 0 ) {
590                // If $index is DB_REPLICA, the server name could vary
591                return $this->lb->getServerName( $index );
592            }
593        }
594
595        return $this->__call( __FUNCTION__, func_get_args() );
596    }
597
598    /** @inheritDoc */
599    public function addQuotes( $s ) {
600        return $this->__call( __FUNCTION__, func_get_args() );
601    }
602
603    /** @inheritDoc */
604    public function expr( string $field, string $op, $value ): Expression {
605        // Does not use __call here to delay creating the db connection
606        return new Expression( $field, $op, $value );
607    }
608
609    /** @inheritDoc */
610    public function andExpr( array $conds ): AndExpressionGroup {
611        // Does not use __call here to delay creating the db connection
612        return AndExpressionGroup::newFromArray( $conds );
613    }
614
615    /** @inheritDoc */
616    public function orExpr( array $conds ): OrExpressionGroup {
617        // Does not use __call here to delay creating the db connection
618        return OrExpressionGroup::newFromArray( $conds );
619    }
620
621    /** @inheritDoc */
622    public function addIdentifierQuotes( $s ) {
623        return $this->__call( __FUNCTION__, func_get_args() );
624    }
625
626    /** @inheritDoc */
627    public function buildLike( $param, ...$params ) {
628        return $this->__call( __FUNCTION__, func_get_args() );
629    }
630
631    /** @inheritDoc */
632    public function anyChar() {
633        return $this->__call( __FUNCTION__, func_get_args() );
634    }
635
636    /** @inheritDoc */
637    public function anyString() {
638        return $this->__call( __FUNCTION__, func_get_args() );
639    }
640
641    /** @inheritDoc */
642    public function replace( $table, $uniqueKeys, $rows, $fname = __METHOD__ ) {
643        $this->assertRoleAllowsWrites();
644
645        return $this->__call( __FUNCTION__, func_get_args() );
646    }
647
648    /** @inheritDoc */
649    public function upsert(
650        $table, array $rows, $uniqueKeys, array $set, $fname = __METHOD__
651    ) {
652        $this->assertRoleAllowsWrites();
653
654        return $this->__call( __FUNCTION__, func_get_args() );
655    }
656
657    /** @inheritDoc */
658    public function deleteJoin(
659        $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__
660    ) {
661        $this->assertRoleAllowsWrites();
662
663        $this->__call( __FUNCTION__, func_get_args() );
664    }
665
666    /** @inheritDoc */
667    public function delete( $table, $conds, $fname = __METHOD__ ) {
668        $this->assertRoleAllowsWrites();
669
670        return $this->__call( __FUNCTION__, func_get_args() );
671    }
672
673    /** @inheritDoc */
674    public function insertSelect(
675        $destTable, $srcTable, $varMap, $conds,
676        $fname = __METHOD__, $insertOptions = [], $selectOptions = [], $selectJoinConds = []
677    ) {
678        $this->assertRoleAllowsWrites();
679
680        return $this->__call( __FUNCTION__, func_get_args() );
681    }
682
683    /** @inheritDoc */
684    public function unionSupportsOrderAndLimit() {
685        return $this->__call( __FUNCTION__, func_get_args() );
686    }
687
688    /** @inheritDoc */
689    public function unionQueries( $sqls, $all, $options = [] ) {
690        return $this->__call( __FUNCTION__, func_get_args() );
691    }
692
693    /** @inheritDoc */
694    public function conditional( $cond, $caseTrueExpression, $caseFalseExpression ) {
695        return $this->__call( __FUNCTION__, func_get_args() );
696    }
697
698    /** @inheritDoc */
699    public function strreplace( $orig, $old, $new ) {
700        return $this->__call( __FUNCTION__, func_get_args() );
701    }
702
703    /** @inheritDoc */
704    public function primaryPosWait( DBPrimaryPos $pos, $timeout ) {
705        return $this->__call( __FUNCTION__, func_get_args() );
706    }
707
708    /** @inheritDoc */
709    public function getPrimaryPos() {
710        return $this->__call( __FUNCTION__, func_get_args() );
711    }
712
713    /** @inheritDoc */
714    public function serverIsReadOnly() {
715        return $this->__call( __FUNCTION__, func_get_args() );
716    }
717
718    /** @inheritDoc */
719    public function onTransactionResolution( callable $callback, $fname = __METHOD__ ) {
720        // DB_REPLICA role: caller might want to refresh cache after a REPEATABLE-READ snapshot
721        return $this->__call( __FUNCTION__, func_get_args() );
722    }
723
724    /** @inheritDoc */
725    public function onTransactionCommitOrIdle( callable $callback, $fname = __METHOD__ ) {
726        // DB_REPLICA role: caller might want to refresh cache after a REPEATABLE-READ snapshot
727        return $this->__call( __FUNCTION__, func_get_args() );
728    }
729
730    /** @inheritDoc */
731    public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ ) {
732        // DB_REPLICA role: caller might want to refresh cache after a cache mutex is released
733        return $this->__call( __FUNCTION__, func_get_args() );
734    }
735
736    /** @inheritDoc */
737    public function setTransactionListener( $name, ?callable $callback = null ) {
738        return $this->__call( __FUNCTION__, func_get_args() );
739    }
740
741    /** @inheritDoc */
742    public function startAtomic(
743        $fname = __METHOD__, $cancelable = IDatabase::ATOMIC_NOT_CANCELABLE
744    ) {
745        // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
746        return $this->__call( __FUNCTION__, func_get_args() );
747    }
748
749    /** @inheritDoc */
750    public function endAtomic( $fname = __METHOD__ ) {
751        // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
752        return $this->__call( __FUNCTION__, func_get_args() );
753    }
754
755    /** @inheritDoc */
756    public function cancelAtomic( $fname = __METHOD__, ?AtomicSectionIdentifier $sectionId = null ) {
757        // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
758        return $this->__call( __FUNCTION__, func_get_args() );
759    }
760
761    /** @inheritDoc */
762    public function doAtomicSection(
763        $fname, callable $callback, $cancelable = self::ATOMIC_NOT_CANCELABLE
764    ) {
765        // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
766        return $this->__call( __FUNCTION__, func_get_args() );
767    }
768
769    /** @inheritDoc */
770    public function begin( $fname = __METHOD__, $mode = IDatabase::TRANSACTION_EXPLICIT ) {
771        return $this->__call( __FUNCTION__, func_get_args() );
772    }
773
774    /** @inheritDoc */
775    public function commit( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) {
776        return $this->__call( __FUNCTION__, func_get_args() );
777    }
778
779    /** @inheritDoc */
780    public function rollback( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) {
781        return $this->__call( __FUNCTION__, func_get_args() );
782    }
783
784    /** @inheritDoc */
785    public function flushSession( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) {
786        return $this->__call( __FUNCTION__, func_get_args() );
787    }
788
789    /** @inheritDoc */
790    public function flushSnapshot( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) {
791        return $this->__call( __FUNCTION__, func_get_args() );
792    }
793
794    /** @inheritDoc */
795    public function timestamp( $ts = 0 ) {
796        return $this->__call( __FUNCTION__, func_get_args() );
797    }
798
799    /** @inheritDoc */
800    public function timestampOrNull( $ts = null ) {
801        return $this->__call( __FUNCTION__, func_get_args() );
802    }
803
804    /** @inheritDoc */
805    public function ping( &$rtt = null ) {
806        return func_num_args()
807            ? $this->__call( __FUNCTION__, [ &$rtt ] )
808            : $this->__call( __FUNCTION__, [] ); // method cares about null vs missing
809    }
810
811    /** @inheritDoc */
812    public function getLag() {
813        return $this->__call( __FUNCTION__, func_get_args() );
814    }
815
816    /** @inheritDoc */
817    public function getSessionLagStatus() {
818        return $this->__call( __FUNCTION__, func_get_args() );
819    }
820
821    /** @inheritDoc */
822    public function encodeBlob( $b ) {
823        return $this->__call( __FUNCTION__, func_get_args() );
824    }
825
826    /** @inheritDoc */
827    public function decodeBlob( $b ) {
828        return $this->__call( __FUNCTION__, func_get_args() );
829    }
830
831    /** @inheritDoc */
832    public function setSessionOptions( array $options ) {
833        $this->__call( __FUNCTION__, func_get_args() );
834    }
835
836    /** @inheritDoc */
837    public function setSchemaVars( $vars ) {
838        return $this->__call( __FUNCTION__, func_get_args() );
839    }
840
841    /** @inheritDoc */
842    public function lockIsFree( $lockName, $method ) {
843        $this->assertRoleAllowsWrites();
844
845        return $this->__call( __FUNCTION__, func_get_args() );
846    }
847
848    /** @inheritDoc */
849    public function lock( $lockName, $method, $timeout = 5, $flags = 0 ) {
850        $this->assertRoleAllowsWrites();
851
852        return $this->__call( __FUNCTION__, func_get_args() );
853    }
854
855    /** @inheritDoc */
856    public function unlock( $lockName, $method ) {
857        $this->assertRoleAllowsWrites();
858
859        return $this->__call( __FUNCTION__, func_get_args() );
860    }
861
862    /** @inheritDoc */
863    #[\NoDiscard]
864    public function getScopedLockAndFlush( $lockKey, $fname, $timeout ): ?ScopedCallback {
865        $this->assertRoleAllowsWrites();
866
867        return $this->__call( __FUNCTION__, func_get_args() );
868    }
869
870    /** @inheritDoc */
871    public function getInfinity() {
872        return $this->__call( __FUNCTION__, func_get_args() );
873    }
874
875    /** @inheritDoc */
876    public function encodeExpiry( $expiry ) {
877        return $this->__call( __FUNCTION__, func_get_args() );
878    }
879
880    /** @inheritDoc */
881    public function decodeExpiry( $expiry, $format = TS::MW ) {
882        return $this->__call( __FUNCTION__, func_get_args() );
883    }
884
885    /** @inheritDoc */
886    public function isReadOnly() {
887        return $this->__call( __FUNCTION__, func_get_args() );
888    }
889
890    /** @inheritDoc */
891    public function setTableAliases( array $aliases ) {
892        return $this->__call( __FUNCTION__, func_get_args() );
893    }
894
895    /** @inheritDoc */
896    public function getTableAliases() {
897        return $this->__call( __FUNCTION__, func_get_args() );
898    }
899
900    /** @inheritDoc */
901    public function tableName( $name, $format = 'quoted' ) {
902        return $this->__call( __FUNCTION__, func_get_args() );
903    }
904
905    /** @inheritDoc */
906    public function tableNames( ...$tables ) {
907        return $this->__call( __FUNCTION__, func_get_args() );
908    }
909
910    /** @inheritDoc */
911    public function tableNamesN( ...$tables ) {
912        return $this->__call( __FUNCTION__, func_get_args() );
913    }
914
915    /** @inheritDoc */
916    public function sourceFile(
917        $filename,
918        ?callable $lineCallback = null,
919        ?callable $resultCallback = null,
920        $fname = false,
921        ?callable $inputCallback = null
922    ) {
923        $this->assertRoleAllowsWrites();
924
925        return $this->__call( __FUNCTION__, func_get_args() );
926    }
927
928    /** @inheritDoc */
929    public function sourceStream(
930        $fp,
931        ?callable $lineCallback = null,
932        ?callable $resultCallback = null,
933        $fname = __METHOD__,
934        ?callable $inputCallback = null
935    ) {
936        $this->assertRoleAllowsWrites();
937
938        return $this->__call( __FUNCTION__, func_get_args() );
939    }
940
941    /** @inheritDoc */
942    public function dropTable( $table, $fname = __METHOD__ ) {
943        $this->assertRoleAllowsWrites();
944
945        return $this->__call( __FUNCTION__, func_get_args() );
946    }
947
948    /** @inheritDoc */
949    public function truncateTable( $table, $fname = __METHOD__ ) {
950        $this->assertRoleAllowsWrites();
951
952        return $this->__call( __FUNCTION__, func_get_args() );
953    }
954
955    /** @inheritDoc */
956    public function streamStatementEnd( &$sql, &$newLine ) {
957        return $this->__call( __FUNCTION__, [ &$sql, &$newLine ] );
958    }
959
960    /** @inheritDoc */
961    public function duplicateTableStructure(
962        $oldName, $newName, $temporary = false, $fname = __METHOD__
963    ) {
964        $this->assertRoleAllowsWrites();
965
966        return $this->__call( __FUNCTION__, func_get_args() );
967    }
968
969    /** @inheritDoc */
970    public function indexUnique( $table, $index, $fname = __METHOD__ ) {
971        return $this->__call( __FUNCTION__, func_get_args() );
972    }
973
974    /** @inheritDoc */
975    public function listTables( $prefix = null, $fname = __METHOD__ ) {
976        return $this->__call( __FUNCTION__, func_get_args() );
977    }
978
979    /** @inheritDoc */
980    public function fieldInfo( $table, $field ) {
981        return $this->__call( __FUNCTION__, func_get_args() );
982    }
983
984    public function __toString() {
985        if ( $this->conn === null ) {
986            return $this->getType() . ' object #' . spl_object_id( $this );
987        }
988
989        return $this->__call( __FUNCTION__, func_get_args() );
990    }
991
992    /**
993     * Error out if the role is not DB_PRIMARY
994     *
995     * Note that the underlying connection may or may not itself be read-only.
996     * It could even be to a writable primary (both server-side and to the application).
997     * This error is meant for the case when a DB_REPLICA handle was requested but a
998     * a write was attempted on that handle regardless.
999     *
1000     * In configurations where the primary DB has some generic read load or is the only server,
1001     * DB_PRIMARY/DB_REPLICA will sometimes (or always) use the same connection to the primary DB.
1002     * This does not effect the role of DBConnRef instances.
1003     * @throws DBReadOnlyRoleError
1004     */
1005    protected function assertRoleAllowsWrites() {
1006        // DB_PRIMARY is "prima facie" writable
1007        if ( $this->role !== ILoadBalancer::DB_PRIMARY ) {
1008            throw new DBReadOnlyRoleError( $this->conn, "Cannot write with role DB_REPLICA" );
1009        }
1010    }
1011
1012    /**
1013     * @return DBUnexpectedError
1014     */
1015    protected function getDomainChangeException() {
1016        return new DBUnexpectedError(
1017            $this,
1018            "Cannot directly change the selected DB domain; any underlying connection handle " .
1019            "is owned by a LoadBalancer instance and possibly shared with other callers. " .
1020            "LoadBalancer automatically manages DB domain re-selection of unused handles."
1021        );
1022    }
1023
1024    /**
1025     * @param int $i Specific or virtual (DB_PRIMARY/DB_REPLICA) server index
1026     * @return int|mixed
1027     */
1028    protected function normalizeServerIndex( $i ) {
1029        return ( $i === ILoadBalancer::DB_PRIMARY ) ? ServerInfo::WRITER_INDEX : $i;
1030    }
1031}