#
# Hashar
-require_once( "Database.php" );
+require_once( 'Database.php' );
class DatabasePgsql extends Database {
var $mInsertId = NULL;
$success = false;
- if ( "" != $dbName ) {
+ if ( '' != $dbName ) {
# start a database connection
@$this->mConn = pg_connect("host=$server dbname=$dbName user=$user password=$password");
if ( $this->mConn == false ) {
return $this->mLastResult=pg_query( $this->mConn , $sql);
}
- function queryIgnore( $sql, $fname = "" ) {
+ function queryIgnore( $sql, $fname = '' ) {
return $this->query( $sql, $fname, true );
}
# hashar : not sure if the following test really trigger if the object
# fetching failled.
if( pg_last_error($this->mConn) ) {
- wfDebugDieBacktrace( "SQL error: " . htmlspecialchars( pg_last_error($this->mConn) ) );
+ wfDebugDieBacktrace( 'SQL error: ' . htmlspecialchars( pg_last_error($this->mConn) ) );
}
return $row;
}
function fetchRow( $res ) {
@$row = pg_fetch_array( $res );
if( pg_last_error($this->mConn) ) {
- wfDebugDieBacktrace( "SQL error: " . htmlspecialchars( pg_last_error($this->mConn) ) );
+ wfDebugDieBacktrace( 'SQL error: ' . htmlspecialchars( pg_last_error($this->mConn) ) );
}
return $row;
}
function numRows( $res ) {
@$n = pg_num_rows( $res );
if( pg_last_error($this->mConn) ) {
- wfDebugDieBacktrace( "SQL error: " . htmlspecialchars( pg_last_error($this->mConn) ) );
+ wfDebugDieBacktrace( 'SQL error: ' . htmlspecialchars( pg_last_error($this->mConn) ) );
}
return $n;
}
# Returns information about an index
# If errors are explicitly ignored, returns NULL on failure
- function indexInfo( $table, $index, $fname = "Database::indexExists" )
+ function indexInfo( $table, $index, $fname = 'Database::indexExists' )
{
$sql = "SELECT indexname FROM pg_indexes WHERE tablename='$table'";
$res = $this->query( $sql, $fname );
function fieldInfo( $table, $field )
{
- wfDebugDieBacktrace( "Database::fieldInfo() error : mysql_fetch_field() not implemented for postgre" );
+ wfDebugDieBacktrace( 'Database::fieldInfo() error : mysql_fetch_field() not implemented for postgre' );
/*
$res = $this->query( "SELECT * FROM '$table' LIMIT 1" );
$n = pg_num_fields( $res );
return false;*/
}
- function insertArray( $table, $a, $fname = "Database::insertArray", $options = array() ) {
+ function insertArray( $table, $a, $fname = 'Database::insertArray', $options = array() ) {
# PostgreSQL doesn't support options
# We have a go at faking one of them
# TODO: DELAYED, LOW_PRIORITY
- # IGNORE is performed using single-row inserts, ignoring errors in each
- if ( in_array( 'IGNORE', $options ) ) {
- # FIXME: need some way to distiguish between key collision and other types of error
+ if ( !is_array($options))
+ $options = array($options);
+
+ if ( in_array( 'IGNORE', $options ) )
$oldIgnore = $this->ignoreErrors( true );
- if ( !is_array( reset( $a ) ) ) {
- $a = array( $a );
- }
- foreach ( $a as $row ) {
- parent::insertArray( $table, $row, $fname, array() );
- }
- $this->ignoreErrors( $oldIgnore );
- $retVal = true;
- } else {
- $retVal = parent::insertArray( $table, $a, $fname, array() );
+
+ # IGNORE is performed using single-row inserts, ignoring errors in each
+ # FIXME: need some way to distiguish between key collision and other types of error
+ $oldIgnore = $this->ignoreErrors( true );
+ if ( !is_array( reset( $a ) ) ) {
+ $a = array( $a );
+ }
+ foreach ( $a as $row ) {
+ parent::insertArray( $table, $row, $fname, array() );
}
+ $this->ignoreErrors( $oldIgnore );
+ $retVal = true;
+
+ if ( in_array( 'IGNORE', $options ) )
+ $this->ignoreErrors( $oldIgnore );
+
return $retVal;
}
function startTimer( $timeout )
{
global $IP;
- wfDebugDieBacktrace( "Database::startTimer() error : mysql_thread_id() not implemented for postgre" );
+ wfDebugDieBacktrace( 'Database::startTimer() error : mysql_thread_id() not implemented for postgre' );
/*$tid = mysql_thread_id( $this->mConn );
exec( "php $IP/killthread.php $timeout $tid &>/dev/null &" );*/
}
# Return the next in a sequence, save the value for retrieval via insertId()
function nextSequenceValue( $seqName ) {
- $value = $this->getField(""," nextval('" . $seqName . "')");
+ $value = $this->getField(''," nextval('" . $seqName . "')");
$this->mInsertId = $value;
return $value;
}
# It may be more efficient to leave off unique indexes which are unlikely to collide.
# However if you do this, you run the risk of encountering errors which wouldn't have
# occurred in MySQL
- function replace( $table, $uniqueIndexes, $rows, $fname = "Database::replace" ) {
+ function replace( $table, $uniqueIndexes, $rows, $fname = 'Database::replace' ) {
$table = $this->tableName( $table );
# Single row case
if ( $first ) {
$first = false;
} else {
- $sql .= ") OR (";
+ $sql .= ') OR (';
}
if ( is_array( $index ) ) {
$first2 = true;
if ( $first2 ) {
$first2 = false;
} else {
- $sql .= " AND ";
+ $sql .= ' AND ';
}
- $sql .= "$col=" . $this->addQuotes( $row[$col] );
+ $sql .= $col.'=' . $this->addQuotes( $row[$col] );
}
} else {
- $sql .= "$index=" . $this->addQuotes( $row[$index] );
+ $sql .= $index.'=' . $this->addQuotes( $row[$index] );
}
}
- $sql .= ")";
+ $sql .= ')';
$this->query( $sql, $fname );
}
$joinTable = $this->tableName( $joinTable );
$sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
if ( $conds != '*' ) {
- $sql .= "WHERE " . $this->makeList( $conds, LIST_AND );
+ $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
}
- $sql .= ")";
+ $sql .= ')';
$this->query( $sql, $fname );
}