Break up $wgDummyLanguageCodes
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DBConnRef.php
1 <?php
2 /**
3 * Helper class to handle automatically marking connections as reusable (via RAII pattern)
4 * as well handling deferring the actual network connection until the handle is used
5 *
6 * @note: proxy methods are defined explicity to avoid interface errors
7 * @ingroup Database
8 * @since 1.22
9 */
10 class DBConnRef implements IDatabase {
11 /** @var ILoadBalancer */
12 private $lb;
13 /** @var Database|null Live connection handle */
14 private $conn;
15 /** @var array|null N-tuple of (server index, group, DatabaseDomain|string) */
16 private $params;
17
18 const FLD_INDEX = 0;
19 const FLD_GROUP = 1;
20 const FLD_DOMAIN = 2;
21
22 /**
23 * @param ILoadBalancer $lb Connection manager for $conn
24 * @param Database|array $conn New connection handle or (server index, query groups, domain)
25 */
26 public function __construct( ILoadBalancer $lb, $conn ) {
27 $this->lb = $lb;
28 if ( $conn instanceof Database ) {
29 $this->conn = $conn; // live handle
30 } elseif ( count( $conn ) >= 3 && $conn[self::FLD_DOMAIN] !== false ) {
31 $this->params = $conn;
32 } else {
33 throw new InvalidArgumentException( "Missing lazy connection arguments." );
34 }
35 }
36
37 function __call( $name, array $arguments ) {
38 if ( $this->conn === null ) {
39 list( $db, $groups, $wiki ) = $this->params;
40 $this->conn = $this->lb->getConnection( $db, $groups, $wiki );
41 }
42
43 return call_user_func_array( [ $this->conn, $name ], $arguments );
44 }
45
46 public function getServerInfo() {
47 return $this->__call( __FUNCTION__, func_get_args() );
48 }
49
50 public function bufferResults( $buffer = null ) {
51 return $this->__call( __FUNCTION__, func_get_args() );
52 }
53
54 public function trxLevel() {
55 return $this->__call( __FUNCTION__, func_get_args() );
56 }
57
58 public function trxTimestamp() {
59 return $this->__call( __FUNCTION__, func_get_args() );
60 }
61
62 public function explicitTrxActive() {
63 return $this->__call( __FUNCTION__, func_get_args() );
64 }
65
66 public function tablePrefix( $prefix = null ) {
67 return $this->__call( __FUNCTION__, func_get_args() );
68 }
69
70 public function dbSchema( $schema = null ) {
71 return $this->__call( __FUNCTION__, func_get_args() );
72 }
73
74 public function getLBInfo( $name = null ) {
75 return $this->__call( __FUNCTION__, func_get_args() );
76 }
77
78 public function setLBInfo( $name, $value = null ) {
79 return $this->__call( __FUNCTION__, func_get_args() );
80 }
81
82 public function setLazyMasterHandle( IDatabase $conn ) {
83 return $this->__call( __FUNCTION__, func_get_args() );
84 }
85
86 public function implicitGroupby() {
87 return $this->__call( __FUNCTION__, func_get_args() );
88 }
89
90 public function implicitOrderby() {
91 return $this->__call( __FUNCTION__, func_get_args() );
92 }
93
94 public function lastQuery() {
95 return $this->__call( __FUNCTION__, func_get_args() );
96 }
97
98 public function doneWrites() {
99 return $this->__call( __FUNCTION__, func_get_args() );
100 }
101
102 public function lastDoneWrites() {
103 return $this->__call( __FUNCTION__, func_get_args() );
104 }
105
106 public function writesPending() {
107 return $this->__call( __FUNCTION__, func_get_args() );
108 }
109
110 public function writesOrCallbacksPending() {
111 return $this->__call( __FUNCTION__, func_get_args() );
112 }
113
114 public function pendingWriteQueryDuration( $type = self::ESTIMATE_TOTAL ) {
115 return $this->__call( __FUNCTION__, func_get_args() );
116 }
117
118 public function pendingWriteCallers() {
119 return $this->__call( __FUNCTION__, func_get_args() );
120 }
121
122 public function isOpen() {
123 return $this->__call( __FUNCTION__, func_get_args() );
124 }
125
126 public function setFlag( $flag, $remember = self::REMEMBER_NOTHING ) {
127 return $this->__call( __FUNCTION__, func_get_args() );
128 }
129
130 public function clearFlag( $flag, $remember = self::REMEMBER_NOTHING ) {
131 return $this->__call( __FUNCTION__, func_get_args() );
132 }
133
134 public function restoreFlags( $state = self::RESTORE_PRIOR ) {
135 return $this->__call( __FUNCTION__, func_get_args() );
136 }
137
138 public function getFlag( $flag ) {
139 return $this->__call( __FUNCTION__, func_get_args() );
140 }
141
142 public function getProperty( $name ) {
143 return $this->__call( __FUNCTION__, func_get_args() );
144 }
145
146 public function getDomainID() {
147 if ( $this->conn === null ) {
148 $domain = $this->params[self::FLD_DOMAIN];
149 // Avoid triggering a database connection
150 return $domain instanceof DatabaseDomain ? $domain->getId() : $domain;
151 }
152
153 return $this->__call( __FUNCTION__, func_get_args() );
154 }
155
156 public function getWikiID() {
157 return $this->getDomainID();
158 }
159
160 public function getType() {
161 return $this->__call( __FUNCTION__, func_get_args() );
162 }
163
164 public function open( $server, $user, $password, $dbName ) {
165 return $this->__call( __FUNCTION__, func_get_args() );
166 }
167
168 public function fetchObject( $res ) {
169 return $this->__call( __FUNCTION__, func_get_args() );
170 }
171
172 public function fetchRow( $res ) {
173 return $this->__call( __FUNCTION__, func_get_args() );
174 }
175
176 public function numRows( $res ) {
177 return $this->__call( __FUNCTION__, func_get_args() );
178 }
179
180 public function numFields( $res ) {
181 return $this->__call( __FUNCTION__, func_get_args() );
182 }
183
184 public function fieldName( $res, $n ) {
185 return $this->__call( __FUNCTION__, func_get_args() );
186 }
187
188 public function insertId() {
189 return $this->__call( __FUNCTION__, func_get_args() );
190 }
191
192 public function dataSeek( $res, $row ) {
193 return $this->__call( __FUNCTION__, func_get_args() );
194 }
195
196 public function lastErrno() {
197 return $this->__call( __FUNCTION__, func_get_args() );
198 }
199
200 public function lastError() {
201 return $this->__call( __FUNCTION__, func_get_args() );
202 }
203
204 public function fieldInfo( $table, $field ) {
205 return $this->__call( __FUNCTION__, func_get_args() );
206 }
207
208 public function affectedRows() {
209 return $this->__call( __FUNCTION__, func_get_args() );
210 }
211
212 public function getSoftwareLink() {
213 return $this->__call( __FUNCTION__, func_get_args() );
214 }
215
216 public function getServerVersion() {
217 return $this->__call( __FUNCTION__, func_get_args() );
218 }
219
220 public function close() {
221 return $this->__call( __FUNCTION__, func_get_args() );
222 }
223
224 public function reportConnectionError( $error = 'Unknown error' ) {
225 return $this->__call( __FUNCTION__, func_get_args() );
226 }
227
228 public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) {
229 return $this->__call( __FUNCTION__, func_get_args() );
230 }
231
232 public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) {
233 return $this->__call( __FUNCTION__, func_get_args() );
234 }
235
236 public function freeResult( $res ) {
237 return $this->__call( __FUNCTION__, func_get_args() );
238 }
239
240 public function selectField(
241 $table, $var, $cond = '', $fname = __METHOD__, $options = []
242 ) {
243 return $this->__call( __FUNCTION__, func_get_args() );
244 }
245
246 public function selectFieldValues(
247 $table, $var, $cond = '', $fname = __METHOD__, $options = []
248 ) {
249 return $this->__call( __FUNCTION__, func_get_args() );
250 }
251
252 public function select(
253 $table, $vars, $conds = '', $fname = __METHOD__,
254 $options = [], $join_conds = []
255 ) {
256 return $this->__call( __FUNCTION__, func_get_args() );
257 }
258
259 public function selectSQLText(
260 $table, $vars, $conds = '', $fname = __METHOD__,
261 $options = [], $join_conds = []
262 ) {
263 return $this->__call( __FUNCTION__, func_get_args() );
264 }
265
266 public function selectRow(
267 $table, $vars, $conds, $fname = __METHOD__,
268 $options = [], $join_conds = []
269 ) {
270 return $this->__call( __FUNCTION__, func_get_args() );
271 }
272
273 public function estimateRowCount(
274 $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = []
275 ) {
276 return $this->__call( __FUNCTION__, func_get_args() );
277 }
278
279 public function selectRowCount(
280 $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
281 ) {
282 return $this->__call( __FUNCTION__, func_get_args() );
283 }
284
285 public function fieldExists( $table, $field, $fname = __METHOD__ ) {
286 return $this->__call( __FUNCTION__, func_get_args() );
287 }
288
289 public function indexExists( $table, $index, $fname = __METHOD__ ) {
290 return $this->__call( __FUNCTION__, func_get_args() );
291 }
292
293 public function tableExists( $table, $fname = __METHOD__ ) {
294 return $this->__call( __FUNCTION__, func_get_args() );
295 }
296
297 public function indexUnique( $table, $index ) {
298 return $this->__call( __FUNCTION__, func_get_args() );
299 }
300
301 public function insert( $table, $a, $fname = __METHOD__, $options = [] ) {
302 return $this->__call( __FUNCTION__, func_get_args() );
303 }
304
305 public function update( $table, $values, $conds, $fname = __METHOD__, $options = [] ) {
306 return $this->__call( __FUNCTION__, func_get_args() );
307 }
308
309 public function makeList( $a, $mode = self::LIST_COMMA ) {
310 return $this->__call( __FUNCTION__, func_get_args() );
311 }
312
313 public function makeWhereFrom2d( $data, $baseKey, $subKey ) {
314 return $this->__call( __FUNCTION__, func_get_args() );
315 }
316
317 public function aggregateValue( $valuedata, $valuename = 'value' ) {
318 return $this->__call( __FUNCTION__, func_get_args() );
319 }
320
321 public function bitNot( $field ) {
322 return $this->__call( __FUNCTION__, func_get_args() );
323 }
324
325 public function bitAnd( $fieldLeft, $fieldRight ) {
326 return $this->__call( __FUNCTION__, func_get_args() );
327 }
328
329 public function bitOr( $fieldLeft, $fieldRight ) {
330 return $this->__call( __FUNCTION__, func_get_args() );
331 }
332
333 public function buildConcat( $stringList ) {
334 return $this->__call( __FUNCTION__, func_get_args() );
335 }
336
337 public function buildGroupConcatField(
338 $delim, $table, $field, $conds = '', $join_conds = []
339 ) {
340 return $this->__call( __FUNCTION__, func_get_args() );
341 }
342
343 public function buildStringCast( $field ) {
344 return $this->__call( __FUNCTION__, func_get_args() );
345 }
346
347 public function selectDB( $db ) {
348 return $this->__call( __FUNCTION__, func_get_args() );
349 }
350
351 public function getDBname() {
352 return $this->__call( __FUNCTION__, func_get_args() );
353 }
354
355 public function getServer() {
356 return $this->__call( __FUNCTION__, func_get_args() );
357 }
358
359 public function addQuotes( $s ) {
360 return $this->__call( __FUNCTION__, func_get_args() );
361 }
362
363 public function buildLike() {
364 return $this->__call( __FUNCTION__, func_get_args() );
365 }
366
367 public function anyChar() {
368 return $this->__call( __FUNCTION__, func_get_args() );
369 }
370
371 public function anyString() {
372 return $this->__call( __FUNCTION__, func_get_args() );
373 }
374
375 public function nextSequenceValue( $seqName ) {
376 return $this->__call( __FUNCTION__, func_get_args() );
377 }
378
379 public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
380 return $this->__call( __FUNCTION__, func_get_args() );
381 }
382
383 public function upsert(
384 $table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__
385 ) {
386 return $this->__call( __FUNCTION__, func_get_args() );
387 }
388
389 public function deleteJoin(
390 $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__
391 ) {
392 return $this->__call( __FUNCTION__, func_get_args() );
393 }
394
395 public function delete( $table, $conds, $fname = __METHOD__ ) {
396 return $this->__call( __FUNCTION__, func_get_args() );
397 }
398
399 public function insertSelect(
400 $destTable, $srcTable, $varMap, $conds,
401 $fname = __METHOD__, $insertOptions = [], $selectOptions = []
402 ) {
403 return $this->__call( __FUNCTION__, func_get_args() );
404 }
405
406 public function unionSupportsOrderAndLimit() {
407 return $this->__call( __FUNCTION__, func_get_args() );
408 }
409
410 public function unionQueries( $sqls, $all ) {
411 return $this->__call( __FUNCTION__, func_get_args() );
412 }
413
414 public function conditional( $cond, $trueVal, $falseVal ) {
415 return $this->__call( __FUNCTION__, func_get_args() );
416 }
417
418 public function strreplace( $orig, $old, $new ) {
419 return $this->__call( __FUNCTION__, func_get_args() );
420 }
421
422 public function getServerUptime() {
423 return $this->__call( __FUNCTION__, func_get_args() );
424 }
425
426 public function wasDeadlock() {
427 return $this->__call( __FUNCTION__, func_get_args() );
428 }
429
430 public function wasLockTimeout() {
431 return $this->__call( __FUNCTION__, func_get_args() );
432 }
433
434 public function wasErrorReissuable() {
435 return $this->__call( __FUNCTION__, func_get_args() );
436 }
437
438 public function wasReadOnlyError() {
439 return $this->__call( __FUNCTION__, func_get_args() );
440 }
441
442 public function masterPosWait( DBMasterPos $pos, $timeout ) {
443 return $this->__call( __FUNCTION__, func_get_args() );
444 }
445
446 public function getReplicaPos() {
447 return $this->__call( __FUNCTION__, func_get_args() );
448 }
449
450 public function getMasterPos() {
451 return $this->__call( __FUNCTION__, func_get_args() );
452 }
453
454 public function serverIsReadOnly() {
455 return $this->__call( __FUNCTION__, func_get_args() );
456 }
457
458 public function onTransactionResolution( callable $callback, $fname = __METHOD__ ) {
459 return $this->__call( __FUNCTION__, func_get_args() );
460 }
461
462 public function onTransactionIdle( callable $callback, $fname = __METHOD__ ) {
463 return $this->__call( __FUNCTION__, func_get_args() );
464 }
465
466 public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ ) {
467 return $this->__call( __FUNCTION__, func_get_args() );
468 }
469
470 public function setTransactionListener( $name, callable $callback = null ) {
471 return $this->__call( __FUNCTION__, func_get_args() );
472 }
473
474 public function startAtomic( $fname = __METHOD__ ) {
475 return $this->__call( __FUNCTION__, func_get_args() );
476 }
477
478 public function endAtomic( $fname = __METHOD__ ) {
479 return $this->__call( __FUNCTION__, func_get_args() );
480 }
481
482 public function doAtomicSection( $fname, callable $callback ) {
483 return $this->__call( __FUNCTION__, func_get_args() );
484 }
485
486 public function begin( $fname = __METHOD__, $mode = IDatabase::TRANSACTION_EXPLICIT ) {
487 return $this->__call( __FUNCTION__, func_get_args() );
488 }
489
490 public function commit( $fname = __METHOD__, $flush = '' ) {
491 return $this->__call( __FUNCTION__, func_get_args() );
492 }
493
494 public function rollback( $fname = __METHOD__, $flush = '' ) {
495 return $this->__call( __FUNCTION__, func_get_args() );
496 }
497
498 public function flushSnapshot( $fname = __METHOD__ ) {
499 return $this->__call( __FUNCTION__, func_get_args() );
500 }
501
502 public function listTables( $prefix = null, $fname = __METHOD__ ) {
503 return $this->__call( __FUNCTION__, func_get_args() );
504 }
505
506 public function timestamp( $ts = 0 ) {
507 return $this->__call( __FUNCTION__, func_get_args() );
508 }
509
510 public function timestampOrNull( $ts = null ) {
511 return $this->__call( __FUNCTION__, func_get_args() );
512 }
513
514 public function ping( &$rtt = null ) {
515 return func_num_args()
516 ? $this->__call( __FUNCTION__, [ &$rtt ] )
517 : $this->__call( __FUNCTION__, [] ); // method cares about null vs missing
518 }
519
520 public function getLag() {
521 return $this->__call( __FUNCTION__, func_get_args() );
522 }
523
524 public function getSessionLagStatus() {
525 return $this->__call( __FUNCTION__, func_get_args() );
526 }
527
528 public function maxListLen() {
529 return $this->__call( __FUNCTION__, func_get_args() );
530 }
531
532 public function encodeBlob( $b ) {
533 return $this->__call( __FUNCTION__, func_get_args() );
534 }
535
536 public function decodeBlob( $b ) {
537 return $this->__call( __FUNCTION__, func_get_args() );
538 }
539
540 public function setSessionOptions( array $options ) {
541 return $this->__call( __FUNCTION__, func_get_args() );
542 }
543
544 public function setSchemaVars( $vars ) {
545 return $this->__call( __FUNCTION__, func_get_args() );
546 }
547
548 public function lockIsFree( $lockName, $method ) {
549 return $this->__call( __FUNCTION__, func_get_args() );
550 }
551
552 public function lock( $lockName, $method, $timeout = 5 ) {
553 return $this->__call( __FUNCTION__, func_get_args() );
554 }
555
556 public function unlock( $lockName, $method ) {
557 return $this->__call( __FUNCTION__, func_get_args() );
558 }
559
560 public function getScopedLockAndFlush( $lockKey, $fname, $timeout ) {
561 return $this->__call( __FUNCTION__, func_get_args() );
562 }
563
564 public function namedLocksEnqueue() {
565 return $this->__call( __FUNCTION__, func_get_args() );
566 }
567
568 public function getInfinity() {
569 return $this->__call( __FUNCTION__, func_get_args() );
570 }
571
572 public function encodeExpiry( $expiry ) {
573 return $this->__call( __FUNCTION__, func_get_args() );
574 }
575
576 public function decodeExpiry( $expiry, $format = TS_MW ) {
577 return $this->__call( __FUNCTION__, func_get_args() );
578 }
579
580 public function setBigSelects( $value = true ) {
581 return $this->__call( __FUNCTION__, func_get_args() );
582 }
583
584 public function isReadOnly() {
585 return $this->__call( __FUNCTION__, func_get_args() );
586 }
587
588 public function setTableAliases( array $aliases ) {
589 return $this->__call( __FUNCTION__, func_get_args() );
590 }
591
592 /**
593 * Clean up the connection when out of scope
594 */
595 function __destruct() {
596 if ( $this->conn ) {
597 $this->lb->reuseConnection( $this->conn );
598 }
599 }
600 }