public function pick_question_dataset($question, $datasetitem) {
        // Select a dataset in the following format:
        // an array indexed by the variable names (d.name) pointing to the value
        // to be substituted.
        global $CFG, $DB;
        if (!$dataitems = $DB->get_records_sql(
                "SELECT i.id, d.name, i.value
                   FROM {question_dataset_definitions} d,
                        {question_dataset_items} i,
                        {question_datasets} q
                  WHERE q.question = ?
                    AND q.datasetdefinition = d.id
                    AND d.id = i.definition
                    AND i.itemnumber = ?
               ORDER BY i.id DESC ", array($question->id, $datasetitem))) {
            $a = new stdClass();
            $a->id = $question->id;
            $a->item = $datasetitem;
            print_error('cannotgetdsfordependent', 'question', '', $a);
        }
        $dataset = Array();
        foreach ($dataitems as $id => $dataitem) {
            if (!isset($dataset[$dataitem->name])) {
                $dataset[$dataitem->name] = $dataitem->value;
            }
        }
        return $dataset;
    }