Commit ffa7ff54 authored by zYne's avatar zYne

Fixed pgsql and sqlite sequence handlers and test cases

parent 1eb8b54d
...@@ -69,7 +69,7 @@ class Doctrine_Sequence_Pgsql extends Doctrine_Sequence ...@@ -69,7 +69,7 @@ class Doctrine_Sequence_Pgsql extends Doctrine_Sequence
*/ */
public function lastInsertId($table = null, $field = null) public function lastInsertId($table = null, $field = null)
{ {
$seq = $table.(empty($field) ? '' : '_'.$field); $seqName = $table . (empty($field) ? '' : '_' . $field);
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true); $sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
return (int) $this->conn->fetchOne("SELECT CURRVAL('" . $sequenceName . "')"); return (int) $this->conn->fetchOne("SELECT CURRVAL('" . $sequenceName . "')");
......
...@@ -67,16 +67,15 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence ...@@ -67,16 +67,15 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
} }
} }
$value = $this->conn->getDbh()->lastInsertID(); $value = $this->conn->getDbh()->lastInsertId();
if (is_numeric($value)) { if (is_numeric($value)) {
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value; $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
$this->conn->exec($query); $this->conn->exec($query);
/** /**
TODO: is the following needed ? TODO: is the following needed ?
if (PEAR::isError($result)) { $this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name;
$this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name;
}
*/ */
} }
return $value; return $value;
......
...@@ -68,8 +68,13 @@ class AdapterMock implements Doctrine_Adapter_Interface { ...@@ -68,8 +68,13 @@ class AdapterMock implements Doctrine_Adapter_Interface {
return 0; return 0;
} }
public function forceLastInsertIdFail() { public function forceLastInsertIdFail($fail = true)
$this->lastInsertIdFail = true; {
if ($fail) {
$this->lastInsertIdFail = true;
} else {
$this->lastInsertIdFail = false;
}
} }
public function lastInsertId() public function lastInsertId()
{ {
......
...@@ -127,6 +127,10 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase ...@@ -127,6 +127,10 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
$users = $q->execute(); $users = $q->execute();
$this->assertEqual($users->count(), 1); $this->assertEqual($users->count(), 1);
}
public function testAggregateValueMappingSupportsLeftJoins3()
{
} }
public function testAggregateValueMappingSupportsInnerJoins() public function testAggregateValueMappingSupportsInnerJoins()
{ {
......
...@@ -34,7 +34,7 @@ class Doctrine_Sequence_Pgsql_TestCase extends Doctrine_UnitTestCase { ...@@ -34,7 +34,7 @@ class Doctrine_Sequence_Pgsql_TestCase extends Doctrine_UnitTestCase {
public function testCurrIdExecutesSql() public function testCurrIdExecutesSql()
{ {
$this->sequence->currId('user'); $this->sequence->currId('user');
$q = "SELECT (last_number-1) FROM user_sequences WHERE sequence_name='user_seq' OR sequence_name='USER_SEQ'"; $q = "SELECT last_value FROM user_seq";
$this->assertEqual($this->adapter->pop(), $q); $this->assertEqual($this->adapter->pop(), $q);
} }
...@@ -49,6 +49,6 @@ class Doctrine_Sequence_Pgsql_TestCase extends Doctrine_UnitTestCase { ...@@ -49,6 +49,6 @@ class Doctrine_Sequence_Pgsql_TestCase extends Doctrine_UnitTestCase {
{ {
$this->sequence->lastInsertId('user'); $this->sequence->lastInsertId('user');
$this->assertEqual($this->adapter->pop(), 'SELECT user_seq.currval'); $this->assertEqual($this->adapter->pop(), "SELECT CURRVAL('user_seq')");
} }
} }
...@@ -34,6 +34,8 @@ class Doctrine_Sequence_Sqlite_TestCase extends Doctrine_UnitTestCase ...@@ -34,6 +34,8 @@ class Doctrine_Sequence_Sqlite_TestCase extends Doctrine_UnitTestCase
{ {
public function testCurrIdExecutesSql() public function testCurrIdExecutesSql()
{ {
$this->adapter->forceLastInsertIdFail(false);
$this->sequence->currId('user'); $this->sequence->currId('user');
$this->assertEqual($this->adapter->pop(), 'SELECT MAX(id) FROM user_seq'); $this->assertEqual($this->adapter->pop(), 'SELECT MAX(id) FROM user_seq');
......
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