X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDatabasePostgres.php;h=57acd012f8efd1f01dfb3654b58a2c0dbe0ec96b;hp=b92d072112e4cf1cac85b11c1c42c7b4da05f8e6;hb=7f3d6713e7191c476adb3d3c30344a0327b853d3;hpb=0a873ed202207e3ab14e6ff372d7c0e9e0c95ea5 diff --git a/includes/libs/rdbms/database/DatabasePostgres.php b/includes/libs/rdbms/database/DatabasePostgres.php index b92d072112..57acd012f8 100644 --- a/includes/libs/rdbms/database/DatabasePostgres.php +++ b/includes/libs/rdbms/database/DatabasePostgres.php @@ -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 ) { @@ -673,14 +681,13 @@ __INDEXATTR__; * @param string $fname * @param array $insertOptions * @param array $selectOptions + * @param array $selectJoinConds * @return bool */ public function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__, - $insertOptions = [], $selectOptions = [] + $insertOptions = [], $selectOptions = [], $selectJoinConds = [] ) { - $destTable = $this->tableName( $destTable ); - if ( !is_array( $insertOptions ) ) { $insertOptions = [ $insertOptions ]; } @@ -697,28 +704,9 @@ __INDEXATTR__; $savepoint->savepoint(); } - if ( !is_array( $selectOptions ) ) { - $selectOptions = [ $selectOptions ]; - } - list( $startOpts, $useIndex, $tailOpts, $ignoreIndex ) = - $this->makeSelectOptions( $selectOptions ); - if ( is_array( $srcTable ) ) { - $srcTable = implode( ',', array_map( [ $this, 'tableName' ], $srcTable ) ); - } else { - $srcTable = $this->tableName( $srcTable ); - } - - $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' . - " SELECT $startOpts " . implode( ',', $varMap ) . - " FROM $srcTable $useIndex $ignoreIndex "; - - if ( $conds != '*' ) { - $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND ); - } - - $sql .= " $tailOpts"; + $res = parent::nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname, + $insertOptions, $selectOptions, $selectJoinConds ); - $res = (bool)$this->query( $sql, $fname, $savepoint ); if ( $savepoint ) { $bar = pg_result_error( $this->mLastResult ); if ( $bar != false ) { @@ -768,7 +756,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 +808,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__ ) { @@ -1051,6 +1039,7 @@ __INDEXATTR__; if ( $schema === false ) { $schema = $this->getCoreSchema(); } + $table = $this->realTableName( $table, 'raw' ); $etable = $this->addQuotes( $table ); $eschema = $this->addQuotes( $schema ); $sql = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "