PDOException : SQLSTATE[42883]: Undefined function: 7 ERREUR: la fonction rand() n'existe pas LINE 8: ORDER BY RAND() LIMIT 10 OFFSET 0 ^ HINT: Aucune fonction ne correspond au nom donné et aux types d'arguments. Vous devez ajouter des conversions explicites de type.: SELECT child_nid as nid, child_vid as vid, n.type FROM {quiz_node_relationship} qnr JOIN {node} n on qnr.child_nid = n.nid WHERE qnr.parent_vid = :parent_vid AND qnr.parent_nid = :parent_nid AND qnr.question_status = :question_status AND n.status = 1 ORDER BY RAND() LIMIT 10 OFFSET 0; Array ( [:parent_vid] => 223 [:parent_nid] => 142 [:question_status] => 0 ) dans _quiz_get_random_questions() (ligne 2818 dans \sites\all\modules\contrib\quiz\quiz.module).

I had to update with ORDER BY RANDOM() to work.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

saturnino created an issue. See original summary.

saturnino’s picture

Version: 7.x-6.x-dev » 7.x-5.0
Issue summary: View changes
Da_Cloud’s picture

Version: 7.x-5.0 » 7.x-5.x-dev
Status: Needs work » Needs review
FileSize
1.57 KB

After a quick search it seems we use the "ORDER BY RAND()" statement twice. Both in quiz.module more precise in the function _quiz_get_random_questions on line 2811 and in _quiz_get_random_taxonomy_question_ids on line 2864. With the second being marked for deletion in issue #2834587: D6 leftover undefined function db_fetch_array().

As for the fix simply changing the line to "ORDER BY RANDOM()" would indeed solve the issue for postgreSQL, but would instead crash any MySQL database. So instead I propose we simply change the current database query to an db_select, which should provide support for both database engines.

Old query

$result = db_query_range(
  "SELECT child_nid as nid, child_vid as vid, n.type
  FROM {quiz_node_relationship} qnr
  JOIN {node} n on qnr.child_nid = n.nid
  WHERE qnr.parent_vid = :parent_vid
  AND qnr.parent_nid = :parent_nid
  AND qnr.question_status = :question_status
  AND n.status = 1
  ORDER BY RAND()", 0, $quiz->number_of_random_questions, array(
    ':parent_vid' => $quiz->vid,
    ':parent_nid' => $quiz->nid,
    ':question_status' => QUIZ_QUESTION_RANDOM
  )
);

New query

$query = db_select('quiz_node_relationship', 'qnr');
$query->join('node', 'n', 'qnr.child_nid = n.nid');
$query->addField('qnr', 'child_nid', 'nid');
$query->addField('qnr', 'child_vid', 'vid');
$query->addField('n', 'type', 'type');
$query->condition('qnr.parent_vid', $quiz->vid);
$query->condition('qnr.parent_nid', $quiz->nid);
$query->condition('qnr.question_status', QUIZ_QUESTION_RANDOM);
$query->condition('n.status', 1);
$query->orderRandom();
$query->range(0, $quiz->number_of_random_questions);
$result = $query->execute();
Da_Cloud’s picture

FileSize
812 bytes

Looking at the testcases the issue in question passed the testscripts, but we're encountering 3 other issues when testing on PostgreSQL.
- The first 2 issues seems to be isolated in the upgrade path from 4.x to 5.x.
- The last issue seems to come from the function _quiz_active_result_id() (line 2653) in quiz.module, not sure however what is happening here.
Both seem to be isolated issues that should be handled in a new issue.

Since it seems the test haven't been run against PostgreSQL for some time I've uploaded an empty patch so we can compare the results.

Da_Cloud’s picture

Status: Needs review » Needs work

The last submitted patch, 6: test.patch, failed testing. View results