Fixed pgsql and sqlite sequence handlers and test cases
This commit is contained in:
parent
1eb8b54d81
commit
ffa7ff54a8
@ -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 . "')");
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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')");
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user