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