Download & Extend

sql error :- create quiz without creating questions

Project:Quiz
Version:7.x-4.0-alpha12
Component:Code - Quiz core
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

i got sql query broken because i have created quiz first without creating question.

messagePDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) AND (parent_vid = '1') AND (parent_nid = '1') AND (question_status = '1') AND' at line 3: SELECT n.nid AS nid, n.type AS type, nr.vid AS vid, nr.title AS title, qnr.question_status AS question_status, qnr.weight AS weight, qnr.max_score AS max_score, n.vid AS latest_vid FROM {node} n INNER JOIN {node_revision} nr ON n.nid = nr.nid LEFT OUTER JOIN {quiz_node_relationship} qnr ON nr.vid = qnr.child_vid WHERE (n.type IN ()) AND (parent_vid = :db_condition_placeholder_0) AND (parent_nid = :db_condition_placeholder_1) AND (question_status = :db_condition_placeholder_2) AND (n.status = :db_condition_placeholder_3) ORDER BY weight ASC; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => 1 [:db_condition_placeholder_2] => 1 [:db_condition_placeholder_3] => 1 ) in quiz_get_questions() (line 3600 of C:\wamp\www\d7\sites\all\modules\contrib\quiz\quiz.module).

This is problem occur due to
quiz.module
line no 3578

<?php
if ($include_all_types === TRUE) {
   
$query->condition('n.type', array_keys(_quiz_get_question_types()), 'IN');
  }
?>

should be

<?php
$question_type
=_quiz_get_question_types();
if (
$include_all_types === TRUE && count($question_type)>0) {
   
$query->condition('n.type', array_keys($question_type), 'IN');
  }
?>

Comments

#1

I was getting a similar error when saving a quiz. The problem in my case was that I had only enabled two of the submodules: quiz and quiz_question. When I enabled a question type (like the README says) the error went away.

So, it seems the problem is that users (like myself :-) ) don't read the documentation. I think a way to fix this is to enble, by default quiz_question and one type of question when quiz installs (quiz.install). Another alternative is to detect if all the requirements are enabled and if they aren't show a message via drupal_set_message() or in the status report.

#2

Please find the patches that handles the above issue for quiz module (7.x-4.0-beta1).
1) The first patch (Create-Quiz-Sql-Error-Handling-1862482-2.patch) handles only the error that is thrown if "Quiz Question" and one of "Question types sub module" are not enabled.
2) Second patch (Create_Quiz_Sql_Error-1862482-2.patch) handles:-
a) The error that is thrown if "Quiz Question" and one of "Question types sub module" are not enabled.
b) Checks & enables "Quiz Question" & "Quiz Multichoice" module if they are not enabled when the quiz module is enabled.

AttachmentSize
Create-Quiz-Sql-Error-Handling-1862482-2.patch 485 bytes
Create_Quiz_Sql_Error-1862482-2.patch 1.33 KB
nobody click here