objectcache: make newFromId()/newWANcacheFromId()/getDefaultKeyspace() private
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseMssql.php
1 <?php
2 /**
3 * This is the MS SQL Server Native database abstraction layer.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Database
22 * @author Joel Penner <a-joelpe at microsoft dot com>
23 * @author Chris Pucci <a-cpucci at microsoft dot com>
24 * @author Ryan Biesemeyer <v-ryanbi at microsoft dot com>
25 * @author Ryan Schmidt <skizzerz at gmail dot com>
26 */
27
28 namespace Wikimedia\Rdbms;
29
30 use Exception;
31 use RuntimeException;
32 use stdClass;
33 use Wikimedia\AtEase\AtEase;
34
35 /**
36 * @ingroup Database
37 */
38 class DatabaseMssql extends Database {
39 /** @var int */
40 protected $serverPort;
41 /** @var bool */
42 protected $useWindowsAuth = false;
43 /** @var int|null */
44 protected $lastInsertId = null;
45 /** @var int|null */
46 protected $lastAffectedRowCount = null;
47 /** @var int */
48 protected $subqueryId = 0;
49 /** @var bool */
50 protected $scrollableCursor = true;
51 /** @var bool */
52 protected $prepareStatements = true;
53 /** @var stdClass[][]|null */
54 protected $binaryColumnCache = null;
55 /** @var stdClass[][]|null */
56 protected $bitColumnCache = null;
57 /** @var bool */
58 protected $ignoreDupKeyErrors = false;
59 /** @var string[] */
60 protected $ignoreErrors = [];
61
62 public function implicitOrderby() {
63 return false;
64 }
65
66 public function unionSupportsOrderAndLimit() {
67 return false;
68 }
69
70 public function __construct( array $params ) {
71 $this->serverPort = $params['port'];
72 $this->useWindowsAuth = $params['UseWindowsAuth'];
73
74 parent::__construct( $params );
75 }
76
77 protected function open( $server, $user, $password, $dbName, $schema, $tablePrefix ) {
78 if ( !function_exists( 'sqlsrv_connect' ) ) {
79 throw new DBConnectionError(
80 $this,
81 "Microsoft SQL Server Native (sqlsrv) functions missing.\n
82 You can download the driver from: http://go.microsoft.com/fwlink/?LinkId=123470"
83 );
84 }
85
86 $this->close();
87
88 if ( $schema !== null ) {
89 throw $this->newExceptionAfterConnectError( "Got schema '$schema'; not supported." );
90 }
91
92 $this->server = $server;
93 $this->user = $user;
94 $this->password = $password;
95
96 $connectionInfo = [];
97 if ( strlen( $dbName ) ) {
98 $connectionInfo['Database'] = $dbName;
99 }
100 if ( !$this->useWindowsAuth ) {
101 $connectionInfo['UID'] = $user;
102 $connectionInfo['PWD'] = $password;
103 }
104
105 AtEase::suppressWarnings();
106 $this->conn = sqlsrv_connect( $server, $connectionInfo ) ?: null;
107 AtEase::restoreWarnings();
108
109 if ( !$this->conn ) {
110 throw $this->newExceptionAfterConnectError( $this->lastError() );
111 }
112
113 try {
114 $this->currentDomain = new DatabaseDomain(
115 strlen( $dbName ) ? $dbName : null,
116 null,
117 $tablePrefix
118 );
119 } catch ( Exception $e ) {
120 throw $this->newExceptionAfterConnectError( $e->getMessage() );
121 }
122 }
123
124 /**
125 * Closes a database connection, if it is open
126 * Returns success, true if already closed
127 * @return bool
128 */
129 protected function closeConnection() {
130 return sqlsrv_close( $this->conn );
131 }
132
133 /**
134 * @param bool|MssqlResultWrapper|resource $result
135 * @return bool|MssqlResultWrapper
136 */
137 protected function resultObject( $result ) {
138 if ( !$result ) {
139 return false;
140 } elseif ( $result instanceof MssqlResultWrapper ) {
141 return $result;
142 } elseif ( $result === true ) {
143 // Successful write query
144 return $result;
145 } else {
146 return new MssqlResultWrapper( $this, $result );
147 }
148 }
149
150 /**
151 * @param string $sql
152 * @return bool|MssqlResultWrapper|resource
153 */
154 protected function doQuery( $sql ) {
155 // several extensions seem to think that all databases support limits
156 // via LIMIT N after the WHERE clause, but MSSQL uses SELECT TOP N,
157 // so to catch any of those extensions we'll do a quick check for a
158 // LIMIT clause and pass $sql through $this->LimitToTopN() which parses
159 // the LIMIT clause and passes the result to $this->limitResult();
160 if ( preg_match( '/\bLIMIT\s*/i', $sql ) ) {
161 // massage LIMIT -> TopN
162 $sql = $this->LimitToTopN( $sql );
163 }
164
165 // MSSQL doesn't have EXTRACT(epoch FROM XXX)
166 if ( preg_match( '#\bEXTRACT\s*?\(\s*?EPOCH\s+FROM\b#i', $sql, $matches ) ) {
167 // This is same as UNIX_TIMESTAMP, we need to calc # of seconds from 1970
168 $sql = str_replace( $matches[0], "DATEDIFF(s,CONVERT(datetime,'1/1/1970'),", $sql );
169 }
170
171 // perform query
172
173 // SQLSRV_CURSOR_STATIC is slower than SQLSRV_CURSOR_CLIENT_BUFFERED (one of the two is
174 // needed if we want to be able to seek around the result set), however CLIENT_BUFFERED
175 // has a bug in the sqlsrv driver where wchar_t types (such as nvarchar) that are empty
176 // strings make php throw a fatal error "Severe error translating Unicode"
177 if ( $this->scrollableCursor ) {
178 $scrollArr = [ 'Scrollable' => SQLSRV_CURSOR_STATIC ];
179 } else {
180 $scrollArr = [];
181 }
182
183 if ( $this->prepareStatements ) {
184 // we do prepare + execute so we can get its field metadata for later usage if desired
185 $stmt = sqlsrv_prepare( $this->conn, $sql, [], $scrollArr );
186 $success = sqlsrv_execute( $stmt );
187 } else {
188 $stmt = sqlsrv_query( $this->conn, $sql, [], $scrollArr );
189 $success = (bool)$stmt;
190 }
191
192 // Make a copy to ensure what we add below does not get reflected in future queries
193 $ignoreErrors = $this->ignoreErrors;
194
195 if ( $this->ignoreDupKeyErrors ) {
196 // ignore duplicate key errors
197 // this emulates INSERT IGNORE in MySQL
198 $ignoreErrors[] = '2601'; // duplicate key error caused by unique index
199 $ignoreErrors[] = '2627'; // duplicate key error caused by primary key
200 $ignoreErrors[] = '3621'; // generic "the statement has been terminated" error
201 }
202
203 if ( $success === false ) {
204 $errors = sqlsrv_errors();
205 $success = true;
206
207 foreach ( $errors as $err ) {
208 if ( !in_array( $err['code'], $ignoreErrors ) ) {
209 $success = false;
210 break;
211 }
212 }
213
214 if ( $success === false ) {
215 return false;
216 }
217 }
218 // remember number of rows affected
219 $this->lastAffectedRowCount = sqlsrv_rows_affected( $stmt );
220
221 return $stmt;
222 }
223
224 public function freeResult( $res ) {
225 sqlsrv_free_stmt( ResultWrapper::unwrap( $res ) );
226 }
227
228 /**
229 * @param IResultWrapper $res
230 * @return stdClass
231 */
232 public function fetchObject( $res ) {
233 // $res is expected to be an instance of MssqlResultWrapper here
234 return $res->fetchObject();
235 }
236
237 /**
238 * @param IResultWrapper $res
239 * @return array
240 */
241 public function fetchRow( $res ) {
242 return $res->fetchRow();
243 }
244
245 /**
246 * @param mixed $res
247 * @return int
248 */
249 public function numRows( $res ) {
250 $res = ResultWrapper::unwrap( $res );
251
252 $ret = sqlsrv_num_rows( $res );
253 if ( $ret === false ) {
254 // we cannot get an amount of rows from this cursor type
255 // has_rows returns bool true/false if the result has rows
256 $ret = (int)sqlsrv_has_rows( $res );
257 }
258
259 return $ret;
260 }
261
262 /**
263 * @param mixed $res
264 * @return int
265 */
266 public function numFields( $res ) {
267 return sqlsrv_num_fields( ResultWrapper::unwrap( $res ) );
268 }
269
270 /**
271 * @param mixed $res
272 * @param int $n
273 * @return int
274 */
275 public function fieldName( $res, $n ) {
276 return sqlsrv_field_metadata( ResultWrapper::unwrap( $res ) )[$n]['Name'];
277 }
278
279 /**
280 * This must be called after nextSequenceVal
281 * @return int|null
282 */
283 public function insertId() {
284 return $this->lastInsertId;
285 }
286
287 /**
288 * @param MssqlResultWrapper $res
289 * @param int $row
290 * @return bool
291 */
292 public function dataSeek( $res, $row ) {
293 return $res->seek( $row );
294 }
295
296 /**
297 * @return string
298 */
299 public function lastError() {
300 $strRet = '';
301 $retErrors = sqlsrv_errors( SQLSRV_ERR_ALL );
302 if ( $retErrors != null ) {
303 foreach ( $retErrors as $arrError ) {
304 $strRet .= $this->formatError( $arrError ) . "\n";
305 }
306 } else {
307 $strRet = "No errors found";
308 }
309
310 return $strRet;
311 }
312
313 /**
314 * @param array $err
315 * @return string
316 */
317 private function formatError( $err ) {
318 return '[SQLSTATE ' .
319 $err['SQLSTATE'] . '][Error Code ' . $err['code'] . ']' . $err['message'];
320 }
321
322 /**
323 * @return string|int
324 */
325 public function lastErrno() {
326 $err = sqlsrv_errors( SQLSRV_ERR_ALL );
327 if ( $err !== null && isset( $err[0] ) ) {
328 return $err[0]['code'];
329 } else {
330 return 0;
331 }
332 }
333
334 protected function wasKnownStatementRollbackError() {
335 $errors = sqlsrv_errors( SQLSRV_ERR_ALL );
336 if ( !$errors ) {
337 return false;
338 }
339 // The transaction vs statement rollback behavior depends on XACT_ABORT, so make sure
340 // that the "statement has been terminated" error (3621) is specifically present.
341 // https://docs.microsoft.com/en-us/sql/t-sql/statements/set-xact-abort-transact-sql
342 $statementOnly = false;
343 $codeWhitelist = [ '2601', '2627', '547' ];
344 foreach ( $errors as $error ) {
345 if ( $error['code'] == '3621' ) {
346 $statementOnly = true;
347 } elseif ( !in_array( $error['code'], $codeWhitelist ) ) {
348 $statementOnly = false;
349 break;
350 }
351 }
352
353 return $statementOnly;
354 }
355
356 public function serverIsReadOnly() {
357 $encDatabase = $this->addQuotes( $this->getDBname() );
358 $res = $this->query(
359 "SELECT IS_READ_ONLY FROM SYS.DATABASES WHERE NAME = $encDatabase",
360 __METHOD__
361 );
362 $row = $this->fetchObject( $res );
363
364 return $row ? (bool)$row->IS_READ_ONLY : false;
365 }
366
367 /**
368 * @return int
369 */
370 protected function fetchAffectedRowCount() {
371 return $this->lastAffectedRowCount;
372 }
373
374 /**
375 * SELECT wrapper
376 *
377 * @param mixed $table Array or string, table name(s) (prefix auto-added)
378 * @param mixed $vars Array or string, field name(s) to be retrieved
379 * @param mixed $conds Array or string, condition(s) for WHERE
380 * @param string $fname Calling function name (use __METHOD__) for logs/profiling
381 * @param array $options Associative array of options (e.g.
382 * [ 'GROUP BY' => 'page_title' ]), see Database::makeSelectOptions
383 * code for list of supported stuff
384 * @param array $join_conds Associative array of table join conditions
385 * (optional) (e.g. [ 'page' => [ 'LEFT JOIN','page_latest=rev_id' ] ]
386 * @return mixed Database result resource (feed to Database::fetchObject
387 * or whatever), or false on failure
388 * @throws DBQueryError
389 * @throws DBUnexpectedError
390 * @throws Exception
391 */
392 public function select( $table, $vars, $conds = '', $fname = __METHOD__,
393 $options = [], $join_conds = []
394 ) {
395 $sql = $this->selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds );
396 if ( isset( $options['EXPLAIN'] ) ) {
397 try {
398 $this->scrollableCursor = false;
399 $this->prepareStatements = false;
400 $this->query( "SET SHOWPLAN_ALL ON" );
401 $ret = $this->query( $sql, $fname );
402 $this->query( "SET SHOWPLAN_ALL OFF" );
403 } catch ( DBQueryError $dqe ) {
404 if ( isset( $options['FOR COUNT'] ) ) {
405 // likely don't have privs for SHOWPLAN, so run a select count instead
406 $this->query( "SET SHOWPLAN_ALL OFF" );
407 unset( $options['EXPLAIN'] );
408 $ret = $this->select(
409 $table,
410 'COUNT(*) AS EstimateRows',
411 $conds,
412 $fname,
413 $options,
414 $join_conds
415 );
416 } else {
417 // someone actually wanted the query plan instead of an est row count
418 // let them know of the error
419 $this->scrollableCursor = true;
420 $this->prepareStatements = true;
421 throw $dqe;
422 }
423 }
424 $this->scrollableCursor = true;
425 $this->prepareStatements = true;
426 return $ret;
427 }
428 return $this->query( $sql, $fname );
429 }
430
431 /**
432 * SELECT wrapper
433 *
434 * @param mixed $table Array or string, table name(s) (prefix auto-added)
435 * @param mixed $vars Array or string, field name(s) to be retrieved
436 * @param mixed $conds Array or string, condition(s) for WHERE
437 * @param string $fname Calling function name (use __METHOD__) for logs/profiling
438 * @param array $options Associative array of options (e.g. [ 'GROUP BY' => 'page_title' ]),
439 * see Database::makeSelectOptions code for list of supported stuff
440 * @param array $join_conds Associative array of table join conditions (optional)
441 * (e.g. [ 'page' => [ 'LEFT JOIN','page_latest=rev_id' ] ]
442 * @return string The SQL text
443 */
444 public function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__,
445 $options = [], $join_conds = []
446 ) {
447 if ( isset( $options['EXPLAIN'] ) ) {
448 unset( $options['EXPLAIN'] );
449 }
450
451 $sql = parent::selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds );
452
453 // try to rewrite aggregations of bit columns (currently MAX and MIN)
454 if ( strpos( $sql, 'MAX(' ) !== false || strpos( $sql, 'MIN(' ) !== false ) {
455 $bitColumns = [];
456 if ( is_array( $table ) ) {
457 $tables = $table;
458 while ( $tables ) {
459 $t = array_pop( $tables );
460 if ( is_array( $t ) ) {
461 $tables = array_merge( $tables, $t );
462 } else {
463 $bitColumns += $this->getBitColumns( $this->tableName( $t ) );
464 }
465 }
466 } else {
467 $bitColumns = $this->getBitColumns( $this->tableName( $table ) );
468 }
469
470 foreach ( $bitColumns as $col => $info ) {
471 $replace = [
472 "MAX({$col})" => "MAX(CAST({$col} AS tinyint))",
473 "MIN({$col})" => "MIN(CAST({$col} AS tinyint))",
474 ];
475 $sql = str_replace( array_keys( $replace ), array_values( $replace ), $sql );
476 }
477 }
478
479 return $sql;
480 }
481
482 public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
483 $fname = __METHOD__
484 ) {
485 $this->scrollableCursor = false;
486 try {
487 parent::deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname );
488 } catch ( Exception $e ) {
489 $this->scrollableCursor = true;
490 throw $e;
491 }
492 $this->scrollableCursor = true;
493 }
494
495 public function delete( $table, $conds, $fname = __METHOD__ ) {
496 $this->scrollableCursor = false;
497 try {
498 parent::delete( $table, $conds, $fname );
499 } catch ( Exception $e ) {
500 $this->scrollableCursor = true;
501 throw $e;
502 }
503 $this->scrollableCursor = true;
504
505 return true;
506 }
507
508 /**
509 * Estimate rows in dataset
510 * Returns estimated count, based on SHOWPLAN_ALL output
511 * This is not necessarily an accurate estimate, so use sparingly
512 * Returns -1 if count cannot be found
513 * Takes same arguments as Database::select()
514 * @param string $table
515 * @param string $var
516 * @param string $conds
517 * @param string $fname
518 * @param array $options
519 * @param array $join_conds
520 * @return int
521 */
522 public function estimateRowCount( $table, $var = '*', $conds = '',
523 $fname = __METHOD__, $options = [], $join_conds = []
524 ) {
525 $conds = $this->normalizeConditions( $conds, $fname );
526 $column = $this->extractSingleFieldFromList( $var );
527 if ( is_string( $column ) && !in_array( $column, [ '*', '1' ] ) ) {
528 $conds[] = "$column IS NOT NULL";
529 }
530
531 // http://msdn2.microsoft.com/en-us/library/aa259203.aspx
532 $options['EXPLAIN'] = true;
533 $options['FOR COUNT'] = true;
534 $res = $this->select( $table, $var, $conds, $fname, $options, $join_conds );
535
536 $rows = -1;
537 if ( $res ) {
538 $row = $this->fetchRow( $res );
539
540 if ( isset( $row['EstimateRows'] ) ) {
541 $rows = (int)$row['EstimateRows'];
542 }
543 }
544
545 return $rows;
546 }
547
548 /**
549 * Returns information about an index
550 * If errors are explicitly ignored, returns NULL on failure
551 * @param string $table
552 * @param string $index
553 * @param string $fname
554 * @return array|bool|null
555 */
556 public function indexInfo( $table, $index, $fname = __METHOD__ ) {
557 # This does not return the same info as MYSQL would, but that's OK
558 # because MediaWiki never uses the returned value except to check for
559 # the existence of indexes.
560 $sql = "sp_helpindex '" . $this->tableName( $table ) . "'";
561 $res = $this->query( $sql, $fname );
562
563 if ( !$res ) {
564 return null;
565 }
566
567 $result = [];
568 foreach ( $res as $row ) {
569 if ( $row->index_name == $index ) {
570 $row->Non_unique = !stristr( $row->index_description, "unique" );
571 $cols = explode( ", ", $row->index_keys );
572 foreach ( $cols as $col ) {
573 $row->Column_name = trim( $col );
574 $result[] = clone $row;
575 }
576 } elseif ( $index == 'PRIMARY' && stristr( $row->index_description, 'PRIMARY' ) ) {
577 $row->Non_unique = 0;
578 $cols = explode( ", ", $row->index_keys );
579 foreach ( $cols as $col ) {
580 $row->Column_name = trim( $col );
581 $result[] = clone $row;
582 }
583 }
584 }
585
586 return $result ?: false;
587 }
588
589 /**
590 * INSERT wrapper, inserts an array into a table
591 *
592 * $arrToInsert may be a single associative array, or an array of these with numeric keys, for
593 * multi-row insert.
594 *
595 * Usually aborts on failure
596 * If errors are explicitly ignored, returns success
597 * @param string $table
598 * @param array $arrToInsert
599 * @param string $fname
600 * @param array $options
601 * @return bool
602 * @throws Exception
603 */
604 public function insert( $table, $arrToInsert, $fname = __METHOD__, $options = [] ) {
605 # No rows to insert, easy just return now
606 if ( !count( $arrToInsert ) ) {
607 return true;
608 }
609
610 if ( !is_array( $options ) ) {
611 $options = [ $options ];
612 }
613
614 $table = $this->tableName( $table );
615
616 if ( !( isset( $arrToInsert[0] ) && is_array( $arrToInsert[0] ) ) ) { // Not multi row
617 $arrToInsert = [ 0 => $arrToInsert ]; // make everything multi row compatible
618 }
619
620 // We know the table we're inserting into, get its identity column
621 $identity = null;
622 // strip matching square brackets and the db/schema from table name
623 $tableRawArr = explode( '.', preg_replace( '#\[([^\]]*)\]#', '$1', $table ) );
624 $tableRaw = array_pop( $tableRawArr );
625 $res = $this->doQuery(
626 "SELECT NAME AS idColumn FROM SYS.IDENTITY_COLUMNS " .
627 "WHERE OBJECT_NAME(OBJECT_ID)='{$tableRaw}'"
628 );
629 if ( $res && sqlsrv_has_rows( $res ) ) {
630 // There is an identity for this table.
631 $identityArr = sqlsrv_fetch_array( $res, SQLSRV_FETCH_ASSOC );
632 $identity = array_pop( $identityArr );
633 }
634 sqlsrv_free_stmt( $res );
635
636 // Determine binary/varbinary fields so we can encode data as a hex string like 0xABCDEF
637 $binaryColumns = $this->getBinaryColumns( $table );
638
639 // INSERT IGNORE is not supported by SQL Server
640 // remove IGNORE from options list and set ignore flag to true
641 if ( in_array( 'IGNORE', $options ) ) {
642 $options = array_diff( $options, [ 'IGNORE' ] );
643 $this->ignoreDupKeyErrors = true;
644 }
645
646 $ret = null;
647 foreach ( $arrToInsert as $a ) {
648 // start out with empty identity column, this is so we can return
649 // it as a result of the INSERT logic
650 $sqlPre = '';
651 $sqlPost = '';
652 $identityClause = '';
653
654 // if we have an identity column
655 if ( $identity ) {
656 // iterate through
657 foreach ( $a as $k => $v ) {
658 if ( $k == $identity ) {
659 if ( !is_null( $v ) ) {
660 // there is a value being passed to us,
661 // we need to turn on and off inserted identity
662 $sqlPre = "SET IDENTITY_INSERT $table ON;";
663 $sqlPost = ";SET IDENTITY_INSERT $table OFF;";
664 } else {
665 // we can't insert NULL into an identity column,
666 // so remove the column from the insert.
667 unset( $a[$k] );
668 }
669 }
670 }
671
672 // we want to output an identity column as result
673 $identityClause = "OUTPUT INSERTED.$identity ";
674 }
675
676 $keys = array_keys( $a );
677
678 // Build the actual query
679 $sql = $sqlPre . 'INSERT ' . implode( ' ', $options ) .
680 " INTO $table (" . implode( ',', $keys ) . ") $identityClause VALUES (";
681
682 $first = true;
683 foreach ( $a as $key => $value ) {
684 if ( isset( $binaryColumns[$key] ) ) {
685 $value = new MssqlBlob( $value );
686 }
687 if ( $first ) {
688 $first = false;
689 } else {
690 $sql .= ',';
691 }
692 if ( is_null( $value ) ) {
693 $sql .= 'null';
694 } else {
695 $sql .= $this->addQuotes( $value );
696 }
697 }
698 $sql .= ')' . $sqlPost;
699
700 // Run the query
701 $this->scrollableCursor = false;
702 try {
703 $ret = $this->query( $sql );
704 } catch ( Exception $e ) {
705 $this->scrollableCursor = true;
706 $this->ignoreDupKeyErrors = false;
707 throw $e;
708 }
709 $this->scrollableCursor = true;
710
711 if ( $ret instanceof IResultWrapper && !is_null( $identity ) ) {
712 // Then we want to get the identity column value we were assigned and save it off
713 $row = $ret->fetchObject();
714 if ( is_object( $row ) ) {
715 $this->lastInsertId = $row->$identity;
716 // It seems that mAffectedRows is -1 sometimes when OUTPUT INSERTED.identity is
717 // used if we got an identity back, we know for sure a row was affected, so
718 // adjust that here
719 if ( $this->lastAffectedRowCount == -1 ) {
720 $this->lastAffectedRowCount = 1;
721 }
722 }
723 }
724 }
725
726 $this->ignoreDupKeyErrors = false;
727
728 return true;
729 }
730
731 /**
732 * INSERT SELECT wrapper
733 * $varMap must be an associative array of the form [ 'dest1' => 'source1', ... ]
734 * Source items may be literals rather than field names, but strings should
735 * be quoted with Database::addQuotes().
736 * @param string $destTable
737 * @param array|string $srcTable May be an array of tables.
738 * @param array $varMap
739 * @param array $conds May be "*" to copy the whole table.
740 * @param string $fname
741 * @param array $insertOptions
742 * @param array $selectOptions
743 * @param array $selectJoinConds
744 * @throws Exception
745 */
746 protected function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
747 $insertOptions = [], $selectOptions = [], $selectJoinConds = []
748 ) {
749 $this->scrollableCursor = false;
750 try {
751 parent::nativeInsertSelect(
752 $destTable,
753 $srcTable,
754 $varMap,
755 $conds,
756 $fname,
757 $insertOptions,
758 $selectOptions,
759 $selectJoinConds
760 );
761 } catch ( Exception $e ) {
762 $this->scrollableCursor = true;
763 throw $e;
764 }
765 $this->scrollableCursor = true;
766 }
767
768 /**
769 * UPDATE wrapper. Takes a condition array and a SET array.
770 *
771 * @param string $table Name of the table to UPDATE. This will be passed through
772 * Database::tableName().
773 *
774 * @param array $values An array of values to SET. For each array element,
775 * the key gives the field name, and the value gives the data
776 * to set that field to. The data will be quoted by
777 * Database::addQuotes().
778 *
779 * @param array $conds An array of conditions (WHERE). See
780 * Database::select() for the details of the format of
781 * condition arrays. Use '*' to update all rows.
782 *
783 * @param string $fname The function name of the caller (from __METHOD__),
784 * for logging and profiling.
785 *
786 * @param array $options An array of UPDATE options, can be:
787 * - IGNORE: Ignore unique key conflicts
788 * @return bool
789 * @throws DBUnexpectedError
790 * @throws Exception
791 */
792 function update( $table, $values, $conds, $fname = __METHOD__, $options = [] ) {
793 $table = $this->tableName( $table );
794 $binaryColumns = $this->getBinaryColumns( $table );
795
796 $opts = $this->makeUpdateOptions( $options );
797 $sql = "UPDATE $opts $table SET " . $this->makeList( $values, LIST_SET, $binaryColumns );
798
799 if ( $conds !== [] && $conds !== '*' ) {
800 $sql .= " WHERE " . $this->makeList( $conds, LIST_AND, $binaryColumns );
801 }
802
803 $this->scrollableCursor = false;
804 try {
805 $this->query( $sql );
806 } catch ( Exception $e ) {
807 $this->scrollableCursor = true;
808 throw $e;
809 }
810 $this->scrollableCursor = true;
811 return true;
812 }
813
814 /**
815 * Makes an encoded list of strings from an array
816 * @param array $a Containing the data
817 * @param int $mode Constant
818 * - LIST_COMMA: comma separated, no field names
819 * - LIST_AND: ANDed WHERE clause (without the WHERE). See
820 * the documentation for $conds in Database::select().
821 * - LIST_OR: ORed WHERE clause (without the WHERE)
822 * - LIST_SET: comma separated with field names, like a SET clause
823 * - LIST_NAMES: comma separated field names
824 * @param array $binaryColumns Contains a list of column names that are binary types
825 * This is a custom parameter only present for MS SQL.
826 *
827 * @throws DBUnexpectedError
828 * @return string
829 */
830 public function makeList( $a, $mode = LIST_COMMA, $binaryColumns = [] ) {
831 if ( !is_array( $a ) ) {
832 throw new DBUnexpectedError( $this, __METHOD__ . ' called with incorrect parameters' );
833 }
834
835 if ( $mode != LIST_NAMES ) {
836 // In MS SQL, values need to be specially encoded when they are
837 // inserted into binary fields. Perform this necessary encoding
838 // for the specified set of columns.
839 foreach ( array_keys( $a ) as $field ) {
840 if ( !isset( $binaryColumns[$field] ) ) {
841 continue;
842 }
843
844 if ( is_array( $a[$field] ) ) {
845 foreach ( $a[$field] as &$v ) {
846 $v = new MssqlBlob( $v );
847 }
848 unset( $v );
849 } else {
850 $a[$field] = new MssqlBlob( $a[$field] );
851 }
852 }
853 }
854
855 return parent::makeList( $a, $mode );
856 }
857
858 /**
859 * @param string $table
860 * @param string $field
861 * @return int Returns the size of a text field, or -1 for "unlimited"
862 */
863 public function textFieldSize( $table, $field ) {
864 $table = $this->tableName( $table );
865 $sql = "SELECT CHARACTER_MAXIMUM_LENGTH,DATA_TYPE FROM INFORMATION_SCHEMA.Columns
866 WHERE TABLE_NAME = '$table' AND COLUMN_NAME = '$field'";
867 $res = $this->query( $sql );
868 $row = $this->fetchRow( $res );
869 $size = -1;
870 if ( strtolower( $row['DATA_TYPE'] ) != 'text' ) {
871 $size = $row['CHARACTER_MAXIMUM_LENGTH'];
872 }
873
874 return $size;
875 }
876
877 /**
878 * Construct a LIMIT query with optional offset
879 * This is used for query pages
880 *
881 * @param string $sql SQL query we will append the limit too
882 * @param int $limit The SQL limit
883 * @param bool|int $offset The SQL offset (default false)
884 * @return array|string
885 * @throws DBUnexpectedError
886 */
887 public function limitResult( $sql, $limit, $offset = false ) {
888 if ( $offset === false || $offset == 0 ) {
889 if ( strpos( $sql, "SELECT" ) === false ) {
890 return "TOP {$limit} " . $sql;
891 } else {
892 return preg_replace( '/\bSELECT(\s+DISTINCT)?\b/Dsi',
893 'SELECT$1 TOP ' . $limit, $sql, 1 );
894 }
895 } else {
896 // This one is fun, we need to pull out the select list as well as any ORDER BY clause
897 $select = $orderby = [];
898 $s1 = preg_match( '#SELECT\s+(.+?)\s+FROM#Dis', $sql, $select );
899 $s2 = preg_match( '#(ORDER BY\s+.+?)(\s*FOR XML .*)?$#Dis', $sql, $orderby );
900 $postOrder = '';
901 $first = $offset + 1;
902 $last = $offset + $limit;
903 $sub1 = 'sub_' . $this->subqueryId;
904 $sub2 = 'sub_' . ( $this->subqueryId + 1 );
905 $this->subqueryId += 2;
906 if ( !$s1 ) {
907 // wat
908 throw new DBUnexpectedError( $this, "Attempting to LIMIT a non-SELECT query\n" );
909 }
910 if ( !$s2 ) {
911 // no ORDER BY
912 $overOrder = 'ORDER BY (SELECT 1)';
913 } else {
914 if ( !isset( $orderby[2] ) || !$orderby[2] ) {
915 // don't need to strip it out if we're using a FOR XML clause
916 $sql = str_replace( $orderby[1], '', $sql );
917 }
918 $overOrder = $orderby[1];
919 $postOrder = ' ' . $overOrder;
920 }
921 $sql = "SELECT {$select[1]}
922 FROM (
923 SELECT ROW_NUMBER() OVER({$overOrder}) AS rowNumber, *
924 FROM ({$sql}) {$sub1}
925 ) {$sub2}
926 WHERE rowNumber BETWEEN {$first} AND {$last}{$postOrder}";
927
928 return $sql;
929 }
930 }
931
932 /**
933 * If there is a limit clause, parse it, strip it, and pass the remaining
934 * SQL through limitResult() with the appropriate parameters. Not the
935 * prettiest solution, but better than building a whole new parser. This
936 * exists becase there are still too many extensions that don't use dynamic
937 * sql generation.
938 *
939 * @param string $sql
940 * @return array|mixed|string
941 */
942 public function LimitToTopN( $sql ) {
943 // Matches: LIMIT {[offset,] row_count | row_count OFFSET offset}
944 $pattern = '/\bLIMIT\s+((([0-9]+)\s*,\s*)?([0-9]+)(\s+OFFSET\s+([0-9]+))?)/i';
945 if ( preg_match( $pattern, $sql, $matches ) ) {
946 $row_count = $matches[4];
947 $offset = $matches[3] ?: $matches[6] ?: false;
948
949 // strip the matching LIMIT clause out
950 $sql = str_replace( $matches[0], '', $sql );
951
952 return $this->limitResult( $sql, $row_count, $offset );
953 }
954
955 return $sql;
956 }
957
958 /**
959 * @return string Wikitext of a link to the server software's web site
960 */
961 public function getSoftwareLink() {
962 return "[{{int:version-db-mssql-url}} MS SQL Server]";
963 }
964
965 /**
966 * @return string Version information from the database
967 */
968 public function getServerVersion() {
969 $server_info = sqlsrv_server_info( $this->conn );
970 $version = $server_info['SQLServerVersion'] ?? 'Error';
971
972 return $version;
973 }
974
975 /**
976 * @param string $table
977 * @param string $fname
978 * @return bool
979 */
980 public function tableExists( $table, $fname = __METHOD__ ) {
981 list( $db, $schema, $table ) = $this->tableName( $table, 'split' );
982
983 if ( $db !== false ) {
984 // remote database
985 $this->queryLogger->error( "Attempting to call tableExists on a remote table" );
986 return false;
987 }
988
989 if ( $schema === false ) {
990 $schema = $this->dbSchema();
991 }
992
993 $res = $this->query( "SELECT 1 FROM INFORMATION_SCHEMA.TABLES
994 WHERE TABLE_TYPE = 'BASE TABLE'
995 AND TABLE_SCHEMA = '$schema' AND TABLE_NAME = '$table'" );
996
997 if ( $res->numRows() ) {
998 return true;
999 } else {
1000 return false;
1001 }
1002 }
1003
1004 /**
1005 * Query whether a given column exists in the mediawiki schema
1006 * @param string $table
1007 * @param string $field
1008 * @param string $fname
1009 * @return bool
1010 */
1011 public function fieldExists( $table, $field, $fname = __METHOD__ ) {
1012 list( $db, $schema, $table ) = $this->tableName( $table, 'split' );
1013
1014 if ( $db !== false ) {
1015 // remote database
1016 $this->queryLogger->error( "Attempting to call fieldExists on a remote table" );
1017 return false;
1018 }
1019
1020 $res = $this->query( "SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
1021 WHERE TABLE_SCHEMA = '$schema' AND TABLE_NAME = '$table' AND COLUMN_NAME = '$field'" );
1022
1023 if ( $res->numRows() ) {
1024 return true;
1025 } else {
1026 return false;
1027 }
1028 }
1029
1030 public function fieldInfo( $table, $field ) {
1031 list( $db, $schema, $table ) = $this->tableName( $table, 'split' );
1032
1033 if ( $db !== false ) {
1034 // remote database
1035 $this->queryLogger->error( "Attempting to call fieldInfo on a remote table" );
1036 return false;
1037 }
1038
1039 $res = $this->query( "SELECT * FROM INFORMATION_SCHEMA.COLUMNS
1040 WHERE TABLE_SCHEMA = '$schema' AND TABLE_NAME = '$table' AND COLUMN_NAME = '$field'" );
1041
1042 $meta = $res->fetchRow();
1043 if ( $meta ) {
1044 return new MssqlField( $meta );
1045 }
1046
1047 return false;
1048 }
1049
1050 protected function doSavepoint( $identifier, $fname ) {
1051 $this->query( 'SAVE TRANSACTION ' . $this->addIdentifierQuotes( $identifier ), $fname );
1052 }
1053
1054 protected function doReleaseSavepoint( $identifier, $fname ) {
1055 // Not supported. Also not really needed, a new doSavepoint() for the
1056 // same identifier will overwrite the old.
1057 }
1058
1059 protected function doRollbackToSavepoint( $identifier, $fname ) {
1060 $this->query( 'ROLLBACK TRANSACTION ' . $this->addIdentifierQuotes( $identifier ), $fname );
1061 }
1062
1063 protected function doBegin( $fname = __METHOD__ ) {
1064 if ( !sqlsrv_begin_transaction( $this->conn ) ) {
1065 $this->reportQueryError( $this->lastError(), $this->lastErrno(), 'BEGIN', $fname );
1066 }
1067 }
1068
1069 /**
1070 * End a transaction
1071 * @param string $fname
1072 */
1073 protected function doCommit( $fname = __METHOD__ ) {
1074 if ( !sqlsrv_commit( $this->conn ) ) {
1075 $this->reportQueryError( $this->lastError(), $this->lastErrno(), 'COMMIT', $fname );
1076 }
1077 }
1078
1079 /**
1080 * Rollback a transaction.
1081 * No-op on non-transactional databases.
1082 * @param string $fname
1083 */
1084 protected function doRollback( $fname = __METHOD__ ) {
1085 if ( !sqlsrv_rollback( $this->conn ) ) {
1086 $this->queryLogger->error(
1087 "{fname}\t{db_server}\t{errno}\t{error}\t",
1088 $this->getLogContext( [
1089 'errno' => $this->lastErrno(),
1090 'error' => $this->lastError(),
1091 'fname' => $fname,
1092 'trace' => ( new RuntimeException() )->getTraceAsString()
1093 ] )
1094 );
1095 }
1096 }
1097
1098 /**
1099 * @param string $s
1100 * @return string
1101 */
1102 public function strencode( $s ) {
1103 // Should not be called by us
1104 return str_replace( "'", "''", $s );
1105 }
1106
1107 /**
1108 * @param string|int|null|bool|Blob $s
1109 * @return string|int
1110 */
1111 public function addQuotes( $s ) {
1112 if ( $s instanceof MssqlBlob ) {
1113 return $s->fetch();
1114 } elseif ( $s instanceof Blob ) {
1115 // this shouldn't really ever be called, but it's here if needed
1116 // (and will quite possibly make the SQL error out)
1117 $blob = new MssqlBlob( $s->fetch() );
1118 return $blob->fetch();
1119 } else {
1120 if ( is_bool( $s ) ) {
1121 $s = $s ? 1 : 0;
1122 }
1123 return parent::addQuotes( $s );
1124 }
1125 }
1126
1127 /**
1128 * @param string $s
1129 * @return string
1130 */
1131 public function addIdentifierQuotes( $s ) {
1132 // http://msdn.microsoft.com/en-us/library/aa223962.aspx
1133 return '[' . $s . ']';
1134 }
1135
1136 /**
1137 * @param string $name
1138 * @return bool
1139 */
1140 public function isQuotedIdentifier( $name ) {
1141 return strlen( $name ) && $name[0] == '[' && substr( $name, -1, 1 ) == ']';
1142 }
1143
1144 /**
1145 * MS SQL supports more pattern operators than other databases (ex: [,],^)
1146 *
1147 * @param string $s
1148 * @param string $escapeChar
1149 * @return string
1150 */
1151 protected function escapeLikeInternal( $s, $escapeChar = '`' ) {
1152 return str_replace( [ $escapeChar, '%', '_', '[', ']', '^' ],
1153 [ "{$escapeChar}{$escapeChar}", "{$escapeChar}%", "{$escapeChar}_",
1154 "{$escapeChar}[", "{$escapeChar}]", "{$escapeChar}^" ],
1155 $s );
1156 }
1157
1158 protected function doSelectDomain( DatabaseDomain $domain ) {
1159 if ( $domain->getSchema() !== null ) {
1160 throw new DBExpectedError(
1161 $this,
1162 __CLASS__ . ": domain '{$domain->getId()}' has a schema component"
1163 );
1164 }
1165
1166 $database = $domain->getDatabase();
1167 if ( $database !== $this->getDBname() ) {
1168 $sql = 'USE ' . $this->addIdentifierQuotes( $database );
1169 list( $res, $err, $errno ) =
1170 $this->executeQuery( $sql, __METHOD__, self::QUERY_IGNORE_DBO_TRX );
1171
1172 if ( $res === false ) {
1173 $this->reportQueryError( $err, $errno, $sql, __METHOD__ );
1174 return false; // unreachable
1175 }
1176 }
1177 // Update that domain fields on success (no exception thrown)
1178 $this->currentDomain = $domain;
1179
1180 return true;
1181 }
1182
1183 /**
1184 * @param array $options An associative array of options to be turned into
1185 * an SQL query, valid keys are listed in the function.
1186 * @return array
1187 */
1188 public function makeSelectOptions( $options ) {
1189 $tailOpts = '';
1190 $startOpts = '';
1191
1192 $noKeyOptions = [];
1193 foreach ( $options as $key => $option ) {
1194 if ( is_numeric( $key ) ) {
1195 $noKeyOptions[$option] = true;
1196 }
1197 }
1198
1199 $tailOpts .= $this->makeGroupByWithHaving( $options );
1200
1201 $tailOpts .= $this->makeOrderBy( $options );
1202
1203 if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) {
1204 $startOpts .= 'DISTINCT';
1205 }
1206
1207 if ( isset( $noKeyOptions['FOR XML'] ) ) {
1208 // used in group concat field emulation
1209 $tailOpts .= " FOR XML PATH('')";
1210 }
1211
1212 // we want this to be compatible with the output of parent::makeSelectOptions()
1213 return [ $startOpts, '', $tailOpts, '', '' ];
1214 }
1215
1216 public function getType() {
1217 return 'mssql';
1218 }
1219
1220 /**
1221 * @param array $stringList
1222 * @return string
1223 */
1224 public function buildConcat( $stringList ) {
1225 return implode( ' + ', $stringList );
1226 }
1227
1228 /**
1229 * Build a GROUP_CONCAT or equivalent statement for a query.
1230 * MS SQL doesn't have GROUP_CONCAT so we emulate it with other stuff (and boy is it nasty)
1231 *
1232 * This is useful for combining a field for several rows into a single string.
1233 * NULL values will not appear in the output, duplicated values will appear,
1234 * and the resulting delimiter-separated values have no defined sort order.
1235 * Code using the results may need to use the PHP unique() or sort() methods.
1236 *
1237 * @param string $delim Glue to bind the results together
1238 * @param string|array $table Table name
1239 * @param string $field Field name
1240 * @param string|array $conds Conditions
1241 * @param string|array $join_conds Join conditions
1242 * @return string SQL text
1243 * @since 1.23
1244 */
1245 public function buildGroupConcatField( $delim, $table, $field, $conds = '',
1246 $join_conds = []
1247 ) {
1248 $gcsq = 'gcsq_' . $this->subqueryId;
1249 $this->subqueryId++;
1250
1251 $delimLen = strlen( $delim );
1252 $fld = "{$field} + {$this->addQuotes( $delim )}";
1253 $sql = "(SELECT LEFT({$field}, LEN({$field}) - {$delimLen}) FROM ("
1254 . $this->selectSQLText( $table, $fld, $conds, null, [ 'FOR XML' ], $join_conds )
1255 . ") {$gcsq} ({$field}))";
1256
1257 return $sql;
1258 }
1259
1260 public function buildSubstring( $input, $startPosition, $length = null ) {
1261 $this->assertBuildSubstringParams( $startPosition, $length );
1262 if ( $length === null ) {
1263 /**
1264 * MSSQL doesn't allow an empty length parameter, so when we don't want to limit the
1265 * length returned use the default maximum size of text.
1266 * @see https://docs.microsoft.com/en-us/sql/t-sql/statements/set-textsize-transact-sql
1267 */
1268 $length = 2147483647;
1269 }
1270 return 'SUBSTRING(' . implode( ',', [ $input, $startPosition, $length ] ) . ')';
1271 }
1272
1273 /**
1274 * Returns an associative array for fields that are of type varbinary, binary, or image
1275 * $table can be either a raw table name or passed through tableName() first
1276 * @param string $table
1277 * @return array
1278 */
1279 private function getBinaryColumns( $table ) {
1280 $tableRawArr = explode( '.', preg_replace( '#\[([^\]]*)\]#', '$1', $table ) );
1281 $tableRaw = array_pop( $tableRawArr );
1282
1283 if ( $this->binaryColumnCache === null ) {
1284 $this->populateColumnCaches();
1285 }
1286
1287 return $this->binaryColumnCache[$tableRaw] ?? [];
1288 }
1289
1290 /**
1291 * @param string $table
1292 * @return array
1293 */
1294 private function getBitColumns( $table ) {
1295 $tableRawArr = explode( '.', preg_replace( '#\[([^\]]*)\]#', '$1', $table ) );
1296 $tableRaw = array_pop( $tableRawArr );
1297
1298 if ( $this->bitColumnCache === null ) {
1299 $this->populateColumnCaches();
1300 }
1301
1302 return $this->bitColumnCache[$tableRaw] ?? [];
1303 }
1304
1305 private function populateColumnCaches() {
1306 $res = $this->select( 'INFORMATION_SCHEMA.COLUMNS', '*',
1307 [
1308 'TABLE_CATALOG' => $this->getDBname(),
1309 'TABLE_SCHEMA' => $this->dbSchema(),
1310 'DATA_TYPE' => [ 'varbinary', 'binary', 'image', 'bit' ]
1311 ] );
1312
1313 $this->binaryColumnCache = [];
1314 $this->bitColumnCache = [];
1315 foreach ( $res as $row ) {
1316 if ( $row->DATA_TYPE == 'bit' ) {
1317 $this->bitColumnCache[$row->TABLE_NAME][$row->COLUMN_NAME] = $row;
1318 } else {
1319 $this->binaryColumnCache[$row->TABLE_NAME][$row->COLUMN_NAME] = $row;
1320 }
1321 }
1322 }
1323
1324 /**
1325 * @param string $name
1326 * @param string $format One of "quoted" (default), "raw", or "split".
1327 * @return string|array When the requested $format is "split", a list of database, schema, and
1328 * table name is returned. Database and schema can be `false`.
1329 */
1330 function tableName( $name, $format = 'quoted' ) {
1331 # Replace reserved words with better ones
1332 switch ( $name ) {
1333 case 'user':
1334 return $this->realTableName( 'mwuser', $format );
1335 default:
1336 return $this->realTableName( $name, $format );
1337 }
1338 }
1339
1340 /**
1341 * call this instead of tableName() in the updater when renaming tables
1342 * @param string $name
1343 * @param string $format One of "quoted" (default), "raw", or "split".
1344 * @return string|array When the requested $format is "split", a list of database, schema, and
1345 * table name is returned. Database and schema can be `false`.
1346 * @private
1347 */
1348 function realTableName( $name, $format = 'quoted' ) {
1349 $table = parent::tableName( $name, $format );
1350 if ( $format == 'split' ) {
1351 // Used internally, we want the schema split off from the table name and returned
1352 // as a list with 3 elements (database, schema, table)
1353 return array_pad( explode( '.', $table, 3 ), -3, false );
1354 }
1355 return $table;
1356 }
1357
1358 /**
1359 * Delete a table
1360 * @param string $tableName
1361 * @param string $fName
1362 * @return bool|IResultWrapper
1363 * @since 1.18
1364 */
1365 public function dropTable( $tableName, $fName = __METHOD__ ) {
1366 if ( !$this->tableExists( $tableName, $fName ) ) {
1367 return false;
1368 }
1369
1370 // parent function incorrectly appends CASCADE, which we don't want
1371 $sql = "DROP TABLE " . $this->tableName( $tableName );
1372
1373 return $this->query( $sql, $fName );
1374 }
1375
1376 /**
1377 * Called in the installer and updater.
1378 * Probably doesn't need to be called anywhere else in the codebase.
1379 * @param bool|null $value
1380 * @return bool|null
1381 */
1382 public function prepareStatements( $value = null ) {
1383 $old = $this->prepareStatements;
1384 if ( $value !== null ) {
1385 $this->prepareStatements = $value;
1386 }
1387
1388 return $old;
1389 }
1390
1391 /**
1392 * Called in the installer and updater.
1393 * Probably doesn't need to be called anywhere else in the codebase.
1394 * @param bool|null $value
1395 * @return bool|null
1396 */
1397 public function scrollableCursor( $value = null ) {
1398 $old = $this->scrollableCursor;
1399 if ( $value !== null ) {
1400 $this->scrollableCursor = $value;
1401 }
1402
1403 return $old;
1404 }
1405
1406 public function buildStringCast( $field ) {
1407 return "CAST( $field AS NVARCHAR )";
1408 }
1409
1410 public static function getAttributes() {
1411 return [ self::ATTR_SCHEMAS_AS_TABLE_GROUPS => true ];
1412 }
1413 }
1414
1415 /**
1416 * @deprecated since 1.29
1417 */
1418 class_alias( DatabaseMssql::class, 'DatabaseMssql' );