Cleanup after the switch of Database::query() to return ResultWrapper instead of resource. * Soft-deprecate the IResultWrapper accessors in IDatabase. * Move relevant DBMS-specific functionality to ResultWrapper subclasses. The deprecated methods in IResultWrapper become short and simple. ResultWrapper is now abstract (b/c break). * Move the implementation of fieldName(), numFields() and one of the fieldInfo() implementations to the ResultWrapper subclass in order to avoid ResultWrapper::unwrap() calls. * Make Database::doQuery() return a ResultWrapper subclass instead of underlying result data, so that the Database parent class does not need to be aware of wrapper construction. * Hard-deprecate ResultWrapper::unwrap(), DatabaseMysqlBase::fieldType(), DatabasePostgres::fieldType(). * Fix the inefficient seeking method in SQLite. * Make FakeResultWrapper extend ResultWrapper with an implementation similar to the SQLite one. This is possible because ResultWrapper does not depend on IDatabase anymore. * Resolve fixme in DatabasePostgres: from studying the source, neither pg_fetch_object() nor pg_num_rows() can set an error retrievable with pg_last_error(). Removed unnecessary warning suppression. * ResultWrapperTest didn't make sense as a unit test anymore, so I adapted it as an integration test against the current DBMS. This change also means that ResultWrapper::key() always gives the correct offset, even if Iterator methods are not being used. Bug: T286694 Change-Id: I935835316c0bd7d3d061bd8fde9c9ce99ce756ec
72 lines
1.5 KiB
PHP
72 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Wikimedia\Rdbms;
|
|
|
|
use Wikimedia\AtEase\AtEase;
|
|
|
|
class PostgresResultWrapper extends ResultWrapper {
|
|
/** @var DatabasePostgres */
|
|
private $db;
|
|
/** @var resource */
|
|
private $handle;
|
|
/** @var resource */
|
|
private $result;
|
|
|
|
/**
|
|
* @internal
|
|
* @param DatabasePostgres $db
|
|
* @param resource $handle
|
|
* @param resource $result
|
|
*/
|
|
public function __construct( DatabasePostgres $db, $handle, $result ) {
|
|
$this->db = $db;
|
|
$this->handle = $handle;
|
|
$this->result = $result;
|
|
}
|
|
|
|
/**
|
|
* Get the underlying result object or array
|
|
*
|
|
* @since 1.37
|
|
* @deprecated since 1.37 Only exists to support deprecated methods
|
|
* @return resource
|
|
*/
|
|
public function getInternalResult() {
|
|
return $this->result;
|
|
}
|
|
|
|
protected function doNumRows() {
|
|
return pg_num_rows( $this->result );
|
|
}
|
|
|
|
protected function doFetchObject() {
|
|
AtEase::suppressWarnings();
|
|
$row = pg_fetch_object( $this->result );
|
|
AtEase::restoreWarnings();
|
|
return $row;
|
|
}
|
|
|
|
protected function doFetchRow() {
|
|
AtEase::suppressWarnings();
|
|
$row = pg_fetch_array( $this->result );
|
|
AtEase::restoreWarnings();
|
|
return $row;
|
|
}
|
|
|
|
protected function doSeek( $pos ) {
|
|
pg_result_seek( $this->result, $pos );
|
|
}
|
|
|
|
protected function doFree() {
|
|
return pg_free_result( $this->result );
|
|
}
|
|
|
|
protected function doGetFieldNames() {
|
|
$names = [];
|
|
$n = pg_num_fields( $this->result );
|
|
for ( $i = 0; $i < $n; $i++ ) {
|
|
$names[] = pg_field_name( $this->result, $i );
|
|
}
|
|
return $names;
|
|
}
|
|
}
|