Merge "Add the ability to know if fullscreen is available"
[lhc/web/wiklou.git] / includes / db / DatabasePostgres.php
index 3e58c66..c8830d3 100644 (file)
@@ -381,7 +381,7 @@ class DatabasePostgres extends DatabaseBase {
                global $wgDBport;
 
                if ( !strlen( $user ) ) { # e.g. the class is being loaded
-                       return;
+                       return null;
                }
 
                $this->mServer = $server;
@@ -819,6 +819,33 @@ __INDEXATTR__;
                return $res->numRows() > 0;
        }
 
+       /**
+        * Change the FOR UPDATE option as necessary based on the join conditions. Then pass
+        * to the parent function to get the actual SQL text.
+        *
+        * In Postgres when using FOR UPDATE, only the main table and tables that are inner joined
+        * can be locked. That means tables in an outer join cannot be FOR UPDATE locked. Trying to do
+        * so causes a DB error. This wrapper checks which tables can be locked and adjusts it accordingly.
+        */
+       function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__,
+               $options = array(), $join_conds = array()
+       ) {
+               if ( is_array( $options ) ) {
+                       $forUpdateKey = array_search( 'FOR UPDATE', $options );
+                       if ( $forUpdateKey !== false && $join_conds ) {
+                               unset( $options[$forUpdateKey] );
+
+                               foreach ( $join_conds as $table_cond => $join_cond ) {
+                                       if ( 0 === preg_match( '/^(?:LEFT|RIGHT|FULL)(?: OUTER)? JOIN$/i', $join_cond[0] ) ) {
+                                               $options['FOR UPDATE'][] = $table_cond;
+                                       }
+                               }
+                       }
+               }
+
+               return parent::selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds );
+       }
+
        /**
         * INSERT wrapper, inserts an array into a table
         *
@@ -1038,7 +1065,7 @@ __INDEXATTR__;
 
        /**
         * Return the next in a sequence, save the value for retrieval via insertId()
-        * 
+        *
         * @param string $seqName
         * @return int|null
         */
@@ -1176,7 +1203,7 @@ __INDEXATTR__;
         * @return string Wikitext of a link to the server software's web site
         */
        public function getSoftwareLink() {
-               return '[http://www.postgresql.org/ PostgreSQL]';
+               return '[{{int:version-db-postgres-url}} PostgreSQL]';
        }
 
        /**
@@ -1537,9 +1564,12 @@ SQL;
                //              : false );
                //}
 
-               if ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
+               if ( isset( $options['FOR UPDATE'] ) ) {
+                       $postLimitTail .= ' FOR UPDATE OF ' . implode( ', ', $options['FOR UPDATE'] );
+               } elseif ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
                        $postLimitTail .= ' FOR UPDATE';
                }
+
                if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) {
                        $startOpts .= 'DISTINCT';
                }
@@ -1547,9 +1577,6 @@ SQL;
                return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
        }
 
-       function setFakeMaster( $enabled = true ) {
-       }
-
        function getDBname() {
                return $this->mDBname;
        }