<DBMIGRATION type="mod/quiz" VERSION="2005120100">
  <TABLES>
    <TABLE name="quiz_attemptonlast_datasets" />
    <TABLE name="quiz_grades" />
    <TABLE name="question_datasets" />
    <TABLE name="quiz_question_instances" />
    <TABLE name="quiz_question_versions" />
    <TABLE name="question_randomsamatch" />
    <TABLE name="question_truefalse" />
    <TABLE name="question_rqp">
      <FIELDS>
        <FIELD name="format" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_rqp_servers">
      <FIELDS>
        <FIELD name="url" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_rqp_states">
      <FIELDS>
        <FIELD name="responses" method="NO_CONV" type="text" length="0" />
        <FIELD name="persistent_data" method="NO_CONV" type="text" length="0" />
        <FIELD name="template_vars" method="NO_CONV" type="text" length="0" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_rqp_types">
      <FIELDS>
        <FIELD name="name" method="NO_CONV" type="varchar" length="255" dropindex="name" adduniqueindex="name (name(255))"/>
      </FIELDS>
    </TABLE>
    <TABLE name="question_shortanswer">
      <FIELDS>
        <FIELD name="answers" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_numerical">
      <FIELDS>
        <FIELD name="tolerance" method="NO_CONV" type="varchar" length="255" default="0.0" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_sessions" />
    <TABLE name="question_multichoice">
      <FIELDS>
        <FIELD name="answers" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_multianswer">
      <FIELDS>
        <FIELD name="sequence" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_match">
      <FIELDS>
        <FIELD name="subquestions" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_essay">
      <FIELDS>
        <FIELD name="answer" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_dataset_items">
      <FIELDS>
        <FIELD name="value" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_calculated">
      <FIELDS>
        <FIELD name="tolerance" method="NO_CONV" type="varchar" length="20" default="0.0" />
      </FIELDS>
    </TABLE>
    <TABLE name="quiz_attempts">
      <FIELDS>
        <FIELD name="layout" method="NO_CONV" type="text" length="0" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_states">
      <FIELDS>
        <FIELD name="answer" method="PLAIN_SQL_UPDATE" type="text" length="0">
          <SQL_DETECT_USER>
           SELECT qa.userid
           FROM {$CFG->prefix}question_states qs,
                {$CFG->prefix}quiz_attempts qa
           WHERE qa.id = qs.attempt
                 AND qs.id=RECORDID
          </SQL_DETECT_USER>
          <SQL_DETECT_COURSE>
           SELECT q.course
           FROM {$CFG->prefix}quiz q,
                {$CFG->prefix}question_states qs,
                {$CFG->prefix}quiz_attempts qa
           WHERE q.id = qa.quiz
                 AND qa.id = qs.attempt
                 AND qs.id = RECORDID
          </SQL_DETECT_COURSE>
        </FIELD>
      </FIELDS>
    </TABLE>
    <TABLE name="question">
      <FIELDS>
        <FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
          <PHP_FUNCTION>
            migrate2utf8_question_name(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
        <FIELD name="questiontext" method="PHP_FUNCTION" type="text" length="0">
          <PHP_FUNCTION>
            migrate2utf8_question_questiontext(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
        <FIELD name="image" method="NO_CONV" type="varchar" length="255" />
        <FIELD name="stamp" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_numerical_units">
      <FIELDS>
        <FIELD name="unit" method="PHP_FUNCTION" type="varchar" length="50">
          <PHP_FUNCTION>
            migrate2utf8_question_numerical_units_unit(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
      </FIELDS>
    </TABLE>
    <TABLE name="question_match_sub">
      <FIELDS>
        <FIELD name="questiontext" method="PHP_FUNCTION" type="text" length="0">
          <PHP_FUNCTION>
            migrate2utf8_question_match_sub_questionext(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
        <FIELD name="answertext" method="PHP_FUNCTION" type="varchar" length="255">
          <PHP_FUNCTION>
            migrate2utf8_question_match_sub_answertext(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
      </FIELDS>
    </TABLE>
    <TABLE name="question_answers">
      <FIELDS>
        <FIELD name="answer" method="PHP_FUNCTION" type="text" length="0">
          <PHP_FUNCTION>
            migrate2utf8_question_answers_answer(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
        <FIELD name="feedback" method="PHP_FUNCTION" type="text" length="0">
          <PHP_FUNCTION>
            migrate2utf8_question_answers_feedback(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
      </FIELDS>
    </TABLE>
    <TABLE name="question_dataset_definitions">
      <FIELDS>
        <FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
          <PHP_FUNCTION>
            migrate2utf8_question_dataset_definitions_name(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
        <FIELD name="options" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="question_essay_states">
      <FIELDS>
        <FIELD name="response" method="PLAIN_SQL_UPDATE" type="text" length="0">
          <SQL_DETECT_USER>
           SELECT qa.userid
           FROM {$CFG->prefix}question_states qs,
                {$CFG->prefix}quiz_attempts qa,
                {$CFG->prefix}question_essay_states qes
           WHERE qa.id = qs.attempt
                 AND qs.id = qes.stateid
                 AND qes.id = RECORDID
          </SQL_DETECT_USER>
          <SQL_DETECT_COURSE>
           SELECT q.course
           FROM {$CFG->prefix}quiz q,
                {$CFG->prefix}quiz_attempts qa,
                {$CFG->prefix}question_states qs,
                {$CFG->prefix}question_essay_states qes
           WHERE q.id = qa.quiz
                 AND qa.id = qs.attempt
                 AND qs.id = qes.stateid
                 AND qes.id = RECORDID
          </SQL_DETECT_COURSE>
        </FIELD>
      </FIELDS>
    </TABLE>
    <TABLE name="question_categories">
      <FIELDS>
        <FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
          <PHP_FUNCTION>
            migrate2utf8_question_categories_name(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
        <FIELD name="info" method="PHP_FUNCTION" type="text" length="0">
          <PHP_FUNCTION>
            migrate2utf8_question_categories_info(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
        <FIELD name="stamp" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
    <TABLE name="quiz">
      <FIELDS>
        <FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
          <PHP_FUNCTION>
            migrate2utf8_quiz_name(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
        <FIELD name="intro" method="PHP_FUNCTION" type="text" length="0">
          <PHP_FUNCTION>
            migrate2utf8_quiz_intro(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
        <FIELD name="questions" method="NO_CONV" type="text" length="0" />
        <FIELD name="password" method="PHP_FUNCTION" type="varchar" length="255">
          <PHP_FUNCTION>
            migrate2utf8_quiz_password(RECORDID)
          </PHP_FUNCTION>
        </FIELD>
        <FIELD name="subnet" method="NO_CONV" type="varchar" length="255" />
      </FIELDS>
    </TABLE>
  </TABLES>
</DBMIGRATION>
