use Wikimedia\Timestamp\ConvertibleTimestamp;
use Wikimedia\WaitConditionLoop;
-use Wikimedia;
+use Wikimedia\AtEase\AtEase;
use Exception;
/**
);
}
+ $this->close();
+
$this->server = $server;
$this->user = $user;
$this->password = $password;
}
$this->connectString = $this->makeConnectionString( $connectVars );
- $this->close();
- $this->installErrorHandler();
+ $this->installErrorHandler();
try {
// Use new connections to let LoadBalancer/LBFactory handle reuse
$this->conn = pg_connect( $this->connectString, PGSQL_CONNECT_FORCE_NEW );
$this->restoreErrorHandler();
throw $ex;
}
-
$phpError = $this->restoreErrorHandler();
if ( !$this->conn ) {
}
public function freeResult( $res ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
- Wikimedia\suppressWarnings();
- $ok = pg_free_result( $res );
- Wikimedia\restoreWarnings();
+ AtEase::suppressWarnings();
+ $ok = pg_free_result( ResultWrapper::unwrap( $res ) );
+ AtEase::restoreWarnings();
if ( !$ok ) {
throw new DBUnexpectedError( $this, "Unable to free Postgres result\n" );
}
}
public function fetchObject( $res ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
- Wikimedia\suppressWarnings();
- $row = pg_fetch_object( $res );
- Wikimedia\restoreWarnings();
+ AtEase::suppressWarnings();
+ $row = pg_fetch_object( ResultWrapper::unwrap( $res ) );
+ AtEase::restoreWarnings();
# @todo FIXME: HACK HACK HACK HACK debug
# @todo hashar: not sure if the following test really trigger if the object
}
public function fetchRow( $res ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
- Wikimedia\suppressWarnings();
- $row = pg_fetch_array( $res );
- Wikimedia\restoreWarnings();
+ AtEase::suppressWarnings();
+ $row = pg_fetch_array( ResultWrapper::unwrap( $res ) );
+ AtEase::restoreWarnings();
$conn = $this->getBindingHandle();
if ( pg_last_error( $conn ) ) {
return 0;
}
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
- Wikimedia\suppressWarnings();
- $n = pg_num_rows( $res );
- Wikimedia\restoreWarnings();
+ AtEase::suppressWarnings();
+ $n = pg_num_rows( ResultWrapper::unwrap( $res ) );
+ AtEase::restoreWarnings();
$conn = $this->getBindingHandle();
if ( pg_last_error( $conn ) ) {
}
public function numFields( $res ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
-
- return pg_num_fields( $res );
+ return pg_num_fields( ResultWrapper::unwrap( $res ) );
}
public function fieldName( $res, $n ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
-
- return pg_field_name( $res, $n );
+ return pg_field_name( ResultWrapper::unwrap( $res ), $n );
}
public function insertId() {
}
public function dataSeek( $res, $row ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
-
- return pg_result_seek( $res, $row );
+ return pg_result_seek( ResultWrapper::unwrap( $res ), $row );
}
public function lastError() {
}
/**
+ * @param string $prefix Only show tables with this prefix, e.g. mw_
+ * @param string $fname Calling function name
+ * @return string[]
* @suppress SecurityCheck-SQLInjection array_map not recognized T204911
*/
- public function listTables( $prefix = null, $fname = __METHOD__ ) {
+ public function listTables( $prefix = '', $fname = __METHOD__ ) {
$eschemas = implode( ',', array_map( [ $this, 'addQuotes' ], $this->getCoreSchemas() ) );
$result = $this->query(
"SELECT DISTINCT tablename FROM pg_tables WHERE schemaname IN ($eschemas)", $fname );
foreach ( $result as $table ) {
$vars = get_object_vars( $table );
$table = array_pop( $vars );
- if ( !$prefix || strpos( $table, $prefix ) === 0 ) {
+ if ( $prefix == '' || strpos( $table, $prefix ) === 0 ) {
$endArray[] = $table;
}
}
* @param string $desiredSchema
*/
public function determineCoreSchema( $desiredSchema ) {
- if ( $this->trxLevel ) {
+ if ( $this->trxLevel() ) {
// We do not want the schema selection to change on ROLLBACK or INSERT SELECT.
// See https://www.postgresql.org/docs/8.3/sql-set.html
throw new DBUnexpectedError(
$this,
- __METHOD__ . ": a transaction is currently active."
+ __METHOD__ . ": a transaction is currently active"
);
}
* @return string
*/
public function fieldType( $res, $index ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
-
- return pg_field_type( $res, $index );
+ return pg_field_type( ResultWrapper::unwrap( $res ), $index );
}
public function encodeBlob( $b ) {