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

cesarmiquel’s picture

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.

aadityawalawalkar’s picture

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.

djdevin’s picture

Title:sql error :- create quiz without creating questions » sql error when creating a quiz without any question modules enabled
Version:7.x-4.0-alpha12» 7.x-4.x-dev
Issue summary:View changes
Status:Active» Needs review
StatusFileSize
new590 bytes

Still happens in 7.x - rerolled.

selvamkf’s picture

I have added the patch for latest quiz version. I tested it to see that working.

sivaji@knackforge.com’s picture

Status:Needs review» Fixed

Thank you. I committed the last patch with some changes.

Status:Fixed» Closed (fixed)

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

  • Commit 2c238bd on 7.x-4.x, 7.x-5.x by sivaji:
    Issue #1862482 by lalit774, aadityawalawalkar, djdevin, selvamkf: Sql...

  • Commit 2c238bd on 7.x-4.x, 7.x-5.x, quiz-pages by sivaji:
    Issue #1862482 by lalit774, aadityawalawalkar, djdevin, selvamkf: Sql...

  • Commit 2c238bd on 7.x-4.x, 7.x-5.x, quiz-pages, 2269219 by sivaji:
    Issue #1862482 by lalit774, aadityawalawalkar, djdevin, selvamkf: Sql...

  • Commit 2c238bd on 7.x-4.x, 7.x-5.x, 2269219 by sivaji:
    Issue #1862482 by lalit774, aadityawalawalkar, djdevin, selvamkf: Sql...