MediaWiki  master
DBConnRef.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Rdbms;
4 
5 use InvalidArgumentException;
6 
29 class DBConnRef implements IDatabase {
31  private $lb;
33  private $conn;
35  private $params;
37  private $role;
38 
39  private const FLD_INDEX = 0;
40  private const FLD_GROUP = 1;
41  private const FLD_DOMAIN = 2;
42  private 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  public 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 getTopologyBasedServerId() {
84  return $this->__call( __FUNCTION__, func_get_args() );
85  }
86 
87  public function getTopologyRole() {
88  return $this->__call( __FUNCTION__, func_get_args() );
89  }
90 
91  public function getTopologyRootPrimary() {
92  return $this->__call( __FUNCTION__, func_get_args() );
93  }
94 
95  public function getTopologyRootMaster() {
96  wfDeprecated( __METHOD__, '1.37' );
97  return $this->__call( __FUNCTION__, func_get_args() );
98  }
99 
100  public function trxLevel() {
101  return $this->__call( __FUNCTION__, func_get_args() );
102  }
103 
104  public function trxTimestamp() {
105  return $this->__call( __FUNCTION__, func_get_args() );
106  }
107 
108  public function explicitTrxActive() {
109  return $this->__call( __FUNCTION__, func_get_args() );
110  }
111 
112  public function assertNoOpenTransactions() {
113  return $this->__call( __FUNCTION__, func_get_args() );
114  }
115 
116  public function tablePrefix( $prefix = null ) {
117  if ( $this->conn === null && $prefix === null ) {
118  $domain = DatabaseDomain::newFromId( $this->params[self::FLD_DOMAIN] );
119  // Avoid triggering a database connection
120  return $domain->getTablePrefix();
121  } elseif ( $this->conn !== null && $prefix === null ) {
122  // This will just return the prefix
123  return $this->__call( __FUNCTION__, func_get_args() );
124  }
125  // Disallow things that might confuse the LoadBalancer tracking
126  throw $this->getDomainChangeException();
127  }
128 
129  public function dbSchema( $schema = null ) {
130  if ( $this->conn === null && $schema === null ) {
131  $domain = DatabaseDomain::newFromId( $this->params[self::FLD_DOMAIN] );
132  // Avoid triggering a database connection
133  return $domain->getSchema();
134  } elseif ( $this->conn !== null && $schema === null ) {
135  // This will just return the schema
136  return $this->__call( __FUNCTION__, func_get_args() );
137  }
138  // Disallow things that might confuse the LoadBalancer tracking
139  throw $this->getDomainChangeException();
140  }
141 
142  public function getLBInfo( $name = null ) {
143  return $this->__call( __FUNCTION__, func_get_args() );
144  }
145 
146  public function setLBInfo( $nameOrArray, $value = null ) {
147  // @phan-suppress-previous-line PhanPluginNeverReturnMethod
148  // Disallow things that might confuse the LoadBalancer tracking
149  throw $this->getDomainChangeException();
150  }
151 
152  public function implicitOrderby() {
153  return $this->__call( __FUNCTION__, func_get_args() );
154  }
155 
156  public function lastQuery() {
157  return $this->__call( __FUNCTION__, func_get_args() );
158  }
159 
160  public function lastDoneWrites() {
161  return $this->__call( __FUNCTION__, func_get_args() );
162  }
163 
164  public function writesPending() {
165  return $this->__call( __FUNCTION__, func_get_args() );
166  }
167 
168  public function preCommitCallbacksPending() {
169  return $this->__call( __FUNCTION__, func_get_args() );
170  }
171 
172  public function writesOrCallbacksPending() {
173  return $this->__call( __FUNCTION__, func_get_args() );
174  }
175 
176  public function pendingWriteQueryDuration( $type = self::ESTIMATE_TOTAL ) {
177  return $this->__call( __FUNCTION__, func_get_args() );
178  }
179 
180  public function pendingWriteCallers() {
181  return $this->__call( __FUNCTION__, func_get_args() );
182  }
183 
184  public function pendingWriteRowsAffected() {
185  return $this->__call( __FUNCTION__, func_get_args() );
186  }
187 
188  public function isOpen() {
189  return $this->__call( __FUNCTION__, func_get_args() );
190  }
191 
192  public function setFlag( $flag, $remember = self::REMEMBER_NOTHING ) {
193  return $this->__call( __FUNCTION__, func_get_args() );
194  }
195 
196  public function clearFlag( $flag, $remember = self::REMEMBER_NOTHING ) {
197  return $this->__call( __FUNCTION__, func_get_args() );
198  }
199 
200  public function restoreFlags( $state = self::RESTORE_PRIOR ) {
201  return $this->__call( __FUNCTION__, func_get_args() );
202  }
203 
204  public function getFlag( $flag ) {
205  return $this->__call( __FUNCTION__, func_get_args() );
206  }
207 
208  public function getProperty( $name ) {
209  return $this->__call( __FUNCTION__, func_get_args() );
210  }
211 
212  public function getDomainID() {
213  if ( $this->conn === null ) {
214  $domain = $this->params[self::FLD_DOMAIN];
215  // Avoid triggering a database connection
216  return $domain instanceof DatabaseDomain ? $domain->getId() : $domain;
217  }
218 
219  return $this->__call( __FUNCTION__, func_get_args() );
220  }
221 
222  public function getType() {
223  if ( $this->conn === null ) {
224  // Avoid triggering a database connection
225  if ( $this->params[self::FLD_INDEX] === ILoadBalancer::DB_PRIMARY ) {
226  $index = $this->lb->getWriterIndex();
227  } else {
228  $index = $this->params[self::FLD_INDEX];
229  }
230  if ( $index >= 0 ) {
231  // In theory, if $index is DB_REPLICA, the type could vary
232  return $this->lb->getServerType( $index );
233  }
234  }
235 
236  return $this->__call( __FUNCTION__, func_get_args() );
237  }
238 
239  public function fetchObject( $res ) {
240  return $this->__call( __FUNCTION__, func_get_args() );
241  }
242 
243  public function fetchRow( $res ) {
244  return $this->__call( __FUNCTION__, func_get_args() );
245  }
246 
247  public function numRows( $res ) {
248  return $this->__call( __FUNCTION__, func_get_args() );
249  }
250 
251  public function numFields( $res ) {
252  return $this->__call( __FUNCTION__, func_get_args() );
253  }
254 
255  public function fieldName( $res, $n ) {
256  return $this->__call( __FUNCTION__, func_get_args() );
257  }
258 
259  public function insertId() {
260  return $this->__call( __FUNCTION__, func_get_args() );
261  }
262 
263  public function dataSeek( $res, $row ) {
264  return $this->__call( __FUNCTION__, func_get_args() );
265  }
266 
267  public function lastErrno() {
268  return $this->__call( __FUNCTION__, func_get_args() );
269  }
270 
271  public function lastError() {
272  return $this->__call( __FUNCTION__, func_get_args() );
273  }
274 
275  public function affectedRows() {
276  return $this->__call( __FUNCTION__, func_get_args() );
277  }
278 
279  public function getSoftwareLink() {
280  return $this->__call( __FUNCTION__, func_get_args() );
281  }
282 
283  public function getServerVersion() {
284  return $this->__call( __FUNCTION__, func_get_args() );
285  }
286 
287  public function close( $fname = __METHOD__, $owner = null ) {
288  // @phan-suppress-previous-line PhanPluginNeverReturnMethod
289  throw new DBUnexpectedError( $this->conn, 'Cannot close shared connection.' );
290  }
291 
292  public function query( $sql, $fname = __METHOD__, $flags = 0 ) {
293  if ( $this->role !== ILoadBalancer::DB_PRIMARY ) {
294  $flags |= IDatabase::QUERY_REPLICA_ROLE;
295  }
296 
297  return $this->__call( __FUNCTION__, [ $sql, $fname, $flags ] );
298  }
299 
300  public function freeResult( $res ) {
301  return $this->__call( __FUNCTION__, func_get_args() );
302  }
303 
305  return $this->__call( __FUNCTION__, func_get_args() );
306  }
307 
308  public function selectField(
309  $table, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = []
310  ) {
311  return $this->__call( __FUNCTION__, func_get_args() );
312  }
313 
314  public function selectFieldValues(
315  $table, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = []
316  ): array {
317  return $this->__call( __FUNCTION__, func_get_args() );
318  }
319 
320  public function select(
321  $table, $vars, $conds = '', $fname = __METHOD__,
322  $options = [], $join_conds = []
323  ) {
324  return $this->__call( __FUNCTION__, func_get_args() );
325  }
326 
327  public function selectSQLText(
328  $table, $vars, $conds = '', $fname = __METHOD__,
329  $options = [], $join_conds = []
330  ) {
331  return $this->__call( __FUNCTION__, func_get_args() );
332  }
333 
334  public function limitResult( $sql, $limit, $offset = false ) {
335  return $this->__call( __FUNCTION__, func_get_args() );
336  }
337 
338  public function selectRow(
339  $table, $vars, $conds, $fname = __METHOD__,
340  $options = [], $join_conds = []
341  ) {
342  return $this->__call( __FUNCTION__, func_get_args() );
343  }
344 
345  public function estimateRowCount(
346  $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
347  ) {
348  return $this->__call( __FUNCTION__, func_get_args() );
349  }
350 
351  public function selectRowCount(
352  $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
353  ) {
354  return $this->__call( __FUNCTION__, func_get_args() );
355  }
356 
357  public function lockForUpdate(
358  $table, $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
359  ) {
360  $this->assertRoleAllowsWrites();
361 
362  return $this->__call( __FUNCTION__, func_get_args() );
363  }
364 
365  public function fieldExists( $table, $field, $fname = __METHOD__ ) {
366  return $this->__call( __FUNCTION__, func_get_args() );
367  }
368 
369  public function indexExists( $table, $index, $fname = __METHOD__ ) {
370  return $this->__call( __FUNCTION__, func_get_args() );
371  }
372 
373  public function tableExists( $table, $fname = __METHOD__ ) {
374  return $this->__call( __FUNCTION__, func_get_args() );
375  }
376 
377  public function insert( $table, $rows, $fname = __METHOD__, $options = [] ) {
378  $this->assertRoleAllowsWrites();
379 
380  return $this->__call( __FUNCTION__, func_get_args() );
381  }
382 
383  public function update( $table, $set, $conds, $fname = __METHOD__, $options = [] ) {
384  $this->assertRoleAllowsWrites();
385 
386  return $this->__call( __FUNCTION__, func_get_args() );
387  }
388 
389  public function makeList( array $a, $mode = self::LIST_COMMA ) {
390  return $this->__call( __FUNCTION__, func_get_args() );
391  }
392 
393  public function makeWhereFrom2d( $data, $baseKey, $subKey ) {
394  return $this->__call( __FUNCTION__, func_get_args() );
395  }
396 
397  public function aggregateValue( $valuedata, $valuename = 'value' ) {
398  return $this->__call( __FUNCTION__, func_get_args() );
399  }
400 
401  public function bitNot( $field ) {
402  return $this->__call( __FUNCTION__, func_get_args() );
403  }
404 
405  public function bitAnd( $fieldLeft, $fieldRight ) {
406  return $this->__call( __FUNCTION__, func_get_args() );
407  }
408 
409  public function bitOr( $fieldLeft, $fieldRight ) {
410  return $this->__call( __FUNCTION__, func_get_args() );
411  }
412 
413  public function buildConcat( $stringList ) {
414  return $this->__call( __FUNCTION__, func_get_args() );
415  }
416 
417  public function buildGroupConcatField(
418  $delim, $table, $field, $conds = '', $join_conds = []
419  ) {
420  return $this->__call( __FUNCTION__, func_get_args() );
421  }
422 
423  public function buildGreatest( $fields, $values ) {
424  return $this->__call( __FUNCTION__, func_get_args() );
425  }
426 
427  public function buildLeast( $fields, $values ) {
428  return $this->__call( __FUNCTION__, func_get_args() );
429  }
430 
431  public function buildSubstring( $input, $startPosition, $length = null ) {
432  return $this->__call( __FUNCTION__, func_get_args() );
433  }
434 
435  public function buildStringCast( $field ) {
436  return $this->__call( __FUNCTION__, func_get_args() );
437  }
438 
439  public function buildIntegerCast( $field ) {
440  return $this->__call( __FUNCTION__, func_get_args() );
441  }
442 
443  public function buildSelectSubquery(
444  $table, $vars, $conds = '', $fname = __METHOD__,
445  $options = [], $join_conds = []
446  ) {
447  return $this->__call( __FUNCTION__, func_get_args() );
448  }
449 
450  public function databasesAreIndependent() {
451  return $this->__call( __FUNCTION__, func_get_args() );
452  }
453 
454  public function selectDB( $db ) {
455  // @phan-suppress-previous-line PhanPluginNeverReturnMethod
456  // Disallow things that might confuse the LoadBalancer tracking
457  throw $this->getDomainChangeException();
458  }
459 
460  public function selectDomain( $domain ) {
461  // @phan-suppress-previous-line PhanPluginNeverReturnMethod
462  // Disallow things that might confuse the LoadBalancer tracking
463  throw $this->getDomainChangeException();
464  }
465 
466  public function getDBname() {
467  if ( $this->conn === null ) {
468  $domain = DatabaseDomain::newFromId( $this->params[self::FLD_DOMAIN] );
469  // Avoid triggering a database connection
470  return $domain->getDatabase();
471  }
472 
473  return $this->__call( __FUNCTION__, func_get_args() );
474  }
475 
476  public function getServer() {
477  return $this->__call( __FUNCTION__, func_get_args() );
478  }
479 
480  public function getServerName() {
481  return $this->__call( __FUNCTION__, func_get_args() );
482  }
483 
484  public function addQuotes( $s ) {
485  return $this->__call( __FUNCTION__, func_get_args() );
486  }
487 
488  public function addIdentifierQuotes( $s ) {
489  return $this->__call( __FUNCTION__, func_get_args() );
490  }
491 
492  public function buildLike( $param, ...$params ) {
493  return $this->__call( __FUNCTION__, func_get_args() );
494  }
495 
496  public function anyChar() {
497  return $this->__call( __FUNCTION__, func_get_args() );
498  }
499 
500  public function anyString() {
501  return $this->__call( __FUNCTION__, func_get_args() );
502  }
503 
504  public function nextSequenceValue( $seqName ) {
505  $this->assertRoleAllowsWrites();
506 
507  return $this->__call( __FUNCTION__, func_get_args() );
508  }
509 
510  public function replace( $table, $uniqueKeys, $rows, $fname = __METHOD__ ) {
511  $this->assertRoleAllowsWrites();
512 
513  return $this->__call( __FUNCTION__, func_get_args() );
514  }
515 
516  public function upsert(
517  $table, array $rows, $uniqueKeys, array $set, $fname = __METHOD__
518  ) {
519  $this->assertRoleAllowsWrites();
520 
521  return $this->__call( __FUNCTION__, func_get_args() );
522  }
523 
524  public function deleteJoin(
525  $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__
526  ) {
527  $this->assertRoleAllowsWrites();
528 
529  return $this->__call( __FUNCTION__, func_get_args() );
530  }
531 
532  public function delete( $table, $conds, $fname = __METHOD__ ) {
533  $this->assertRoleAllowsWrites();
534 
535  return $this->__call( __FUNCTION__, func_get_args() );
536  }
537 
538  public function insertSelect(
539  $destTable, $srcTable, $varMap, $conds,
540  $fname = __METHOD__, $insertOptions = [], $selectOptions = [], $selectJoinConds = []
541  ) {
542  $this->assertRoleAllowsWrites();
543 
544  return $this->__call( __FUNCTION__, func_get_args() );
545  }
546 
547  public function unionSupportsOrderAndLimit() {
548  return $this->__call( __FUNCTION__, func_get_args() );
549  }
550 
551  public function unionQueries( $sqls, $all ) {
552  return $this->__call( __FUNCTION__, func_get_args() );
553  }
554 
555  public function unionConditionPermutations(
556  $table, $vars, array $permute_conds, $extra_conds = '', $fname = __METHOD__,
557  $options = [], $join_conds = []
558  ) {
559  return $this->__call( __FUNCTION__, func_get_args() );
560  }
561 
562  public function conditional( $cond, $caseTrueExpression, $caseFalseExpression ) {
563  return $this->__call( __FUNCTION__, func_get_args() );
564  }
565 
566  public function strreplace( $orig, $old, $new ) {
567  return $this->__call( __FUNCTION__, func_get_args() );
568  }
569 
570  public function getServerUptime() {
571  return $this->__call( __FUNCTION__, func_get_args() );
572  }
573 
574  public function wasDeadlock() {
575  return $this->__call( __FUNCTION__, func_get_args() );
576  }
577 
578  public function wasLockTimeout() {
579  return $this->__call( __FUNCTION__, func_get_args() );
580  }
581 
582  public function wasConnectionLoss() {
583  return $this->__call( __FUNCTION__, func_get_args() );
584  }
585 
586  public function wasReadOnlyError() {
587  return $this->__call( __FUNCTION__, func_get_args() );
588  }
589 
590  public function wasErrorReissuable() {
591  return $this->__call( __FUNCTION__, func_get_args() );
592  }
593 
594  public function primaryPosWait( DBPrimaryPos $pos, $timeout ) {
595  return $this->__call( __FUNCTION__, func_get_args() );
596  }
597 
598  public function masterPosWait( DBPrimaryPos $pos, $timeout ) {
599  wfDeprecated( __METHOD__, '1.37' );
600  return $this->__call( __FUNCTION__, func_get_args() );
601  }
602 
603  public function getReplicaPos() {
604  return $this->__call( __FUNCTION__, func_get_args() );
605  }
606 
607  public function getPrimaryPos() {
608  return $this->__call( __FUNCTION__, func_get_args() );
609  }
610 
611  public function getMasterPos() {
612  wfDeprecated( __METHOD__, '1.37' );
613  return $this->getPrimaryPos();
614  }
615 
616  public function serverIsReadOnly() {
617  return $this->__call( __FUNCTION__, func_get_args() );
618  }
619 
620  public function onTransactionResolution( callable $callback, $fname = __METHOD__ ) {
621  // DB_REPLICA role: caller might want to refresh cache after a REPEATABLE-READ snapshot
622  return $this->__call( __FUNCTION__, func_get_args() );
623  }
624 
625  public function onTransactionCommitOrIdle( callable $callback, $fname = __METHOD__ ) {
626  // DB_REPLICA role: caller might want to refresh cache after a REPEATABLE-READ snapshot
627  return $this->__call( __FUNCTION__, func_get_args() );
628  }
629 
630  public function onTransactionIdle( callable $callback, $fname = __METHOD__ ) {
631  return $this->onTransactionCommitOrIdle( $callback, $fname );
632  }
633 
634  public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ ) {
635  // DB_REPLICA role: caller might want to refresh cache after a cache mutex is released
636  return $this->__call( __FUNCTION__, func_get_args() );
637  }
638 
639  public function onAtomicSectionCancel( callable $callback, $fname = __METHOD__ ) {
640  return $this->__call( __FUNCTION__, func_get_args() );
641  }
642 
643  public function setTransactionListener( $name, callable $callback = null ) {
644  return $this->__call( __FUNCTION__, func_get_args() );
645  }
646 
647  public function startAtomic(
648  $fname = __METHOD__, $cancelable = IDatabase::ATOMIC_NOT_CANCELABLE
649  ) {
650  // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
651  return $this->__call( __FUNCTION__, func_get_args() );
652  }
653 
654  public function endAtomic( $fname = __METHOD__ ) {
655  // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
656  return $this->__call( __FUNCTION__, func_get_args() );
657  }
658 
659  public function cancelAtomic( $fname = __METHOD__, AtomicSectionIdentifier $sectionId = null ) {
660  // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
661  return $this->__call( __FUNCTION__, func_get_args() );
662  }
663 
664  public function doAtomicSection(
665  $fname, callable $callback, $cancelable = self::ATOMIC_NOT_CANCELABLE
666  ) {
667  // Don't call assertRoleAllowsWrites(); caller might want a REPEATABLE-READ snapshot
668  return $this->__call( __FUNCTION__, func_get_args() );
669  }
670 
671  public function begin( $fname = __METHOD__, $mode = IDatabase::TRANSACTION_EXPLICIT ) {
672  return $this->__call( __FUNCTION__, func_get_args() );
673  }
674 
675  public function commit( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) {
676  return $this->__call( __FUNCTION__, func_get_args() );
677  }
678 
679  public function rollback( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) {
680  return $this->__call( __FUNCTION__, func_get_args() );
681  }
682 
683  public function flushSnapshot( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) {
684  return $this->__call( __FUNCTION__, func_get_args() );
685  }
686 
687  public function timestamp( $ts = 0 ) {
688  return $this->__call( __FUNCTION__, func_get_args() );
689  }
690 
691  public function timestampOrNull( $ts = null ) {
692  return $this->__call( __FUNCTION__, func_get_args() );
693  }
694 
695  public function ping( &$rtt = null ) {
696  return func_num_args()
697  ? $this->__call( __FUNCTION__, [ &$rtt ] )
698  : $this->__call( __FUNCTION__, [] ); // method cares about null vs missing
699  }
700 
701  public function getLag() {
702  return $this->__call( __FUNCTION__, func_get_args() );
703  }
704 
705  public function getSessionLagStatus() {
706  return $this->__call( __FUNCTION__, func_get_args() );
707  }
708 
709  public function maxListLen() {
710  return $this->__call( __FUNCTION__, func_get_args() );
711  }
712 
713  public function encodeBlob( $b ) {
714  return $this->__call( __FUNCTION__, func_get_args() );
715  }
716 
717  public function decodeBlob( $b ) {
718  return $this->__call( __FUNCTION__, func_get_args() );
719  }
720 
721  public function setSessionOptions( array $options ) {
722  $this->__call( __FUNCTION__, func_get_args() );
723  }
724 
725  public function setSchemaVars( $vars ) {
726  return $this->__call( __FUNCTION__, func_get_args() );
727  }
728 
729  public function lockIsFree( $lockName, $method ) {
730  $this->assertRoleAllowsWrites();
731 
732  return $this->__call( __FUNCTION__, func_get_args() );
733  }
734 
735  public function lock( $lockName, $method, $timeout = 5, $flags = 0 ) {
736  $this->assertRoleAllowsWrites();
737 
738  return $this->__call( __FUNCTION__, func_get_args() );
739  }
740 
741  public function unlock( $lockName, $method ) {
742  $this->assertRoleAllowsWrites();
743 
744  return $this->__call( __FUNCTION__, func_get_args() );
745  }
746 
747  public function getScopedLockAndFlush( $lockKey, $fname, $timeout ) {
748  $this->assertRoleAllowsWrites();
749 
750  return $this->__call( __FUNCTION__, func_get_args() );
751  }
752 
753  public function namedLocksEnqueue() {
754  return $this->__call( __FUNCTION__, func_get_args() );
755  }
756 
757  public function getInfinity() {
758  return $this->__call( __FUNCTION__, func_get_args() );
759  }
760 
761  public function encodeExpiry( $expiry ) {
762  return $this->__call( __FUNCTION__, func_get_args() );
763  }
764 
765  public function decodeExpiry( $expiry, $format = TS_MW ) {
766  return $this->__call( __FUNCTION__, func_get_args() );
767  }
768 
769  public function setBigSelects( $value = true ) {
770  return $this->__call( __FUNCTION__, func_get_args() );
771  }
772 
773  public function isReadOnly() {
774  return $this->__call( __FUNCTION__, func_get_args() );
775  }
776 
777  public function setTableAliases( array $aliases ) {
778  return $this->__call( __FUNCTION__, func_get_args() );
779  }
780 
781  public function setIndexAliases( array $aliases ) {
782  return $this->__call( __FUNCTION__, func_get_args() );
783  }
784 
785  public function __toString() {
786  if ( $this->conn === null ) {
787  return $this->getType() . ' object #' . spl_object_id( $this );
788  }
789 
790  return $this->__call( __FUNCTION__, func_get_args() );
791  }
792 
806  protected function assertRoleAllowsWrites() {
807  // DB_PRIMARY is "prima facie" writable
808  if ( $this->role !== ILoadBalancer::DB_PRIMARY ) {
809  throw new DBReadOnlyRoleError( $this->conn, "Cannot write with role DB_REPLICA" );
810  }
811  }
812 
816  protected function getDomainChangeException() {
817  return new DBUnexpectedError(
818  $this,
819  "Cannot directly change the selected DB domain; any underlying connection handle " .
820  "is owned by a LoadBalancer instance and possibly shared with other callers. " .
821  "LoadBalancer automatically manages DB domain re-selection of unused handles."
822  );
823  }
824 
828  public function __destruct() {
829  if ( $this->conn ) {
830  $this->lb->reuseConnection( $this->conn );
831  }
832  }
833 }
834 
839 class_alias( DBConnRef::class, 'DBConnRef' );
Wikimedia\Rdbms\DBConnRef\isOpen
isOpen()
Definition: DBConnRef.php:188
Wikimedia\Rdbms\DBConnRef\explicitTrxActive
explicitTrxActive()
Definition: DBConnRef.php:108
Wikimedia\Rdbms\DBConnRef\affectedRows
affectedRows()
Get the number of rows affected by the last write query.
Definition: DBConnRef.php:275
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:52
Wikimedia\Rdbms\DBConnRef\buildGreatest
buildGreatest( $fields, $values)
Build a GREATEST function statement comparing columns/values.
Definition: DBConnRef.php:423
Wikimedia\Rdbms\DBConnRef\buildLike
buildLike( $param,... $params)
LIKE statement wrapper.
Definition: DBConnRef.php:492
Wikimedia\Rdbms\DBConnRef\strreplace
strreplace( $orig, $old, $new)
Returns a SQL expression for simple string replacement (e.g.
Definition: DBConnRef.php:566
Wikimedia\Rdbms\DBConnRef\FLD_FLAGS
const FLD_FLAGS
Definition: DBConnRef.php:42
Wikimedia\Rdbms\DBConnRef\getType
getType()
Get the RDBMS type of the server (e.g.
Definition: DBConnRef.php:222
Wikimedia\Rdbms\DatabaseDomain\getId
getId()
Definition: DatabaseDomain.php:200
Wikimedia\Rdbms\DatabaseDomain\newFromId
static newFromId( $domain)
Definition: DatabaseDomain.php:77
Wikimedia\Rdbms\DBConnRef\replace
replace( $table, $uniqueKeys, $rows, $fname=__METHOD__)
Insert row(s) into a table, deleting all conflicting rows beforehand.
Definition: DBConnRef.php:510
Wikimedia\Rdbms\DBConnRef\buildGroupConcatField
buildGroupConcatField( $delim, $table, $field, $conds='', $join_conds=[])
Build a GROUP_CONCAT or equivalent statement for a query.
Definition: DBConnRef.php:417
Wikimedia\Rdbms\DBConnRef\query
query( $sql, $fname=__METHOD__, $flags=0)
Run an SQL query and return the result.
Definition: DBConnRef.php:292
Wikimedia\Rdbms\DBConnRef\nextSequenceValue
nextSequenceValue( $seqName)
Deprecated method, calls should be removed.
Definition: DBConnRef.php:504
Wikimedia\Rdbms\DBConnRef\assertNoOpenTransactions
assertNoOpenTransactions()
Assert that all explicit transactions or atomic sections have been closed.
Definition: DBConnRef.php:112
Wikimedia\Rdbms\DBConnRef\decodeExpiry
decodeExpiry( $expiry, $format=TS_MW)
Decode an expiry time into a DBMS independent format.
Definition: DBConnRef.php:765
Wikimedia\Rdbms\DBConnRef\setSessionOptions
setSessionOptions(array $options)
Override database's default behavior.
Definition: DBConnRef.php:721
Wikimedia\Rdbms\DBConnRef\selectDomain
selectDomain( $domain)
Set the current domain (database, schema, and table prefix)
Definition: DBConnRef.php:460
Wikimedia\Rdbms\ILoadBalancer\DB_PRIMARY
const DB_PRIMARY
Request a primary, write-enabled DB connection.
Definition: ILoadBalancer.php:88
Wikimedia\Rdbms\DBConnRef\insert
insert( $table, $rows, $fname=__METHOD__, $options=[])
Insert the given row(s) into a table.
Definition: DBConnRef.php:377
Wikimedia\Rdbms\DBConnRef\serverIsReadOnly
serverIsReadOnly()
Definition: DBConnRef.php:616
Wikimedia\Rdbms\DBConnRef\getDomainChangeException
getDomainChangeException()
Definition: DBConnRef.php:816
Wikimedia\Rdbms\DBConnRef\tableExists
tableExists( $table, $fname=__METHOD__)
Query whether a given table exists.
Definition: DBConnRef.php:373
Wikimedia\Rdbms\DBConnRef\anyString
anyString()
Returns a token for buildLike() that denotes a '' to be used in a LIKE query.
Definition: DBConnRef.php:500
Wikimedia\Rdbms\DBConnRef\selectRowCount
selectRowCount( $tables, $vars=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Get the number of rows in dataset.
Definition: DBConnRef.php:351
Wikimedia\Rdbms\DBReadOnlyRoleError
Exception class for attempted DB write access to a DBConnRef with the DB_REPLICA role.
Definition: DBReadOnlyRoleError.php:30
Wikimedia\Rdbms\DBConnRef\timestampOrNull
timestampOrNull( $ts=null)
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for ins...
Definition: DBConnRef.php:691
Wikimedia\Rdbms\DBConnRef\dataSeek
dataSeek( $res, $row)
Definition: DBConnRef.php:263
Wikimedia\Rdbms\DBConnRef\getDomainID
getDomainID()
Return the currently selected domain ID.
Definition: DBConnRef.php:212
Wikimedia\Rdbms\DBConnRef\$lb
ILoadBalancer $lb
Definition: DBConnRef.php:31
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\DBConnRef\unionSupportsOrderAndLimit
unionSupportsOrderAndLimit()
Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION.
Definition: DBConnRef.php:547
Wikimedia\Rdbms\DBConnRef\buildStringCast
buildStringCast( $field)
Definition: DBConnRef.php:435
Wikimedia\Rdbms\DBConnRef\getLag
getLag()
Get the amount of replication lag for this database server.
Definition: DBConnRef.php:701
Wikimedia\Rdbms\DBConnRef\pendingWriteCallers
pendingWriteCallers()
Get the list of method names that did write queries for this transaction.
Definition: DBConnRef.php:180
Wikimedia\Rdbms\DBConnRef\buildSelectSubquery
buildSelectSubquery( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery.
Definition: DBConnRef.php:443
Wikimedia\Rdbms\DBConnRef\rollback
rollback( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Rollback a transaction previously started using begin()
Definition: DBConnRef.php:679
Wikimedia\Rdbms\DBConnRef\setFlag
setFlag( $flag, $remember=self::REMEMBER_NOTHING)
Set a flag for this connection.
Definition: DBConnRef.php:192
Wikimedia\Rdbms\DBConnRef\maxListLen
maxListLen()
Return the maximum number of items allowed in a list, or 0 for unlimited.
Definition: DBConnRef.php:709
Wikimedia\Rdbms\DBConnRef\getSessionLagStatus
getSessionLagStatus()
Get the replica DB lag when the current transaction started or a general lag estimate if not transact...
Definition: DBConnRef.php:705
Wikimedia\Rdbms\DBConnRef\implicitOrderby
implicitOrderby()
Returns true if this database does an implicit order by when the column has an index For example: SEL...
Definition: DBConnRef.php:152
Wikimedia\Rdbms\DBConnRef\upsert
upsert( $table, array $rows, $uniqueKeys, array $set, $fname=__METHOD__)
Upsert the given row(s) into a table.
Definition: DBConnRef.php:516
$res
$res
Definition: testCompression.php:57
Wikimedia\Rdbms\DBConnRef\getTopologyRootMaster
getTopologyRootMaster()
Definition: DBConnRef.php:95
LIST_COMMA
const LIST_COMMA
Definition: Defines.php:42
Wikimedia\Rdbms\DBConnRef\lastError
lastError()
Get a description of the last error.
Definition: DBConnRef.php:271
Wikimedia\Rdbms\DBConnRef\getFlag
getFlag( $flag)
Returns a boolean whether the flag $flag is set for this connection.
Definition: DBConnRef.php:204
Wikimedia\Rdbms\DBConnRef\wasLockTimeout
wasLockTimeout()
Determines if the last failure was due to a lock timeout.
Definition: DBConnRef.php:578
Wikimedia\Rdbms\DBConnRef\doAtomicSection
doAtomicSection( $fname, callable $callback, $cancelable=self::ATOMIC_NOT_CANCELABLE)
Perform an atomic section of reversable SQL statements from a callback.
Definition: DBConnRef.php:664
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
Wikimedia\Rdbms\DBConnRef\getLBInfo
getLBInfo( $name=null)
Get properties passed down from the server info array of the load balancer.
Definition: DBConnRef.php:142
Wikimedia\Rdbms\DBPrimaryPos
An object representing a primary or replica DB position in a replicated setup.
Definition: DBPrimaryPos.php:15
Wikimedia\Rdbms\DBConnRef\$params
array $params
N-tuple of (server index, group, DatabaseDomain|string)
Definition: DBConnRef.php:35
Wikimedia\Rdbms\DBConnRef\setTableAliases
setTableAliases(array $aliases)
Make certain table names use their own database, schema, and table prefix when passed into SQL querie...
Definition: DBConnRef.php:777
Wikimedia\Rdbms\DBConnRef\getProperty
getProperty( $name)
Definition: DBConnRef.php:208
Wikimedia\Rdbms\DBConnRef\preCommitCallbacksPending
preCommitCallbacksPending()
Definition: DBConnRef.php:168
Wikimedia\Rdbms\DBConnRef\getInfinity
getInfinity()
Find out when 'infinity' is.
Definition: DBConnRef.php:757
Wikimedia\Rdbms\DBConnRef\pendingWriteQueryDuration
pendingWriteQueryDuration( $type=self::ESTIMATE_TOTAL)
Get the time spend running write queries for this transaction.
Definition: DBConnRef.php:176
Wikimedia\Rdbms\DBConnRef\addIdentifierQuotes
addIdentifierQuotes( $s)
Escape a SQL identifier (e.g.
Definition: DBConnRef.php:488
Wikimedia\Rdbms\DBConnRef\select
select( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
Definition: DBConnRef.php:320
Wikimedia\Rdbms\DBConnRef\insertSelect
insertSelect( $destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[], $selectJoinConds=[])
INSERT SELECT wrapper.
Definition: DBConnRef.php:538
Wikimedia\Rdbms\DBConnRef\buildIntegerCast
buildIntegerCast( $field)
Definition: DBConnRef.php:439
Wikimedia\Rdbms\DBConnRef\$conn
Database null $conn
Live connection handle.
Definition: DBConnRef.php:33
Wikimedia\Rdbms\DBConnRef\selectRow
selectRow( $table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
Wrapper to IDatabase::select() that only fetches one row (via LIMIT)
Definition: DBConnRef.php:338
Wikimedia\Rdbms\DBConnRef\onAtomicSectionCancel
onAtomicSectionCancel(callable $callback, $fname=__METHOD__)
Run a callback when the atomic section is cancelled.
Definition: DBConnRef.php:639
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:997
Wikimedia\Rdbms\DBConnRef\getScopedLockAndFlush
getScopedLockAndFlush( $lockKey, $fname, $timeout)
Acquire a named lock, flush any transaction, and return an RAII style unlocker object.
Definition: DBConnRef.php:747
Wikimedia\Rdbms\DBConnRef\getServerInfo
getServerInfo()
Get a human-readable string describing the current software version.
Definition: DBConnRef.php:79
Wikimedia\Rdbms\DBConnRef\indexExists
indexExists( $table, $index, $fname=__METHOD__)
Determines whether an index exists.
Definition: DBConnRef.php:369
Wikimedia\Rdbms\DBConnRef\encodeExpiry
encodeExpiry( $expiry)
Encode an expiry time into the DBMS dependent format.
Definition: DBConnRef.php:761
Wikimedia\Rdbms\DBConnRef\wasDeadlock
wasDeadlock()
Determines if the last failure was due to a deadlock.
Definition: DBConnRef.php:574
Wikimedia\Rdbms\DBConnRef\selectSQLText
selectSQLText( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Take the same arguments as IDatabase::select() and return the SQL it would use.
Definition: DBConnRef.php:327
Wikimedia\Rdbms\DBConnRef\writesOrCallbacksPending
writesOrCallbacksPending()
Whether there is a transaction open with either possible write queries or unresolved pre-commit/commi...
Definition: DBConnRef.php:172
Wikimedia\Rdbms\DBConnRef\__destruct
__destruct()
Clean up the connection when out of scope.
Definition: DBConnRef.php:828
Wikimedia\Rdbms\DBConnRef\lock
lock( $lockName, $method, $timeout=5, $flags=0)
Acquire a named lock.
Definition: DBConnRef.php:735
Wikimedia\Rdbms\DBConnRef\fetchObject
fetchObject( $res)
Definition: DBConnRef.php:239
Wikimedia\Rdbms\DBConnRef\selectFieldValues
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:314
Wikimedia\Rdbms\DBConnRef\anyChar
anyChar()
Returns a token for buildLike() that denotes a '_' to be used in a LIKE query.
Definition: DBConnRef.php:496
Wikimedia\Rdbms\DBConnRef\startAtomic
startAtomic( $fname=__METHOD__, $cancelable=IDatabase::ATOMIC_NOT_CANCELABLE)
Begin an atomic section of SQL statements.
Definition: DBConnRef.php:647
Wikimedia\Rdbms\DBConnRef\endAtomic
endAtomic( $fname=__METHOD__)
Ends an atomic section of SQL statements.
Definition: DBConnRef.php:654
Wikimedia\Rdbms\DBConnRef\unlock
unlock( $lockName, $method)
Release a lock.
Definition: DBConnRef.php:741
Wikimedia\Rdbms\DBConnRef\getTopologyRole
getTopologyRole()
Get the replication topology role of this server.
Definition: DBConnRef.php:87
Wikimedia\Rdbms\DBConnRef\setSchemaVars
setSchemaVars( $vars)
Set schema variables to be used when streaming commands from SQL files or stdin.
Definition: DBConnRef.php:725
Wikimedia\Rdbms\DBConnRef\tablePrefix
tablePrefix( $prefix=null)
Get/set the table prefix.
Definition: DBConnRef.php:116
Wikimedia\Rdbms\DBConnRef\conditional
conditional( $cond, $caseTrueExpression, $caseFalseExpression)
Returns an SQL expression for a simple conditional.
Definition: DBConnRef.php:562
Wikimedia\Rdbms\DBConnRef\buildSubstring
buildSubstring( $input, $startPosition, $length=null)
Definition: DBConnRef.php:431
Wikimedia\Rdbms\DBConnRef\writesPending
writesPending()
Definition: DBConnRef.php:164
Wikimedia\Rdbms\SelectQueryBuilder
Definition: SelectQueryBuilder.php:11
Wikimedia\Rdbms\DBConnRef\getServer
getServer()
Get the hostname or IP address of the server.
Definition: DBConnRef.php:476
Wikimedia\Rdbms\DBConnRef\update
update( $table, $set, $conds, $fname=__METHOD__, $options=[])
Update all rows in a table that match a given condition.
Definition: DBConnRef.php:383
Wikimedia\Rdbms\DBConnRef\setLBInfo
setLBInfo( $nameOrArray, $value=null)
Set the entire array or a particular key of the managing load balancer info array.
Definition: DBConnRef.php:146
Wikimedia\Rdbms\DBConnRef\primaryPosWait
primaryPosWait(DBPrimaryPos $pos, $timeout)
Wait for the replica DB to catch up to a given primary DB position.
Definition: DBConnRef.php:594
Wikimedia\Rdbms\DBConnRef\fieldExists
fieldExists( $table, $field, $fname=__METHOD__)
Determines whether a field exists in a table.
Definition: DBConnRef.php:365
Wikimedia\Rdbms\DBConnRef\selectDB
selectDB( $db)
Change the current database.
Definition: DBConnRef.php:454
Wikimedia\Rdbms\DBConnRef\commit
commit( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Commits a transaction previously started using begin()
Definition: DBConnRef.php:675
Wikimedia\Rdbms\DBConnRef\limitResult
limitResult( $sql, $limit, $offset=false)
Construct a LIMIT query with optional offset.
Definition: DBConnRef.php:334
Wikimedia\Rdbms\DBConnRef\fieldName
fieldName( $res, $n)
Definition: DBConnRef.php:255
Wikimedia\Rdbms\DBConnRef\bitNot
bitNot( $field)
Definition: DBConnRef.php:401
Wikimedia\Rdbms\DBConnRef\onTransactionCommitOrIdle
onTransactionCommitOrIdle(callable $callback, $fname=__METHOD__)
Run a callback when the current transaction commits or now if there is none.
Definition: DBConnRef.php:625
Wikimedia\Rdbms\DBConnRef\restoreFlags
restoreFlags( $state=self::RESTORE_PRIOR)
Restore the flags to their prior state before the last setFlag/clearFlag call.
Definition: DBConnRef.php:200
Wikimedia\Rdbms\DBConnRef\lastQuery
lastQuery()
Get the last query that sent on account of IDatabase::query()
Definition: DBConnRef.php:156
Wikimedia\Rdbms\DBConnRef\getServerUptime
getServerUptime()
Determines how long the server has been up.
Definition: DBConnRef.php:570
Wikimedia\Rdbms\DBConnRef\makeList
makeList(array $a, $mode=self::LIST_COMMA)
Makes an encoded list of strings from an array.
Definition: DBConnRef.php:389
Wikimedia\Rdbms\DBConnRef\getDBname
getDBname()
Get the current database name; null if there isn't one.
Definition: DBConnRef.php:466
Wikimedia\Rdbms\DBConnRef\pendingWriteRowsAffected
pendingWriteRowsAffected()
Get the number of affected rows from pending write queries.
Definition: DBConnRef.php:184
Wikimedia\Rdbms\DBConnRef\decodeBlob
decodeBlob( $b)
Some DBMSs return a special placeholder object representing blob fields in result objects.
Definition: DBConnRef.php:717
Wikimedia\Rdbms\DBConnRef\lastDoneWrites
lastDoneWrites()
Get the last time the connection may have been used for a write query.
Definition: DBConnRef.php:160
$s
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
Definition: mergeMessageFileList.php:206
Wikimedia\Rdbms\DBConnRef\FLD_GROUP
const FLD_GROUP
Definition: DBConnRef.php:40
Wikimedia\Rdbms\DBConnRef\assertRoleAllowsWrites
assertRoleAllowsWrites()
Error out if the role is not DB_PRIMARY.
Definition: DBConnRef.php:806
Wikimedia\Rdbms\DBConnRef\trxTimestamp
trxTimestamp()
Get the UNIX timestamp of the time that the transaction was established.
Definition: DBConnRef.php:104
Wikimedia\Rdbms\DBConnRef\unionConditionPermutations
unionConditionPermutations( $table, $vars, array $permute_conds, $extra_conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Construct a UNION query for permutations of conditions.
Definition: DBConnRef.php:555
Wikimedia\Rdbms\DBConnRef\trxLevel
trxLevel()
Gets the current transaction level.
Definition: DBConnRef.php:100
Wikimedia\Rdbms\DBConnRef\getSoftwareLink
getSoftwareLink()
Returns a wikitext style link to the DB's website (e.g.
Definition: DBConnRef.php:279
Wikimedia\Rdbms\DBConnRef\FLD_INDEX
const FLD_INDEX
Definition: DBConnRef.php:39
Wikimedia\Rdbms\DBConnRef\addQuotes
addQuotes( $s)
Escape and quote a raw value string for use in a SQL query.
Definition: DBConnRef.php:484
Wikimedia\Rdbms\AtomicSectionIdentifier
Class used for token representing identifiers for atomic sections from IDatabase instances.
Definition: AtomicSectionIdentifier.php:26
Wikimedia\Rdbms\DBConnRef\$role
int $role
One of DB_PRIMARY/DB_REPLICA.
Definition: DBConnRef.php:37
Wikimedia\Rdbms\DBConnRef\timestamp
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for ins...
Definition: DBConnRef.php:687
Wikimedia\Rdbms\DBConnRef\wasReadOnlyError
wasReadOnlyError()
Determines if the last failure was due to the database being read-only.
Definition: DBConnRef.php:586
Wikimedia\Rdbms\DBConnRef\encodeBlob
encodeBlob( $b)
Some DBMSs have a special format for inserting into blob fields, they don't allow simple quoted strin...
Definition: DBConnRef.php:713
Wikimedia\Rdbms\DBConnRef\onTransactionResolution
onTransactionResolution(callable $callback, $fname=__METHOD__)
Run a callback when the current transaction commits or rolls back.
Definition: DBConnRef.php:620
Wikimedia\Rdbms\DBConnRef\freeResult
freeResult( $res)
Definition: DBConnRef.php:300
Wikimedia\Rdbms\DBConnRef\buildConcat
buildConcat( $stringList)
Build a concatenation list to feed into a SQL query.
Definition: DBConnRef.php:413
Wikimedia\Rdbms\DBConnRef\selectField
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:308
Wikimedia\Rdbms\DBConnRef\makeWhereFrom2d
makeWhereFrom2d( $data, $baseKey, $subKey)
Build a partial where clause from a 2-d array such as used for LinkBatch.
Definition: DBConnRef.php:393
Wikimedia\Rdbms\DBConnRef\getTopologyRootPrimary
getTopologyRootPrimary()
Get the readable name of the sole root primary DB server for the replication topology.
Definition: DBConnRef.php:91
Wikimedia\Rdbms\DBConnRef\setTransactionListener
setTransactionListener( $name, callable $callback=null)
Run a callback after each time any transaction commits or rolls back.
Definition: DBConnRef.php:643
Wikimedia\Rdbms\DBConnRef\lockForUpdate
lockForUpdate( $table, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Lock all rows meeting the given conditions/options FOR UPDATE.
Definition: DBConnRef.php:357
Wikimedia\Rdbms\DBConnRef\bitOr
bitOr( $fieldLeft, $fieldRight)
Definition: DBConnRef.php:409
Wikimedia\Rdbms\DBConnRef\setBigSelects
setBigSelects( $value=true)
Allow or deny "big selects" for this session only.
Definition: DBConnRef.php:769
Wikimedia\Rdbms\DBConnRef\newSelectQueryBuilder
newSelectQueryBuilder()
Create an empty SelectQueryBuilder which can be used to run queries against this connection.
Definition: DBConnRef.php:304
Wikimedia\Rdbms\DBUnexpectedError
@newable
Definition: DBUnexpectedError.php:29
Wikimedia\Rdbms\DBConnRef\numRows
numRows( $res)
Get the number of rows in a query result.
Definition: DBConnRef.php:247
Wikimedia\Rdbms\DBConnRef\dbSchema
dbSchema( $schema=null)
Get/set the db schema.
Definition: DBConnRef.php:129
Wikimedia\Rdbms\DBConnRef
Helper class used for automatically marking an IDatabase connection as reusable (once it no longer ma...
Definition: DBConnRef.php:29
Wikimedia\Rdbms\DBConnRef\getReplicaPos
getReplicaPos()
Get the replication position of this replica DB.
Definition: DBConnRef.php:603
Wikimedia\Rdbms\DBConnRef\getPrimaryPos
getPrimaryPos()
Get the position of this primary DB.
Definition: DBConnRef.php:607
Wikimedia\Rdbms\DBConnRef\setIndexAliases
setIndexAliases(array $aliases)
Convert certain index names to alternative names before querying the DB.
Definition: DBConnRef.php:781
Wikimedia\Rdbms\DBConnRef\estimateRowCount
estimateRowCount( $tables, $vars=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Estimate the number of rows in dataset.
Definition: DBConnRef.php:345
Wikimedia\Rdbms\DBConnRef\masterPosWait
masterPosWait(DBPrimaryPos $pos, $timeout)
Definition: DBConnRef.php:598
Wikimedia\Rdbms\DBConnRef\ping
ping(&$rtt=null)
Ping the server and try to reconnect if it there is no connection.
Definition: DBConnRef.php:695
Wikimedia\Rdbms\DBConnRef\getReferenceRole
getReferenceRole()
Definition: DBConnRef.php:75
Wikimedia\Rdbms\DBConnRef\deleteJoin
deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__)
DELETE where the condition is a join.
Definition: DBConnRef.php:524
Wikimedia\Rdbms\DBConnRef\unionQueries
unionQueries( $sqls, $all)
Construct a UNION query.
Definition: DBConnRef.php:551
Wikimedia\Rdbms\DBConnRef\onTransactionPreCommitOrIdle
onTransactionPreCommitOrIdle(callable $callback, $fname=__METHOD__)
Run a callback before the current transaction commits or now if there is none.
Definition: DBConnRef.php:634
Wikimedia\Rdbms\DBConnRef\insertId
insertId()
Get the inserted value of an auto-increment row.
Definition: DBConnRef.php:259
Wikimedia\Rdbms\DBConnRef\isReadOnly
isReadOnly()
Definition: DBConnRef.php:773
Wikimedia\Rdbms\DBConnRef\getMasterPos
getMasterPos()
Definition: DBConnRef.php:611
Wikimedia\Rdbms\DBConnRef\databasesAreIndependent
databasesAreIndependent()
Returns true if DBs are assumed to be on potentially different servers.
Definition: DBConnRef.php:450
Wikimedia\Rdbms\DBConnRef\wasConnectionLoss
wasConnectionLoss()
Determines if the last query error was due to a dropped connection.
Definition: DBConnRef.php:582
Wikimedia\Rdbms\DBConnRef\FLD_DOMAIN
const FLD_DOMAIN
Definition: DBConnRef.php:41
Wikimedia\Rdbms\DBConnRef\numFields
numFields( $res)
Definition: DBConnRef.php:251
Wikimedia\Rdbms\DBConnRef\__construct
__construct(ILoadBalancer $lb, $conn, $role)
Definition: DBConnRef.php:50
Wikimedia\Rdbms\DatabaseDomain
Class to handle database/schema/prefix specifications for IDatabase.
Definition: DatabaseDomain.php:40
Wikimedia\Rdbms\DBConnRef\flushSnapshot
flushSnapshot( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Commit any transaction but error out if writes or callbacks are pending.
Definition: DBConnRef.php:683
Wikimedia\Rdbms\DBConnRef\getServerName
getServerName()
Get the readable name for the server.
Definition: DBConnRef.php:480
Wikimedia\Rdbms\DBConnRef\buildLeast
buildLeast( $fields, $values)
Build a LEAST function statement comparing columns/values.
Definition: DBConnRef.php:427
Wikimedia\Rdbms\DBConnRef\clearFlag
clearFlag( $flag, $remember=self::REMEMBER_NOTHING)
Clear a flag for this connection.
Definition: DBConnRef.php:196
Wikimedia\Rdbms\DBConnRef\lockIsFree
lockIsFree( $lockName, $method)
Check to see if a named lock is not locked by any thread (non-blocking)
Definition: DBConnRef.php:729
Wikimedia\Rdbms\DBConnRef\close
close( $fname=__METHOD__, $owner=null)
Close the database connection.
Definition: DBConnRef.php:287
Wikimedia\Rdbms\DBConnRef\onTransactionIdle
onTransactionIdle(callable $callback, $fname=__METHOD__)
Alias for onTransactionCommitOrIdle() for backwards-compatibility.
Definition: DBConnRef.php:630
Wikimedia\Rdbms\DBConnRef\fetchRow
fetchRow( $res)
Definition: DBConnRef.php:243
Wikimedia\Rdbms\DBConnRef\getTopologyBasedServerId
getTopologyBasedServerId()
Get a non-recycled ID that uniquely identifies this server within the replication topology.
Definition: DBConnRef.php:83
Wikimedia\Rdbms\DBConnRef\lastErrno
lastErrno()
Get the last error number.
Definition: DBConnRef.php:267
Wikimedia\Rdbms\DBConnRef\namedLocksEnqueue
namedLocksEnqueue()
Check to see if a named lock used by lock() use blocking queues.
Definition: DBConnRef.php:753
Wikimedia\Rdbms\DBConnRef\__toString
__toString()
Get a debugging string that mentions the database type, the ID of this instance, and the ID of any un...
Definition: DBConnRef.php:785
Wikimedia\Rdbms\DBConnRef\getServerVersion
getServerVersion()
A string describing the current software version, like from mysql_get_server_info()
Definition: DBConnRef.php:283
Wikimedia\Rdbms\DBConnRef\begin
begin( $fname=__METHOD__, $mode=IDatabase::TRANSACTION_EXPLICIT)
Begin a transaction.
Definition: DBConnRef.php:671
Wikimedia\Rdbms\DBConnRef\wasErrorReissuable
wasErrorReissuable()
Determines if the last query error was due to something outside of the query itself.
Definition: DBConnRef.php:590
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
Wikimedia\Rdbms\DBConnRef\bitAnd
bitAnd( $fieldLeft, $fieldRight)
Definition: DBConnRef.php:405
Wikimedia\Rdbms\DBConnRef\__call
__call( $name, array $arguments)
Definition: DBConnRef.php:62
Wikimedia\Rdbms\DBConnRef\aggregateValue
aggregateValue( $valuedata, $valuename='value')
Return aggregated value alias.
Definition: DBConnRef.php:397
$type
$type
Definition: testCompression.php:52
Wikimedia\Rdbms\DBConnRef\cancelAtomic
cancelAtomic( $fname=__METHOD__, AtomicSectionIdentifier $sectionId=null)
Cancel an atomic section of SQL statements.
Definition: DBConnRef.php:659