From 588af7d081e11db69277612f196f8cb264ac1243 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 24 Jan 2013 13:06:19 +0100 Subject: Store user query and if query was correct --- sqlbox/db/install.xml | 18 +++++++++++++++++- sqlbox/db/upgrade.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) (limited to 'sqlbox/db') diff --git a/sqlbox/db/install.xml b/sqlbox/db/install.xml index 2c818c1..9123411 100644 --- a/sqlbox/db/install.xml +++ b/sqlbox/db/install.xml @@ -4,7 +4,7 @@ xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" > - +
@@ -22,5 +22,21 @@
+ + + + + + + + + + + + + + + +
diff --git a/sqlbox/db/upgrade.php b/sqlbox/db/upgrade.php index fb0c671..08724e4 100644 --- a/sqlbox/db/upgrade.php +++ b/sqlbox/db/upgrade.php @@ -67,7 +67,49 @@ function xmldb_sqlbox_upgrade($oldversion) { // http://docs.moodle.org/en/Development:XMLDB_Documentation // and to play with the XMLDB Editor (in the admin menu) and its // PHP generation posibilities. + if ($oldversion < 2013012402) { + $table = new xmldb_table('sqlbox_solutions'); + $field = new xmldb_field('correct', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'query'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + upgrade_mod_savepoint(true, 2013012402, 'sqlbox'); + } + if ($oldversion < 2013012401) { + $table = new xmldb_table('sqlbox_solutions'); + $fieldold = new xmldb_field('correct'); + if ($dbman->field_exists($table, $fieldold)) { + $dbman->drop_field($table, $fieldold); + } + // sqlbox savepoint reached + upgrade_mod_savepoint(true, 2013012401, 'sqlbox'); + } + if ($oldversion < 2013012400) { + // Define table sqlbox_solutions to be created + $table = new xmldb_table('sqlbox_solutions'); + + // Adding fields to table sqlbox_solutions + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('sqlboxid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); + $table->add_field('query', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); + $table->add_field('correct', XMLDB_TYPE_BINARY, null, null, null, null, null); + + // Adding keys to table sqlbox_solutions + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('sqlboxid', XMLDB_KEY_FOREIGN, array('sqlboxid'), 'sqlbox', array('id')); + + // Adding indexes to table sqlbox_solutions + $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); + + // Conditionally launch create table for sqlbox_solutions + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + // sqlbox savepoint reached + upgrade_mod_savepoint(true, 2013012400, 'sqlbox'); + } if ($oldversion < 20121223) { // Define field query to be added to sqlbox $table = new xmldb_table('sqlbox'); -- cgit