From 87f9122f7d777171ac63d594e3c7c493ec604493 Mon Sep 17 00:00:00 2001 From: zYne Date: Wed, 1 Nov 2006 10:31:49 +0000 Subject: [PATCH] Updated pgsql connection driver --- lib/Doctrine/Connection/Pgsql.php | 62 +++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/Connection/Pgsql.php b/lib/Doctrine/Connection/Pgsql.php index 8f8ca28bd..4ca749dcb 100644 --- a/lib/Doctrine/Connection/Pgsql.php +++ b/lib/Doctrine/Connection/Pgsql.php @@ -59,19 +59,75 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { 'identifier_quoting' => true, 'pattern_escaping' => true, ); + + $this->options['multi_query'] = false; parent::__construct($manager, $pdo); } + /** + * Set the charset on the current connection + * + * @param string charset + * + * @return void + */ + public function setCharset($charset) { + $query = 'SET NAMES '.$this->dbh->quote($charset); + $this->dbh->query($query); + } /** * returns the next value in the given sequence * @param string $sequence * @return integer */ - public function getNextID($sequence) { - $stmt = $this->query("SELECT NEXTVAL('$sequence')"); + public function nextId($sequence) { + $stmt = $this->dbh->query("SELECT NEXTVAL('$sequence')"); $data = $stmt->fetch(PDO::FETCH_NUM); return $data[0]; } + /** + * Returns the current id of a sequence + * + * @param string $seq_name name of the sequence + * @return mixed MDB2 Error Object or id + * @access public + */ + function currId($sequence) { + $stmt = $this->dbh->query('SELECT last_value FROM '.$sequence); + $data = $stmt->fetch(PDO::FETCH_NUM); + return $data[0]; + } + /** + * Changes a query string for various DBMS specific reasons + * + * @param string $query query to modify + * @param integer $limit limit the number of rows + * @param integer $offset start reading from given offset + * @param boolean $isManip if the query is a DML query + + * @return string modified query + */ + public function modifyLimitQuery($query, $limit, $offset, $isManip = false) { + if ($limit > 0) { + $query = rtrim($query); + + if (substr($query, -1) == ';') { + $query = substr($query, 0, -1); + } + + if ($isManip) { + $manip = preg_replace('/^(DELETE FROM|UPDATE).*$/', '\\1', $query); + $from = $match[2]; + $where = $match[3]; + $query = $manip . ' ' . $from . ' WHERE ctid=(SELECT ctid FROM ' + . $from . ' ' . $where . ' LIMIT ' . $limit . ')'; + + } else { + $query .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } + } + return $query; + } /** * Set the transacton isolation level. * @@ -82,7 +138,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { * SERIALIZABLE (prevents phantom reads) * @return void */ - function setTransactionIsolation($isolation) { + public function setTransactionIsolation($isolation) { switch ($isolation) { case 'READ UNCOMMITTED': case 'READ COMMITTED':