* @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
*
* @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 ) {
/**
* 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,
// 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' );
}
}
$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(
$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'] ) );
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 ) );
* @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' );