By editing first time poll content gives this error:

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'NO' for column 'chvotes' at row 1: INSERT INTO {poll_choice} (nid, chtext, chvotes, weight) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 4 [:db_insert_placeholder_1] => Yes [:db_insert_placeholder_2] => NO [:db_insert_placeholder_3] => 0 ) in poll_insert() (line 546 of C:\xampp\htdocs\drupal7\modules\poll\poll.module).

Comments

furamag’s picture

I'm able to reproduce this bug. It looks like you added 'No' to 'Vote count' field and validation doesn't work for this field in some reason.

furamag’s picture

There is bug in function poll_insert in poll.module. We are using following code (line 537):

  foreach ($node->choice as $choice) {
    if ($choice['chtext'] != '') {
      db_insert('poll_choice')
        ->fields(array(
          'nid' => $node->nid,
          'chtext' => $choice['chtext'],
          'chvotes' => $choice['chvotes'],
          'weight' => $choice['weight'],
        ))
        ->execute();
    }
  }

To fix bug we should use updated code:

  foreach ($node->choice as $choice) {
    if ($choice['chtext'] != '') {
      db_insert('poll_choice')
        ->fields(array(
          'nid' => $node->nid,
          'chtext' => $choice['chtext'],
          'chvotes' => (int) $choice['chvotes'],
          'weight' => $choice['weight'],
        ))
        ->execute();
    }
  }
Wolfflow’s picture

Thanks @furamag for feedback, going to apply code.

amateescu’s picture

Version: 7.0-beta1 » 8.x-dev
amateescu’s picture

Status: Active » Needs review
Issue tags: +String freeze, +Needs backport to D7
StatusFileSize
new1.2 KB

The solution here is to fix the validation, not the database insert.

Attached patch cleans up this mess and applies cleanly to D7 and D8. I promise to follow up with tests in #295993: TestingParty08: Poll form validation :)

amateescu’s picture

Assigned: Unassigned » amateescu
StatusFileSize
new1.06 KB

Re-rolled to take http://drupal.org/node/1274212#comment-4973492 into account.

amateescu’s picture

Issue tags: -String freeze
StatusFileSize
new1.27 KB

The string changes were not accepted for D7, so here's another patch that keeps the string and reuses one from number.module.

Again, I'd recommend to postpone this until #1274212: Incorrect order of choices in Poll module. is fixed.

Status: Needs review » Needs work

The last submitted patch, 939880-3.patch, failed testing.

marcingy’s picture

StatusFileSize
new493 bytes

Can't we just use element_validate_integer_positive as an element validator?

marcingy’s picture

Status: Needs work » Needs review
marcingy’s picture

Issue tags: +Needs tests

This really also needs tests.

Status: Needs review » Needs work

The last submitted patch, valid-option.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new2.62 KB
new1.64 KB

@marcingy: good idea, but element_validate_integer instead of element_validate_integer_positive because the vote count can be 0.

amateescu’s picture

StatusFileSize
new2.59 KB
new1.61 KB

I asked @chx in IRC to validate the test-only patch, and the only 'complaint' was that we don't need to logout the admin user because login does it for us.

So, new patches for review (It's sad that I can't stop the testbot from reviewing the previous ones..), and if everythings checks out, I'm going to RTBC based on the idea from #9 and the validated tests :)

amateescu’s picture

Title: Poll Module throws PDOException when create poll content » Poll Module throws PDOException when creating poll content
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

RTBC it is then.

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Thanks. Committed/pushed to 8.x. Moving to 7.x for backport.

amateescu’s picture

Status: Patch (to be ported) » Reviewed & tested by the community
StatusFileSize
new2.55 KB

7.x patch.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 7.x. Thanks for the fix, and the test!

Status: Fixed » Closed (fixed)
Issue tags: -Needs backport to D7

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

George Bills’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review

Shouldn't the code also include #required => true?

Otherwise saving a poll node form with no values in the "count" fields gives "PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'chvotes'".

secretsayan’s picture

Ok! Right!
So just added '#required => True' in line 412

$form['chvotes'] = array(
    '#type' => 'textfield',
    '#title' => $value !== '' ? t('Vote count for choice @label', array('@label' => $value)) : t('Vote count for new choice'),
    '#title_display' => 'invisible',
    '#default_value' => $votes,
    '#size' => 5,
    '#maxlength' => 7,
    '#parents' => array('choice', $key, 'chvotes'),
    '#access' => user_access('administer nodes'),
    '#required' => True,
    '#element_validate' => array('element_validate_integer'),
  );
mgifford’s picture

Assigned: amateescu » Unassigned
Status: Needs review » Needs work

We still need to D7 patch to review so changing the status.

  • catch committed 82d39d6 on 8.3.x
    Issue #939880 by amateescu, marcingy: Fixed Poll Module throws...

  • catch committed 82d39d6 on 8.3.x
    Issue #939880 by amateescu, marcingy: Fixed Poll Module throws...

  • catch committed 82d39d6 on 8.4.x
    Issue #939880 by amateescu, marcingy: Fixed Poll Module throws...

  • catch committed 82d39d6 on 8.4.x
    Issue #939880 by amateescu, marcingy: Fixed Poll Module throws...

  • catch committed 82d39d6 on 9.1.x
    Issue #939880 by amateescu, marcingy: Fixed Poll Module throws...

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.