Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.12.3

Bug #287 nextId() uses wrong sequence
Submitted: 2003-11-23 23:07 UTC
From: ieure at websprockets dot com Assigned: danielc
Status: Bogus Package: DB
PHP Version: Irrelevant OS: Linux
Roadmaps: (Not assigned)    
Subscription  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
2004-01-16 07:55 UTC
Package:
Bug Type:
Summary:
From: ieure at websprockets dot com
New email:
PHP Version: Package Version: OS:

 

 [2003-11-23 23:07 UTC] ieure at websprockets dot com
Description: ------------ Calling nextId (with pgsql) uses a different sequence than what I pass in $seq_name. Reproduce code: --------------- Table def: CREATE TABLE "users" ( "username" text NOT NULL, "password" text NOT NULL, "id" serial ); (this autocreates 'users_id_seq') Then: $id = $DB->nextId('users_id_seq'); Expected result: ---------------- nextId() returns the next value from 'users_id_seq,' per the documentation. http://pear.php.net/manual/en/package.database.db.db-common.nextid.php "string $seq_name - name of the sequence" Actual result: -------------- nextId() creates 'users_id_seq_seq' and returns the next value from that. If the database was seeded prior to using DB, the insert will fail due to duplicate IDs. getSequenceName() (in DB/common.php) seems to be the cuplrit, as it returns 'users_id_seq_seq' when called from nextId().

Comments

 [2003-12-18 16:50 UTC] chagenbu at php dot net
This is now nextId() has always behaved, and changing it would break a lot of applications. Is there a reason you can't just call $db->nextId('users_id')?
 [2004-01-15 17:57 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2004-01-15 17:57 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2004-01-15 19:28 UTC] ieure at websprockets dot com
The bug isn't bogus, the problem is real. The fact that DB has had the bug for a long time and code now depends on it is irrelevant. At the very least, the documentation should be updated to indicate that it does /not/ use the sequence you tell it to, and perhaps a warning not to let nextId create sequences for you. Long-term, it should be fixed (perhaps in 2.0), or if we absolutely must keep it's (utterly broken) behavior, a replacement function which works correctly and has a different name should be added.
 [2004-01-15 19:33 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2004-01-15 19:46 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2004-01-15 21:01 UTC] ieure at websprockets dot com
In response to Chuck's question, no, there is no reason I can't simply use 'tablename_fieldname' instead of (the correct) 'tablename_fieldname_seq.' Indeed, it's what I /had/ to do in order to work around this problem. Regardless, the documentation does not say "name of the sequence, with _seq omitted," nor does it say "sequence name will be converted to the format specified in the 'seqname_format' option. It says "name of the sequence," and it does not use the name you give it. It's not obvious that this is the behavior until you start having problems with your database and have to track down what's going wrong. Setting seqname_format to '%s' makes nextId() use the sequence I pass it. This still should be documented somewhere.
 [2004-01-16 04:50 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2004-01-16 07:55 UTC] ieure at websprockets dot com
All this discussion is quite irrelevant, imo. The function does not do what the documentation claims. Either the documentation needs to be updated to tell what the function does, or the function needs to be changed to do what the documentation says. I'll be happy to provide a patch for either one. We could argue about use cases forever, but the simple fact is that the function doesn't do what the docs say.
 [2004-11-26 13:13 UTC] cece at syrup dot hu
Why not use $id = $DB->nextId('users_id'); instead?