Commit d829e223 authored by zYne's avatar zYne

Removed sequence module methods from main driver classes

parent 68227522
......@@ -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);
}
}
......@@ -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);
}
}
......@@ -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
......
......@@ -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');
}
}
......@@ -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
*
......
......@@ -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);
}
}
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment