Add 3D filetype for STL files
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabasePostgres.php
index 109f848..5049f9b 100644 (file)
  * @file
  * @ingroup Database
  */
+namespace Wikimedia\Rdbms;
+
+use Wikimedia\Timestamp\ConvertibleTimestamp;
 use Wikimedia\WaitConditionLoop;
-use Wikimedia\Rdbms\Blob;
-use Wikimedia\Rdbms\PostgresBlob;
-use Wikimedia\Rdbms\PostgresField;
+use MediaWiki;
+use DBUnexpectedError;
+use DBConnectionError;
+use Exception;
 
 /**
  * @ingroup Database
@@ -857,10 +861,10 @@ __INDEXATTR__;
         *
         * @since 1.19
         * @param string $text Postgreql array returned in a text form like {a,b}
-        * @param string $output
+        * @param string[] $output
         * @param int|bool $limit
         * @param int $offset
-        * @return string
+        * @return string[]
         */
        private function pg_array_parse( $text, &$output, $limit = false, $offset = 1 ) {
                if ( false === $limit ) {
@@ -985,7 +989,7 @@ __INDEXATTR__;
                                /**
                                 * Prepend our schema (e.g. 'mediawiki') in front
                                 * of the search path
-                                * Fixes bug 15816
+                                * Fixes T17816
                                 */
                                $search_path = $this->getSearchPath();
                                array_unshift( $search_path,
@@ -1026,7 +1030,7 @@ __INDEXATTR__;
                                // Normal client
                                $this->numericVersion = $versionInfo['server'];
                        } else {
-                               // Bug 16937: broken pgsql extension from PHP<5.3
+                               // T18937: broken pgsql extension from PHP<5.3
                                $this->numericVersion = pg_parameter_status( $conn, 'server_version' );
                        }
                }
@@ -1079,8 +1083,8 @@ __INDEXATTR__;
                $q = <<<SQL
        SELECT 1 FROM pg_class, pg_namespace, pg_trigger
                WHERE relnamespace=pg_namespace.oid AND relkind='r'
-                         AND tgrelid=pg_class.oid
-                         AND nspname=%s AND relname=%s AND tgname=%s
+                       AND tgrelid=pg_class.oid
+                       AND nspname=%s AND relname=%s AND tgname=%s
 SQL;
                $res = $this->query(
                        sprintf(
@@ -1252,12 +1256,6 @@ SQL;
 
                $preLimitTail .= $this->makeOrderBy( $options );
 
-               // if ( isset( $options['LIMIT'] ) ) {
-               //      $tailOpts .= $this->limitResult( '', $options['LIMIT'],
-               //              isset( $options['OFFSET'] ) ? $options['OFFSET']
-               //              : false );
-               // }
-
                if ( isset( $options['FOR UPDATE'] ) ) {
                        $postLimitTail .= ' FOR UPDATE OF ' .
                                implode( ', ', array_map( [ $this, 'tableName' ], $options['FOR UPDATE'] ) );
@@ -1309,6 +1307,33 @@ SQL;
                return parent::streamStatementEnd( $sql, $newLine );
        }
 
+       public function doLockTables( array $read, array $write, $method ) {
+               $tablesWrite = [];
+               foreach ( $write as $table ) {
+                       $tablesWrite[] = $this->tableName( $table );
+               }
+               $tablesRead = [];
+               foreach ( $read as $table ) {
+                       $tablesRead[] = $this->tableName( $table );
+               }
+
+               // Acquire locks for the duration of the current transaction...
+               if ( $tablesWrite ) {
+                       $this->query(
+                               'LOCK TABLE ONLY ' . implode( ',', $tablesWrite ) . ' IN EXCLUSIVE MODE',
+                               $method
+                       );
+               }
+               if ( $tablesRead ) {
+                       $this->query(
+                               'LOCK TABLE ONLY ' . implode( ',', $tablesRead ) . ' IN SHARE MODE',
+                               $method
+                       );
+               }
+
+               return true;
+       }
+
        public function lockIsFree( $lockName, $method ) {
                // http://www.postgresql.org/docs/8.2/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS
                $key = $this->addQuotes( $this->bigintFromLockName( $lockName ) );
@@ -1360,6 +1385,8 @@ SQL;
         * @return string Integer
         */
        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 );
        }
 }
+
+class_alias( DatabasePostgres::class, 'DatabasePostgres' );