$n->conname = $row->conname;
$n->has_default = ( $row->atthasdef === 't' );
$n->default = $row->adsrc;
+
return $n;
}
function conname() {
return $this->conname;
}
+
/**
* @since 1.19
*/
return false;
}
}
-
}
/**
}
$old = next( $this->mCurrentState );
$new = next( $this->mNewState );
-
}
}
}
$this->didbegin = false;
/* If we are not in a transaction, we need to be for savepoint trickery */
if ( !$dbw->trxLevel() ) {
- $dbw->begin( "FOR SAVEPOINT" );
- $this->didbegin = true;
+ $dbw->begin( "FOR SAVEPOINT" );
+ $this->didbegin = true;
}
}
global $wgDebugDBTransactions;
if ( $this->dbw->doQuery( $keyword . " " . $this->id ) !== false ) {
if ( $wgDebugDBTransactions ) {
- wfDebug( sprintf ( $msg_ok, $this->id ) );
+ wfDebug( sprintf( $msg_ok, $this->id ) );
}
} else {
- wfDebug( sprintf ( $msg_failed, $this->id ) );
+ wfDebug( sprintf( $msg_failed, $this->id ) );
}
}
function cascadingDeletes() {
return true;
}
+
function cleanupTriggers() {
return true;
}
+
function strictIPs() {
return true;
}
+
function realTimestamps() {
return true;
}
+
function implicitGroupby() {
return false;
}
+
function implicitOrderby() {
return false;
}
+
function searchableIPs() {
return true;
}
+
function functionalIndexes() {
return true;
}
function hasConstraint( $name ) {
$SQL = "SELECT 1 FROM pg_catalog.pg_constraint c, pg_catalog.pg_namespace n WHERE c.connamespace = n.oid AND conname = '" .
- pg_escape_string( $this->mConn, $name ) . "' AND n.nspname = '" . pg_escape_string( $this->mConn, $this->getCoreSchema() ) . "'";
+ pg_escape_string( $this->mConn, $name ) . "' AND n.nspname = '" . pg_escape_string( $this->mConn, $this->getCoreSchema() ) . "'";
$res = $this->doQuery( $SQL );
+
return $this->numRows( $res );
}
foreach ( $vars as $name => $value ) {
$s .= "$name='" . str_replace( "'", "\\'", $value ) . "' ";
}
+
return $s;
}
if ( pg_result_error( $this->mLastResult ) ) {
return false;
}
+
return $this->mLastResult;
}
protected function dumpError() {
- $diags = array( PGSQL_DIAG_SEVERITY,
- PGSQL_DIAG_SQLSTATE,
- PGSQL_DIAG_MESSAGE_PRIMARY,
- PGSQL_DIAG_MESSAGE_DETAIL,
- PGSQL_DIAG_MESSAGE_HINT,
- PGSQL_DIAG_STATEMENT_POSITION,
- PGSQL_DIAG_INTERNAL_POSITION,
- PGSQL_DIAG_INTERNAL_QUERY,
- PGSQL_DIAG_CONTEXT,
- PGSQL_DIAG_SOURCE_FILE,
- PGSQL_DIAG_SOURCE_LINE,
- PGSQL_DIAG_SOURCE_FUNCTION );
+ $diags = array(
+ PGSQL_DIAG_SEVERITY,
+ PGSQL_DIAG_SQLSTATE,
+ PGSQL_DIAG_MESSAGE_PRIMARY,
+ PGSQL_DIAG_MESSAGE_DETAIL,
+ PGSQL_DIAG_MESSAGE_HINT,
+ PGSQL_DIAG_STATEMENT_POSITION,
+ PGSQL_DIAG_INTERNAL_POSITION,
+ PGSQL_DIAG_INTERNAL_QUERY,
+ PGSQL_DIAG_CONTEXT,
+ PGSQL_DIAG_SOURCE_FILE,
+ PGSQL_DIAG_SOURCE_LINE,
+ PGSQL_DIAG_SOURCE_FUNCTION
+ );
foreach ( $diags as $d ) {
wfDebug( sprintf( "PgSQL ERROR(%d): %s\n", $d, pg_result_error_field( $this->mLastResult, $d ) ) );
}
/* Check for constraint violation */
if ( $errno === '23505' ) {
parent::reportQueryError( $error, $errno, $sql, $fname, $tempIgnore );
+
return;
}
}
if ( pg_last_error( $this->mConn ) ) {
throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) );
}
+
return $row;
}
if ( pg_last_error( $this->mConn ) ) {
throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) );
}
+
return $row;
}
if ( pg_last_error( $this->mConn ) ) {
throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) );
}
+
return $n;
}
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
}
+
return pg_num_fields( $res );
}
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
}
+
return pg_field_name( $res, $n );
}
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
}
+
return pg_result_seek( $res, $row );
}
return 'No database connection';
}
}
+
function lastErrno() {
if ( $this->mLastResult ) {
return pg_result_error_field( $this->mLastResult, PGSQL_DIAG_SQLSTATE );
if ( empty( $this->mLastResult ) ) {
return 0;
}
+
return pg_affected_rows( $this->mLastResult );
}
$rows = $count[1];
}
}
+
return $rows;
}
return $row;
}
}
+
return false;
}
} else {
return null;
}
+
return $a;
}
foreach ( $res as $row ) {
return true;
}
+
return false;
}
* @return bool
*/
function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
- $insertOptions = array(), $selectOptions = array() )
- {
+ $insertOptions = array(), $selectOptions = array() ) {
$destTable = $this->tableName( $destTable );
if ( !is_array( $insertOptions ) ) {
}
$sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
- " SELECT $startOpts " . implode( ',', $varMap ) .
- " FROM $srcTable $useIndex";
+ " SELECT $startOpts " . implode( ',', $varMap ) .
+ " FROM $srcTable $useIndex";
if ( $conds != '*' ) {
$sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
$res = $this->query( "SELECT nextval('$safeseq')" );
$row = $this->fetchRow( $res );
$this->mInsertId = $row[0];
+
return $this->mInsertId;
}
$res = $this->query( "SELECT currval('$safeseq')" );
$row = $this->fetchRow( $res );
$currval = $row[0];
+
return $currval;
}
} else {
$size = $row->size;
}
+
return $size;
}
function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ) {
$newName = $this->addIdentifierQuotes( $newName );
$oldName = $this->addIdentifierQuotes( $oldName );
+
return $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newName (LIKE $oldName INCLUDING DEFAULTS)", $fname );
}
$text, $match, 0, $offset );
$offset += strlen( $match[0] );
$output[] = ( '"' != $match[1][0]
- ? $match[1]
- : stripcslashes( substr( $match[1], 1, -1 ) ) );
+ ? $match[1]
+ : stripcslashes( substr( $match[1], 1, -1 ) ) );
if ( '},' == $match[3] ) {
return $output;
}
$offset = $this->pg_array_parse( $text, $output, $limit, $offset + 1 );
}
} while ( $limit > $offset );
+
return $output;
}
function getCurrentSchema() {
$res = $this->query( "SELECT current_schema()", __METHOD__ );
$row = $this->fetchRow( $res );
+
return $row[0];
}
$res = $this->query( "SELECT current_schemas(false)", __METHOD__ );
$row = $this->fetchRow( $res );
$schemas = array();
+
/* PHP pgsql support does not support array type, "{a,b}" string is returned */
+
return $this->pg_array_parse( $row[0], $schemas );
}
function getSearchPath() {
$res = $this->query( "SHOW search_path", __METHOD__ );
$row = $this->fetchRow( $res );
+
/* PostgreSQL returns SHOW values as strings */
+
return explode( ",", $row[0] );
}
*/
$search_path = $this->getSearchPath();
array_unshift( $search_path,
- $this->addIdentifierQuotes( $desired_schema ));
+ $this->addIdentifierQuotes( $desired_schema ) );
$this->setSearchPath( $search_path );
$this->mCoreSchema = $desired_schema;
wfDebug( "Schema \"" . $desired_schema . "\" added to the search path\n" );
$this->numeric_version = pg_parameter_status( $this->mConn, 'server_version' );
}
}
+
return $this->numeric_version;
}
. "AND c.relkind IN ('" . implode( "','", $types ) . "')";
$res = $this->query( $SQL );
$count = $res ? $res->numRows() : 0;
+
return (bool)$count;
}
return null;
}
$rows = $res->numRows();
+
return $rows;
}
'schemaname' => $this->getCoreSchema()
)
);
+
return $exists === $rule;
}
function constraintExists( $table, $constraint ) {
$SQL = sprintf( "SELECT 1 FROM information_schema.table_constraints " .
- "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
+ "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
$this->addQuotes( $this->getCoreSchema() ),
$this->addQuotes( $table ),
$this->addQuotes( $constraint )
return null;
}
$rows = $res->numRows();
+
return $rows;
}
function schemaExists( $schema ) {
$exists = $this->selectField( '"pg_catalog"."pg_namespace"', 1,
array( 'nspname' => $schema ), __METHOD__ );
+
return (bool)$exists;
}
function roleExists( $roleName ) {
$exists = $this->selectField( '"pg_catalog"."pg_roles"', 1,
array( 'rolname' => $roleName ), __METHOD__ );
+
return (bool)$exists;
}
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
}
+
return pg_field_type( $res, $index );
}
if ( $b instanceof Blob ) {
$b = $b->fetch();
}
+
return pg_unescape_bytea( $b );
}
} elseif ( $s instanceof Blob ) {
return "'" . $s->fetch( $s ) . "'";
}
+
return "'" . pg_escape_string( $this->mConn, $s ) . "'";
}
$delimiter, $table, $field, $conds = '', $options = array(), $join_conds = array()
) {
$fld = "array_to_string(array_agg($field)," . $this->addQuotes( $delimiter ) . ')';
+
return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')';
}
if ( substr( $newLine, 0, 4 ) == '$mw$' ) {
if ( $this->delimiter ) {
$this->delimiter = false;
- }
- else {
+ } else {
$this->delimiter = ';';
}
}
+
return parent::streamStatementEnd( $sql, $newLine );
}
$result = $this->query( "SELECT (CASE(pg_try_advisory_lock($key))
WHEN 'f' THEN 'f' ELSE pg_advisory_unlock($key) END) AS lockstatus", $method );
$row = $this->fetchObject( $result );
+
return ( $row->lockstatus === 't' );
}
}
}
wfDebug( __METHOD__ . " failed to acquire lock\n" );
+
return false;
}
$key = $this->addQuotes( $this->bigintFromLockName( $lockName ) );
$result = $this->query( "SELECT pg_advisory_unlock($key) as lockstatus", $method );
$row = $this->fetchObject( $result );
+
return ( $row->lockstatus === 't' );
}