r72454 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72453‎ | r72454 | r72455 >
Date:18:35, 5 September 2010
Author:ashley
Status:ok
Tags:
Comment:
coding style tweaks
Modified paths:
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -301,7 +301,6 @@
302302
303303 $sql = preg_replace( '/^EXPLAIN /', 'EXPLAIN PLAN SET STATEMENT_ID = \'' . $explain_id . '\' FOR', $sql, 1, $explain_count );
304304
305 -
306305 wfSuppressWarnings();
307306
308307 if ( ( $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ) ) === false ) {
@@ -560,7 +559,9 @@
561560
562561 if ( ( $sequenceData = $this->getSequenceData( $destTable ) ) !== false &&
563562 !isset( $varMap[$sequenceData['column']] ) )
 563+ {
564564 $varMap[$sequenceData['column']] = 'GET_SEQUENCE_VALUE(\'' . $sequenceData['sequence'] . '\')';
 565+ }
565566
566567 // count-alias subselect fields to avoid abigious definition errors
567568 $i = 0;
@@ -675,15 +676,23 @@
676677 return ( isset( $this->sequenceData[$table] ) ) ? $this->sequenceData[$table] : false;
677678 }
678679
679 - # REPLACE query wrapper
680 - # Oracle simulates this with a DELETE followed by INSERT
681 - # $row is the row to insert, an associative array
682 - # $uniqueIndexes is an array of indexes. Each element may be either a
683 - # field name or an array of field names
684 - #
685 - # It may be more efficient to leave off unique indexes which are unlikely to collide.
686 - # However if you do this, you run the risk of encountering errors which wouldn't have
687 - # occurred in MySQL
 680+ /**
 681+ * REPLACE query wrapper
 682+ * Oracle simulates this with a DELETE followed by INSERT
 683+ * $row is the row to insert, an associative array
 684+ * $uniqueIndexes is an array of indexes. Each element may be either a
 685+ * field name or an array of field names
 686+ *
 687+ * It may be more efficient to leave off unique indexes which are unlikely to collide.
 688+ * However if you do this, you run the risk of encountering errors which wouldn't have
 689+ * occurred in MySQL.
 690+ *
 691+ * @param $table String: table name
 692+ * @param $uniqueIndexes Array: array of indexes. Each element may be
 693+ * either a field name or an array of field names
 694+ * @param $rows Array: rows to insert to $table
 695+ * @param $fname String: function name, you can use __METHOD__ here
 696+ */
