Details
Description
When creating a backup of a course the questions aren't included in the moodle.xml. When we activate the debug tool the followings error are showed:
ERROR 1 - ORA-00918: column ambiguously defined
To solve the problem it's necessary to revise the SQL sentence in the question/backuplib.php file (line 167) to add "q." before the id ordering field (as following):
$questions = get_records_sql("SELECT q.* FROM {$CFG->prefix}backup_ids bk, {$CFG->prefix}question q ".
"WHERE q.category= $category AND ".
"bk.old_id=q.id AND ".
"bk.backup_code = {$preferences->backup_unique_code} ".
"ORDER BY parent ASC, q.id"); // <----- This is where it's necessary to change id for q.id
ERROR2 - ORA-01400: cannot insert NULL into ("USU8"."MLBACKUP_IDS"."INFO")
To solve this problem it's necessary to revise also another SQL sentence in the question/backuplib.php file (line 464) to add a space in the info value:
$status = execute_sql("INSERT INTO {$CFG->prefix}backup_ids
(backup_code, table_name, old_id, info)
SELECT '$backup_unique_code', 'question', q.id, ' ' // <----- This is where it's necessary to change '' for ' '
FROM {$CFG->prefix}question q, {$CFG->prefix}backup_ids bk
WHERE q.category = bk.old_id AND bk.table_name = 'question_categories'
AND " . sql_compare_text('bk.info') . " = '$info'
AND bk.backup_code = '$backup_unique_code'", false);
Could you include this improvement to the main branch to solve the question backup problem in the following versions?
Activity
- All
- Comments
- History
- Activity
- Source
- Test Sessions
Great! Thanks for finding and working out the fix to the problem.
You just made one mistake. The ' ' bit is for Oracle only, not other databases, to work round the rather strange fact that Oracle thinks that '' and NULL are the same thing. Therefore, the correct fix is to use the sql_empty() function.
Fix committed to 1.9 branch and 2.0 dev.