I cannot get the advpoll_choices table to install. The table was not created during the module installation. It did not get created when update.php was run. I even tried to paste the text of the CREATE table command and run a MySQL query, and that would not create the table.

When I try to run as a query, here is the code I used:
CREATE TABLE advpoll_choices (nid int(10) NOT NULL, label text NOT NULL, vote_offset int(2) unsigned default NULL, writein tinyint NOT NULL default '0', PRIMARY KEY (nid, vote_offset), KEY vote_offset (vote_offset) ) /*!40100 DEFAULT CHARACTER SET utf8 */;

I get this error message: "All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead."

But changing vote_offset to NOT NULL or UNIQUE does not work. I'm not sure what to try next.

Comments

ChrisKennedy’s picture

Status: Active » Postponed (maintainer needs more info)

Hmm what version of MySQL are you using and what error do you get when you change vote_offset to be NOT NULL?

jimsmith’s picture

MySQL version 3.23.58

Error message when vote_offset is changed to NOT NULL:

failed : You have an error in your SQL syntax near 'NOT NULL, writein tinyint NOT NULL default '0', PRIMARY KEY (nid, vote_offset), ' at line 1

ChrisKennedy’s picture

Ah, take out the preceding "default" when you change it to "not null".

jimsmith’s picture

That fixed the problem. Thank you!

anders.fajerson’s picture

Status: Postponed (maintainer needs more info) » Fixed
ChrisKennedy’s picture

Status: Fixed » Active

We might as well fix this in the code, as I don't see a good reason to keep "default NULL".

Here's the old MySQL bug for this btw (fixed in more recent versions): http://bugs.mysql.com/bug.php?id=390

I think we can remove that "KEY vote_offset (vote_offset)" also, because if a column is already listed as a primary key it shouldn't need another separate key, no?

anders.fajerson’s picture

Sounds fair to me, even though not really my area.

ChrisKennedy’s picture

Status: Active » Needs review
StatusFileSize
new2.02 KB

Here's a patch. I tested upgrading and installing from scratch and I didn't get any errors.

ChrisKennedy’s picture

StatusFileSize
new2.03 KB

Bah, just noticed an error in the pgsql code.

ChrisKennedy’s picture

And like many areas, we should look to poll.module for comparison: http://cvs.drupal.org/viewvc.py/drupal/drupal/modules/poll/poll.install?...

In this case poll.module has its vote_offset (chorder) as NOT NULL, and does not have a separate index. Also note that each choice has a unique id in core, which is something we should eventually do too (for reordering, etc., esp. with the sweet AHAH drag-and-drop in D6).

ChrisKennedy’s picture

Title: advpoll_choices » Refactor advpoll_choices schema for unique ids, etc.
Assigned: Unassigned » ChrisKennedy
Priority: Normal » Critical
Status: Needs review » Needs work

I realized I should just stop being lazy and implement unique ids for choices. A comprehensive patch is in the works.

anders.fajerson’s picture

Excellent. Testers are lined up.

ChrisKennedy’s picture

Status: Needs work » Needs review
StatusFileSize
new11.32 KB

Here's an initial patch with basic functionality - needs more testing though.

ChrisKennedy’s picture

Thought: should we also rename vote_offset to "order"?

anders.fajerson’s picture

Status: Needs review » Needs work

0. Old polls doesn't display the results correctly. I couldn't find the problem but I think it's a display issue, and not a problem with the upgrade path.

1. (nid, label, vote_offset, writein) VALUES (%d, '%s', %d, 0) - If writein is never anything else than 0, it should be safe to leave it out.
2. db_query('SELECT cid, vote_offset, label, writein - can be db_query('SELECT *, not sure what is prefered.
3. $form_values['nid'], check_plain(implode(', ', $form_values['promote']))); - usually check_plain is only used on output.
4. I prefer {order} instead of {vote_offset}
5. Just an observation: Core uses 'chid' instead of 'cid' (but also prefixes all column names with ch).

I will run the upgrade path on a bigger dataset when this is ready.

ChrisKennedy’s picture

Btw, D6 just got drag-and-drop reordering: http://drupal.org/node/193076

ChrisKennedy’s picture

Status: Needs work » Needs review
StatusFileSize
new11.69 KB

0. Ah should be fixed; I needed to update votingapi_cache as well as votingapi_vote for the new choice ids.
1. Double true.
2. Eh I prefer to write em out.
3. I noticed that, but it's a separate issue.
4. I started doing order but I realized it might mess up the SQL since it's probably a reserved word. The D6 reordering patch also renamed that column and they chose weight, so that's what I did here.
5. Yeah that's just because poll.module is old and bad.

anders.fajerson’s picture

Status: Needs review » Needs work

Quick code review, will do some more testing later.

1. Typo, should be cid int unsigned NOT NULL auto_increment
2. I core, when serial is used, this is often used: cid serial CHECK (cid >= 0)
3. update_sql('ALTER TABLE {advpoll_choices} ADD cid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST') - Double-check use of upper/lower case?

ChrisKennedy’s picture

Status: Needs work » Needs review
StatusFileSize
new11.68 KB

1. & 3. - got it.
2. Yeah I thought about doing that but I couldn't find an example of getting that added in an update function. Since it's optional I would prefer to keep the installs and updates with the same db schema.

anders.fajerson’s picture

Status: Needs review » Reviewed & tested by the community

Run the upgrade on a larger dataset and I couldn't see any problems.

Don't forget to bump up the upgrade to 8 (7 just went in), apart from that this is ready. Exciting times in Drupal 6!

ChrisKennedy’s picture

Status: Reviewed & tested by the community » Fixed
ChrisKennedy’s picture

Right after the commit I realized I forgot about advpoll_convert.module. Fixed now: http://drupal.org/cvs?commit=90031

anders.fajerson’s picture

Status: Fixed » Needs work

Ok, cool. The last SQL statement in that row is mixing %d and numbers (1 and 0), extremely minor, but we might as well fix that.

ChrisKennedy’s picture

Which way of fixing it do you prefer? I'm ambivalent.

anders.fajerson’s picture

Me too, that's why I didn't suggest anything :) I search core some days ago and at least saw that they used 0 instead of %d once. But you decide :)

ChrisKennedy’s picture

Status: Needs work » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.