From d829e223b2cd2f586ae390ef49537685057a7ba3 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 11 Jan 2007 11:57:48 +0000 Subject: [PATCH] Removed sequence module methods from main driver classes --- lib/Doctrine/Connection/Firebird.php | 9 ------ lib/Doctrine/Connection/Mssql.php | 41 -------------------------- lib/Doctrine/Connection/Mysql.php | 39 ------------------------ lib/Doctrine/Connection/Oracle.php | 23 --------------- lib/Doctrine/Connection/Pgsql.php | 19 ------------ lib/Doctrine/Connection/Sqlite.php | 16 +++------- lib/Doctrine/Connection/UnitOfWork.php | 4 +-- 7 files changed, 6 insertions(+), 145 deletions(-) diff --git a/lib/Doctrine/Connection/Firebird.php b/lib/Doctrine/Connection/Firebird.php index 837caf151..75f4440fb 100644 --- a/lib/Doctrine/Connection/Firebird.php +++ b/lib/Doctrine/Connection/Firebird.php @@ -105,13 +105,4 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection } return $query; } - /** - * returns the next value in the given sequence - * @param string $sequence - * @return integer - */ - public function nextId($sequence) - { - return $this->fetchOne('SELECT UNIQUE FROM ' . $sequence); - } } diff --git a/lib/Doctrine/Connection/Mssql.php b/lib/Doctrine/Connection/Mssql.php index c3612c097..bd2b83347 100644 --- a/lib/Doctrine/Connection/Mssql.php +++ b/lib/Doctrine/Connection/Mssql.php @@ -84,26 +84,6 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection } return '[' . str_replace(']', ']]', $identifier) . ']'; } - /** - * returns the next value in the given sequence - * - * @param string $sequence name of the sequence - * @return integer the next value in the given sequence - */ - public function nextId($sequence) - { - $sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true); - $seqcolName = $this->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true); - $query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (0)'; - $result = $this->exec($query); - $value = $this->dbh->lastInsertId(); - - if (is_numeric($value)) { - $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value; - $result = $this->exec($query); - } - return $value; - } /** * Adds an adapter-specific LIMIT clause to the SELECT statement. * [ borrowed from Zend Framework ] @@ -158,25 +138,4 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection return $query; } - /** - * Returns the autoincrement ID if supported or $id or fetches the current - * ID in a sequence called: $table.(empty($field) ? '' : '_'.$field) - * - * @param string $table name of the table into which a new row was inserted - * @param string $field name of the field into which a new row was inserted - * @return integer - */ - public function lastInsertID($table = null, $field = null) - { - $server_info = $this->getServerVersion(); - if (is_array($server_info) - && !is_null($server_info['major']) - && $server_info['major'] >= 8) { - $query = "SELECT SCOPE_IDENTITY()"; - } else { - $query = "SELECT @@IDENTITY"; - } - - return $this->fetchOne($query); - } } diff --git a/lib/Doctrine/Connection/Mysql.php b/lib/Doctrine/Connection/Mysql.php index 903ffe0b6..33ef7994b 100644 --- a/lib/Doctrine/Connection/Mysql.php +++ b/lib/Doctrine/Connection/Mysql.php @@ -101,45 +101,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common $query = 'SET NAMES '.$this->dbh->quote($charset); $this->exec($query); } - /** - * Returns the next free id of a sequence - * - * @param string $seq_name name of the sequence - * @param boolean $ondemand when true the sequence is - * automatic created, if it - * not exists - * - * TODO: on demand creation of sequence table - * - * @return integer - */ - public function nextId($seqName, $ondemand = true) - { - $sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true); - $seqcolName = $this->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true); - $query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)'; - $result = $this->exec($query); - $value = $this->dbh->lastInsertId(); - - if (is_numeric($value)) { - $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value; - $result = $this->exec($query); - } - return $value; - } - /** - * Returns the current id of a sequence - * - * @param string $seq_name name of the sequence - * @return integer - */ - public function currId($seqName) - { - $sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true); - $seqcolName = $this->quoteIdentifier($this->options['seqcol_name'], true); - $query = 'SELECT MAX(' . $seqcolName . ') FROM ' . $sequenceName; - return $this->fetchOne($query); - } /** * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT * query, except that if there is already a row in the table with the same diff --git a/lib/Doctrine/Connection/Oracle.php b/lib/Doctrine/Connection/Oracle.php index 6e89d9ab6..7532b2f8f 100644 --- a/lib/Doctrine/Connection/Oracle.php +++ b/lib/Doctrine/Connection/Oracle.php @@ -103,27 +103,4 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection } return $query; } - /** - * returns the next value in the given sequence - * - * @param string $sequence name of the sequence - * @throws PDOException if something went wrong at database level - * @return integer - */ - public function nextId($sequence) - { - return $this->fetchOne('SELECT ' . $sequence . '.nextval FROM dual'); - } - /** - * Returns the current id of a sequence - * - * @param string $sequence name of the sequence - * @throws PDOException if something went wrong at database level - * @return mixed id - */ - public function currId($sequence) - { - $sequence = $this->quoteIdentifier($this->getSequenceName($sequence), true); - return $this->fetchOne('SELECT ' . $sequence . '.currval FROM dual'); - } } diff --git a/lib/Doctrine/Connection/Pgsql.php b/lib/Doctrine/Connection/Pgsql.php index 7230a861f..8642513ef 100644 --- a/lib/Doctrine/Connection/Pgsql.php +++ b/lib/Doctrine/Connection/Pgsql.php @@ -89,25 +89,6 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common $query = 'SET NAMES '.$this->dbh->quote($charset); $this->exec($query); } - /** - * returns the next value in the given sequence - * @param string $sequence - * @return integer - */ - public function nextId($sequence) - { - return $this->fetchOne("SELECT NEXTVAL('$sequence')"); - } - /** - * Returns the current id of a sequence - * - * @param string $seq_name name of the sequence - * @return integer - */ - public function currId($sequence) - { - return $this->fetcOne('SELECT last_value FROM '.$sequence); - } /** * Changes a query string for various DBMS specific reasons * diff --git a/lib/Doctrine/Connection/Sqlite.php b/lib/Doctrine/Connection/Sqlite.php index e1ecf0f58..331325b26 100644 --- a/lib/Doctrine/Connection/Sqlite.php +++ b/lib/Doctrine/Connection/Sqlite.php @@ -74,9 +74,13 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common $this->options['server_version'] = ''; */ parent::__construct($manager, $adapter); + $this->initFunctions(); } /** * initializes database functions missing in sqlite + * + * @see Doctrine_Expression + * @return void */ public function initFunctions() { @@ -85,16 +89,4 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common $this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl')); $this->dbh->sqliteCreateFunction('now', 'time', 0); } - /** - * Returns the current id of a sequence - * - * @param string $seq_name name of the sequence - * @return integer the current id in the given sequence - */ - public function currId($sequence) - { - $sequence = $this->quoteIdentifier($sequence, true); - $seqColumn = $this->quoteIdentifier($this->options['seqcol_name'], true); - return $this->fetchOne('SELECT MAX(' . $seqColumn . ') FROM ' . $sequence); - } } diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index f66c60e04..bd2224a13 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -314,10 +314,10 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen $table = $record->getTable(); $keys = $table->getPrimaryKeys(); - $seq = $record->getTable()->getSequenceName(); + $seq = $record->getTable()->getSequenceName(); if ( ! empty($seq)) { - $id = $this->nextId($seq); + $id = $this->conn->sequence->nextId($seq); $name = $record->getTable()->getIdentifier(); $array[$name] = $id; }