Sequences for DB:MySQL
| From: | Blair Robertson | Date: | Fri, 02 May 2003 00:04:46 +0000 |
| Subject: | Sequences for DB:MySQL | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-15761@lists.php.net to get a copy of this message | ||
Hi there,
I have just noticed an inconsistency between MySQL and PostgreSQL DB
objects when you are creating sequences.
When you call createSequence() with MySQL it set's the value to 1,
so when you make your first call with nextId() a 2 is returned.
When you call createSequence() with Postgre and then call nextId() a 1
is returned, which is what I would expect.
I can't test what the other databases do, but by looking at nextId() fn
in the other DB classes that are using tables to emulate sequences (ie
mssql, fbsql and odbc) createSequence() appears to initialise the value
to zero because these fns repeat in the do..while loop after creating
the sequence.
I have attached a patch to the DB/mysql.php that fixes this issue in
createSequence() and alters nextId() to perform the same repeat that the
other classes do - please tell me what you think.
BTW - if you are wondering why I need to call createSequence() rather
than just using the on demand feature of nextId() it has to do with
Postgre, transactions and a failed NEXTVAL() call - see the points
raised in this bug report, http://bugs.php.net/bug.php?id=22761
cheers
BCR