1
0
mirror of synced 2025-01-18 22:41:43 +03:00

Fixed pgsql and sqlite sequence handlers and test cases

This commit is contained in:
zYne 2007-01-21 22:10:45 +00:00
parent 1eb8b54d81
commit ffa7ff54a8
6 changed files with 19 additions and 9 deletions

View File

@ -69,7 +69,7 @@ class Doctrine_Sequence_Pgsql extends Doctrine_Sequence
*/
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);
return (int) $this->conn->fetchOne("SELECT CURRVAL('" . $sequenceName . "')");

View File

@ -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)) {
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
$this->conn->exec($query);
/**
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;

View File

@ -68,8 +68,13 @@ class AdapterMock implements Doctrine_Adapter_Interface {
return 0;
}
public function forceLastInsertIdFail() {
$this->lastInsertIdFail = true;
public function forceLastInsertIdFail($fail = true)
{
if ($fail) {
$this->lastInsertIdFail = true;
} else {
$this->lastInsertIdFail = false;
}
}
public function lastInsertId()
{

View File

@ -127,6 +127,10 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
$users = $q->execute();
$this->assertEqual($users->count(), 1);
}
public function testAggregateValueMappingSupportsLeftJoins3()
{
}
public function testAggregateValueMappingSupportsInnerJoins()
{

View File

@ -34,7 +34,7 @@ class Doctrine_Sequence_Pgsql_TestCase extends Doctrine_UnitTestCase {
public function testCurrIdExecutesSql()
{
$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);
}
@ -49,6 +49,6 @@ class Doctrine_Sequence_Pgsql_TestCase extends Doctrine_UnitTestCase {
{
$this->sequence->lastInsertId('user');
$this->assertEqual($this->adapter->pop(), 'SELECT user_seq.currval');
$this->assertEqual($this->adapter->pop(), "SELECT CURRVAL('user_seq')");
}
}

View File

@ -34,6 +34,8 @@ class Doctrine_Sequence_Sqlite_TestCase extends Doctrine_UnitTestCase
{
public function testCurrIdExecutesSql()
{
$this->adapter->forceLastInsertIdFail(false);
$this->sequence->currId('user');
$this->assertEqual($this->adapter->pop(), 'SELECT MAX(id) FROM user_seq');