688697 function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseOracle::replace' ) {
689698 $table = $this->tableName( $table );
690699
@@ -702,9 +711,10 @@
703712 # Delete rows which collide
704713 if ( $uniqueIndexes ) {
705714 $condsDelete = array();
706 - foreach ( $uniqueIndexes as $index )
 715+ foreach ( $uniqueIndexes as $index ) {
707716 $condsDelete[$index] = $row[$index];
708 - if (count($condsDelete) > 0) {
 717+ }
 718+ if ( count( $condsDelete ) > 0 ) {
709719 $this->delete( $table, $condsDelete, $fname );
710720 }
711721 }
@@ -719,9 +729,9 @@
720730 }
721731
722732 # DELETE where the condition is a join
723 - function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = "DatabaseOracle::deleteJoin" ) {
 733+ function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseOracle::deleteJoin' ) {
724734 if ( !$conds ) {
725 - throw new DBUnexpectedError( $this, 'DatabaseOracle::deleteJoin() called with empty $conds' );
 735+ throw new DBUnexpectedError( $this, 'DatabaseOracle::deleteJoin() called with empty $conds' );
726736 }
727737
728738 $delTable = $this->tableName( $delTable );
@@ -738,7 +748,7 @@
739749 # Returns the size of a text field, or -1 for "unlimited"
740750 function textFieldSize( $table, $field ) {
741751 $fieldInfoData = $this->fieldInfo( $table, $field);
742 - if ( $fieldInfoData->type == "varchar" ) {
 752+ if ( $fieldInfoData->type == 'varchar' ) {
743753 $size = $row->size - 4;
744754 } else {
745755 $size = $row->size;
@@ -753,7 +763,6 @@
754764 return "SELECT * FROM ($sql) WHERE rownum >= (1 + $offset) AND rownum < (1 + $limit + $offset)";
755765 }
756766
757 -
758767 function unionQueries( $sqls, $all ) {
759768 $glue = ' UNION ALL ';
760769 return 'SELECT * ' . ( $all ? '':'/* UNION_UNIQUE */ ' ) . 'FROM (' . implode( $glue, $sqls ) . ')' ;
@@ -763,28 +772,27 @@
764773 return $this->lastErrno() == 'OCI-00060';
765774 }
766775
767 -
768776 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseOracle::duplicateTableStructure' ) {
769777 $temporary = $temporary ? 'TRUE' : 'FALSE';
770 - $oldName = trim(strtoupper($oldName), '"');
771 - $oldParts = explode('_', $oldName);
 778+ $oldName = trim( strtoupper( $oldName ), '"');
 779+ $oldParts = explode( '_', $oldName );
772780
773 - $newName = trim(strtoupper($newName), '"');
774 - $newParts = explode('_', $newName);
 781+ $newName = trim( strtoupper( $newName ), '"');
 782+ $newParts = explode( '_', $newName );
775783
776784 $oldPrefix = '';
777785 $newPrefix = '';
778 - for ($i = count($oldParts)-1; $i >= 0; $i--) {
779 - if ($oldParts[$i] != $newParts[$i]) {
780 - $oldPrefix = implode('_', $oldParts).'_';
781 - $newPrefix = implode('_', $newParts).'_';
 786+ for ( $i = count( $oldParts ) - 1; $i >= 0; $i-- ) {
 787+ if ( $oldParts[$i] != $newParts[$i] ) {
 788+ $oldPrefix = implode( '_', $oldParts ) . '_';
 789+ $newPrefix = implode( '_', $newParts ) . '_';
782790 break;
783791 }
784 - unset($oldParts[$i]);
785 - unset($newParts[$i]);
 792+ unset( $oldParts[$i] );
 793+ unset( $newParts[$i] );
786794 }
787795
788 - $tabName = substr($oldName, strlen($oldPrefix));
 796+ $tabName = substr( $oldName, strlen( $oldPrefix ) );
789797
790798 return $this->query( 'BEGIN DUPLICATE_TABLE(\'' . $tabName . '\', \'' . $oldPrefix . '\', \''.$newPrefix.'\', ' . $temporary . '); END;', $fname );
791799 }
@@ -854,21 +862,21 @@
855863 */
856864 private function fieldInfoMulti( $table, $field ) {
857865 $tableWhere = '';
858 - $field = strtoupper($field);
859 - if (is_array($table)) {
 866+ $field = strtoupper( $field );
 867+ if ( is_array( $table ) ) {
860868 $table = array_map( array( &$this, 'tableName' ), $table );
861869 $tableWhere = 'IN (';
862 - foreach($table as &$singleTable) {
863 - $singleTable = strtoupper(trim( $singleTable, '"' ));
864 - if (isset($this->mFieldInfoCache["$singleTable.$field"])) {
 870+ foreach( $table as &$singleTable ) {
 871+ $singleTable = strtoupper( trim( $singleTable, '"' ) );
 872+ if ( isset( $this->mFieldInfoCache["$singleTable.$field"] ) ) {
865873 return $this->mFieldInfoCache["$singleTable.$field"];
866874 }
867 - $tableWhere .= '\''.$singleTable.'\',';
 875+ $tableWhere .= '\'' . $singleTable . '\',';
868876 }
869 - $tableWhere = rtrim($tableWhere, ',').')';
 877+ $tableWhere = rtrim( $tableWhere, ',' ) . ')';
870878 } else {
871 - $table = strtoupper(trim( $this->tableName($table), '"' ));
872 - if (isset($this->mFieldInfoCache["$table.$field"])) {
 879+ $table = strtoupper( trim( $this->tableName( $table ), '"' ) );
 880+ if ( isset( $this->mFieldInfoCache["$table.$field"] ) ) {
873881 return $this->mFieldInfoCache["$table.$field"];
874882 }
875883 $tableWhere = '= \''.$table.'\'';
@@ -881,9 +889,9 @@
882890 return false;
883891 }
884892 $res = new ORAResult( $this, $fieldInfoStmt );
885 - if ($res->numRows() == 0 ) {
886 - if (is_array($table)) {
887 - foreach($table as &$singleTable) {
 893+ if ( $res->numRows() == 0 ) {
 894+ if ( is_array( $table ) ) {
 895+ foreach( $table as &$singleTable ) {
888896 $this->mFieldInfoCache["$singleTable.$field"] = false;
889897 }
890898 } else {
@@ -992,7 +1000,7 @@
9931001
9941002 function setup_database() {
9951003 $res = $this->sourceFile( "../maintenance/ora/tables.sql" );
996 - if ($res === true) {
 1004+ if ( $res === true ) {
9971005 print " done.</li>\n";
9981006 } else {
9991007 print " <b>FAILED</b></li>\n";
@@ -1007,7 +1015,7 @@
10081016 }
10091017
10101018 // do it like the postgres :D
1011 - $SQL = "INSERT INTO ".$this->tableName('interwiki')." (iw_prefix,iw_url,iw_local) VALUES ";
 1019+ $SQL = "INSERT INTO " . $this->tableName( 'interwiki' ) . " (iw_prefix,iw_url,iw_local) VALUES ";
10121020 while ( !feof( $f ) ) {
10131021 $line = fgets( $f, 1024 );
10141022 $matches = array();
@@ -1040,7 +1048,7 @@
10411049 global $wgContLang;
10421050
10431051 $conds2 = array();
1044 - $conds = ($conds != null && !is_array($conds)) ? array($conds) : $conds;
 1052+ $conds = ( $conds != null && !is_array( $conds ) ) ? array( $conds ) : $conds;
10451053 foreach ( $conds as $col => $val ) {
10461054 $col_info = $this->fieldInfoMulti( $table, $col );
10471055 $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
@@ -1104,7 +1112,7 @@
11051113
11061114 if ( $wgContLang != null ) {
11071115 $conds2 = array();
1108 - $conds = ($conds != null && !is_array($conds)) ? array($conds) : $conds;
 1116+ $conds = ( $conds != null && !is_array( $conds ) ) ? array( $conds ) : $conds;
11091117 foreach ( $conds as $col => $val ) {
11101118 $col_info = $this->fieldInfoMulti( $table, $col );
11111119 $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -34,21 +34,25 @@
3535 SQL;
3636
3737 $table = $db->tableName( $table );
38 - $res = $db->query(sprintf($q,
39 - $db->addQuotes($wgDBmwschema),
40 - $db->addQuotes($table),
41 - $db->addQuotes($field)));
42 - $row = $db->fetchObject($res);
43 - if (!$row)
 38+ $res = $db->query(
 39+ sprintf( $q,
 40+ $db->addQuotes( $wgDBmwschema ),
 41+ $db->addQuotes( $table ),
 42+ $db->addQuotes( $field )
 43+ )
 44+ );
 45+ $row = $db->fetchObject( $res );
 46+ if ( !$row ) {
4447 return null;
 48+ }
4549 $n = new PostgresField;
4650 $n->type = $row->typname;
47 - $n->nullable = ($row->attnotnull == 'f');
 51+ $n->nullable = ( $row->attnotnull == 'f' );
4852 $n->name = $field;
4953 $n->tablename = $table;
5054 $n->max_length = $row->attlen;
51 - $n->deferrable = ($row->deferrable == 't');
52 - $n->deferred = ($row->deferred == 't');
 55+ $n->deferrable = ( $row->deferrable == 't' );
 56+ $n->deferred = ( $row->deferred == 't' );
5357 $n->conname = $row->conname;
5458 return $n;
5559 }
@@ -96,14 +100,12 @@
97101 var $numeric_version = null;
98102 var $mAffectedRows = null;
99103
100 - function __construct($server = false, $user = false, $password = false, $dbName = false,
 104+ function __construct( $server = false, $user = false, $password = false, $dbName = false,
101105 $failFunction = false, $flags = 0 )
102106 {
103 -
104107 $this->mFailFunction = $failFunction;
105108 $this->mFlags = $flags;
106 - $this->open( $server, $user, $password, $dbName);
107 -
 109+ $this->open( $server, $user, $password, $dbName );
108110 }
109111
110112 function getType() {
@@ -138,10 +140,10 @@
139141 function hasConstraint( $name ) {
140142 global $wgDBmwschema;
141143 $SQL = "SELECT 1 FROM pg_catalog.pg_constraint c, pg_catalog.pg_namespace n WHERE c.connamespace = n.oid AND conname = '" . pg_escape_string( $this->mConn, $name ) . "' AND n.nspname = '" . pg_escape_string( $this->mConn, $wgDBmwschema ) ."'";
142 - return $this->numRows($res = $this->doQuery($SQL));
 144+ return $this->numRows( $res = $this->doQuery( $SQL ) );
143145 }
144146
145 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0)
 147+ static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
146148 {
147149 return new DatabasePostgres( $server, $user, $password, $dbName, $failFunction, $flags );
148150 }
@@ -158,7 +160,7 @@
159161
160162 global $wgDBport;
161163
162 - if (!strlen($user)) { ## e.g. the class is being loaded
 164+ if ( !strlen( $user ) ) { # e.g. the class is being loaded
163165 return;
164166 }
165167 $this->close();
@@ -171,11 +173,12 @@
172174 $connectVars = array(
173175 'dbname' => $dbName,
174176 'user' => $user,
175 - 'password' => $password );
176 - if ($server!=false && $server!="") {
 177+ 'password' => $password
 178+ );
 179+ if ( $server != false && $server != '' ) {
177180 $connectVars['host'] = $server;
178181 }
179 - if ($port!=false && $port!="") {
 182+ if ( $port != false && $port != '' ) {
180183 $connectVars['port'] = $port;
181184 }
182185 $connectString = $this->makeConnectionString( $connectVars, PGSQL_CONNECT_FORCE_NEW );
@@ -187,7 +190,7 @@
188191 if ( !$this->mConn ) {
189192 wfDebug( "DB connection error\n" );
190193 wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" );
191 - wfDebug( $this->lastError()."\n" );
 194+ wfDebug( $this->lastError() . "\n" );
192195 if ( !$this->mFailFunction ) {
193196 throw new DBConnectionError( $this, $phpError );
194197 } else {
@@ -198,21 +201,21 @@
199202 $this->mOpened = true;
200203
201204 global $wgCommandLineMode;
202 - ## If called from the command-line (e.g. importDump), only show errors
203 - if ($wgCommandLineMode) {
 205+ # If called from the command-line (e.g. importDump), only show errors
 206+ if ( $wgCommandLineMode ) {
204207 $this->doQuery( "SET client_min_messages = 'ERROR'" );
205208 }
206209
207210 $this->doQuery( "SET client_encoding='UTF8'" );
208211
209212 global $wgDBmwschema, $wgDBts2schema;
210 - if (isset( $wgDBmwschema ) && isset( $wgDBts2schema )
 213+ if ( isset( $wgDBmwschema ) && isset( $wgDBts2schema )
211214 && $wgDBmwschema !== 'mediawiki'
212215 && preg_match( '/^\w+$/', $wgDBmwschema )
213216 && preg_match( '/^\w+$/', $wgDBts2schema )
214217 ) {
215 - $safeschema = $this->quote_ident($wgDBmwschema);
216 - $safeschema2 = $this->quote_ident($wgDBts2schema);
 218+ $safeschema = $this->quote_ident( $wgDBmwschema );
 219+ $safeschema2 = $this->quote_ident( $wgDBts2schema );
217220 $this->doQuery( "SET search_path = $safeschema, $wgDBts2schema, public" );
218221 }
219222
@@ -228,83 +231,81 @@
229232 }
230233
231234
232 - function initial_setup($superuser, $password, $dbName) {
 235+ function initial_setup( $superuser, $password, $dbName ) {
233236 // If this is the initial connection, setup the schema stuff and possibly create the user
234237 global $wgDBname, $wgDBuser, $wgDBpassword, $wgDBmwschema, $wgDBts2schema;
235238
236 - print "<li>Checking the version of Postgres...";
 239+ print '<li>Checking the version of Postgres...';
237240 $version = $this->getServerVersion();
238241 $PGMINVER = '8.1';
239 - if ($version < $PGMINVER) {
 242+ if ( $version < $PGMINVER ) {
240243 print "<b>FAILED</b>. Required version is $PGMINVER. You have " . htmlspecialchars( $version ) . "</li>\n";
241 - dieout("</ul>");
 244+ dieout( '</ul>' );
242245 }
243 - print "version " . htmlspecialchars( $this->numeric_version ) . " is OK.</li>\n";
 246+ print 'version ' . htmlspecialchars( $this->numeric_version ) . " is OK.</li>\n";
244247
245 - $safeuser = $this->quote_ident($wgDBuser);
 248+ $safeuser = $this->quote_ident( $wgDBuser );
246249 // Are we connecting as a superuser for the first time?
247 - if ($superuser) {
 250+ if ( $superuser ) {
248251 // Are we really a superuser? Check out our rights
249252 $SQL = "SELECT
250253 CASE WHEN usesuper IS TRUE THEN
251254 CASE WHEN usecreatedb IS TRUE THEN 3 ELSE 1 END
252255 ELSE CASE WHEN usecreatedb IS TRUE THEN 2 ELSE 0 END
253256 END AS rights
254 - FROM pg_catalog.pg_user WHERE usename = " . $this->addQuotes($superuser);
255 - $rows = $this->numRows($res = $this->doQuery($SQL));
256 - if (!$rows) {
257 - print "<li>ERROR: Could not read permissions for user \"" . htmlspecialchars( $superuser ) . "\"</li>\n";
258 - dieout('</ul>');
 257+ FROM pg_catalog.pg_user WHERE usename = " . $this->addQuotes( $superuser );
 258+ $rows = $this->numRows( $res = $this->doQuery( $SQL ) );
 259+ if ( !$rows ) {
 260+ print '<li>ERROR: Could not read permissions for user "' . htmlspecialchars( $superuser ) . "\"</li>\n";
 261+ dieout( '</ul>' );
259262 }
260 - $perms = pg_fetch_result($res, 0, 0);
 263+ $perms = pg_fetch_result( $res, 0, 0 );
261264
262 - $SQL = "SELECT 1 FROM pg_catalog.pg_user WHERE usename = " . $this->addQuotes($wgDBuser);
263 - $rows = $this->numRows($this->doQuery($SQL));
264 - if ($rows) {
265 - print "<li>User \"" . htmlspecialchars( $wgDBuser ) . "\" already exists, skipping account creation.</li>";
266 - }
267 - else {
268 - if ($perms != 1 and $perms != 3) {
269 - print "<li>ERROR: the user \"" . htmlspecialchars( $superuser ) . "\" cannot create other users. ";
 265+ $SQL = "SELECT 1 FROM pg_catalog.pg_user WHERE usename = " . $this->addQuotes( $wgDBuser );
 266+ $rows = $this->numRows( $this->doQuery( $SQL ) );
 267+ if ( $rows ) {
 268+ print '<li>User "' . htmlspecialchars( $wgDBuser ) . '" already exists, skipping account creation.</li>';
 269+ } else {
 270+ if ( $perms != 1 && $perms != 3 ) {
 271+ print '<li>ERROR: the user "' . htmlspecialchars( $superuser ) . '" cannot create other users. ';
270272 print 'Please use a different Postgres user.</li>';
271 - dieout('</ul>');
 273+ dieout( '</ul>' );
272274 }
273 - print "<li>Creating user <b>" . htmlspecialchars( $wgDBuser ) . "</b>...";
274 - $safepass = $this->addQuotes($wgDBpassword);
 275+ print '<li>Creating user <b>' . htmlspecialchars( $wgDBuser ) . '</b>...';
 276+ $safepass = $this->addQuotes( $wgDBpassword );
275277 $SQL = "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass";
276 - $this->doQuery($SQL);
 278+ $this->doQuery( $SQL );
277279 print "OK</li>\n";
278280 }
279281 // User now exists, check out the database
280 - if ($dbName != $wgDBname) {
281 - $SQL = "SELECT 1 FROM pg_catalog.pg_database WHERE datname = " . $this->addQuotes($wgDBname);
282 - $rows = $this->numRows($this->doQuery($SQL));
283 - if ($rows) {
284 - print "<li>Database \"" . htmlspecialchars( $wgDBname ) . "\" already exists, skipping database creation.</li>";
285 - }
286 - else {
287 - if ($perms < 1) {
288 - print "<li>ERROR: the user \"" . htmlspecialchars( $superuser ) . "\" cannot create databases. ";
 282+ if ( $dbName != $wgDBname ) {
 283+ $SQL = "SELECT 1 FROM pg_catalog.pg_database WHERE datname = " . $this->addQuotes( $wgDBname );
 284+ $rows = $this->numRows( $this->doQuery( $SQL ) );
 285+ if ( $rows ) {
 286+ print '<li>Database "' . htmlspecialchars( $wgDBname ) . '" already exists, skipping database creation.</li>';
 287+ } else {
 288+ if ( $perms < 1 ) {
 289+ print '<li>ERROR: the user "' . htmlspecialchars( $superuser ) . '" cannot create databases. ';
289290 print 'Please use a different Postgres user.</li>';
290 - dieout('</ul>');
 291+ dieout( '</ul>' );
291292 }
292 - print "<li>Creating database <b>" . htmlspecialchars( $wgDBname ) . "</b>...";
293 - $safename = $this->quote_ident($wgDBname);
 293+ print '<li>Creating database <b>' . htmlspecialchars( $wgDBname ) . '</b>...';
 294+ $safename = $this->quote_ident( $wgDBname );
294295 $SQL = "CREATE DATABASE $safename OWNER $safeuser ";
295 - $this->doQuery($SQL);
 296+ $this->doQuery( $SQL );
296297 print "OK</li>\n";
297298 // Hopefully tsearch2 and plpgsql are in template1...
298299 }
299300
300301 // Reconnect to check out tsearch2 rights for this user
301 - print "<li>Connecting to \"" . htmlspecialchars( $wgDBname ) . "\" as superuser \"" .
302 - htmlspecialchars( $superuser ) . "\" to check rights...";
 302+ print '<li>Connecting to "' . htmlspecialchars( $wgDBname ) . '" as superuser "' .
 303+ htmlspecialchars( $superuser ) . '" to check rights...';
303304
304305 $connectVars = array();
305 - if ($this->mServer!=false && $this->mServer!="") {
 306+ if ( $this->mServer != false && $this->mServer != '' ) {
306307 $connectVars['host'] = $this->mServer;
307308 }
308 - if ($this->mPort!=false && $this->mPort!="") {
 309+ if ( $this->mPort != false && $this->mPort != '' ) {
309310 $connectVars['port'] = $this->mPort;
310311 }
311312 $connectVars['dbname'] = $wgDBname;
@@ -314,47 +315,46 @@
315316 @$this->mConn = pg_connect( $this->makeConnectionString( $connectVars ) );
316317 if ( !$this->mConn ) {
317318 print "<b>FAILED TO CONNECT!</b></li>";
318 - dieout("</ul>");
 319+ dieout( '</ul>' );
319320 }
320321 print "OK</li>\n";
321322 }
322323
323 - if ($this->numeric_version < 8.3) {
 324+ if ( $this->numeric_version < 8.3 ) {
324325 // Tsearch2 checks
325 - print "<li>Checking that tsearch2 is installed in the database \"" .
326 - htmlspecialchars( $wgDBname ) . "\"...";
327 - if (! $this->tableExists("pg_ts_cfg", $wgDBts2schema)) {
328 - print "<b>FAILED</b>. tsearch2 must be installed in the database \"" .
329 - htmlspecialchars( $wgDBname ) . "\".";
330 - print "Please see <a href='http://www.devx.com/opensource/Article/21674/0/page/2'>this article</a>";
 326+ print '<li>Checking that tsearch2 is installed in the database "' .
 327+ htmlspecialchars( $wgDBname ) . '"...';
 328+ if ( !$this->tableExists( 'pg_ts_cfg', $wgDBts2schema ) ) {
 329+ print '<b>FAILED</b>. tsearch2 must be installed in the database "' .
 330+ htmlspecialchars( $wgDBname ) . '".';
 331+ print 'Please see <a href="http://www.devx.com/opensource/Article/21674/0/page/2">this article</a>';
331332 print " for instructions or ask on #postgresql on irc.freenode.net</li>\n";
332 - dieout("</ul>");
 333+ dieout( '</ul>' );
333334 }
334335 print "OK</li>\n";
335 - print "<li>Ensuring that user \"" . htmlspecialchars( $wgDBuser ) .
336 - "\" has select rights on the tsearch2 tables...";
337 - foreach (array('cfg','cfgmap','dict','parser') as $table) {
 336+ print '<li>Ensuring that user "' . htmlspecialchars( $wgDBuser ) .
 337+ '" has select rights on the tsearch2 tables...';
 338+ foreach ( array( 'cfg', 'cfgmap', 'dict', 'parser' ) as $table ) {
338339 $SQL = "GRANT SELECT ON pg_ts_$table TO $safeuser";
339 - $this->doQuery($SQL);
 340+ $this->doQuery( $SQL );
340341 }
341342 print "OK</li>\n";
342343 }
343344
344345 // Setup the schema for this user if needed
345 - $result = $this->schemaExists($wgDBmwschema);
346 - $safeschema = $this->quote_ident($wgDBmwschema);
347 - if (!$result) {
348 - print "<li>Creating schema <b>" . htmlspecialchars( $wgDBmwschema ) . "</b> ...";
349 - $result = $this->doQuery("CREATE SCHEMA $safeschema AUTHORIZATION $safeuser");
350 - if (!$result) {
 346+ $result = $this->schemaExists( $wgDBmwschema );
 347+ $safeschema = $this->quote_ident( $wgDBmwschema );
 348+ if ( !$result ) {
 349+ print '<li>Creating schema <b>' . htmlspecialchars( $wgDBmwschema ) . '</b> ...';
 350+ $result = $this->doQuery( "CREATE SCHEMA $safeschema AUTHORIZATION $safeuser" );
 351+ if ( !$result ) {
351352 print "<b>FAILED</b>.</li>\n";
352 - dieout("</ul>");
 353+ dieout( '</ul>' );
353354 }
354355 print "OK</li>\n";
355 - }
356 - else {
 356+ } else {
357357 print "<li>Schema already exists, explicitly granting rights...\n";
358 - $safeschema2 = $this->addQuotes($wgDBmwschema);
 358+ $safeschema2 = $this->addQuotes( $wgDBmwschema );
359359 $SQL = "SELECT 'GRANT ALL ON '||pg_catalog.quote_ident(relname)||' TO $safeuser;'\n".
360360 "FROM pg_catalog.pg_class p, pg_catalog.pg_namespace n\n".
361361 "WHERE relnamespace = n.oid AND n.nspname = $safeschema2\n".
@@ -364,16 +364,16 @@
365365 "pg_catalog.oidvectortypes(p.proargtypes)||') TO $safeuser;'\n".
366366 "FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n\n".
367367 "WHERE p.pronamespace = n.oid AND n.nspname = $safeschema2";
368 - $res = $this->doQuery($SQL);
369 - if (!$res) {
 368+ $res = $this->doQuery( $SQL );
 369+ if ( !$res ) {
370370 print "<b>FAILED</b>. Could not set rights for the user.</li>\n";
371 - dieout("</ul>");
 371+ dieout( '</ul>' );
372372 }
373 - $this->doQuery("SET search_path = $safeschema");
374 - $rows = $this->numRows($res);
375 - while ($rows) {
 373+ $this->doQuery( "SET search_path = $safeschema" );
 374+ $rows = $this->numRows( $res );
 375+ while ( $rows ) {
376376 $rows--;
377 - $this->doQuery(pg_fetch_result($res, $rows, 0));
 377+ $this->doQuery( pg_fetch_result( $res, $rows, 0 ) );
378378 }
379379 print "OK</li>";
380380 }
@@ -386,207 +386,203 @@
387387
388388 } // end superuser
389389
390 - if (!defined('POSTGRES_SEARCHPATH')) {
 390+ if ( !defined( 'POSTGRES_SEARCHPATH' ) ) {
391391
392 - if ($this->numeric_version < 8.3) {
 392+ if ( $this->numeric_version < 8.3 ) {
393393 // Do we have the basic tsearch2 table?
394 - print "<li>Checking for tsearch2 in the schema \"" . htmlspecialchars( $wgDBts2schema ) . "\"...";
395 - if (! $this->tableExists("pg_ts_dict", $wgDBts2schema)) {
396 - print "<b>FAILED</b>. Make sure tsearch2 is installed. See <a href=";
397 - print "'http://www.devx.com/opensource/Article/21674/0/page/2'>this article</a>";
 394+ print '<li>Checking for tsearch2 in the schema "' . htmlspecialchars( $wgDBts2schema ) . '"...';
 395+ if ( !$this->tableExists( 'pg_ts_dict', $wgDBts2schema ) ) {
 396+ print '<b>FAILED</b>. Make sure tsearch2 is installed. See <a href="';
 397+ print 'http://www.devx.com/opensource/Article/21674/0/page/2">this article</a>';
398398 print " for instructions.</li>\n";
399 - dieout("</ul>");
 399+ dieout( '</ul>' );
400400 }
401401 print "OK</li>\n";
402402
403403 // Does this user have the rights to the tsearch2 tables?
404 - $ctype = pg_fetch_result($this->doQuery("SHOW lc_ctype"),0,0);
405 - print "<li>Checking tsearch2 permissions...";
 404+ $ctype = pg_fetch_result( $this->doQuery( 'SHOW lc_ctype' ), 0, 0 );
 405+ print '<li>Checking tsearch2 permissions...';
406406 // Let's check all four, just to be safe
407407 error_reporting( 0 );
408 - $ts2tables = array('cfg','cfgmap','dict','parser');
409 - $safetsschema = $this->quote_ident($wgDBts2schema);
410 - foreach ( $ts2tables AS $tname ) {
 408+ $ts2tables = array( 'cfg', 'cfgmap', 'dict', 'parser' );
 409+ $safetsschema = $this->quote_ident( $wgDBts2schema );
 410+ foreach ( $ts2tables as $tname ) {
411411 $SQL = "SELECT count(*) FROM $safetsschema.pg_ts_$tname";
412 - $res = $this->doQuery($SQL);
413 - if (!$res) {
 412+ $res = $this->doQuery( $SQL );
 413+ if ( !$res ) {
414414 print "<b>FAILED</b> to access " . htmlspecialchars( "pg_ts_$tname" ) .
415415 ". Make sure that the user \"". htmlspecialchars( $wgDBuser ) .
416416 "\" has SELECT access to all four tsearch2 tables</li>\n";
417 - dieout("</ul>");
 417+ dieout( '</ul>' );
418418 }
419419 }
420420 $SQL = "SELECT ts_name FROM $safetsschema.pg_ts_cfg WHERE locale = " . $this->addQuotes( $ctype ) ;
421421 $SQL .= " ORDER BY CASE WHEN ts_name <> 'default' THEN 1 ELSE 0 END";
422 - $res = $this->doQuery($SQL);
 422+ $res = $this->doQuery( $SQL );
423423 error_reporting( E_ALL );
424 - if (!$res) {
 424+ if ( !$res ) {
425425 print "<b>FAILED</b>. Could not determine the tsearch2 locale information</li>\n";
426426 dieout("</ul>");
427427 }
428 - print "OK</li>";
 428+ print 'OK</li>';
429429
430430 // Will the current locale work? Can we force it to?
431 - print "<li>Verifying tsearch2 locale with " . htmlspecialchars( $ctype ) . "...";
432 - $rows = $this->numRows($res);
 431+ print '<li>Verifying tsearch2 locale with ' . htmlspecialchars( $ctype ) . '...';
 432+ $rows = $this->numRows( $res );
433433 $resetlocale = 0;
434 - if (!$rows) {
 434+ if ( !$rows ) {
435435 print "<b>not found</b></li>\n";
436 - print "<li>Attempting to set default tsearch2 locale to \"" . htmlspecialchars( $ctype ) . "\"...";
 436+ print '<li>Attempting to set default tsearch2 locale to "' . htmlspecialchars( $ctype ) . '"...';
437437 $resetlocale = 1;
438 - }
439 - else {
440 - $tsname = pg_fetch_result($res, 0, 0);
441 - if ($tsname != 'default') {
 438+ } else {
 439+ $tsname = pg_fetch_result( $res, 0, 0 );
 440+ if ( $tsname != 'default' ) {
442441 print "<b>not set to default (" . htmlspecialchars( $tsname ) . ")</b>";
443442 print "<li>Attempting to change tsearch2 default locale to \"" .
444443 htmlspecialchars( $ctype ) . "\"...";
445444 $resetlocale = 1;
446445 }
447446 }
448 - if ($resetlocale) {
 447+ if ( $resetlocale ) {
449448 $SQL = "UPDATE $safetsschema.pg_ts_cfg SET locale = " . $this->addQuotes( $ctype ) . " WHERE ts_name = 'default'";
450 - $res = $this->doQuery($SQL);
451 - if (!$res) {
452 - print "<b>FAILED</b>. ";
453 - print "Please make sure that the locale in pg_ts_cfg for \"default\" is set to \"" .
 449+ $res = $this->doQuery( $SQL );
 450+ if ( !$res ) {
 451+ print '<b>FAILED</b>. ';
 452+ print 'Please make sure that the locale in pg_ts_cfg for "default" is set to "' .
454453 htmlspecialchars( $ctype ) . "\"</li>\n";
455 - dieout("</ul>");
 454+ dieout( '</ul>' );
456455 }
457 - print "OK</li>";
 456+ print 'OK</li>';
458457 }
459458
460459 // Final test: try out a simple tsearch2 query
461460 $SQL = "SELECT $safetsschema.to_tsvector('default','MediaWiki tsearch2 testing')";
462 - $res = $this->doQuery($SQL);
463 - if (!$res) {
464 - print "<b>FAILED</b>. Specifically, \"" . htmlspecialchars( $SQL ) . "\" did not work.</li>";
465 - dieout("</ul>");
 461+ $res = $this->doQuery( $SQL );
 462+ if ( !$res ) {
 463+ print '<b>FAILED</b>. Specifically, "' . htmlspecialchars( $SQL ) . '" did not work.</li>';
 464+ dieout( '</ul>' );
466465 }
467 - print "OK</li>";
 466+ print 'OK</li>';
468467 }
469468
470469 // Install plpgsql if needed
471470 $this->setup_plpgsql();
472471
473472 // Does the schema already exist? Who owns it?
474 - $result = $this->schemaExists($wgDBmwschema);
475 - if (!$result) {
476 - print "<li>Creating schema <b>" . htmlspecialchars( $wgDBmwschema ) . "</b> ...";
 473+ $result = $this->schemaExists( $wgDBmwschema );
 474+ if ( !$result ) {
 475+ print '<li>Creating schema <b>' . htmlspecialchars( $wgDBmwschema ) . '</b> ...';
477476 error_reporting( 0 );
478 - $safeschema = $this->quote_ident($wgDBmwschema);
479 - $result = $this->doQuery("CREATE SCHEMA $safeschema");
 477+ $safeschema = $this->quote_ident( $wgDBmwschema );
 478+ $result = $this->doQuery( "CREATE SCHEMA $safeschema" );
480479 error_reporting( E_ALL );
481 - if (!$result) {
482 - print "<b>FAILED</b>. The user \"" . htmlspecialchars( $wgDBuser ) .
483 - "\" must be able to access the schema. ".
484 - "You can try making them the owner of the database, or try creating the schema with a ".
485 - "different user, and then grant access to the \"" .
 480+ if ( !$result ) {
 481+ print '<b>FAILED</b>. The user "' . htmlspecialchars( $wgDBuser ) .
 482+ '" must be able to access the schema. '.
 483+ 'You can try making them the owner of the database, or try creating the schema with a '.
 484+ 'different user, and then grant access to the "' .
486485 htmlspecialchars( $wgDBuser ) . "\" user.</li>\n";
487 - dieout("</ul>");
 486+ dieout( '</ul>' );
488487 }
489488 print "OK</li>\n";
490 - }
491 - else if ($result != $wgDBuser) {
492 - print "<li>Schema \"" . htmlspecialchars( $wgDBmwschema ) . "\" exists but is not owned by \"" .
 489+ } elseif ( $result != $wgDBuser ) {
 490+ print '<li>Schema "' . htmlspecialchars( $wgDBmwschema ) . '" exists but is not owned by "' .
493491 htmlspecialchars( $wgDBuser ) . "\". Not ideal.</li>\n";
494 - }
495 - else {
496 - print "<li>Schema \"" . htmlspecialchars( $wgDBmwschema ) . "\" exists and is owned by \"" .
 492+ } else {
 493+ print '<li>Schema "' . htmlspecialchars( $wgDBmwschema ) . '" exists and is owned by "' .
497494 htmlspecialchars( $wgDBuser ) . "\". Excellent.</li>\n";
498495 }
499496
500497 // Always return GMT time to accomodate the existing integer-based timestamp assumption
501 - print "<li>Setting the timezone to GMT for user \"" . htmlspecialchars( $wgDBuser ) . "\" ...";
 498+ print "<li>Setting the timezone to GMT for user \"" . htmlspecialchars( $wgDBuser ) . '" ...';
502499 $SQL = "ALTER USER $safeuser SET timezone = 'GMT'";
503 - $result = pg_query($this->mConn, $SQL);
504 - if (!$result) {
 500+ $result = pg_query( $this->mConn, $SQL );
 501+ if ( !$result ) {
505502 print "<b>FAILED</b>.</li>\n";
506 - dieout("</ul>");
 503+ dieout( '</ul>' );
507504 }
508505 print "OK</li>\n";
509506 // Set for the rest of this session
510507 $SQL = "SET timezone = 'GMT'";
511 - $result = pg_query($this->mConn, $SQL);
512 - if (!$result) {
 508+ $result = pg_query( $this->mConn, $SQL );
 509+ if ( !$result ) {
513510 print "<li>Failed to set timezone</li>\n";
514 - dieout("</ul>");
 511+ dieout( '</ul>' );
515512 }
516513
517 - print "<li>Setting the datestyle to ISO, YMD for user \"" . htmlspecialchars( $wgDBuser ) . "\" ...";
 514+ print '<li>Setting the datestyle to ISO, YMD for user "' . htmlspecialchars( $wgDBuser ) . '" ...';
518515 $SQL = "ALTER USER $safeuser SET datestyle = 'ISO, YMD'";
519 - $result = pg_query($this->mConn, $SQL);
520 - if (!$result) {
 516+ $result = pg_query( $this->mConn, $SQL );
 517+ if ( !$result ) {
521518 print "<b>FAILED</b>.</li>\n";
522 - dieout("</ul>");
 519+ dieout( '</ul>' );
523520 }
524521 print "OK</li>\n";
525522 // Set for the rest of this session
526523 $SQL = "SET datestyle = 'ISO, YMD'";
527 - $result = pg_query($this->mConn, $SQL);
528 - if (!$result) {
 524+ $result = pg_query( $this->mConn, $SQL );
 525+ if ( !$result ) {
529526 print "<li>Failed to set datestyle</li>\n";
530 - dieout("</ul>");
 527+ dieout( '</ul>' );
531528 }
532529
533530 // Fix up the search paths if needed
534 - print "<li>Setting the search path for user \"" . htmlspecialchars( $wgDBuser ) . "\" ...";
535 - $path = $this->quote_ident($wgDBmwschema);
536 - if ($wgDBts2schema !== $wgDBmwschema)
537 - $path .= ", ". $this->quote_ident($wgDBts2schema);
538 - if ($wgDBmwschema !== 'public' and $wgDBts2schema !== 'public')
539 - $path .= ", public";
 531+ print '<li>Setting the search path for user "' . htmlspecialchars( $wgDBuser ) . '" ...';
 532+ $path = $this->quote_ident( $wgDBmwschema );
 533+ if ( $wgDBts2schema !== $wgDBmwschema ) {
 534+ $path .= ', '. $this->quote_ident( $wgDBts2schema );
 535+ }
 536+ if ( $wgDBmwschema !== 'public' && $wgDBts2schema !== 'public' ) {
 537+ $path .= ', public';
 538+ }
540539 $SQL = "ALTER USER $safeuser SET search_path = $path";
541 - $result = pg_query($this->mConn, $SQL);
542 - if (!$result) {
 540+ $result = pg_query( $this->mConn, $SQL );
 541+ if ( !$result ) {
543542 print "<b>FAILED</b>.</li>\n";
544 - dieout("</ul>");
 543+ dieout( '</ul>' );
545544 }
546545 print "OK</li>\n";
547546 // Set for the rest of this session
548547 $SQL = "SET search_path = $path";
549 - $result = pg_query($this->mConn, $SQL);
550 - if (!$result) {
 548+ $result = pg_query( $this->mConn, $SQL );
 549+ if ( !$result ) {
551550 print "<li>Failed to set search_path</li>\n";
552 - dieout("</ul>");
 551+ dieout( '</ul>' );
553552 }
554 - define( "POSTGRES_SEARCHPATH", $path );
 553+ define( 'POSTGRES_SEARCHPATH', $path );
555554 }
556555 }
557556
558 -
559557 function setup_plpgsql() {
560 - print "<li>Checking for PL/pgSQL ...";
 558+ print '<li>Checking for PL/pgSQL ...';
561559 $SQL = "SELECT 1 FROM pg_catalog.pg_language WHERE lanname = 'plpgsql'";
562 - $rows = $this->numRows($this->doQuery($SQL));
563 - if ($rows < 1) {
 560+ $rows = $this->numRows( $this->doQuery( $SQL ) );
 561+ if ( $rows < 1 ) {
564562 // plpgsql is not installed, but if we have a pg_pltemplate table, we should be able to create it
565 - print "not installed. Attempting to install PL/pgSQL ...";
 563+ print 'not installed. Attempting to install PL/pgSQL ...';
566564 $SQL = "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace) ".
567565 "WHERE relname = 'pg_pltemplate' AND nspname='pg_catalog'";
568 - $rows = $this->numRows($this->doQuery($SQL));
 566+ $rows = $this->numRows( $this->doQuery( $SQL ) );
569567 global $wgDBname;
570 - if ($rows >= 1) {
571 - $olde = error_reporting(0);
572 - error_reporting($olde - E_WARNING);
573 - $result = $this->doQuery("CREATE LANGUAGE plpgsql");
574 - error_reporting($olde);
575 - if (!$result) {
576 - print "<b>FAILED</b>. You need to install the language PL/pgSQL in the database <tt>" .
577 - htmlspecialchars( $wgDBname ) . "</tt></li>";
578 - dieout("</ul>");
 568+ if ( $rows >= 1 ) {
 569+ $olde = error_reporting( 0 );
 570+ error_reporting( $olde - E_WARNING );
 571+ $result = $this->doQuery( 'CREATE LANGUAGE plpgsql' );
 572+ error_reporting( $olde );
 573+ if ( !$result ) {
 574+ print '<b>FAILED</b>. You need to install the language PL/pgSQL in the database <tt>' .
 575+ htmlspecialchars( $wgDBname ) . '</tt></li>';
 576+ dieout( '</ul>' );
579577 }
 578+ } else {
 579+ print '<b>FAILED</b>. You need to install the language PL/pgSQL in the database <tt>' .
 580+ htmlspecialchars( $wgDBname ) . '</tt></li>';
 581+ dieout( '</ul>' );
580582 }
581 - else {
582 - print "<b>FAILED</b>. You need to install the language PL/pgSQL in the database <tt>" .
583 - htmlspecialchars( $wgDBname ) . "</tt></li>";
584 - dieout("</ul>");
585 - }
586583 }
587584 print "OK</li>\n";
588585 }
589586
590 -
591587 /**
592588 * Closes a database connection, if it is open
593589 * Returns success, true if already closed
@@ -601,10 +597,10 @@
602598 }
603599
604600 function doQuery( $sql ) {
605 - if (function_exists('mb_convert_encoding')) {
606 - $sql = mb_convert_encoding($sql,'UTF-8');
 601+ if ( function_exists( 'mb_convert_encoding' ) ) {
 602+ $sql = mb_convert_encoding( $sql, 'UTF-8' );
607603 }
608 - $this->mLastResult = pg_query( $this->mConn, $sql);
 604+ $this->mLastResult = pg_query( $this->mConn, $sql );
609605 $this->mAffectedRows = null; // use pg_affected_rows(mLastResult)
610606 return $this->mLastResult;
611607 }
@@ -618,7 +614,7 @@
619615 $res = $res->result;
620616 }
621617 if ( !@pg_free_result( $res ) ) {
622 - throw new DBUnexpectedError($this, "Unable to free Postgres result\n" );
 618+ throw new DBUnexpectedError( $this, "Unable to free Postgres result\n" );
623619 }
624620 }
625621
@@ -632,8 +628,8 @@
633629 # TODO:
634630 # hashar : not sure if the following test really trigger if the object
635631 # fetching failed.
636 - if( pg_last_error($this->mConn) ) {
637 - throw new DBUnexpectedError($this, 'SQL error: ' . htmlspecialchars( pg_last_error($this->mConn) ) );
 632+ if( pg_last_error( $this->mConn ) ) {
 633+ throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) );
638634 }
639635 return $row;
640636 }
@@ -643,8 +639,8 @@
644640 $res = $res->result;
645641 }
646642 @$row = pg_fetch_array( $res );
647 - if( pg_last_error($this->mConn) ) {
648 - throw new DBUnexpectedError($this, 'SQL error: ' . htmlspecialchars( pg_last_error($this->mConn) ) );
 643+ if( pg_last_error( $this->mConn ) ) {
 644+ throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) );
649645 }
650646 return $row;
651647 }
@@ -654,17 +650,19 @@
655651 $res = $res->result;
656652 }
657653 @$n = pg_num_rows( $res );
658 - if( pg_last_error($this->mConn) ) {
659 - throw new DBUnexpectedError($this, 'SQL error: ' . htmlspecialchars( pg_last_error($this->mConn) ) );
 654+ if( pg_last_error( $this->mConn ) ) {
 655+ throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) );
660656 }
661657 return $n;
662658 }
 659+
663660 function numFields( $res ) {
664661 if ( $res instanceof ResultWrapper ) {
665662 $res = $res->result;
666663 }
667664 return pg_num_fields( $res );
668665 }
 666+
669667 function fieldName( $res, $n ) {
670668 if ( $res instanceof ResultWrapper ) {
671669 $res = $res->result;
@@ -689,10 +687,9 @@
690688 function lastError() {
691689 if ( $this->mConn ) {
692690 return pg_last_error();
 691+ } else {
 692+ return 'No database connection';
693693 }
694 - else {
695 - return "No database connection";
696 - }
697694 }
698695 function lastErrno() {
699696 return pg_last_error() ? 1 : 0;
@@ -703,8 +700,9 @@
704701 // Forced result for simulated queries
705702 return $this->mAffectedRows;
706703 }
707 - if( empty( $this->mLastResult ) )
 704+ if( empty( $this->mLastResult ) ) {
708705 return 0;
 706+ }
709707 return pg_affected_rows( $this->mLastResult );
710708 }
711709
@@ -715,8 +713,7 @@
716714 * Returns -1 if count cannot be found
717715 * Takes same arguments as Database::select()
718716 */
719 -
720 - function estimateRowCount( $table, $vars='*', $conds='', $fname = 'DatabasePostgres::estimateRowCount', $options = array() ) {
 717+ function estimateRowCount( $table, $vars = '*', $conds='', $fname = 'DatabasePostgres::estimateRowCount', $options = array() ) {
721718 $options['EXPLAIN'] = true;
722719 $res = $this->select( $table, $vars, $conds, $fname, $options );
723720 $rows = -1;
@@ -730,7 +727,6 @@
731728 return $rows;
732729 }
733730
734 -
735731 /**
736732 * Returns information about an index
737733 * If errors are explicitly ignored, returns NULL on failure
@@ -749,16 +745,18 @@
750746 return false;
751747 }
752748
753 - function indexUnique ($table, $index, $fname = 'DatabasePostgres::indexUnique' ) {
 749+ function indexUnique( $table, $index, $fname = 'DatabasePostgres::indexUnique' ) {
754750 $sql = "SELECT indexname FROM pg_indexes WHERE tablename='{$table}'".
755751 " AND indexdef LIKE 'CREATE UNIQUE%(" .
756752 $this->strencode( $this->indexName( $index ) ) .
757753 ")'";
758754 $res = $this->query( $sql, $fname );
759 - if ( !$res )
 755+ if ( !$res ) {
760756 return null;
761 - while ($row = $this->fetchObject( $res ))
 757+ }
 758+ while ( $row = $this->fetchObject( $res ) ) {
762759 return true;
 760+ }
763761 return false;
764762
765763 }
@@ -786,14 +784,14 @@
787785 $this->getServerVersion();
788786 }
789787
790 - if ( !is_array( $options ) )
 788+ if ( !is_array( $options ) ) {
791789 $options = array( $options );
 790+ }
792791
793792 if ( isset( $args[0] ) && is_array( $args[0] ) ) {
794793 $multi = true;
795794 $keys = array_keys( $args[0] );
796 - }
797 - else {
 795+ } else {
798796 $multi = false;
799797 $keys = array_keys( $args );
800798 }
@@ -804,7 +802,7 @@
805803 // If we are not in a transaction, we need to be for savepoint trickery
806804 $didbegin = 0;
807805 if ( $ignore ) {
808 - if (! $this->mTrxLevel) {
 806+ if ( !$this->mTrxLevel ) {
809807 $this->begin();
810808 $didbegin = 1;
811809 }
@@ -828,8 +826,7 @@
829827 $sql .= '(' . $this->makeList( $row ) . ')';
830828 }
831829 $res = (bool)$this->query( $sql, $fname, $ignore );
832 - }
833 - else {
 830+ } else {
834831 $res = true;
835832 $origsql = $sql;
836833 foreach ( $args as $row ) {
@@ -837,17 +834,16 @@
838835 $tempsql .= '(' . $this->makeList( $row ) . ')';
839836
840837 if ( $ignore ) {
841 - pg_query($this->mConn, "SAVEPOINT $ignore");
 838+ pg_query( $this->mConn, "SAVEPOINT $ignore" );
842839 }
843840
844841 $tempres = (bool)$this->query( $tempsql, $fname, $ignore );
845842
846843 if ( $ignore ) {
847844 $bar = pg_last_error();
848 - if ($bar != false) {
 845+ if ( $bar != false ) {
849846 pg_query( $this->mConn, "ROLLBACK TO $ignore" );
850 - }
851 - else {
 847+ } else {
852848 pg_query( $this->mConn, "RELEASE $ignore" );
853849 $numrowsinserted++;
854850 }
@@ -855,12 +851,12 @@
856852
857853 // If any of them fail, we fail overall for this function call
858854 // Note that this will be ignored if IGNORE is set
859 - if (! $tempres)
 855+ if ( !$tempres ) {
860856 $res = false;
 857+ }
861858 }
862859 }
863 - }
864 - else {
 860+ } else {
865861 // Not multi, just a lone insert
866862 if ( $ignore ) {
867863 pg_query($this->mConn, "SAVEPOINT $ignore");
@@ -870,10 +866,9 @@
871867 $res = (bool)$this->query( $sql, $fname, $ignore );
872868 if ( $ignore ) {
873869 $bar = pg_last_error();
874 - if ($bar != false) {
 870+ if ( $bar != false ) {
875871 pg_query( $this->mConn, "ROLLBACK TO $ignore" );
876 - }
877 - else {
 872+ } else {
878873 pg_query( $this->mConn, "RELEASE $ignore" );
879874 $numrowsinserted++;
880875 }
@@ -881,7 +876,7 @@
882877 }
883878 if ( $ignore ) {
884879 $olde = error_reporting( $olde );
885 - if ($didbegin) {
 880+ if ( $didbegin ) {
886881 $this->commit();
887882 }
888883
@@ -892,9 +887,7 @@
893888 return true;
894889 }
895890
896 -
897891 return $res;
898 -
899892 }
900893
901894 /**
@@ -904,7 +897,7 @@
905898 * $conds may be "*" to copy the whole table
906899 * srcTable may be an array of tables.
907900 * @todo FIXME: implement this a little better (seperate select/insert)?
908 - */
 901+ */
909902 function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'DatabasePostgres::insertSelect',
910903 $insertOptions = array(), $selectOptions = array() )
911904 {
@@ -942,7 +935,7 @@
943936 " SELECT $startOpts " . implode( ',', $varMap ) .
944937 " FROM $srcTable $useIndex";
945938
946 - if ( $conds != '*') {
 939+ if ( $conds != '*' ) {
947940 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
948941 }
949942
@@ -1006,19 +999,21 @@
10071000 return $currval;
10081001 }
10091002
1010 - # REPLACE query wrapper
1011 - # Postgres simulates this with a DELETE followed by INSERT
1012 - # $row is the row to insert, an associative array
1013 - # $uniqueIndexes is an array of indexes. Each element may be either a
1014 - # field name or an array of field names
1015 - #
1016 - # It may be more efficient to leave off unique indexes which are unlikely to collide.
1017 - # However if you do this, you run the risk of encountering errors which wouldn't have
1018 - # occurred in MySQL
 1003+ /**
 1004+ * REPLACE query wrapper
 1005+ * Postgres simulates this with a DELETE followed by INSERT
 1006+ * $row is the row to insert, an associative array
 1007+ * $uniqueIndexes is an array of indexes. Each element may be either a
 1008+ * field name or an array of field names
 1009+ *
 1010+ * It may be more efficient to leave off unique indexes which are unlikely to collide.
 1011+ * However if you do this, you run the risk of encountering errors which wouldn't have
 1012+ * occurred in MySQL
 1013+ */
10191014 function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabasePostgres::replace' ) {
10201015 $table = $this->tableName( $table );
10211016
1022 - if (count($rows)==0) {
 1017+ if ( count( $rows ) == 0 ) {
10231018 return;
10241019 }
10251020
@@ -1035,7 +1030,7 @@
10361031 foreach ( $uniqueIndexes as $index ) {
10371032 if ( $first ) {
10381033 $first = false;
1039 - $sql .= "(";
 1034+ $sql .= '(';
10401035 } else {
10411036 $sql .= ') OR (';
10421037 }
@@ -1067,7 +1062,7 @@
10681063 # DELETE where the condition is a join
10691064 function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabasePostgres::deleteJoin' ) {
10701065 if ( !$conds ) {
1071 - throw new DBUnexpectedError($this, 'Database::deleteJoin() called with empty $conds' );
 1066+ throw new DBUnexpectedError( $this, 'DatabasePostgres::deleteJoin() called with empty $conds' );
10721067 }
10731068
10741069 $delTable = $this->tableName( $delTable );
@@ -1088,18 +1083,18 @@
10891084 FROM pg_class c, pg_attribute a, pg_type t
10901085 WHERE relname='$table' AND a.attrelid=c.oid AND
10911086 a.atttypid=t.oid and a.attname='$field'";
1092 - $res =$this->query($sql);
1093 - $row=$this->fetchObject($res);
1094 - if ($row->ftype=="varchar") {
1095 - $size=$row->size-4;
 1087+ $res =$this->query( $sql );
 1088+ $row = $this->fetchObject( $res );
 1089+ if ( $row->ftype == 'varchar' ) {
 1090+ $size = $row->size - 4;
10961091 } else {
1097 - $size=$row->size;
 1092+ $size = $row->size;
10981093 }
10991094 return $size;
11001095 }
11011096
1102 - function limitResult($sql, $limit, $offset=false) {
1103 - return "$sql LIMIT $limit ".(is_numeric($offset)?" OFFSET {$offset} ":"");
 1097+ function limitResult( $sql, $limit, $offset = false ) {
 1098+ return "$sql LIMIT $limit " . ( is_numeric( $offset ) ? " OFFSET {$offset} " : '' );
11041099 }
11051100
11061101 function wasDeadlock() {
@@ -1110,33 +1105,31 @@
11111106 return $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newName (LIKE $oldName INCLUDING DEFAULTS)", $fname );
11121107 }
11131108
1114 - function timestamp( $ts=0 ) {
1115 - return wfTimestamp(TS_POSTGRES,$ts);
 1109+ function timestamp( $ts = 0 ) {
 1110+ return wfTimestamp( TS_POSTGRES, $ts );
11161111 }
11171112
11181113 /**
11191114 * Return aggregated value function call
11201115 */
1121 - function aggregateValue ($valuedata,$valuename='value') {
 1116+ function aggregateValue( $valuedata, $valuename = 'value' ) {
11221117 return $valuedata;
11231118 }
11241119
1125 -
11261120 function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) {
11271121 // Ignore errors during error handling to avoid infinite recursion
11281122 $ignore = $this->ignoreErrors( true );
11291123 $this->mErrorCount++;
11301124
1131 - if ($ignore || $tempIgnore) {
1132 - wfDebug("SQL ERROR (ignored): $error\n");
 1125+ if ( $ignore || $tempIgnore ) {
 1126+ wfDebug( "SQL ERROR (ignored): $error\n" );
11331127 $this->ignoreErrors( $ignore );
1134 - }
1135 - else {
 1128+ } else {
11361129 $message = "A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" .
11371130 "Query: $sql\n" .
11381131 "Function: $fname\n" .
11391132 "Error: $errno $error\n";
1140 - throw new DBUnexpectedError($this, $message);
 1133+ throw new DBUnexpectedError( $this, $message );
11411134 }
11421135 }
11431136
@@ -1144,7 +1137,7 @@
11451138 * @return string wikitext of a link to the server software's web site
11461139 */
11471140 public static function getSoftwareLink() {
1148 - return "[http://www.postgresql.org/ PostgreSQL]";
 1141+ return '[http://www.postgresql.org/ PostgreSQL]';
11491142 }
11501143
11511144 /**
@@ -1173,21 +1166,23 @@
11741167 */
11751168 function relationExists( $table, $types, $schema = false ) {
11761169 global $wgDBmwschema;
1177 - if ( !is_array( $types ) )
 1170+ if ( !is_array( $types ) ) {
11781171 $types = array( $types );
1179 - if ( !$schema )
 1172+ }
 1173+ if ( !$schema ) {
11801174 $schema = $wgDBmwschema;
 1175+ }
11811176 $etable = $this->addQuotes( $table );
11821177 $eschema = $this->addQuotes( $schema );
11831178 $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
11841179 . "WHERE c.relnamespace = n.oid AND c.relname = $etable AND n.nspname = $eschema "
1185 - . "AND c.relkind IN ('" . implode("','", $types) . "')";
 1180+ . "AND c.relkind IN ('" . implode( "','", $types ) . "')";
11861181 $res = $this->query( $SQL );
11871182 $count = $res ? $res->numRows() : 0;
11881183 return $count ? true : false;
11891184 }
11901185
1191 - /*
 1186+ /**
11921187 * For backward compatibility, this function checks both tables and
11931188 * views.
11941189 */
@@ -1208,35 +1203,45 @@
12091204 AND tgrelid=pg_class.oid
12101205 AND nspname=%s AND relname=%s AND tgname=%s
12111206 SQL;
1212 - $res = $this->query(sprintf($q,
1213 - $this->addQuotes($wgDBmwschema),
1214 - $this->addQuotes($table),
1215 - $this->addQuotes($trigger)));
1216 - if (!$res)
 1207+ $res = $this->query(
 1208+ sprintf(
 1209+ $q,
 1210+ $this->addQuotes( $wgDBmwschema ),
 1211+ $this->addQuotes( $table ),
 1212+ $this->addQuotes( $trigger )
 1213+ )
 1214+ );
 1215+ if ( !$res ) {
12171216 return null;
 1217+ }
12181218 $rows = $res->numRows();
12191219 return $rows;
12201220 }
12211221
12221222 function ruleExists( $table, $rule ) {
12231223 global $wgDBmwschema;
1224 - $exists = $this->selectField("pg_rules", "rulename",
1225 - array( "rulename" => $rule,
1226 - "tablename" => $table,
1227 - "schemaname" => $wgDBmwschema ) );
 1224+ $exists = $this->selectField( 'pg_rules', 'rulename',
 1225+ array(
 1226+ 'rulename' => $rule,
 1227+ 'tablename' => $table,
 1228+ 'schemaname' => $wgDBmwschema
 1229+ )
 1230+ );
12281231 return $exists === $rule;
12291232 }
12301233
12311234 function constraintExists( $table, $constraint ) {
12321235 global $wgDBmwschema;
1233 - $SQL = sprintf("SELECT 1 FROM information_schema.table_constraints ".
 1236+ $SQL = sprintf( "SELECT 1 FROM information_schema.table_constraints ".
12341237 "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
1235 - $this->addQuotes($wgDBmwschema),
1236 - $this->addQuotes($table),
1237 - $this->addQuotes($constraint));
1238 - $res = $this->query($SQL);
1239 - if (!$res)
 1238+ $this->addQuotes( $wgDBmwschema ),
 1239+ $this->addQuotes( $table ),
 1240+ $this->addQuotes( $constraint )
 1241+ );
 1242+ $res = $this->query( $SQL );
 1243+ if ( !$res ) {
12401244 return null;
 1245+ }
12411246 $rows = $res->numRows();
12421247 return $rows;
12431248 }
@@ -1245,7 +1250,7 @@
12461251 * Query whether a given schema exists. Returns the name of the owner
12471252 */
12481253 function schemaExists( $schema ) {
1249 - $eschema = preg_replace("/'/", "''", $schema);
 1254+ $eschema = preg_replace( "/'/", "''", $schema );
12501255 $SQL = "SELECT rolname FROM pg_catalog.pg_namespace n, pg_catalog.pg_roles r "
12511256 ."WHERE n.nspowner=r.oid AND n.nspname = '$eschema'";
12521257 $res = $this->query( $SQL );
@@ -1259,7 +1264,7 @@
12601265 }
12611266
12621267 function fieldInfo( $table, $field ) {
1263 - return PostgresField::fromText($this, $table, $field);
 1268+ return PostgresField::fromText( $this, $table, $field );
12641269 }
12651270
12661271 /**
@@ -1282,90 +1287,90 @@
12831288
12841289 // Make sure that we can write to the correct schema
12851290 // If not, Postgres will happily and silently go to the next search_path item
1286 - $ctest = "mediawiki_test_table";
1287 - $safeschema = $this->quote_ident($wgDBmwschema);
1288 - if ($this->tableExists($ctest, $wgDBmwschema)) {
1289 - $this->doQuery("DROP TABLE $safeschema.$ctest");
 1291+ $ctest = 'mediawiki_test_table';
 1292+ $safeschema = $this->quote_ident( $wgDBmwschema );
 1293+ if ( $this->tableExists( $ctest, $wgDBmwschema ) ) {
 1294+ $this->doQuery( "DROP TABLE $safeschema.$ctest" );
12901295 }
12911296 $SQL = "CREATE TABLE $safeschema.$ctest(a int)";
12921297 $olde = error_reporting( 0 );
1293 - $res = $this->doQuery($SQL);
 1298+ $res = $this->doQuery( $SQL );
12941299 error_reporting( $olde );
1295 - if (!$res) {
1296 - print "<b>FAILED</b>. Make sure that the user \"" . htmlspecialchars( $wgDBuser ) .
1297 - "\" can write to the schema \"" . htmlspecialchars( $wgDBmwschema ) . "\"</li>\n";
1298 - dieout(""); # Will close the main list <ul> and finish the page.
 1300+ if ( !$res ) {
 1301+ print '<b>FAILED</b>. Make sure that the user "' . htmlspecialchars( $wgDBuser ) .
 1302+ '" can write to the schema "' . htmlspecialchars( $wgDBmwschema ) . "\"</li>\n";
 1303+ dieout( '' ); # Will close the main list <ul> and finish the page.
12991304 }
1300 - $this->doQuery("DROP TABLE $safeschema.$ctest");
 1305+ $this->doQuery( "DROP TABLE $safeschema.$ctest" );
13011306
13021307 $res = $this->sourceFile( "../maintenance/postgres/tables.sql" );
1303 - if ($res === true) {
 1308+ if ( $res === true ) {
13041309 print " done.</li>\n";
13051310 } else {
13061311 print " <b>FAILED</b></li>\n";
13071312 dieout( htmlspecialchars( $res ) );
13081313 }
13091314
1310 - ## Update version information
1311 - $mwv = $this->addQuotes($wgVersion);
1312 - $pgv = $this->addQuotes($this->getServerVersion());
1313 - $pgu = $this->addQuotes($this->mUser);
1314 - $mws = $this->addQuotes($wgDBmwschema);
1315 - $tss = $this->addQuotes($wgDBts2schema);
1316 - $pgp = $this->addQuotes($wgDBport);
1317 - $dbn = $this->addQuotes($this->mDBname);
1318 - $ctype = $this->addQuotes( pg_fetch_result($this->doQuery("SHOW lc_ctype"),0,0) );
 1315+ # Update version information
 1316+ $mwv = $this->addQuotes( $wgVersion);
 1317+ $pgv = $this->addQuotes( $this->getServerVersion() );
 1318+ $pgu = $this->addQuotes( $this->mUser );
 1319+ $mws = $this->addQuotes( $wgDBmwschema );
 1320+ $tss = $this->addQuotes( $wgDBts2schema );
 1321+ $pgp = $this->addQuotes( $wgDBport );
 1322+ $dbn = $this->addQuotes( $this->mDBname );
 1323+ $ctype = $this->addQuotes( pg_fetch_result( $this->doQuery( 'SHOW lc_ctype' ), 0, 0 ) );
13191324
1320 - echo "<li>Populating interwiki table... ";
1321 - ## Avoid the non-standard "REPLACE INTO" syntax
 1325+ echo '<li>Populating interwiki table... ';
 1326+ # Avoid the non-standard "REPLACE INTO" syntax
13221327 $f = fopen( "../maintenance/interwiki.sql", 'r' );
13231328 if ( !$f ) {
1324 - print "<b>FAILED</b></li>";
1325 - dieout( "Could not find the interwiki.sql file" );
 1329+ print '<b>FAILED</b></li>';
 1330+ dieout( 'Could not find the interwiki.sql file' );
13261331 }
1327 - ## We simply assume it is already empty as we have just created it
 1332+ # We simply assume it is already empty as we have just created it
13281333 $SQL = "INSERT INTO interwiki(iw_prefix,iw_url,iw_local) VALUES ";
1329 - while ( ! feof( $f ) ) {
1330 - $line = fgets($f,1024);
 1334+ while ( !feof( $f ) ) {
 1335+ $line = fgets( $f, 1024 );
13311336 $matches = array();
1332 - if (!preg_match('/^\s*(\(.+?),(\d)\)/', $line, $matches)) {
 1337+ if ( !preg_match( '/^\s*(\(.+?),(\d)\)/', $line, $matches ) ) {
13331338 continue;
13341339 }
1335 - $this->query("$SQL $matches[1],$matches[2])");
 1340+ $this->query( "$SQL $matches[1],$matches[2])" );
13361341 }
13371342 print " successfully populated.</li>\n";
13381343
1339 - $this->doQuery("COMMIT");
 1344+ $this->doQuery( 'COMMIT' );
13401345 }
13411346
13421347 function encodeBlob( $b ) {
1343 - return new Blob ( pg_escape_bytea( $this->mConn, $b ) ) ;
 1348+ return new Blob( pg_escape_bytea( $this->mConn, $b ) );
13441349 }
13451350
13461351 function decodeBlob( $b ) {
1347 - if ($b instanceof Blob) {
 1352+ if ( $b instanceof Blob ) {
13481353 $b = $b->fetch();
13491354 }
13501355 return pg_unescape_bytea( $b );
13511356 }
13521357
1353 - function strencode( $s ) { ## Should not be called by us
 1358+ function strencode( $s ) { # Should not be called by us
13541359 return pg_escape_string( $this->mConn, $s );
13551360 }
13561361
13571362 function addQuotes( $s ) {
13581363 if ( is_null( $s ) ) {
13591364 return 'NULL';
1360 - } else if ( is_bool( $s ) ) {
 1365+ } elseif ( is_bool( $s ) ) {
13611366 return intval( $s );
1362 - } else if ($s instanceof Blob) {
1363 - return "'".$s->fetch($s)."'";
 1367+ } elseif ( $s instanceof Blob ) {
 1368+ return "'" . $s->fetch( $s ) . "'";
13641369 }
13651370 return "'" . pg_escape_string( $this->mConn, $s ) . "'";
13661371 }
13671372
13681373 function quote_ident( $s ) {
1369 - return '"' . preg_replace( '/"/', '""', $s) . '"';
 1374+ return '"' . preg_replace( '/"/', '""', $s ) . '"';
13701375 }
13711376
13721377 /**
@@ -1379,15 +1384,14 @@
13801385 * @return string SQL string
13811386 */
13821387 protected function replaceVars( $ins ) {
1383 -
13841388 $ins = parent::replaceVars( $ins );
13851389
1386 - if ($this->numeric_version >= 8.3) {
 1390+ if ( $this->numeric_version >= 8.3 ) {
13871391 // Thanks for not providing backwards-compatibility, 8.3
13881392 $ins = preg_replace( "/to_tsvector\s*\(\s*'default'\s*,/", 'to_tsvector(', $ins );
13891393 }
13901394
1391 - if ($this->numeric_version <= 8.1) { // Our minimum version
 1395+ if ( $this->numeric_version <= 8.1 ) { // Our minimum version
13921396 $ins = str_replace( 'USING gin', 'USING gist', $ins );
13931397 }
13941398
@@ -1414,19 +1418,31 @@
14151419 }
14161420 }
14171421
1418 - if ( isset( $options['GROUP BY'] ) ) $preLimitTail .= " GROUP BY " . $options['GROUP BY'];
1419 - if ( isset( $options['HAVING'] ) ) $preLimitTail .= " HAVING {$options['HAVING']}";
1420 - if ( isset( $options['ORDER BY'] ) ) $preLimitTail .= " ORDER BY " . $options['ORDER BY'];
 1422+ if ( isset( $options['GROUP BY'] ) ) {
 1423+ $preLimitTail .= ' GROUP BY ' . $options['GROUP BY'];
 1424+ }
 1425+ if ( isset( $options['HAVING'] ) ) {
 1426+ $preLimitTail .= " HAVING {$options['HAVING']}";
 1427+ }
 1428+ if ( isset( $options['ORDER BY'] ) ) {
 1429+ $preLimitTail .= ' ORDER BY ' . $options['ORDER BY'];
 1430+ }
14211431
1422 - //if (isset($options['LIMIT'])) {
1423 - // $tailOpts .= $this->limitResult('', $options['LIMIT'],
1424 - // isset($options['OFFSET']) ? $options['OFFSET']
1425 - // : false);
 1432+ //if ( isset( $options['LIMIT'] ) ) {
 1433+ // $tailOpts .= $this->limitResult( '', $options['LIMIT'],
 1434+ // isset( $options['OFFSET'] ) ? $options['OFFSET']
 1435+ // : false );
14261436 //}
14271437
1428 - if ( isset( $noKeyOptions['FOR UPDATE'] ) ) $postLimitTail .= ' FOR UPDATE';
1429 - if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) $postLimitTail .= ' LOCK IN SHARE MODE';
1430 - if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) $startOpts .= 'DISTINCT';
 1438+ if ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
 1439+ $postLimitTail .= ' FOR UPDATE';
 1440+ }
 1441+ if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) {
 1442+ $postLimitTail .= ' LOCK IN SHARE MODE';
 1443+ }
 1444+ if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) {
 1445+ $startOpts .= 'DISTINCT';
 1446+ }
14311447
14321448 return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
14331449 }
@@ -1446,6 +1462,6 @@
14471463 }
14481464
14491465 public function getSearchEngine() {
1450 - return "SearchPostgres";
 1466+ return 'SearchPostgres';
14511467 }
14521468 } // end DatabasePostgres class

Status & tagging log