MediaWiki  master
DBConnRef.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Rdbms;
4 
6 
29 class DBConnRef implements IDatabase {
31  private $lb;
33  private $conn;
35  private $params;
37  private $role;
38 
39  const FLD_INDEX = 0;
40  const FLD_GROUP = 1;
41  const FLD_DOMAIN = 2;
42  const FLD_FLAGS = 3;
43 
50  public function __construct( ILoadBalancer $lb, $conn, $role ) {
51  $this->lb = $lb;
52  $this->role = $role;
53  if ( $conn instanceof IDatabase && !( $conn instanceof DBConnRef ) ) {
54  $this->conn = $conn; // live handle
55  } elseif ( is_array( $conn ) && count( $conn ) >= 4 && $conn[self::FLD_DOMAIN] !== false ) {
56  $this->params = $conn;
57  } else {
58  throw new InvalidArgumentException( "Missing lazy connection arguments." );
59  }
60  }
61 
62  function __call( $name, array $arguments ) {
63  if ( $this->conn === null ) {
64  list( $index, $groups, $wiki, $flags ) = $this->params;
65  $this->conn = $this->lb->getConnection( $index, $groups, $wiki, $flags );
66  }
67 
68  return $this->conn->$name( ...$arguments );
69  }
70 
75  public function getReferenceRole() {
76  return $this->role;
77  }
78 
79  public function getServerInfo() {
80  return $this->__call( __FUNCTION__, func_get_args() );
81  }
82 
83  public function bufferResults( $buffer = null ) {
84  return $this->__call( __FUNCTION__, func_get_args() );
85  }
86 
87  public function trxLevel() {
88  return $this->__call( __FUNCTION__, func_get_args() );
89  }
90 
91  public function trxTimestamp() {
92  return $this->__call( __FUNCTION__, func_get_args() );
93  }
94 
95  public function explicitTrxActive() {
96  return $this->__call( __FUNCTION__, func_get_args() );
97  }
98 
99  public function assertNoOpenTransactions() {
100  return $this->__call( __FUNCTION__, func_get_args() );
101  }
102 
103  public function tablePrefix( $prefix = null ) {
104  if ( $this->conn === null && $prefix === null ) {
105  $domain = DatabaseDomain::newFromId( $this->params[self::FLD_DOMAIN] );
106  // Avoid triggering a database connection
107  return $domain->getTablePrefix();
108  } elseif ( $this->conn !== null && $prefix === null ) {
109  // This will just return the prefix
110  return $this->__call( __FUNCTION__, func_get_args() );
111  }
112  // Disallow things that might confuse the LoadBalancer tracking
113  throw new DBUnexpectedError( $this, "Database selection is disallowed to enable reuse." );
114  }
115 
116  public function dbSchema( $schema = null ) {
117  if ( $this->conn === null && $schema === null ) {
118  $domain = DatabaseDomain::newFromId( $this->params[self::FLD_DOMAIN] );
119  // Avoid triggering a database connection
120  return $domain->getSchema();
121  } elseif ( $this->conn !== null && $schema === null ) {
122  // This will just return the schema
123  return $this->__call( __FUNCTION__, func_get_args() );
124  }
125  // Disallow things that might confuse the LoadBalancer tracking
126  throw new DBUnexpectedError( $this, "Database selection is disallowed to enable reuse." );
127  }
128 
129  public function getLBInfo( $name = null ) {
130  return $this->__call( __FUNCTION__, func_get_args() );
131  }
132 
133  public function setLBInfo( $nameOrArray, $value = null ) {
134  // Disallow things that might confuse the LoadBalancer tracking
135  throw new DBUnexpectedError( $this, "Changing LB info is disallowed to enable reuse." );
136  }
137 
138  public function setLazyMasterHandle( IDatabase $conn ) {
139  // Disallow things that might confuse the LoadBalancer tracking
140  throw new DBUnexpectedError( $this, "Database injection is disallowed to enable reuse." );
141  }
142 
143  public function implicitGroupby() {
144  return $this->__call( __FUNCTION__, func_get_args() );
145  }
146 
147  public function implicitOrderby() {
148  return $this->__call( __FUNCTION__, func_get_args() );
149  }
150 
151  public function lastQuery() {
152  return $this->__call( __FUNCTION__, func_get_args() );
153  }
154 
155  public function doneWrites() {
156  return $this->__call( __FUNCTION__, func_get_args() );
157  }
158 
159  public function lastDoneWrites() {
160  return $this->__call( __FUNCTION__, func_get_args() );
161  }
162 
163  public function writesPending() {
164  return $this->__call( __FUNCTION__, func_get_args() );
165  }
166 
167  public function preCommitCallbacksPending() {
168  return $this->__call( __FUNCTION__, func_get_args() );
169  }
170 
171  public function writesOrCallbacksPending() {
172  return $this->__call( __FUNCTION__, func_get_args() );
173  }
174 
175  public function pendingWriteQueryDuration( $type = self::ESTIMATE_TOTAL ) {
176  return $this->__call( __FUNCTION__, func_get_args() );
177  }
178 
179  public function pendingWriteCallers() {
180  return $this->__call( __FUNCTION__, func_get_args() );
181  }
182 
183  public function pendingWriteRowsAffected() {
184  return $this->__call( __FUNCTION__, func_get_args() );
185  }
186 
187  public function isOpen() {
188  return $this->__call( __FUNCTION__, func_get_args() );
189  }
190 
191  public function setFlag( $flag, $remember = self::REMEMBER_NOTHING ) {
192  return $this->__call( __FUNCTION__, func_get_args() );
193  }
194 
195  public function clearFlag( $flag, $remember = self::REMEMBER_NOTHING ) {
196  return $this->__call( __FUNCTION__, func_get_args() );
197  }
198 
199  public function restoreFlags( $state = self::RESTORE_PRIOR ) {
200  return $this->__call( __FUNCTION__, func_get_args() );
201  }
202 
203  public function getFlag( $flag ) {
204  return $this->__call( __FUNCTION__, func_get_args() );
205  }
206 
207  public function getProperty( $name ) {
208  return $this->__call( __FUNCTION__, func_get_args() );
209  }
210 
211  public function getDomainID() {
212  if ( $this->conn === null ) {
213  $domain = $this->params[self::FLD_DOMAIN];
214  // Avoid triggering a database connection
215  return $domain instanceof DatabaseDomain ? $domain->getId() : $domain;
216  }
217 
218  return $this->__call( __FUNCTION__, func_get_args() );
219  }
220 
224  public function getWikiID() {
225  return $this->getDomainID();
226  }
227 
228  public function getType() {
229  if ( $this->conn === null ) {
230  // Avoid triggering a database connection
231  if ( $this->params[self::FLD_INDEX] === ILoadBalancer::DB_MASTER ) {
232  $index = $this->lb->getWriterIndex();
233  } else {
234  $index = $this->params[self::FLD_INDEX];
235  }
236  if ( $index >= 0 ) {
237  // In theory, if $index is DB_REPLICA, the type could vary
238  return $this->lb->getServerType( $index );
239  }
240  }
241 
242  return $this->__call( __FUNCTION__, func_get_args() );
243  }
244 
245  public function fetchObject( $res ) {
246  return $this->__call( __FUNCTION__, func_get_args() );
247  }
248 
249  public function fetchRow( $res ) {
250  return $this->__call( __FUNCTION__, func_get_args() );
251  }
252 
253  public function numRows( $res ) {
254  return $this->__call( __FUNCTION__, func_get_args() );
255  }
256 
257  public function numFields( $res ) {
258  return $this->__call( __FUNCTION__, func_get_args() );
259  }
260 
261  public function fieldName( $res, $n ) {
262  return $this->__call( __FUNCTION__, func_get_args() );
263  }
264 
265  public function insertId() {
266  return $this->__call( __FUNCTION__, func_get_args() );
267  }
268 
269  public function dataSeek( $res, $row ) {
270  return $this->__call( __FUNCTION__, func_get_args() );
271  }
272 
273  public function lastErrno() {
274  return $this->__call( __FUNCTION__, func_get_args() );
275  }
276 
277  public function lastError() {
278  return $this->__call( __FUNCTION__, func_get_args() );
279  }
280 
281  public function affectedRows() {
282  return $this->__call( __FUNCTION__, func_get_args() );
283  }
284 
285  public function getSoftwareLink() {
286  return $this->__call( __FUNCTION__, func_get_args() );
287  }
288 
289  public function getServerVersion() {
290  return $this->__call( __FUNCTION__, func_get_args() );
291  }
292 
293  public function close() {
294  throw new DBUnexpectedError( $this->conn, 'Cannot close shared connection.' );
295  }
296 
297  public function query( $sql, $fname = __METHOD__, $flags = 0 ) {
298  if ( $this->role !== ILoadBalancer::DB_MASTER ) {
299  $flags |= IDatabase::QUERY_REPLICA_ROLE;
300  }
301 
302  return $this->__call( __FUNCTION__, [ $sql, $fname, $flags ] );
303  }
304 
305  public function freeResult( $res ) {
306  return $this->__call( __FUNCTION__, func_get_args() );
307  }
308 
309  public function selectField(
310  $table, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = []
311  ) {
312  return $this->__call( __FUNCTION__, func_get_args() );
313  }
314 
315  public function selectFieldValues(
316  $table, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = []
317  ) {
318  return $this->__call( __FUNCTION__, func_get_args() );
319  }
320 
321  public function select(
322  $table, $vars, $conds = '', $fname = __METHOD__,
323  $options = [], $join_conds = []
324  ) {
325  return $this->__call( __FUNCTION__, func_get_args() );
326  }
327 
328  public function selectSQLText(
329  $table, $vars, $conds = '', $fname = __METHOD__,
330  $options = [], $join_conds = []
331  ) {
332  return $this->__call( __FUNCTION__, func_get_args() );
333  }
334 
335  public function limitResult( $sql, $limit, $offset = false ) {
336  return $this->__call( __FUNCTION__, func_get_args() );
337  }
338 
339  public function selectRow(
340  $table, $vars, $conds, $fname = __METHOD__,
341  $options = [], $join_conds = []
342  ) {
343  return $this->__call( __FUNCTION__, func_get_args() );
344  }
345 
346  public function estimateRowCount(
347  $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
348  ) {
349  return $this->__call( __FUNCTION__, func_get_args() );
350  }
351 
352  public function selectRowCount(
353  $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
354  ) {
355  return $this->__call( __FUNCTION__, func_get_args() );
356  }
357 
358  public function lockForUpdate(
359  $table, $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
360  ) {
361  $this->assertRoleAllowsWrites();
362 
363  return $this->__call( __FUNCTION__, func_get_args() );
364  }
365 
366  public function fieldExists( $table, $field, $fname = __METHOD__ ) {
367  return $this->__call( __FUNCTION__, func_get_args() );
368  }
369 
370  public function indexExists( $table, $index, $fname = __METHOD__ ) {
371  return $this->__call( __FUNCTION__, func_get_args() );
372  }
373 
374  public function tableExists( $table, $fname = __METHOD__ ) {
375  return $this->__call( __FUNCTION__, func_get_args() );
376  }
377 
378  public function insert( $table, $a, $fname = __METHOD__, $options = [] ) {
379  $this->assertRoleAllowsWrites();
380 
381  return $this->__call( __FUNCTION__, func_get_args() );
382  }
383 
384  public function update( $table, $values, $conds, $fname = __METHOD__, $options = [] ) {
385  $this->assertRoleAllowsWrites();
386 
387  return $this->__call( __FUNCTION__, func_get_args() );
388  }
389 
390  public function makeList( $a, $mode = self::LIST_COMMA ) {
391  return $this->__call( __FUNCTION__, func_get_args() );
392  }
393 
394  public function makeWhereFrom2d( $data, $baseKey, $subKey ) {
395  return $this->__call( __FUNCTION__, func_get_args() );
396  }
397 
398  public function aggregateValue( $valuedata, $valuename = 'value' ) {
399  return $this->__call( __FUNCTION__, func_get_args() );
400  }
401 
402  public function bitNot( $field ) {
403  return $this->__call( __FUNCTION__, func_get_args() );
404  }
405 
406  public function bitAnd( $fieldLeft, $fieldRight ) {
407  return $this->__call( __FUNCTION__, func_get_args() );
408  }
409 
410  public function bitOr( $fieldLeft, $fieldRight ) {
411  return $this->__call( __FUNCTION__, func_get_args() );
412  }
413 
414  public function buildConcat( $stringList ) {
415  return $this->__call( __FUNCTION__, func_get_args() );
416  }
417 
418  public function buildGroupConcatField(
419  $delim, $table, $field, $conds = '', $join_conds = []
420  ) {
421  return $this->__call( __FUNCTION__, func_get_args() );
422  }
423 
424  public function buildSubstring( $input, $startPosition, $length = null ) {
425  return $this->__call( __FUNCTION__, func_get_args() );
426  }
427 
428  public function buildStringCast( $field ) {
429  return $this->__call( __FUNCTION__, func_get_args() );
430  }
431 
432  public function buildIntegerCast( $field ) {
433  return $this->__call( __FUNCTION__, func_get_args() );
434  }
435 
436  public function buildSelectSubquery(
437  $table, $vars, $conds = '', $fname = __METHOD__,
438  $options = [], $join_conds = []
439  ) {
440  return $this->__call( __FUNCTION__, func_get_args() );
441  }
442 
443  public function databasesAreIndependent() {
444  return $this->__call( __FUNCTION__, func_get_args() );
445  }
446 
447  public function selectDB( $db ) {
448  // Disallow things that might confuse the LoadBalancer tracking
449  throw new DBUnexpectedError( $this, "Database selection is disallowed to enable reuse." );
450  }
451 
452  public function selectDomain( $domain ) {
453  // Disallow things that might confuse the LoadBalancer tracking
454  throw new DBUnexpectedError( $this, "Database selection is disallowed to enable reuse." );
455  }
456 
457  public function getDBname() {
458  if ( $this->conn === null ) {
459  $domain = DatabaseDomain::newFromId( $this->params[self::FLD_DOMAIN] );
460  // Avoid triggering a database connection
461  return $domain->getDatabase();
462  }
463 
464  return $this->__call( __FUNCTION__, func_get_args() );
465  }
466 
467  public function getServer() {
468  return $this->__call( __FUNCTION__, func_get_args() );
469  }
470 
471  public function addQuotes( $s ) {
472  return $this->__call( __FUNCTION__, func_get_args() );
473  }
474 
475  public function addIdentifierQuotes( $s ) {
476  return $this->__call( __FUNCTION__, func_get_args() );
477  }
478 
479  public function buildLike( $param ) {
480  return $this->__call( __FUNCTION__, func_get_args() );
481  }
482 
483  public function anyChar() {
484  return $this->__call( __FUNCTION__, func_get_args() );
485  }
486 
487  public function anyString() {
488  return $this->__call( __FUNCTION__, func_get_args() );
489  }
490 
491  public function nextSequenceValue( $seqName ) {
492  $this->assertRoleAllowsWrites();
493 
494  return $this->__call( __FUNCTION__, func_get_args() );
495  }
496 
497  public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
498  $this->assertRoleAllowsWrites();
499 
500  return $this->__call( __FUNCTION__, func_get_args() );
501  }
502 
503  public function upsert(
504  $table, array $rows, $uniqueIndexes, array $set, $fname = __METHOD__
505  ) {
506  $this->assertRoleAllowsWrites();
507 
508  return $this->__call( __FUNCTION__, func_get_args() );
509  }
510 
511  public function deleteJoin(
512  $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__
513  ) {
514  $this->assertRoleAllowsWrites();
515 
516  return $this->__call( __FUNCTION__, func_get_args() );
517  }
518 
519  public function delete( $table, $conds, $fname = __METHOD__ ) {
520  $this->assertRoleAllowsWrites();
521 
522  return $this->__call( __FUNCTION__, func_get_args() );
523  }
524 
525  public function insertSelect(
526  $destTable, $srcTable, $varMap, $conds,
527  $fname = __METHOD__, $insertOptions = [], $selectOptions = [], $selectJoinConds = []
528  ) {
529  $this->assertRoleAllowsWrites();
530 
531  return $this->__call( __FUNCTION__, func_get_args() );
532  }
533 
534  public function unionSupportsOrderAndLimit() {
535  return $this->__call( __FUNCTION__, func_get_args() );
536  }
537 
538  public function unionQueries( $sqls, $all ) {
539  return $this->__call( __FUNCTION__, func_get_args() );
540  }
541 
542  public function unionConditionPermutations(
543  $table, $vars, array $permute_conds, $extra_conds = '', $fname = __METHOD__,
544  $options = [], $join_conds = []
545  ) {
546  return $this->__call( __FUNCTION__, func_get_args() );
547  }
548 
549  public function conditional( $cond, $trueVal, $falseVal ) {
550  return $this->__call( __FUNCTION__, func_get_args() );
551  }
552 
553  public function strreplace( $orig, $old, $new ) {
554  return $this->__call( __FUNCTION__, func_get_args() );
555  }
556 
557  public function getServerUptime() {
558  return $this->__call( __FUNCTION__, func_get_args() );
559  }
560 
561  public function wasDeadlock() {
562  return $this->__call( __FUNCTION__, func_get_args() );
563  }
564 
565  public function wasLockTimeout() {
566  return $this->__call( __FUNCTION__, func_get_args() );
567  }
568 
569  public function wasConnectionLoss() {
570  return $this->__call( __FUNCTION__, func_get_args() );
571  }
572 
573  public function wasReadOnlyError() {
574  return $this->__call( __FUNCTION__, func_get_args() );
575  }
576 
577  public function wasErrorReissuable() {
578  return $this->__call( __FUNCTION__, func_get_args() );
579  }
580 
581  public function masterPosWait( DBMasterPos $pos, $timeout ) {
582  return $this->__call( __FUNCTION__, func_get_args() );
583  }
584 
585  public function getReplicaPos() {
586  return $this->__call( __FUNCTION__, func_get_args() );
587  }
588 
589  public function getMasterPos() {
590  return $this->__call( __FUNCTION__, func_get_args() );
591  }
592 
593  public function serverIsReadOnly() {
594  return $this->__call( __FUNCTION__, func_get_args() );
595  }
596 
597  public function onTransactionResolution( callable $callback, $fname = __METHOD__ ) {
598  // DB_REPLICA role: caller might want to refresh cache after a REPEATABLE-READ snapshot
599  return $this->__call( __FUNCTION__, func_get_args() );
600  }
601 
602  public function onTransactionCommitOrIdle( callable $callback, $fname = __METHOD__ ) {
603  // DB_REPLICA role: caller might want to refresh cache after a REPEATABLE-READ snapshot
604  return $this->__call( __FUNCTION__, func_get_args() );
605  }
606 
607  public function onTransactionIdle( callable $callback, $fname = __METHOD__ ) {
608  return $this->onTransactionCommitOrIdle( $callback, $fname );
609  }
610 
611  public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ ) {
612  // DB_REPLICA role: caller might want to refresh cache after a cache mutex is released
613  return $this->__call( __FUNCTION__, func_get_args() );
614  }
615 
616  public function onAtomicSectionCancel( callable $callback, $fname = __METHOD__ ) {
617  return $this->__call( __FUNCTION__, func_get_args() );
618  }
619 
620  public function setTransactionListener( $name, callable $callback = null ) {
621  return $this->__call( __FUNCTION__, func_get_args() );
622  }
623 
624  public function startAtomic(
625  $fname = __METHOD__, $cancelable = IDatabase::ATOMIC_NOT_CANCELABLE
626  ) {
627  // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
628  return $this->__call( __FUNCTION__, func_get_args() );
629  }
630 
631  public function endAtomic( $fname = __METHOD__ ) {
632  // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
633  return $this->__call( __FUNCTION__, func_get_args() );
634  }
635 
636  public function cancelAtomic( $fname = __METHOD__, AtomicSectionIdentifier $sectionId = null ) {
637  // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
638  return $this->__call( __FUNCTION__, func_get_args() );
639  }
640 
641  public function doAtomicSection(
642  $fname, callable $callback, $cancelable = self::ATOMIC_NOT_CANCELABLE
643  ) {
644  // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
645  return $this->__call( __FUNCTION__, func_get_args() );
646  }
647 
648  public function begin( $fname = __METHOD__, $mode = IDatabase::TRANSACTION_EXPLICIT ) {
649  return $this->__call( __FUNCTION__, func_get_args() );
650  }
651 
652  public function commit( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) {
653  return $this->__call( __FUNCTION__, func_get_args() );
654  }
655 
656  public function rollback( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) {
657  return $this->__call( __FUNCTION__, func_get_args() );
658  }
659 
660  public function flushSnapshot( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) {
661  return $this->__call( __FUNCTION__, func_get_args() );
662  }
663 
664  public function timestamp( $ts = 0 ) {
665  return $this->__call( __FUNCTION__, func_get_args() );
666  }
667 
668  public function timestampOrNull( $ts = null ) {
669  return $this->__call( __FUNCTION__, func_get_args() );
670  }
671 
672  public function ping( &$rtt = null ) {
673  return func_num_args()
674  ? $this->__call( __FUNCTION__, [ &$rtt ] )
675  : $this->__call( __FUNCTION__, [] ); // method cares about null vs missing
676  }
677 
678  public function getLag() {
679  return $this->__call( __FUNCTION__, func_get_args() );
680  }
681 
682  public function getSessionLagStatus() {
683  return $this->__call( __FUNCTION__, func_get_args() );
684  }
685 
686  public function maxListLen() {
687  return $this->__call( __FUNCTION__, func_get_args() );
688  }
689 
690  public function encodeBlob( $b ) {
691  return $this->__call( __FUNCTION__, func_get_args() );
692  }
693 
694  public function decodeBlob( $b ) {
695  return $this->__call( __FUNCTION__, func_get_args() );
696  }
697 
698  public function setSessionOptions( array $options ) {
699  return $this->__call( __FUNCTION__, func_get_args() );
700  }
701 
702  public function setSchemaVars( $vars ) {
703  return $this->__call( __FUNCTION__, func_get_args() );
704  }
705 
706  public function lockIsFree( $lockName, $method ) {
707  $this->assertRoleAllowsWrites();
708 
709  return $this->__call( __FUNCTION__, func_get_args() );
710  }
711 
712  public function lock( $lockName, $method, $timeout = 5 ) {
713  $this->assertRoleAllowsWrites();
714 
715  return $this->__call( __FUNCTION__, func_get_args() );
716  }
717 
718  public function unlock( $lockName, $method ) {
719  $this->assertRoleAllowsWrites();
720 
721  return $this->__call( __FUNCTION__, func_get_args() );
722  }
723 
724  public function getScopedLockAndFlush( $lockKey, $fname, $timeout ) {
725  $this->assertRoleAllowsWrites();
726 
727  return $this->__call( __FUNCTION__, func_get_args() );
728  }
729 
730  public function namedLocksEnqueue() {
731  return $this->__call( __FUNCTION__, func_get_args() );
732  }
733 
734  public function getInfinity() {
735  return $this->__call( __FUNCTION__, func_get_args() );
736  }
737 
738  public function encodeExpiry( $expiry ) {
739  return $this->__call( __FUNCTION__, func_get_args() );
740  }
741 
742  public function decodeExpiry( $expiry, $format = TS_MW ) {
743  return $this->__call( __FUNCTION__, func_get_args() );
744  }
745 
746  public function setBigSelects( $value = true ) {
747  return $this->__call( __FUNCTION__, func_get_args() );
748  }
749 
750  public function isReadOnly() {
751  return $this->__call( __FUNCTION__, func_get_args() );
752  }
753 
754  public function setTableAliases( array $aliases ) {
755  return $this->__call( __FUNCTION__, func_get_args() );
756  }
757 
758  public function setIndexAliases( array $aliases ) {
759  return $this->__call( __FUNCTION__, func_get_args() );
760  }
761 
762  public function __toString() {
763  if ( $this->conn === null ) {
764  // spl_object_id is PHP >= 7.2
765  $id = function_exists( 'spl_object_id' )
766  ? spl_object_id( $this )
767  : spl_object_hash( $this );
768 
769  return $this->getType() . ' object #' . $id;
770  }
771 
772  return $this->__call( __FUNCTION__, func_get_args() );
773  }
774 
788  protected function assertRoleAllowsWrites() {
789  // DB_MASTER is "prima facie" writable
790  if ( $this->role !== ILoadBalancer::DB_MASTER ) {
791  throw new DBReadOnlyRoleError( $this->conn, "Cannot write with role DB_REPLICA" );
792  }
793  }
794 
798  function __destruct() {
799  if ( $this->conn ) {
800  $this->lb->reuseConnection( $this->conn );
801  }
802  }
803 }
804 
809 class_alias( DBConnRef::class, 'DBConnRef' );
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition: hooks.txt:2620
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
insertId()
Get the inserted value of an auto-increment row.
Definition: DBConnRef.php:265
affectedRows()
Get the number of rows affected by the last write query.
Definition: DBConnRef.php:281
bufferResults( $buffer=null)
Turns buffering of SQL result sets on (true) or off (false).
Definition: DBConnRef.php:83
buildSelectSubquery( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Equivalent to IDatabase::selectSQLText() except wraps the result in Subqyery.
Definition: DBConnRef.php:436
bitAnd( $fieldLeft, $fieldRight)
Definition: DBConnRef.php:406
int $role
One of DB_MASTER/DB_REPLICA.
Definition: DBConnRef.php:37
endAtomic( $fname=__METHOD__)
Ends an atomic section of SQL statements.
Definition: DBConnRef.php:631
anyString()
Returns a token for buildLike() that denotes a &#39;&#39; to be used in a LIKE query.
Definition: DBConnRef.php:487
if(is_array( $mode)) switch( $mode) $input
buildLike( $param)
LIKE statement wrapper, receives a variable-length argument list with parts of pattern to match conta...
Definition: DBConnRef.php:479
getScopedLockAndFlush( $lockKey, $fname, $timeout)
Acquire a named lock, flush any transaction, and return an RAII style unlocker object.
Definition: DBConnRef.php:724
getReplicaPos()
Get the replication position of this replica DB.
Definition: DBConnRef.php:585
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
estimateRowCount( $table, $vars=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Estimate the number of rows in dataset.
Definition: DBConnRef.php:346
lastDoneWrites()
Returns the last time the connection may have been used for write queries.
Definition: DBConnRef.php:159
ping(&$rtt=null)
Ping the server and try to reconnect if it there is no connection.
Definition: DBConnRef.php:672
getFlag( $flag)
Returns a boolean whether the flag $flag is set for this connection.
Definition: DBConnRef.php:203
close()
Close the database connection.
Definition: DBConnRef.php:293
selectField( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[])
A SELECT wrapper which returns a single field from a single result row.
Definition: DBConnRef.php:309
addIdentifierQuotes( $s)
Quotes an identifier, in order to make user controlled input safe.
Definition: DBConnRef.php:475
rollback( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Rollback a transaction previously started using begin().
Definition: DBConnRef.php:656
addQuotes( $s)
Adds quotes and backslashes.
Definition: DBConnRef.php:471
pendingWriteCallers()
Get the list of method names that did write queries for this transaction.
Definition: DBConnRef.php:179
numFields( $res)
Get the number of fields in a result object.
Definition: DBConnRef.php:257
$value
getSessionLagStatus()
Get the replica DB lag when the current transaction started or a general lag estimate if not transact...
Definition: DBConnRef.php:682
setTransactionListener( $name, callable $callback=null)
Run a callback after each time any transaction commits or rolls back.
Definition: DBConnRef.php:620
implicitOrderby()
Returns true if this database does an implicit order by when the column has an index For example: SEL...
Definition: DBConnRef.php:147
getServer()
Get the server hostname or IP address.
Definition: DBConnRef.php:467
pendingWriteRowsAffected()
Get the number of affected rows from pending write queries.
Definition: DBConnRef.php:183
__construct(ILoadBalancer $lb, $conn, $role)
Definition: DBConnRef.php:50
anyChar()
Returns a token for buildLike() that denotes a &#39;_&#39; to be used in a LIKE query.
Definition: DBConnRef.php:483
insert( $table, $a, $fname=__METHOD__, $options=[])
INSERT wrapper, inserts an array into a table.
Definition: DBConnRef.php:378
Helper class used for automatically marking an IDatabase connection as reusable (once it no longer ma...
Definition: DBConnRef.php:29
fieldName( $res, $n)
Get a field name in a result object.
Definition: DBConnRef.php:261
selectDomain( $domain)
Set the current domain (database, schema, and table prefix)
Definition: DBConnRef.php:452
setBigSelects( $value=true)
Allow or deny "big selects" for this session only.
Definition: DBConnRef.php:746
insertSelect( $destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[], $selectJoinConds=[])
INSERT SELECT wrapper.
Definition: DBConnRef.php:525
selectSQLText( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
The equivalent of IDatabase::select() except that the constructed SQL is returned, instead of being immediately executed.
Definition: DBConnRef.php:328
fetchObject( $res)
Fetch the next row from the given result object, in object form.
Definition: DBConnRef.php:245
aggregateValue( $valuedata, $valuename='value')
Return aggregated value alias.
Definition: DBConnRef.php:398
maxListLen()
Return the maximum number of items allowed in a list, or 0 for unlimited.
Definition: DBConnRef.php:686
const DB_MASTER
Definition: defines.php:26
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition: hooks.txt:960
getServerInfo()
A string describing the current software version, and possibly other details in a user-friendly way...
Definition: DBConnRef.php:79
makeWhereFrom2d( $data, $baseKey, $subKey)
Build a partial where clause from a 2-d array such as used for LinkBatch.
Definition: DBConnRef.php:394
selectRowCount( $tables, $vars=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Get the number of rows in dataset.
Definition: DBConnRef.php:352
nextSequenceValue( $seqName)
Deprecated method, calls should be removed.
Definition: DBConnRef.php:491
startAtomic( $fname=__METHOD__, $cancelable=IDatabase::ATOMIC_NOT_CANCELABLE)
Begin an atomic section of SQL statements.
Definition: DBConnRef.php:624
deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__)
DELETE where the condition is a join.
Definition: DBConnRef.php:511
__call( $name, array $arguments)
Definition: DBConnRef.php:62
buildGroupConcatField( $delim, $table, $field, $conds='', $join_conds=[])
Build a GROUP_CONCAT or equivalent statement for a query.
Definition: DBConnRef.php:418
freeResult( $res)
Free a result object returned by query() or select().
Definition: DBConnRef.php:305
update( $table, $values, $conds, $fname=__METHOD__, $options=[])
UPDATE wrapper.
Definition: DBConnRef.php:384
commit( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Commits a transaction previously started using begin().
Definition: DBConnRef.php:652
writesOrCallbacksPending()
Whether there is a transaction open with either possible write queries or unresolved pre-commit/commi...
Definition: DBConnRef.php:171
conditional( $cond, $trueVal, $falseVal)
Returns an SQL expression for a simple conditional.
Definition: DBConnRef.php:549
tablePrefix( $prefix=null)
Get/set the table prefix.
Definition: DBConnRef.php:103
getLBInfo( $name=null)
Get properties passed down from the server info array of the load balancer.
Definition: DBConnRef.php:129
cancelAtomic( $fname=__METHOD__, AtomicSectionIdentifier $sectionId=null)
Cancel an atomic section of SQL statements.
Definition: DBConnRef.php:636
An object representing a master or replica DB position in a replicated setup.
Definition: DBMasterPos.php:12
Database null $conn
Live connection handle.
Definition: DBConnRef.php:33
begin( $fname=__METHOD__, $mode=IDatabase::TRANSACTION_EXPLICIT)
Begin a transaction.
Definition: DBConnRef.php:648
doneWrites()
Returns true if the connection may have been used for write queries.
Definition: DBConnRef.php:155
unionSupportsOrderAndLimit()
Returns true if current database backend supports ORDER BY or LIMIT for separate subqueries within th...
Definition: DBConnRef.php:534
const LIST_COMMA
Definition: Defines.php:38
$res
Definition: database.txt:21
restoreFlags( $state=self::RESTORE_PRIOR)
Restore the flags to their prior state before the last setFlag/clearFlag call.
Definition: DBConnRef.php:199
encodeBlob( $b)
Some DBMSs have a special format for inserting into blob fields, they don&#39;t allow simple quoted strin...
Definition: DBConnRef.php:690
unlock( $lockName, $method)
Release a lock.
Definition: DBConnRef.php:718
wasReadOnlyError()
Determines if the last failure was due to the database being read-only.
Definition: DBConnRef.php:573
setSessionOptions(array $options)
Override database&#39;s default behavior.
Definition: DBConnRef.php:698
setSchemaVars( $vars)
Set variables to be used in sourceFile/sourceStream, in preference to the ones in $GLOBALS...
Definition: DBConnRef.php:702
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1971
fetchRow( $res)
Fetch the next row from the given result object, in associative array form.
Definition: DBConnRef.php:249
databasesAreIndependent()
Returns true if DBs are assumed to be on potentially different servers.
Definition: DBConnRef.php:443
tableExists( $table, $fname=__METHOD__)
Query whether a given table exists.
Definition: DBConnRef.php:374
__destruct()
Clean up the connection when out of scope.
Definition: DBConnRef.php:798
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
bitOr( $fieldLeft, $fieldRight)
Definition: DBConnRef.php:410
$buffer
lockIsFree( $lockName, $method)
Check to see if a named lock is not locked by any thread (non-blocking)
Definition: DBConnRef.php:706
limitResult( $sql, $limit, $offset=false)
Construct a LIMIT query with optional offset.
Definition: DBConnRef.php:335
getServerVersion()
A string describing the current software version, like from mysql_get_server_info().
Definition: DBConnRef.php:289
numRows( $res)
Get the number of rows in a query result.
Definition: DBConnRef.php:253
trxLevel()
Gets the current transaction level.
Definition: DBConnRef.php:87
unionConditionPermutations( $table, $vars, array $permute_conds, $extra_conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Construct a UNION query for permutations of conditions.
Definition: DBConnRef.php:542
lastErrno()
Get the last error number.
Definition: DBConnRef.php:273
indexExists( $table, $index, $fname=__METHOD__)
Determines whether an index exists Usually throws a DBQueryError on failure If errors are explicitly ...
Definition: DBConnRef.php:370
isOpen()
Is a connection to the database open?
Definition: DBConnRef.php:187
dataSeek( $res, $row)
Change the position of the cursor in a result object.
Definition: DBConnRef.php:269
setFlag( $flag, $remember=self::REMEMBER_NOTHING)
Set a flag for this connection.
Definition: DBConnRef.php:191
doAtomicSection( $fname, callable $callback, $cancelable=self::ATOMIC_NOT_CANCELABLE)
Perform an atomic section of reversable SQL statements from a callback.
Definition: DBConnRef.php:641
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings, LocalSettings).
Definition: Setup.php:131
query( $sql, $fname=__METHOD__, $flags=0)
Run an SQL query and return the result.
Definition: DBConnRef.php:297
makeList( $a, $mode=self::LIST_COMMA)
Makes an encoded list of strings from an array.
Definition: DBConnRef.php:390
getDBname()
Get the current DB name.
Definition: DBConnRef.php:457
lockForUpdate( $table, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Lock all rows meeting the given conditions/options FOR UPDATE.
Definition: DBConnRef.php:358
onTransactionCommitOrIdle(callable $callback, $fname=__METHOD__)
Run a callback as soon as there is no transaction pending.
Definition: DBConnRef.php:602
decodeBlob( $b)
Some DBMSs return a special placeholder object representing blob fields in result objects...
Definition: DBConnRef.php:694
select( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
Definition: DBConnRef.php:321
getMasterPos()
Get the position of this master.
Definition: DBConnRef.php:589
decodeExpiry( $expiry, $format=TS_MW)
Decode an expiry time into a DBMS independent format.
Definition: DBConnRef.php:742
wasDeadlock()
Determines if the last failure was due to a deadlock.
Definition: DBConnRef.php:561
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
buildConcat( $stringList)
Build a concatenation list to feed into a SQL query.
Definition: DBConnRef.php:414
upsert( $table, array $rows, $uniqueIndexes, array $set, $fname=__METHOD__)
INSERT ON DUPLICATE KEY UPDATE wrapper, upserts an array into a table.
Definition: DBConnRef.php:503
trxTimestamp()
Get the UNIX timestamp of the time that the transaction was established.
Definition: DBConnRef.php:91
getLag()
Get the amount of replication lag for this database server.
Definition: DBConnRef.php:678
getServerUptime()
Determines how long the server has been up.
Definition: DBConnRef.php:557
Database cluster connection, tracking, load balancing, and transaction manager interface.
wasConnectionLoss()
Determines if the last query error was due to a dropped connection.
Definition: DBConnRef.php:569
pendingWriteQueryDuration( $type=self::ESTIMATE_TOTAL)
Get the time spend running write queries for this transaction.
Definition: DBConnRef.php:175
strreplace( $orig, $old, $new)
Returns a command for str_replace function in SQL query.
Definition: DBConnRef.php:553
selectDB( $db)
Change the current database.
Definition: DBConnRef.php:447
Class to handle database/prefix specification for IDatabase domains.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
unionQueries( $sqls, $all)
Construct a UNION query This is used for providing overload point for other DB abstractions not compa...
Definition: DBConnRef.php:538
selectFieldValues( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[])
A SELECT wrapper which returns a list of single field values from result rows.
Definition: DBConnRef.php:315
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
Definition: DBConnRef.php:228
assertRoleAllowsWrites()
Error out if the role is not DB_MASTER.
Definition: DBConnRef.php:788
onTransactionPreCommitOrIdle(callable $callback, $fname=__METHOD__)
Run a callback before the current transaction commits or now if there is none.
Definition: DBConnRef.php:611
implicitGroupby()
Returns true if this database does an implicit sort when doing GROUP BY.
Definition: DBConnRef.php:143
masterPosWait(DBMasterPos $pos, $timeout)
Wait for the replica DB to catch up to a given master position.
Definition: DBConnRef.php:581
clearFlag( $flag, $remember=self::REMEMBER_NOTHING)
Clear a flag for this connection.
Definition: DBConnRef.php:195
onTransactionIdle(callable $callback, $fname=__METHOD__)
Alias for onTransactionCommitOrIdle() for backwards-compatibility.
Definition: DBConnRef.php:607
array null $params
N-tuple of (server index, group, DatabaseDomain|string)
Definition: DBConnRef.php:35
onAtomicSectionCancel(callable $callback, $fname=__METHOD__)
Run a callback when the atomic section is cancelled.
Definition: DBConnRef.php:616
selectRow( $table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
Single row SELECT wrapper.
Definition: DBConnRef.php:339
lastError()
Get a description of the last error.
Definition: DBConnRef.php:277
fieldExists( $table, $field, $fname=__METHOD__)
Determines whether a field exists in a table.
Definition: DBConnRef.php:366
encodeExpiry( $expiry)
Encode an expiry time into the DBMS dependent format.
Definition: DBConnRef.php:738
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
replace( $table, $uniqueIndexes, $rows, $fname=__METHOD__)
REPLACE query wrapper.
Definition: DBConnRef.php:497
lastQuery()
Return the last query that sent on account of IDatabase::query()
Definition: DBConnRef.php:151
onTransactionResolution(callable $callback, $fname=__METHOD__)
Run a callback as soon as the current transaction commits or rolls back.
Definition: DBConnRef.php:597
Exception class for attempted DB write access to a DBConnRef with the DB_REPLICA role.
assertNoOpenTransactions()
Assert that all explicit transactions or atomic sections have been closed.
Definition: DBConnRef.php:99
__toString()
Get a debugging string that mentions the database type, the ID of this instance, and the ID of any un...
Definition: DBConnRef.php:762
timestampOrNull( $ts=null)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
Definition: DBConnRef.php:668
setIndexAliases(array $aliases)
Convert certain index names to alternative names before querying the DB.
Definition: DBConnRef.php:758
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
Definition: DBConnRef.php:664
getWikiID()
Alias for getDomainID()
Definition: DBConnRef.php:224
buildSubstring( $input, $startPosition, $length=null)
Definition: DBConnRef.php:424
Class used for token representing identifiers for atomic sections from IDatabase instances.
getDomainID()
Return the currently selected domain ID.
Definition: DBConnRef.php:211
wasLockTimeout()
Determines if the last failure was due to a lock timeout.
Definition: DBConnRef.php:565
dbSchema( $schema=null)
Get/set the db schema.
Definition: DBConnRef.php:116
getSoftwareLink()
Returns a wikitext link to the DB&#39;s website, e.g., return "[https://www.mysql.com/ MySQL]"; Should at...
Definition: DBConnRef.php:285
setTableAliases(array $aliases)
Make certain table names use their own database, schema, and table prefix when passed into SQL querie...
Definition: DBConnRef.php:754
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:2204
flushSnapshot( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Commit any transaction but error out if writes or callbacks are pending.
Definition: DBConnRef.php:660
setLazyMasterHandle(IDatabase $conn)
Set a lazy-connecting DB handle to the master DB (for replication status purposes) ...
Definition: DBConnRef.php:138
namedLocksEnqueue()
Check to see if a named lock used by lock() use blocking queues.
Definition: DBConnRef.php:730
wasErrorReissuable()
Determines if the last query error was due to something outside of the query itself.
Definition: DBConnRef.php:577
getInfinity()
Find out when &#39;infinity&#39; is.
Definition: DBConnRef.php:734
lock( $lockName, $method, $timeout=5)
Acquire a named lock.
Definition: DBConnRef.php:712
setLBInfo( $nameOrArray, $value=null)
Set the entire array or a particular key of the managing load balancer info array.
Definition: DBConnRef.php:133