aboutsummaryrefslogtreecommitdiffstats
path: root/includes/DatabasePostgreSQL.php
diff options
context:
space:
mode:
authorDomas Mituzas <midom@users.mediawiki.org>2004-06-11 14:32:05 +0000
committerDomas Mituzas <midom@users.mediawiki.org>2004-06-11 14:32:05 +0000
commit5f2b3f41e0ba38f5f22b3d0e3b51d2e173b4d573 (patch)
treea834025bd5d814b13f6cdd16e5eeaa454ec98f36 /includes/DatabasePostgreSQL.php
parent13904cdbbd60ecf4f78f325a01e1fef40242efd2 (diff)
downloadmediawikicore-5f2b3f41e0ba38f5f22b3d0e3b51d2e173b4d573.tar.gz
mediawikicore-5f2b3f41e0ba38f5f22b3d0e3b51d2e173b4d573.zip
* fix affected_rows, uses resultset instead of connection as an argument
* allow wfGetSQL to fetch non-table variables * InvertTimestamp creates old-style inverse timestamp * insertArray needed quote-fixing * added wfLimitResult function, in order to solve SQL LIMIT incompatibilities
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/3990
Diffstat (limited to 'includes/DatabasePostgreSQL.php')
-rw-r--r--includes/DatabasePostgreSQL.php28
1 files changed, 21 insertions, 7 deletions
diff --git a/includes/DatabasePostgreSQL.php b/includes/DatabasePostgreSQL.php
index eade5b57a7c0..633f61d5b955 100644
--- a/includes/DatabasePostgreSQL.php
+++ b/includes/DatabasePostgreSQL.php
@@ -38,6 +38,7 @@ class Database {
/* private */ var $mOut, $mDebug, $mOpened = false;
/* private */ var $mFailFunction;
+ /* private */ var $mLastResult;
#------------------------------------------------------------------------------
# Accessors
@@ -171,7 +172,8 @@ class Database {
}
$ret = pg_query( $this->mConn , $sql);
- if ( false === $ret ) {
+ $this->mLastResult = $ret;
+ if ( false == $ret ) {
$error = pg_last_error( $this->mConn );
// TODO FIXME : no error number function in postgre
// $errno = mysql_errno( $this->mConn );
@@ -230,12 +232,14 @@ class Database {
// TODO FIXME: need to implement something here
function insertId() {
//return mysql_insert_id( $this->mConn );
- wfDebugDieBacktrace( "Database::insertId() error : not implemented for postgre" );
+ wfDebugDieBacktrace( "Database::insertId() error : not implemented for postgre, use sequences" );
}
function dataSeek( $res, $row ) { return pg_result_seek( $res, $row ); }
function lastErrno() { return $this->lastError(); }
function lastError() { return pg_last_error(); }
- function affectedRows() { return pg_affected_rows( $this->mConn ); }
+ function affectedRows() {
+ return pg_affected_rows( $this->mLastResult );
+ }
# Simple UPDATE wrapper
# Usually aborts on failure
@@ -252,13 +256,17 @@ class Database {
# If errors are explicitly ignored, returns FALSE on failure
function get( $table, $var, $cond, $fname = "Database::get" )
{
- $sql = "SELECT \"$var\" FROM \"$table\" WHERE ($cond)";
+ $from=$table?" FROM \"$table\" ":"";
+ $where=$cond?" WHERE ($cond)":"";
+
+ $sql = "SELECT $var $from $where";
+
$result = $this->query( $sql, DB_READ, $fname );
$ret = "";
if ( pg_num_rows( $result ) > 0 ) {
- $s = pg_fetch_object( $result );
- $ret = $s->$var;
+ $s = pg_fetch_array( $result );
+ $ret = $s[0];
pg_free_result( $result );
}
return $ret;
@@ -384,7 +392,7 @@ class Database {
# If errors are explicitly ignored, returns success
function insertArray( $table, $a, $fname = "Database::insertArray" )
{
- $sql1 = "INSERT INTO '$table' (";
+ $sql1 = "INSERT INTO \"$table\" (";
$sql2 = "VALUES (" . Database::makeList( $a );
$first = true;
foreach ( $a as $field => $value ) {
@@ -524,10 +532,16 @@ function wfTimestampNow() {
# Sorting hack for MySQL 3, which doesn't use index sorts for DESC
function wfInvertTimestamp( $ts ) {
+ $ts=preg_replace("/\D/","",$ts);
return strtr(
$ts,
"0123456789",
"9876543210"
);
}
+
+function wfLimitResult( $limit, $offset ) {
+ return " LIMIT $limit ".(is_numeric($offset)?" OFFSET {$offset} ":"");
+}
+
?>