diff --git a/lib/db/install.xml b/lib/db/install.xml index 44a5e65bce8..809ff5ec733 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -1352,9 +1352,6 @@ - - - diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 64fe2567f95..e2dff5017b7 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -4700,5 +4700,20 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2015111605.07); } + if ($oldversion < 2015111606.01) { + + // Define index attemptstepid-name (unique) to be dropped from question_attempt_step_data. + $table = new xmldb_table('question_attempt_step_data'); + $index = new xmldb_index('attemptstepid-name', XMLDB_INDEX_UNIQUE, array('attemptstepid', 'name')); + + // Conditionally launch drop index attemptstepid-name. + if ($dbman->index_exists($table, $index)) { + $dbman->drop_index($table, $index); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2015111606.01); + } + return true; } diff --git a/question/engine/datalib.php b/question/engine/datalib.php index 0731252ff0b..a30b54bba76 100644 --- a/question/engine/datalib.php +++ b/question/engine/datalib.php @@ -287,10 +287,19 @@ class question_engine_data_mapper { */ public function update_question_attempt_metadata(question_attempt $qa, array $names) { global $DB; - list($condition, $params) = $DB->get_in_or_equal($names); - $params[] = $qa->get_step(0)->get_id(); + if (!$names) { + return []; + } + // Use case-sensitive LIKE instead of get_in_or_equal. + // Some databases may use case-insensitive collation, we don't want to delete 'X' instead of 'x'. + $sqls = []; + $params = [$qa->get_step(0)->get_id()]; + foreach ($names as $name) { + $sqls[] = $DB->sql_like('name', '?', true); + $params[] = $DB->sql_like_escape($name); + } $DB->delete_records_select('question_attempt_step_data', - 'name ' . $condition . ' AND attemptstepid = ?', $params); + 'attemptstepid = ? AND (' . join(' OR ', $sqls) . ')', $params); return $this->insert_question_attempt_metadata($qa, $names); } diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index 896def424f5..4426c6205e6 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -281,9 +281,9 @@ class qtype_calculated extends question_type { if ($sharedatasetdefs = $DB->get_records_select( 'question_dataset_definitions', "type = '1' - AND name = ? + AND " . $DB->sql_like('name', '?') . " AND category = ? - ORDER BY id DESC ", array($dataset->name, $question->category) + ORDER BY id DESC ", array($DB->sql_like_escape($dataset->name), $question->category) )) { // So there is at least one. $sharedatasetdef = array_shift($sharedatasetdefs); if ($sharedatasetdef->options == $datasetdef->options) {// Identical so use it. @@ -1400,9 +1400,9 @@ class qtype_calculated extends question_type { // can manage to automatically take care of // some possible realtime concurrence. if ($olderdatasetdefs = $DB->get_records_select('question_dataset_definitions', - "type = ? AND name = ? AND category = ? AND id < ? + "type = ? AND " . $DB->sql_like('name', '?') . " AND category = ? AND id < ? ORDER BY id DESC", - array($datasetdef->type, $datasetdef->name, + array($datasetdef->type, $DB->sql_like_escape($datasetdef->name), $datasetdef->category, $datasetdef->id))) { while ($olderdatasetdef = array_shift($olderdatasetdefs)) { @@ -1484,8 +1484,9 @@ class qtype_calculated extends question_type { // Construct question local options. $sql = "SELECT a.* FROM {question_dataset_definitions} a, {question_datasets} b - WHERE a.id = b.datasetdefinition AND a.type = '1' AND b.question = ? AND a.name = ?"; - $currentdatasetdef = $DB->get_record_sql($sql, array($form->id, $name)); + WHERE a.id = b.datasetdefinition AND a.type = '1' AND b.question = ? AND ". + $DB->sql_like('a.name', '?'); + $currentdatasetdef = $DB->get_record_sql($sql, array($form->id, $DB->sql_like_escape($name))); if (!$currentdatasetdef) { $currentdatasetdef = new stdClass(); $currentdatasetdef->type = '0'; @@ -1506,7 +1507,7 @@ class qtype_calculated extends question_type { WHERE a.id = b.datasetdefinition AND a.type = '1' AND a.category = ? - AND a.name = ?", array($form->category, $name)); + AND " . $DB->sql_like('a.name', '?'), array($form->category, $DB->sql_like_escape($name))); $type = 1; $key = "{$type}-{$form->category}-{$name}"; if (!empty($categorydatasetdefs)) { diff --git a/version.php b/version.php index 13337212ccf..40e27515841 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2015111606.00; // 20151116 = branching date YYYYMMDD - do not modify! +$version = 2015111606.01; // 20151116 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes.