mediawiki.userSuggest: Use formatversion=2 for API request
[mediawiki.git] / includes / db / DBConnRef.php
blobf09de4fb39ecfa487b8edcc5918d2a2d291a575e
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
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 LoadBalancer */
12 private $lb;
14 /** @var DatabaseBase|null */
15 private $conn;
17 /** @var array|null */
18 private $params;
20 /**
21 * @param LoadBalancer $lb
22 * @param DatabaseBase|array $conn Connection or (server index, group, wiki ID) array
24 public function __construct( LoadBalancer $lb, $conn ) {
25 $this->lb = $lb;
26 if ( $conn instanceof DatabaseBase ) {
27 $this->conn = $conn;
28 } else {
29 $this->params = $conn;
33 function __call( $name, array $arguments ) {
34 if ( $this->conn === null ) {
35 list( $db, $groups, $wiki ) = $this->params;
36 $this->conn = $this->lb->getConnection( $db, $groups, $wiki );
39 return call_user_func_array( array( $this->conn, $name ), $arguments );
42 public function getServerInfo() {
43 return $this->__call( __FUNCTION__, func_get_args() );
46 public function bufferResults( $buffer = null ) {
47 return $this->__call( __FUNCTION__, func_get_args() );
50 public function trxLevel() {
51 return $this->__call( __FUNCTION__, func_get_args() );
54 public function trxTimestamp() {
55 return $this->__call( __FUNCTION__, func_get_args() );
58 public function tablePrefix( $prefix = null ) {
59 return $this->__call( __FUNCTION__, func_get_args() );
62 public function dbSchema( $schema = null ) {
63 return $this->__call( __FUNCTION__, func_get_args() );
66 public function getLBInfo( $name = null ) {
67 return $this->__call( __FUNCTION__, func_get_args() );
70 public function setLBInfo( $name, $value = null ) {
71 return $this->__call( __FUNCTION__, func_get_args() );
74 public function implicitGroupby() {
75 return $this->__call( __FUNCTION__, func_get_args() );
78 public function implicitOrderby() {
79 return $this->__call( __FUNCTION__, func_get_args() );
82 public function lastQuery() {
83 return $this->__call( __FUNCTION__, func_get_args() );
86 public function doneWrites() {
87 return $this->__call( __FUNCTION__, func_get_args() );
90 public function lastDoneWrites() {
91 return $this->__call( __FUNCTION__, func_get_args() );
94 public function writesPending() {
95 return $this->__call( __FUNCTION__, func_get_args() );
98 public function writesOrCallbacksPending() {
99 return $this->__call( __FUNCTION__, func_get_args() );
102 public function pendingWriteQueryDuration() {
103 return $this->__call( __FUNCTION__, func_get_args() );
106 public function pendingWriteCallers() {
107 return $this->__call( __FUNCTION__, func_get_args() );
110 public function isOpen() {
111 return $this->__call( __FUNCTION__, func_get_args() );
114 public function setFlag( $flag ) {
115 return $this->__call( __FUNCTION__, func_get_args() );
118 public function clearFlag( $flag ) {
119 return $this->__call( __FUNCTION__, func_get_args() );
122 public function getFlag( $flag ) {
123 return $this->__call( __FUNCTION__, func_get_args() );
126 public function getProperty( $name ) {
127 return $this->__call( __FUNCTION__, func_get_args() );
130 public function getWikiID() {
131 return $this->__call( __FUNCTION__, func_get_args() );
134 public function getType() {
135 return $this->__call( __FUNCTION__, func_get_args() );
138 public function open( $server, $user, $password, $dbName ) {
139 return $this->__call( __FUNCTION__, func_get_args() );
142 public function fetchObject( $res ) {
143 return $this->__call( __FUNCTION__, func_get_args() );
146 public function fetchRow( $res ) {
147 return $this->__call( __FUNCTION__, func_get_args() );
150 public function numRows( $res ) {
151 return $this->__call( __FUNCTION__, func_get_args() );
154 public function numFields( $res ) {
155 return $this->__call( __FUNCTION__, func_get_args() );
158 public function fieldName( $res, $n ) {
159 return $this->__call( __FUNCTION__, func_get_args() );
162 public function insertId() {
163 return $this->__call( __FUNCTION__, func_get_args() );
166 public function dataSeek( $res, $row ) {
167 return $this->__call( __FUNCTION__, func_get_args() );
170 public function lastErrno() {
171 return $this->__call( __FUNCTION__, func_get_args() );
174 public function lastError() {
175 return $this->__call( __FUNCTION__, func_get_args() );
178 public function fieldInfo( $table, $field ) {
179 return $this->__call( __FUNCTION__, func_get_args() );
182 public function affectedRows() {
183 return $this->__call( __FUNCTION__, func_get_args() );
186 public function getSoftwareLink() {
187 return $this->__call( __FUNCTION__, func_get_args() );
190 public function getServerVersion() {
191 return $this->__call( __FUNCTION__, func_get_args() );
194 public function close() {
195 return $this->__call( __FUNCTION__, func_get_args() );
198 public function reportConnectionError( $error = 'Unknown error' ) {
199 return $this->__call( __FUNCTION__, func_get_args() );
202 public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) {
203 return $this->__call( __FUNCTION__, func_get_args() );
206 public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) {
207 return $this->__call( __FUNCTION__, func_get_args() );
210 public function freeResult( $res ) {
211 return $this->__call( __FUNCTION__, func_get_args() );
214 public function selectField(
215 $table, $var, $cond = '', $fname = __METHOD__, $options = array()
217 return $this->__call( __FUNCTION__, func_get_args() );
220 public function selectFieldValues(
221 $table, $var, $cond = '', $fname = __METHOD__, $options = array()
223 return $this->__call( __FUNCTION__, func_get_args() );
226 public function select(
227 $table, $vars, $conds = '', $fname = __METHOD__,
228 $options = array(), $join_conds = array()
230 return $this->__call( __FUNCTION__, func_get_args() );
233 public function selectSQLText(
234 $table, $vars, $conds = '', $fname = __METHOD__,
235 $options = array(), $join_conds = array()
237 return $this->__call( __FUNCTION__, func_get_args() );
240 public function selectRow(
241 $table, $vars, $conds, $fname = __METHOD__,
242 $options = array(), $join_conds = array()
244 return $this->__call( __FUNCTION__, func_get_args() );
247 public function estimateRowCount(
248 $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array()
250 return $this->__call( __FUNCTION__, func_get_args() );
253 public function selectRowCount(
254 $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = array(), $join_conds = array()
256 return $this->__call( __FUNCTION__, func_get_args() );
259 public function fieldExists( $table, $field, $fname = __METHOD__ ) {
260 return $this->__call( __FUNCTION__, func_get_args() );
263 public function indexExists( $table, $index, $fname = __METHOD__ ) {
264 return $this->__call( __FUNCTION__, func_get_args() );
267 public function tableExists( $table, $fname = __METHOD__ ) {
268 return $this->__call( __FUNCTION__, func_get_args() );
271 public function indexUnique( $table, $index ) {
272 return $this->__call( __FUNCTION__, func_get_args() );
275 public function insert( $table, $a, $fname = __METHOD__, $options = array() ) {
276 return $this->__call( __FUNCTION__, func_get_args() );
279 public function update( $table, $values, $conds, $fname = __METHOD__, $options = array() ) {
280 return $this->__call( __FUNCTION__, func_get_args() );
283 public function makeList( $a, $mode = LIST_COMMA ) {
284 return $this->__call( __FUNCTION__, func_get_args() );
287 public function makeWhereFrom2d( $data, $baseKey, $subKey ) {
288 return $this->__call( __FUNCTION__, func_get_args() );
291 public function bitNot( $field ) {
292 return $this->__call( __FUNCTION__, func_get_args() );
295 public function bitAnd( $fieldLeft, $fieldRight ) {
296 return $this->__call( __FUNCTION__, func_get_args() );
299 public function bitOr( $fieldLeft, $fieldRight ) {
300 return $this->__call( __FUNCTION__, func_get_args() );
303 public function buildConcat( $stringList ) {
304 return $this->__call( __FUNCTION__, func_get_args() );
307 public function buildGroupConcatField(
308 $delim, $table, $field, $conds = '', $join_conds = array()
310 return $this->__call( __FUNCTION__, func_get_args() );
313 public function selectDB( $db ) {
314 return $this->__call( __FUNCTION__, func_get_args() );
317 public function getDBname() {
318 return $this->__call( __FUNCTION__, func_get_args() );
321 public function getServer() {
322 return $this->__call( __FUNCTION__, func_get_args() );
325 public function addQuotes( $s ) {
326 return $this->__call( __FUNCTION__, func_get_args() );
329 public function buildLike() {
330 return $this->__call( __FUNCTION__, func_get_args() );
333 public function anyChar() {
334 return $this->__call( __FUNCTION__, func_get_args() );
337 public function anyString() {
338 return $this->__call( __FUNCTION__, func_get_args() );
341 public function nextSequenceValue( $seqName ) {
342 return $this->__call( __FUNCTION__, func_get_args() );
345 public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
346 return $this->__call( __FUNCTION__, func_get_args() );
349 public function upsert(
350 $table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__
352 return $this->__call( __FUNCTION__, func_get_args() );
355 public function deleteJoin(
356 $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__
358 return $this->__call( __FUNCTION__, func_get_args() );
361 public function delete( $table, $conds, $fname = __METHOD__ ) {
362 return $this->__call( __FUNCTION__, func_get_args() );
365 public function insertSelect(
366 $destTable, $srcTable, $varMap, $conds,
367 $fname = __METHOD__, $insertOptions = array(), $selectOptions = array()
369 return $this->__call( __FUNCTION__, func_get_args() );
372 public function unionSupportsOrderAndLimit() {
373 return $this->__call( __FUNCTION__, func_get_args() );
376 public function unionQueries( $sqls, $all ) {
377 return $this->__call( __FUNCTION__, func_get_args() );
380 public function conditional( $cond, $trueVal, $falseVal ) {
381 return $this->__call( __FUNCTION__, func_get_args() );
384 public function strreplace( $orig, $old, $new ) {
385 return $this->__call( __FUNCTION__, func_get_args() );
388 public function getServerUptime() {
389 return $this->__call( __FUNCTION__, func_get_args() );
392 public function wasDeadlock() {
393 return $this->__call( __FUNCTION__, func_get_args() );
396 public function wasLockTimeout() {
397 return $this->__call( __FUNCTION__, func_get_args() );
400 public function wasErrorReissuable() {
401 return $this->__call( __FUNCTION__, func_get_args() );
404 public function wasReadOnlyError() {
405 return $this->__call( __FUNCTION__, func_get_args() );
408 public function masterPosWait( DBMasterPos $pos, $timeout ) {
409 return $this->__call( __FUNCTION__, func_get_args() );
412 public function getSlavePos() {
413 return $this->__call( __FUNCTION__, func_get_args() );
416 public function getMasterPos() {
417 return $this->__call( __FUNCTION__, func_get_args() );
420 public function onTransactionIdle( $callback ) {
421 return $this->__call( __FUNCTION__, func_get_args() );
424 public function onTransactionPreCommitOrIdle( $callback ) {
425 return $this->__call( __FUNCTION__, func_get_args() );
428 public function startAtomic( $fname = __METHOD__ ) {
429 return $this->__call( __FUNCTION__, func_get_args() );
432 public function endAtomic( $fname = __METHOD__ ) {
433 return $this->__call( __FUNCTION__, func_get_args() );
436 public function doAtomicSection( $fname, $callback ) {
437 return $this->__call( __FUNCTION__, func_get_args() );
440 public function begin( $fname = __METHOD__ ) {
441 return $this->__call( __FUNCTION__, func_get_args() );
444 public function commit( $fname = __METHOD__, $flush = '' ) {
445 return $this->__call( __FUNCTION__, func_get_args() );
448 public function rollback( $fname = __METHOD__, $flush = '' ) {
449 return $this->__call( __FUNCTION__, func_get_args() );
452 public function listTables( $prefix = null, $fname = __METHOD__ ) {
453 return $this->__call( __FUNCTION__, func_get_args() );
456 public function timestamp( $ts = 0 ) {
457 return $this->__call( __FUNCTION__, func_get_args() );
460 public function timestampOrNull( $ts = null ) {
461 return $this->__call( __FUNCTION__, func_get_args() );
464 public function ping() {
465 return $this->__call( __FUNCTION__, func_get_args() );
468 public function getLag() {
469 return $this->__call( __FUNCTION__, func_get_args() );
472 public function getSessionLagStatus() {
473 return $this->__call( __FUNCTION__, func_get_args() );
476 public function maxListLen() {
477 return $this->__call( __FUNCTION__, func_get_args() );
480 public function encodeBlob( $b ) {
481 return $this->__call( __FUNCTION__, func_get_args() );
484 public function decodeBlob( $b ) {
485 return $this->__call( __FUNCTION__, func_get_args() );
488 public function setSessionOptions( array $options ) {
489 return $this->__call( __FUNCTION__, func_get_args() );
492 public function setSchemaVars( $vars ) {
493 return $this->__call( __FUNCTION__, func_get_args() );
496 public function lockIsFree( $lockName, $method ) {
497 return $this->__call( __FUNCTION__, func_get_args() );
500 public function lock( $lockName, $method, $timeout = 5 ) {
501 return $this->__call( __FUNCTION__, func_get_args() );
504 public function unlock( $lockName, $method ) {
505 return $this->__call( __FUNCTION__, func_get_args() );
508 public function namedLocksEnqueue() {
509 return $this->__call( __FUNCTION__, func_get_args() );
512 public function getInfinity() {
513 return $this->__call( __FUNCTION__, func_get_args() );
516 public function encodeExpiry( $expiry ) {
517 return $this->__call( __FUNCTION__, func_get_args() );
520 public function decodeExpiry( $expiry, $format = TS_MW ) {
521 return $this->__call( __FUNCTION__, func_get_args() );
524 public function setBigSelects( $value = true ) {
525 return $this->__call( __FUNCTION__, func_get_args() );
528 public function isReadOnly() {
529 return $this->__call( __FUNCTION__, func_get_args() );
533 * Clean up the connection when out of scope
535 function __destruct() {
536 if ( $this->conn !== null ) {
537 $this->lb->reuseConnection( $this->conn );