fixed sequence handling
This commit is contained in:
parent
8e071b75e3
commit
d275bed4e7
@ -43,9 +43,11 @@ class Doctrine_Sequence_Db2 extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function lastSequenceId($sequenceName)
|
public function lastSequenceId($sequenceName)
|
||||||
{
|
{
|
||||||
$this->_connect();
|
$sql = 'SELECT PREVVAL FOR '
|
||||||
$sql = 'SELECT PREVVAL FOR '.$this->quoteIdentifier($sequenceName).' AS VAL FROM SYSIBM.SYSDUMMY1';
|
. $this->quoteIdentifier($this->conn->formatter->getSequenceName($sequenceName))
|
||||||
$stmt = $this->query($sql);
|
. ' AS VAL FROM SYSIBM.SYSDUMMY1';
|
||||||
|
|
||||||
|
$stmt = $this->query($sql);
|
||||||
$result = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
|
$result = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $result[0]['VAL'];
|
return $result[0]['VAL'];
|
||||||
@ -66,7 +68,9 @@ class Doctrine_Sequence_Db2 extends Doctrine_Sequence
|
|||||||
public function nextSequenceId($sequenceName)
|
public function nextSequenceId($sequenceName)
|
||||||
{
|
{
|
||||||
$this->_connect();
|
$this->_connect();
|
||||||
$sql = 'SELECT NEXTVAL FOR '.$this->quoteIdentifier($sequenceName).' AS VAL FROM SYSIBM.SYSDUMMY1';
|
$sql = 'SELECT NEXTVAL FOR '
|
||||||
|
. $this->quoteIdentifier($this->conn->formatter->getSequenceName($sequenceName))
|
||||||
|
. ' AS VAL FROM SYSIBM.SYSDUMMY1';
|
||||||
$stmt = $this->query($sql);
|
$stmt = $this->query($sql);
|
||||||
$result = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
|
$result = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
@ -42,7 +42,7 @@ class Doctrine_Sequence_Firebird extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function nextID($seqName, $onDemand = true)
|
public function nextID($seqName, $onDemand = true)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
|
|
||||||
$query = 'SELECT GEN_ID(' . $sequenceName . ', 1) as the_value FROM RDB$DATABASE';
|
$query = 'SELECT GEN_ID(' . $sequenceName . ', 1) as the_value FROM RDB$DATABASE';
|
||||||
try {
|
try {
|
||||||
@ -88,7 +88,7 @@ class Doctrine_Sequence_Firebird extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function currId($seqName)
|
public function currId($seqName)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
|
|
||||||
|
|
||||||
$query = 'SELECT GEN_ID(' . $sequenceName . ', 0) as the_value FROM RDB$DATABASE';
|
$query = 'SELECT GEN_ID(' . $sequenceName . ', 0) as the_value FROM RDB$DATABASE';
|
||||||
|
@ -42,7 +42,7 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function nextId($seqName, $ondemand = true)
|
public function nextId($seqName, $ondemand = true)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->formatter->getSequenceName($seqName), true);
|
||||||
$seqcolName = $this->conn->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
|
$seqcolName = $this->conn->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function nextId($seqName, $ondemand = true)
|
public function nextId($seqName, $ondemand = true)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
|
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
|
||||||
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
|
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function currId($seqName)
|
public function currId($seqName)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
|
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
|
||||||
$query = 'SELECT MAX(' . $seqcolName . ') FROM ' . $sequenceName;
|
$query = 'SELECT MAX(' . $seqcolName . ') FROM ' . $sequenceName;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function nextID($seqName, $onDemand = true)
|
public function nextID($seqName, $onDemand = true)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
$query = 'SELECT ' . $sequenceName . '.nextval FROM DUAL';
|
$query = 'SELECT ' . $sequenceName . '.nextval FROM DUAL';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -71,7 +71,7 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
|
|||||||
public function lastInsertID($table = null, $field = null)
|
public function lastInsertID($table = null, $field = null)
|
||||||
{
|
{
|
||||||
$seqName = $table . (empty($field) ? '' : '_'.$field);
|
$seqName = $table . (empty($field) ? '' : '_'.$field);
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
|
|
||||||
return $this->conn->fetchOne('SELECT ' . $sequenceName . '.currval');
|
return $this->conn->fetchOne('SELECT ' . $sequenceName . '.currval');
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function currID($seqName)
|
public function currID($seqName)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
$query = 'SELECT (last_number-1) FROM user_sequences';
|
$query = 'SELECT (last_number-1) FROM user_sequences';
|
||||||
$query .= ' WHERE sequence_name=' . $this->conn->quote($sequenceName, 'text');
|
$query .= ' WHERE sequence_name=' . $this->conn->quote($sequenceName, 'text');
|
||||||
$query .= ' OR sequence_name=' . $this->conn->quote(strtoupper($sequenceName), 'text');
|
$query .= ' OR sequence_name=' . $this->conn->quote(strtoupper($sequenceName), 'text');
|
||||||
|
@ -42,7 +42,7 @@ class Doctrine_Sequence_Pgsql extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function nextId($seqName, $onDemand = true)
|
public function nextId($seqName, $onDemand = true)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
|
|
||||||
$query = "SELECT NEXTVAL('" . $sequenceName . "')";
|
$query = "SELECT NEXTVAL('" . $sequenceName . "')";
|
||||||
try {
|
try {
|
||||||
@ -70,7 +70,7 @@ class Doctrine_Sequence_Pgsql extends Doctrine_Sequence
|
|||||||
public function lastInsertId($table = null, $field = null)
|
public function lastInsertId($table = null, $field = null)
|
||||||
{
|
{
|
||||||
$seqName = $table . (empty($field) ? '' : '_' . $field);
|
$seqName = $table . (empty($field) ? '' : '_' . $field);
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
|
|
||||||
return (int) $this->conn->fetchOne("SELECT CURRVAL('" . $sequenceName . "')");
|
return (int) $this->conn->fetchOne("SELECT CURRVAL('" . $sequenceName . "')");
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ class Doctrine_Sequence_Pgsql extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function currId($seqName)
|
public function currId($seqName)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
return (int) $this->conn->fetchOne('SELECT last_value FROM ' . $sequenceName);
|
return (int) $this->conn->fetchOne('SELECT last_value FROM ' . $sequenceName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function nextId($seqName, $onDemand = true)
|
public function nextId($seqName, $onDemand = true)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
|
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
|
||||||
|
|
||||||
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
|
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
|
||||||
@ -101,7 +101,7 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
|
|||||||
*/
|
*/
|
||||||
public function currId($seqName)
|
public function currId($seqName)
|
||||||
{
|
{
|
||||||
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
|
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
|
||||||
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
|
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
|
||||||
|
|
||||||
$query = 'SELECT MAX(' . $seqcolName . ') FROM ' . $sequenceName;
|
$query = 'SELECT MAX(' . $seqcolName . ') FROM ' . $sequenceName;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user