summaryrefslogtreecommitdiff
path: root/includes/db/DatabasePostgres.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2009-06-10 13:00:47 +0200
committerPierre Schmitz <pierre@archlinux.de>2009-06-10 13:00:47 +0200
commit72e90545454c0e014318fa3c81658e035aac58c1 (patch)
tree9212e3f46868989c4d57ae9a5c8a1a80e4dc0702 /includes/db/DatabasePostgres.php
parent565a0ccc371ec1a2a0e9b39487cbac18e6f60e25 (diff)
applying patch to version 1.15.0
Diffstat (limited to 'includes/db/DatabasePostgres.php')
-rw-r--r--includes/db/DatabasePostgres.php65
1 files changed, 36 insertions, 29 deletions
diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php
index 16a74b53..c940ad09 100644
--- a/includes/db/DatabasePostgres.php
+++ b/includes/db/DatabasePostgres.php
@@ -174,9 +174,11 @@ class DatabasePostgres extends Database {
global $wgCommandLineMode;
## If called from the command-line (e.g. importDump), only show errors
if ($wgCommandLineMode) {
- $this->doQuery("SET client_min_messages = 'ERROR'");
+ $this->doQuery( "SET client_min_messages = 'ERROR'" );
}
+ $this->doQuery( "SET client_encoding='UTF8'" );
+
global $wgDBmwschema, $wgDBts2schema;
if (isset( $wgDBmwschema ) && isset( $wgDBts2schema )
&& $wgDBmwschema !== 'mediawiki'
@@ -185,7 +187,7 @@ class DatabasePostgres extends Database {
) {
$safeschema = $this->quote_ident($wgDBmwschema);
$safeschema2 = $this->quote_ident($wgDBts2schema);
- $this->doQuery("SET search_path = $safeschema, $wgDBts2schema, public");
+ $this->doQuery( "SET search_path = $safeschema, $wgDBts2schema, public" );
}
return $this->mConn;
@@ -255,7 +257,7 @@ class DatabasePostgres extends Database {
print "<li>Database \"" . htmlspecialchars( $wgDBname ) . "\" already exists, skipping database creation.</li>";
}
else {
- if ($perms < 2) {
+ if ($perms < 1) {
print "<li>ERROR: the user \"" . htmlspecialchars( $wgDBsuperuser ) . "\" cannot create databases. ";
print 'Please use a different Postgres user.</li>';
dieout('</ul>');
@@ -687,7 +689,7 @@ class DatabasePostgres extends Database {
* Takes same arguments as Database::select()
*/
- function estimateRowCount( $table, $vars='*', $conds='', $fname = 'Database::estimateRowCount', $options = array() ) {
+ function estimateRowCount( $table, $vars='*', $conds='', $fname = 'DatabasePostgres::estimateRowCount', $options = array() ) {
$options['EXPLAIN'] = true;
$res = $this->select( $table, $vars, $conds, $fname, $options );
$rows = -1;
@@ -707,23 +709,25 @@ class DatabasePostgres extends Database {
* Returns information about an index
* If errors are explicitly ignored, returns NULL on failure
*/
- function indexInfo( $table, $index, $fname = 'Database::indexExists' ) {
+ function indexInfo( $table, $index, $fname = 'DatabasePostgres::indexInfo' ) {
$sql = "SELECT indexname FROM pg_indexes WHERE tablename='$table'";
$res = $this->query( $sql, $fname );
if ( !$res ) {
return NULL;
}
while ( $row = $this->fetchObject( $res ) ) {
- if ( $row->indexname == $index ) {
+ if ( $row->indexname == $this->indexName( $index ) ) {
return $row;
}
}
return false;
}
- function indexUnique ($table, $index, $fname = 'Database::indexUnique' ) {
+ function indexUnique ($table, $index, $fname = 'DatabasePostgres::indexUnique' ) {
$sql = "SELECT indexname FROM pg_indexes WHERE tablename='{$table}'".
- " AND indexdef LIKE 'CREATE UNIQUE%({$index})'";
+ " AND indexdef LIKE 'CREATE UNIQUE%(" .
+ $this->strencode( $this->indexName( $index ) ) .
+ ")'";
$res = $this->query( $sql, $fname );
if ( !$res )
return NULL;
@@ -921,7 +925,7 @@ class DatabasePostgres extends Database {
# It may be more efficient to leave off unique indexes which are unlikely to collide.
# However if you do this, you run the risk of encountering errors which wouldn't have
# occurred in MySQL
- function replace( $table, $uniqueIndexes, $rows, $fname = 'Database::replace' ) {
+ function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabasePostgres::replace' ) {
$table = $this->tableName( $table );
if (count($rows)==0) {
@@ -971,7 +975,7 @@ class DatabasePostgres extends Database {
}
# DELETE where the condition is a join
- function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = "Database::deleteJoin" ) {
+ function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabasePostgres::deleteJoin' ) {
if ( !$conds ) {
throw new DBUnexpectedError($this, 'Database::deleteJoin() called with empty $conds' );
}
@@ -1072,12 +1076,15 @@ class DatabasePostgres extends Database {
*/
function getServerVersion() {
$versionInfo = pg_version( $this->mConn );
- if ( isset( $versionInfo['server'] ) ) {
+ if ( version_compare( $versionInfo['client'], '7.4.0', 'lt' ) ) {
+ // Old client, abort install
+ $this->numeric_version = '7.3 or earlier';
+ } elseif ( isset( $versionInfo['server'] ) ) {
+ // Normal client
$this->numeric_version = $versionInfo['server'];
} else {
- // There's no way to identify the precise version before 7.4, but
- // it doesn't matter anyway since we're just going to give an error.
- $this->numeric_version = '7.3 or earlier';
+ // Bug 16937: broken pgsql extension from PHP<5.3
+ $this->numeric_version = pg_parameter_status( $this->mConn, 'server_version' );
}
return $this->numeric_version;
}
@@ -1088,12 +1095,12 @@ class DatabasePostgres extends Database {
*/
function relationExists( $table, $types, $schema = false ) {
global $wgDBmwschema;
- if (!is_array($types))
- $types = array($types);
- if (! $schema )
+ if ( !is_array( $types ) )
+ $types = array( $types );
+ if ( !$schema )
$schema = $wgDBmwschema;
- $etable = $this->addQuotes($table);
- $eschema = $this->addQuotes($schema);
+ $etable = $this->addQuotes( $table );
+ $eschema = $this->addQuotes( $schema );
$SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
. "WHERE c.relnamespace = n.oid AND c.relname = $etable AND n.nspname = $eschema "
. "AND c.relkind IN ('" . implode("','", $types) . "')";
@@ -1108,15 +1115,15 @@ class DatabasePostgres extends Database {
* For backward compatibility, this function checks both tables and
* views.
*/
- function tableExists ($table, $schema = false) {
- return $this->relationExists($table, array('r', 'v'), $schema);
+ function tableExists( $table, $schema = false ) {
+ return $this->relationExists( $table, array( 'r', 'v' ), $schema );
}
- function sequenceExists ($sequence, $schema = false) {
- return $this->relationExists($sequence, 'S', $schema);
+ function sequenceExists( $sequence, $schema = false ) {
+ return $this->relationExists( $sequence, 'S', $schema );
}
- function triggerExists($table, $trigger) {
+ function triggerExists( $table, $trigger ) {
global $wgDBmwschema;
$q = <<<END
@@ -1132,20 +1139,20 @@ END;
if (!$res)
return NULL;
$rows = $res->numRows();
- $this->freeResult($res);
+ $this->freeResult( $res );
return $rows;
}
- function ruleExists($table, $rule) {
+ function ruleExists( $table, $rule ) {
global $wgDBmwschema;
$exists = $this->selectField("pg_rules", "rulename",
array( "rulename" => $rule,
"tablename" => $table,
- "schemaname" => $wgDBmwschema));
+ "schemaname" => $wgDBmwschema ) );
return $exists === $rule;
}
- function constraintExists($table, $constraint) {
+ function constraintExists( $table, $constraint ) {
global $wgDBmwschema;
$SQL = sprintf("SELECT 1 FROM information_schema.table_constraints ".
"WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
@@ -1224,7 +1231,7 @@ END;
}
/* Not even sure why this is used in the main codebase... */
- function limitResultForUpdate($sql, $num) {
+ function limitResultForUpdate( $sql, $num ) {
return $sql;
}