Commit ba8aae60 authored by lsmith's avatar lsmith

- ensure that nextId() always relies in autoincrement id generation to ensure...

- ensure that nextId() always relies in autoincrement id generation to ensure that last insert id works reliably
parent 16ef556f
......@@ -45,23 +45,19 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
try {
$this->conn->exec($query);
} catch(Doctrine_Connection_Exception $e) {
if ($onDemand && $e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) {
// Since we are creating the sequence on demand
// we know the first id = 1 so initialize the
// sequence at 2
try {
$result = $this->conn->export->createSequence($seqName, 2);
$this->conn->export->createSequence($seqName);
return $this->nextId($seqName, false);
} catch(Doctrine_Exception $e) {
throw new Doctrine_Sequence_Exception('on demand sequence ' . $seqName . ' could not be created');
}
// First ID of a newly created sequence is 1
return 1;
}
throw $e;
}
......@@ -70,13 +66,11 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
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;
try {
$this->conn->exec($query);
} catch(Doctrine_Exception $e) {
throw new Doctrine_Sequence_Exception('could not delete previous sequence table values from ' . $seqName);
}
*/
}
return $value;
}
......@@ -109,4 +103,4 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
return (int) $this->conn->fetchOne($query);
}
}
\ No newline at end of file
}
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