"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "includes/libs/rdbms/database/DatabasePostgres.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

DatabasePostgres.php  (mediawiki-1.31.1):DatabasePostgres.php  (mediawiki-1.32.0)
skipping to change at line 57 skipping to change at line 57
private $tempSchema; private $tempSchema;
/** @var string[] Map of (reserved table name => alternate table name) */ /** @var string[] Map of (reserved table name => alternate table name) */
private $keywordTableMap = []; private $keywordTableMap = [];
/** /**
* @see Database::__construct() * @see Database::__construct()
* @param array $params Additional parameters include: * @param array $params Additional parameters include:
* - keywordTableMap : Map of reserved table names to alternative table names to use * - keywordTableMap : Map of reserved table names to alternative table names to use
*/ */
public function __construct( array $params ) { public function __construct( array $params ) {
$this->port = isset( $params['port'] ) ? $params['port'] : false; $this->port = $params['port'] ?? false;
$this->keywordTableMap = isset( $params['keywordTableMap'] ) $this->keywordTableMap = $params['keywordTableMap'] ?? [];
? $params['keywordTableMap']
: [];
parent::__construct( $params ); parent::__construct( $params );
} }
public function getType() { public function getType() {
return 'postgres'; return 'postgres';
} }
public function implicitGroupby() { public function implicitGroupby() {
return false; return false;
skipping to change at line 91 skipping to change at line 89
$this->addQuotes( $name ) . " AND n.nspname = " . $this->addQuotes( $name ) . " AND n.nspname = " .
$this->addQuotes( $schema ); $this->addQuotes( $schema );
$res = $this->doQuery( $sql ); $res = $this->doQuery( $sql );
if ( $res && $this->numRows( $res ) ) { if ( $res && $this->numRows( $res ) ) {
return true; return true;
} }
} }
return false; return false;
} }
public function open( $server, $user, $password, $dbName ) { protected function open( $server, $user, $password, $dbName, $schema, $ta blePrefix ) {
# Test for Postgres support, to avoid suppressed fatal error # Test for Postgres support, to avoid suppressed fatal error
if ( !function_exists( 'pg_connect' ) ) { if ( !function_exists( 'pg_connect' ) ) {
throw new DBConnectionError( throw new DBConnectionError(
$this, $this,
"Postgres functions missing, have you compiled PH P with the --with-pgsql\n" . "Postgres functions missing, have you compiled PH P with the --with-pgsql\n" .
"option? (Note: if you recently installed PHP, yo u may need to restart your\n" . "option? (Note: if you recently installed PHP, yo u may need to restart your\n" .
"webserver and database)\n" "webserver and database)\n"
); );
} }
$this->server = $server; $this->server = $server;
$this->user = $user; $this->user = $user;
$this->password = $password; $this->password = $password;
$this->dbName = $dbName;
$connectVars = [ $connectVars = [
// pg_connect() user $user as the default database. Since a database is *required*, // pg_connect() user $user as the default database. Since a database is *required*,
// at least pick a "don't care" database that is more lik ely to exist. This case // at least pick a "don't care" database that is more lik ely to exist. This case
// arrises when LoadBalancer::getConnection( $i, [], '' ) is used. // arrises when LoadBalancer::getConnection( $i, [], '' ) is used.
'dbname' => strlen( $dbName ) ? $dbName : 'postgres', 'dbname' => strlen( $dbName ) ? $dbName : 'postgres',
'user' => $user, 'user' => $user,
'password' => $password 'password' => $password
]; ];
if ( $server != false && $server != '' ) { if ( $server != false && $server != '' ) {
skipping to change at line 162 skipping to change at line 159
if ( $this->cliMode ) { if ( $this->cliMode ) {
$this->doQuery( "SET client_min_messages = 'ERROR'" ); $this->doQuery( "SET client_min_messages = 'ERROR'" );
} }
$this->query( "SET client_encoding='UTF8'", __METHOD__ ); $this->query( "SET client_encoding='UTF8'", __METHOD__ );
$this->query( "SET datestyle = 'ISO, YMD'", __METHOD__ ); $this->query( "SET datestyle = 'ISO, YMD'", __METHOD__ );
$this->query( "SET timezone = 'GMT'", __METHOD__ ); $this->query( "SET timezone = 'GMT'", __METHOD__ );
$this->query( "SET standard_conforming_strings = on", __METHOD__ ); $this->query( "SET standard_conforming_strings = on", __METHOD__ );
$this->query( "SET bytea_output = 'escape'", __METHOD__ ); // PHP bug 53127 $this->query( "SET bytea_output = 'escape'", __METHOD__ ); // PHP bug 53127
$this->determineCoreSchema( $this->schema ); $this->determineCoreSchema( $schema );
// The schema to be used is now in the search path; no need for e $this->currentDomain = new DatabaseDomain( $dbName, $schema, $tab
xplicit qualification lePrefix );
$this->schema = '';
return $this->conn; return (bool)$this->conn;
}
protected function relationSchemaQualifier() {
if ( $this->coreSchema === $this->currentDomain->getSchema() ) {
// The schema to be used is now in the search path; no ne
ed for explicit qualification
return '';
}
return parent::relationSchemaQualifier();
} }
public function databasesAreIndependent() { public function databasesAreIndependent() {
return true; return true;
} }
/** public function doSelectDomain( DatabaseDomain $domain ) {
* Postgres doesn't support selectDB in the same way MySQL does. So if th if ( $this->getDBname() !== $domain->getDatabase() ) {
e // Postgres doesn't support selectDB in the same way MySQ
* DB name doesn't match the open connection, open a new one L does.
* @param string $db // So if the DB name doesn't match the open connection, o
* @return bool pen a new one
* @throws DBUnexpectedError $this->open(
*/ $this->server,
public function selectDB( $db ) { $this->user,
if ( $this->dbName !== $db ) { $this->password,
return (bool)$this->open( $this->server, $this->user, $th $domain->getDatabase(),
is->password, $db ); $domain->getSchema(),
$domain->getTablePrefix()
);
} else { } else {
return true; $this->currentDomain = $domain;
} }
return true;
} }
/** /**
* @param string[] $vars * @param string[] $vars
* @return string * @return string
*/ */
private function makeConnectionString( $vars ) { private function makeConnectionString( $vars ) {
$s = ''; $s = '';
foreach ( $vars as $name => $value ) { foreach ( $vars as $name => $value ) {
$s .= "$name='" . str_replace( "'", "\\'", $value ) . "' "; $s .= "$name='" . str_replace( "'", "\\'", $value ) . "' ";
skipping to change at line 304 skipping to change at line 313
throw new DBUnexpectedError( throw new DBUnexpectedError(
$this, $this,
'SQL error: ' . htmlspecialchars( pg_last_error( $conn ) ) 'SQL error: ' . htmlspecialchars( pg_last_error( $conn ) )
); );
} }
return $row; return $row;
} }
public function numRows( $res ) { public function numRows( $res ) {
if ( $res === false ) {
return 0;
}
if ( $res instanceof ResultWrapper ) { if ( $res instanceof ResultWrapper ) {
$res = $res->result; $res = $res->result;
} }
Wikimedia\suppressWarnings(); Wikimedia\suppressWarnings();
$n = pg_num_rows( $res ); $n = pg_num_rows( $res );
Wikimedia\restoreWarnings(); Wikimedia\restoreWarnings();
$conn = $this->getBindingHandle(); $conn = $this->getBindingHandle();
if ( pg_last_error( $conn ) ) { if ( pg_last_error( $conn ) ) {
throw new DBUnexpectedError( throw new DBUnexpectedError(
skipping to change at line 650 skipping to change at line 663
return true; return true;
} }
/** /**
* INSERT SELECT wrapper * INSERT SELECT wrapper
* $varMap must be an associative array of the form [ 'dest1' => 'source1 ', ... ] * $varMap must be an associative array of the form [ 'dest1' => 'source1 ', ... ]
* Source items may be literals rather then field names, but strings shou ld * Source items may be literals rather then field names, but strings shou ld
* be quoted with Database::addQuotes() * be quoted with Database::addQuotes()
* $conds may be "*" to copy the whole table * $conds may be "*" to copy the whole table
* srcTable may be an array of tables. * srcTable may be an array of tables.
* @todo FIXME: Implement this a little better (seperate select/insert)? * @todo FIXME: Implement this a little better (separate select/insert)?
* *
* @param string $destTable * @param string $destTable
* @param array|string $srcTable * @param array|string $srcTable
* @param array $varMap * @param array $varMap
* @param array $conds * @param array $conds
* @param string $fname * @param string $fname
* @param array $insertOptions * @param array $insertOptions
* @param array $selectOptions * @param array $selectOptions
* @param array $selectJoinConds * @param array $selectJoinConds
* @return bool * @return bool
skipping to change at line 713 skipping to change at line 726
$name = $this->remappedTableName( $name ); $name = $this->remappedTableName( $name );
return parent::tableName( $name, $format ); return parent::tableName( $name, $format );
} }
/** /**
* @param string $name * @param string $name
* @return string Value of $name or remapped name if $name is a reserved keyword * @return string Value of $name or remapped name if $name is a reserved keyword
*/ */
public function remappedTableName( $name ) { public function remappedTableName( $name ) {
return isset( $this->keywordTableMap[$name] ) ? $this->keywordTab leMap[$name] : $name; return $this->keywordTableMap[$name] ?? $name;
} }
/** /**
* @param string $name * @param string $name
* @param string $format * @param string $format
* @return string Qualified and encoded (if requested) table name * @return string Qualified and encoded (if requested) table name
*/ */
public function realTableName( $name, $format = 'quoted' ) { public function realTableName( $name, $format = 'quoted' ) {
return parent::tableName( $name, $format ); return parent::tableName( $name, $format );
} }
skipping to change at line 862 skipping to change at line 875
$fname $fname
); );
return true; return true;
} }
return false; return false;
} }
return false; return false;
} }
/**
* @suppress SecurityCheck-SQLInjection array_map not recognized T204911
*/
public function listTables( $prefix = null, $fname = __METHOD__ ) { public function listTables( $prefix = null, $fname = __METHOD__ ) {
$eschemas = implode( ',', array_map( [ $this, 'addQuotes' ], $thi s->getCoreSchemas() ) ); $eschemas = implode( ',', array_map( [ $this, 'addQuotes' ], $thi s->getCoreSchemas() ) );
$result = $this->query( $result = $this->query(
"SELECT DISTINCT tablename FROM pg_tables WHERE schemanam e IN ($eschemas)", $fname ); "SELECT DISTINCT tablename FROM pg_tables WHERE schemanam e IN ($eschemas)", $fname );
$endArray = []; $endArray = [];
foreach ( $result as $table ) { foreach ( $result as $table ) {
$vars = get_object_vars( $table ); $vars = get_object_vars( $table );
$table = array_pop( $vars ); $table = array_pop( $vars );
if ( !$prefix || strpos( $table, $prefix ) === 0 ) { if ( !$prefix || strpos( $table, $prefix ) === 0 ) {
skipping to change at line 1318 skipping to change at line 1334
$postLimitTail .= ' FOR UPDATE'; $postLimitTail .= ' FOR UPDATE';
} }
if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions[' DISTINCTROW'] ) ) { if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions[' DISTINCTROW'] ) ) {
$startOpts .= 'DISTINCT'; $startOpts .= 'DISTINCT';
} }
return [ $startOpts, $useIndex, $preLimitTail, $postLimitTail, $i gnoreIndex ]; return [ $startOpts, $useIndex, $preLimitTail, $postLimitTail, $i gnoreIndex ];
} }
public function getDBname() {
return $this->dbName;
}
public function getServer() { public function getServer() {
return $this->server; return $this->server;
} }
public function buildConcat( $stringList ) { public function buildConcat( $stringList ) {
return implode( ' || ', $stringList ); return implode( ' || ', $stringList );
} }
public function buildGroupConcatField( public function buildGroupConcatField(
$delimiter, $table, $field, $conds = '', $options = [], $join_con ds = [] $delimiter, $table, $field, $conds = '', $options = [], $join_con ds = []
skipping to change at line 1447 skipping to change at line 1459
/** /**
* @param string $lockName * @param string $lockName
* @return string Integer * @return string Integer
*/ */
private function bigintFromLockName( $lockName ) { private function bigintFromLockName( $lockName ) {
return \Wikimedia\base_convert( substr( sha1( $lockName ), 0, 15 ), 16, 10 ); return \Wikimedia\base_convert( substr( sha1( $lockName ), 0, 15 ), 16, 10 );
} }
} }
/**
* @deprecated since 1.29
*/
class_alias( DatabasePostgres::class, 'DatabasePostgres' ); class_alias( DatabasePostgres::class, 'DatabasePostgres' );
 End of changes. 14 change blocks. 
30 lines changed or deleted 46 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)