Merge "install.php: Allow extensions and skins to be specified"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseMssql.php
index 1246e44..61367f5 100644 (file)
@@ -77,7 +77,7 @@ class DatabaseMssql extends Database {
                parent::__construct( $params );
        }
 
-       protected function open( $server, $user, $password, $dbName ) {
+       protected function open( $server, $user, $password, $dbName, $schema, $tablePrefix ) {
                # Test for driver support, to avoid suppressed fatal error
                if ( !function_exists( 'sqlsrv_connect' ) ) {
                        throw new DBConnectionError(
@@ -96,11 +96,10 @@ class DatabaseMssql extends Database {
                $this->server = $server;
                $this->user = $user;
                $this->password = $password;
-               $this->dbName = $dbName;
 
                $connectionInfo = [];
 
-               if ( $dbName ) {
+               if ( $dbName != '' ) {
                        $connectionInfo['Database'] = $dbName;
                }
 
@@ -120,6 +119,11 @@ class DatabaseMssql extends Database {
                }
 
                $this->opened = true;
+               $this->currentDomain = new DatabaseDomain(
+                       ( $dbName != '' ) ? $dbName : null,
+                       null,
+                       $tablePrefix
+               );
 
                return (bool)$this->conn;
        }
@@ -1006,7 +1010,7 @@ class DatabaseMssql extends Database {
                }
 
                if ( $schema === false ) {
-                       $schema = $this->schema;
+                       $schema = $this->dbSchema();
                }
 
                $res = $this->query( "SELECT 1 FROM INFORMATION_SCHEMA.TABLES
@@ -1167,18 +1171,13 @@ class DatabaseMssql extends Database {
                        $s );
        }
 
-       /**
-        * @param string $db
-        * @return bool
-        */
-       public function selectDB( $db ) {
-               try {
-                       $this->dbName = $db;
-                       $this->query( "USE $db" );
-                       return true;
-               } catch ( Exception $e ) {
-                       return false;
-               }
+       protected function doSelectDomain( DatabaseDomain $domain ) {
+               $encDatabase = $this->addIdentifierQuotes( $domain->getDatabase() );
+               $this->query( "USE $encDatabase" );
+               // Update that domain fields on success (no exception thrown)
+               $this->currentDomain = $domain;
+
+               return true;
        }
 
        /**
@@ -1306,8 +1305,8 @@ class DatabaseMssql extends Database {
        private function populateColumnCaches() {
                $res = $this->select( 'INFORMATION_SCHEMA.COLUMNS', '*',
                        [
-                               'TABLE_CATALOG' => $this->dbName,
-                               'TABLE_SCHEMA' => $this->schema,
+                               'TABLE_CATALOG' => $this->getDBname(),
+                               'TABLE_SCHEMA' => $this->dbSchema(),
                                'DATA_TYPE' => [ 'varbinary', 'binary', 'image', 'bit' ]
                        ] );