1
0
mirror of synced 2025-03-26 18:03:49 +03:00

- ensure that nextId() always relies in autoincrement id generation to ensure that last insert id works reliably

This commit is contained in:
lsmith 2008-01-10 08:47:00 +00:00
parent 16ef556f62
commit ba8aae6005

View File

@ -52,16 +52,12 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
} catch(Doctrine_Connection_Exception $e) { } catch(Doctrine_Connection_Exception $e) {
if ($onDemand && $e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) { 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 { try {
$result = $this->conn->export->createSequence($seqName, 2); $this->conn->export->createSequence($seqName);
return $this->nextId($seqName, false);
} catch(Doctrine_Exception $e) { } catch(Doctrine_Exception $e) {
throw new Doctrine_Sequence_Exception('on demand sequence ' . $seqName . ' could not be created'); 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; throw $e;
} }
@ -70,13 +66,11 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
if (is_numeric($value)) { if (is_numeric($value)) {
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value; $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
try {
$this->conn->exec($query); $this->conn->exec($query);
/** } catch(Doctrine_Exception $e) {
TODO: is the following needed ? throw new Doctrine_Sequence_Exception('could not delete previous sequence table values from ' . $seqName);
if (PEAR::isError($result)) {
$this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name;
} }
*/
} }
return $value; return $value;
} }