<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AQuestion_database_structure</id>
	<title>Development:Question database structure - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AQuestion_database_structure"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Question_database_structure&amp;action=history"/>
	<updated>2026-05-06T18:42:14Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Question_database_structure&amp;diff=11618&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Question_database_structure&amp;diff=11618&amp;oldid=prev"/>
		<updated>2024-10-21T08:52:59Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:52, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Question_database_structure&amp;diff=11617&amp;oldid=prev</id>
		<title>1&gt;TimHunt: /* Following what happens when questions are attempted */</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Question_database_structure&amp;diff=11617&amp;oldid=prev"/>
		<updated>2009-04-01T12:00:59Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Following what happens when questions are attempted&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Question development}}&lt;br /&gt;
&lt;br /&gt;
This page documents the database tables use by the question bank and question engine.&lt;br /&gt;
&lt;br /&gt;
The distinction between the question bank and the question engine is that the question bank stores the question definitions, organised into categories, while the question engine stores the information a user&amp;#039;s attempts at a question or questions.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
[[Image:Question_database.png]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Question_database.dia]] [http://projects.gnome.org/dia/ Dia ] file, should you wish to have a copy of this diagram in an editable format.&lt;br /&gt;
&lt;br /&gt;
==Common field types==&lt;br /&gt;
&lt;br /&gt;
* Fields that hold a question score, like question.defaultgrade or question_answers.fraction, should be NUMBER(12,7).&lt;br /&gt;
* Question text, feedback, etc. should be TEXT(short).&lt;br /&gt;
&lt;br /&gt;
==Detailed table descriptions==&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.0 dev, you can get these by going to Administration -&amp;gt; Development -&amp;gt; XMLDB and clicking on the [Doc] link next in any of the relevant rows (mod/quiz/db, mod/quiz/report/&amp;#039;&amp;#039;xxx&amp;#039;&amp;#039;/db). Looking directly there is much more likely to be up-to-date than relying on information that has been copied here.&lt;br /&gt;
&lt;br /&gt;
(Wouldn&amp;#039;t it be nice if that documentation was automatically build and available online.)&lt;br /&gt;
&lt;br /&gt;
==Individual question types==&lt;br /&gt;
&lt;br /&gt;
The following core question types have their own database tables:&lt;br /&gt;
&lt;br /&gt;
* [[Development:Calculated_question_type#Database_tables|Calculated]]&lt;br /&gt;
* [[Development:Matching_question_type#Database_tables|Matching]]&lt;br /&gt;
* [[Development:Multiple_Choice_question_type#quiz_multichoice_table|Multiple choice]]&lt;br /&gt;
* [[Development:Cloze_question_type#Data_structure|Multi-answer (Cloze)]]&lt;br /&gt;
* [[Development:Numerical_question_type#Database_tables|Numerical]]&lt;br /&gt;
* [[Development:Random_Short-Answer_Matching_question_type#Database_tables|Random short-answer matching]]&lt;br /&gt;
* [[Development:Short_Answer_question_type#Database_tables|Short answer]]&lt;br /&gt;
* [[Development:True/False_question_type#Database_tables|True/false]]&lt;br /&gt;
&lt;br /&gt;
==Following what happens when questions are attempted==&lt;br /&gt;
&lt;br /&gt;
When a user is attempting questions (for example by attempting a quiz), the following query gives the best view of what is happening:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT st.id, st.attempt, st.question, st.seq_number,&lt;br /&gt;
    CASE WHEN st.id = sess.newest THEN &amp;#039;newest&amp;#039; END AS isnewest,&lt;br /&gt;
    CASE WHEN st.id = sess.newgraded THEN &amp;#039;newgraded&amp;#039; END AS isnewgraded,&lt;br /&gt;
    CASE st.event WHEN 0 THEN &amp;#039;0 (open)&amp;#039; WHEN 2 THEN &amp;#039;2 (save)&amp;#039; WHEN 3 THEN &amp;#039;3 (grade)&amp;#039;&lt;br /&gt;
        WHEN 5 THEN &amp;#039;5 (validate)&amp;#039; WHEN 6 THEN &amp;#039;6 (close&amp;amp;grade)&amp;#039; WHEN 7 THEN &amp;#039;7 (submit)&amp;#039;&lt;br /&gt;
        WHEN 8 THEN &amp;#039;8 (close)&amp;#039; WHEN 9 THEN &amp;#039;9 (manualgrade)&amp;#039; ELSE CAST(st.event AS varchar) END AS event,&lt;br /&gt;
    st.answer, st.raw_grade, st.grade, st.penalty, sess.sumpenalty, sess.manualcomment, st.timestamp&lt;br /&gt;
FROM mdl_question_states st&lt;br /&gt;
JOIN mdl_question_sessions sess ON st.question = sess.questionid AND st.attempt = sess.attemptid&lt;br /&gt;
WHERE st.attempt &amp;gt; 0&lt;br /&gt;
ORDER BY st.attempt, st.question, st.seq_number;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I believe that works in both Postgres and MySQL. You probably need to adjust the WHERE clause so that only returns the rows you are interested in. (Actually, does not quite work in MySQL. You need to change &amp;#039;CAST(st.event AS varchar)&amp;#039; to &amp;#039;st.event&amp;#039; in the middle.)&lt;br /&gt;
&lt;br /&gt;
Watching the results of that query as you work through a quiz attempt with a test user account is a very good way to work out what is going on in the code and find bugs.&lt;br /&gt;
&lt;br /&gt;
==Rough change-log==&lt;br /&gt;
&lt;br /&gt;
===Moodle 2.0===&lt;br /&gt;
&lt;br /&gt;
* New field question_sessions.flagged.&lt;br /&gt;
* All fields that store grades were reviewed and set to the recommended types mentioned above.&lt;br /&gt;
&lt;br /&gt;
===Moodle 1.9===&lt;br /&gt;
&lt;br /&gt;
* New question bank:&lt;br /&gt;
** New fields question.timecreated, timemodified, createdby and modifiedby.&lt;br /&gt;
** question_category.course changed to question_category.contextid.&lt;br /&gt;
** Removed field question_category.published.&lt;br /&gt;
&lt;br /&gt;
===Moodle 1.7===&lt;br /&gt;
&lt;br /&gt;
* question_sessions.comment renamed to manualcomment (reserved word).&lt;br /&gt;
* new column question.generalfeedback.&lt;br /&gt;
&lt;br /&gt;
TODO, check CVS history for more.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Development:Quiz_database_structure|Quiz database structure]]&lt;br /&gt;
* [[Development:Database_schema_introduction|Database schema introduction]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Questions]]&lt;/div&gt;</summary>
		<author><name>1&gt;TimHunt</name></author>
	</entry>
</feed>