Merge "Add fr (French) as fallback for kbp (Kabiyè)"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabasePostgres.php
index b92d072..2fe275b 100644 (file)
@@ -105,7 +105,10 @@ class DatabasePostgres extends Database {
                $this->mDBname = $dbName;
 
                $connectVars = [
-                       'dbname' => $dbName,
+                       // pg_connect() user $user as the default database. Since a database is *required*,
+                       // at least pick a "don't care" database that is more likely to exist. This case
+                       // arrises when LoadBalancer::getConnection( $i, [], '' ) is used.
+                       'dbname' => strlen( $dbName ) ? $dbName : 'postgres',
                        'user' => $user,
                        'password' => $password
                ];
@@ -165,11 +168,16 @@ class DatabasePostgres extends Database {
                return $this->mConn;
        }
 
+       public function databasesAreIndependent() {
+               return true;
+       }
+
        /**
         * Postgres doesn't support selectDB in the same way MySQL does. So if the
         * DB name doesn't match the open connection, open a new one
         * @param string $db
         * @return bool
+        * @throws DBUnexpectedError
         */
        public function selectDB( $db ) {
                if ( $this->mDBname !== $db ) {
@@ -768,7 +776,7 @@ __INDEXATTR__;
                $safeseq = str_replace( "'", "''", $seqName );
                $res = $this->query( "SELECT nextval('$safeseq')" );
                $row = $this->fetchRow( $res );
-               $this->mInsertId = $row[0];
+               $this->mInsertId = is_null( $row[0] ) ? null : (int)$row[0];
 
                return $this->mInsertId;
        }
@@ -820,7 +828,7 @@ __INDEXATTR__;
                $oldName = $this->addIdentifierQuotes( $oldName );
 
                return $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newName " .
-                       "(LIKE $oldName INCLUDING DEFAULTS)", $fname );
+                       "(LIKE $oldName INCLUDING DEFAULTS INCLUDING INDEXES)", $fname );
        }
 
        public function listTables( $prefix = null, $fname = __METHOD__ ) {