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