Problem/Motivation

I face an error while deleting question of type MCQ that was assigned with quiz, when i try to delete a question i receive the below error message

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'question_nid' in 'where clause': SELECT id FROM {quiz_multichoice_user_answers} WHERE question_nid = :nid; Array ( [:nid] => 4 ) in MultichoiceQuestion->delete() (line 336 of E:\xampp\htdocs\d7-lab\sites\all\modules\quiz\question_types\multichoice\multichoice.classes.inc).

i am using the below versions
Core
7.34
Quiz
7.x-5.0-alpha7+57-dev
Quiz Multichoice
7.x-5.0-alpha7+57-dev

Proposed resolution

my expectation that the MultichoiceQuestion->delete function have to be modified to depend on quiz_multichoice_answers & quiz_multichoice_user_answers to get the question_nid and delete all answers by users that happened before for this question

this is the first time that i post issues as i like this module and used it in one of my projects so i thought this information may be useful.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

djdevin’s picture

Thanks, this is a bug.

djdevin’s picture

Status: Active » Needs review
FileSize
1.73 KB

This is already happening correctly in MultichoiceResponse::delete(), the patch removes the user answer deletion from the Question class. I think the same thing happens in TrueFalse as well.

Additionally I think in _quiz_delete_question we have to fire off the response deletion method. It seems to be deleting responses in both the question and the response class, when it really should be only the response class doing it.

Sherif Darwish’s picture

Hi,

Thanks for your quick support for the patch, i have also checked the below question types and they have same error when trying to delete a questions

Scale question
Short answer question
True/false question
Long Answer question

The below were deleted without errors

Drag Drop Question
Quiz evaluation question
Quiz directions

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'question_nid' in 'where clause': DELETE FROM {quiz_long_answer_user_answers} WHERE (question_nid = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => 16 ) in LongAnswerQuestion->delete() (line 72 of sites\all\modules\quiz\question_types\long_answer\long_answer.classes.inc).



PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'question_nid' in 'where clause': DELETE FROM {quiz_truefalse_user_answers} WHERE (question_nid = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => 8 ) in TrueFalseQuestion->delete() (line 68 of sites\all\modules\quiz\question_types\truefalse\truefalse.classes.inc).
djdevin’s picture

Removed deletions from question types. This should at least get rid of the fatals, however old data will remain (but it will not be associated with any results - orphaned).

I am going to add code into the question type, to delete all the result answers, which will then correctly remove the per-question type answers. This gets rid of a lot of code in the question types too.

zuernBernhard’s picture

FileSize
58.87 KB

same problem for shoranswer and true/false (see attached screenshot)

djdevin’s picture

Is that with the patch above?

idebr’s picture

I had the same problems as OP and I can confirm the patch resolved the issue.

djdevin’s picture

  • djdevin committed 84b6058 on 7.x-5.x
    Issue #2413821 by djdevin, Sherif Darwish, zuernBernhard: PDOException...

  • djdevin committed 52e0807 on 7.x-5.x
    Issue #2413821: dont delete quiz result answers
    
djdevin’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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