We're encountering a strange problem where creating new survey choices is causing some of those choices to apparently "go missing." Here's what {advpoll_choices} looks like at the start:

+-----+-----+---------+--------+---------+
| cid | nid | label   | weight | writein |
+-----+-----+---------+--------+---------+
|   1 |  49 | English |      0 |       0 |
|   2 |  49 | Music   |      1 |       0 |
|   3 |  49 | Biology |      2 |       0 |
|   4 |  49 | History |      3 |       0 |
+-----+-----+---------+--------+---------+

Now we create a poll with, say, seven entries, labeled 1 through 7. But when the poll is saved, it appears to only have the choices for 4, 5, 6, and 7. Here's what {advpoll_choices} now looks like:

+-----+-----+---------+--------+---------+
| cid | nid | label   | weight | writein |
+-----+-----+---------+--------+---------+
|   1 |  49 | English |      0 |       0 |
|   2 |  49 | Music   |      1 |       0 |
|   3 |  49 | Biology |      2 |       0 |
|   4 |  49 | History |      3 |       0 |
|   5 |  91 | 5       |      4 |       0 |
|   6 |  91 | 6       |      5 |       0 |
|   7 |  91 | 7       |      6 |       0 |
|   8 |  91 | 4       |      3 |       0 |
+-----+-----+---------+--------+---------+

So yeah, that's not right. Here's the queries that are being executed:

SELECT COUNT(cid) FROM advpoll_choices WHERE nid = 91 AND cid = 1
INSERT INTO advpoll_choices (nid, label, weight) VALUES (91, '1', 0)
SELECT COUNT(cid) FROM advpoll_choices WHERE nid = 91 AND cid = 2
INSERT INTO advpoll_choices (nid, label, weight) VALUES (91, '2', 1)
SELECT COUNT(cid) FROM advpoll_choices WHERE nid = 91 AND cid = 3
INSERT INTO advpoll_choices (nid, label, weight) VALUES (91, '3', 2)
SELECT COUNT(cid) FROM advpoll_choices WHERE nid = 91 AND cid = 4
INSERT INTO advpoll_choices (nid, label, weight) VALUES (91, '4', 3)
SELECT COUNT(cid) FROM advpoll_choices WHERE nid = 91 AND cid = 5
UPDATE advpoll_choices SET label = '5', weight = 4 WHERE cid = 5
SELECT COUNT(cid) FROM advpoll_choices WHERE nid = 91 AND cid = 6
UPDATE advpoll_choices SET label = '6', weight = 5 WHERE cid = 6
SELECT COUNT(cid) FROM advpoll_choices WHERE nid = 91 AND cid = 7
UPDATE advpoll_choices SET label = '7', weight = 6 WHERE cid = 7
SELECT cid, label FROM advpoll_choices WHERE nid = 91

And that all seems to be entirely what the code expects it to do. The "cid" values of the items being created by our poll starts at 5, but the SELECT query to determine if it should insert a new row or update a current one starts looking at 1. All goes well until it gets to 5, finds a row, and updates that just-inserted choice instead of creating another new one. Ugh.

To compound the oddness, when further surveys are created, everything goes fine.

I can probably fix this (drupal_write_record() ftw), but before I do, I'd like to see if anyone else has encountered and fixed this. Or knows how this doesn't just fail entirely every time a new survey is created, because it's pretty bizarre.

CommentFileSizeAuthor
#2 patch.diff905 bytesGarrett Albright

Comments

Garrett Albright’s picture

StatusFileSize
new905 bytes

Here's the patch I used to absolve this problem, though I still haven't determined why it's happening in the first place. You'll have to apply it manually since I didn't create the patch relative to the right directory - sorry , can't be bothered with that at the moment, and it's only a one-line change anyway.

Garrett Albright’s picture

Status: Active » Needs work
gobinathm’s picture

Status: Needs work » Closed (outdated)

D6 is EOL hence this issue won't be fixed (or) attended. So closing it.