Adding two helper functions and modify upgrade to
work properly under MSSQL and Oracle. MDL-8303
This commit is contained in:
@@ -1621,6 +1621,22 @@ function sql_as() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the empty string char used by every supported DB. To be used when
|
||||
* we are searching for that values in our queries. Only Oracle uses this
|
||||
* for now (will be out, once we migrate to proper NULLs if that days arrives)
|
||||
*/
|
||||
function sql_empty() {
|
||||
global $CFG;
|
||||
|
||||
switch ($CFG->dbtype) {
|
||||
case 'oci8po':
|
||||
return ' '; //Only Oracle uses 1 white-space
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the proper substr() function for each DB
|
||||
* Relies on ADOdb $db->substr property
|
||||
@@ -1632,6 +1648,19 @@ function sql_substr() {
|
||||
return $db->substr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL text to be used to compare one TEXT (clob) column with
|
||||
* one varchar column, because some RDBMS doesn't support such direct
|
||||
* comparisons.
|
||||
* @param string fieldname the name of the TEXT field we need to order by
|
||||
* @param string number of chars to use for the ordering (defaults to 32)
|
||||
* @return string the piece of SQL code to be used in your statement.
|
||||
*/
|
||||
function sql_compare_text($fieldname, $numchars=32) {
|
||||
return sql_order_by_text($fieldname, $numchars);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the SQL text to be used to order by one TEXT (clob) column, because
|
||||
* some RDBMS doesn't support direct ordering of such fields.
|
||||
|
||||
@@ -27,7 +27,7 @@ function xmldb_qtype_numerical_upgrade($oldversion=0) {
|
||||
// from the empty string to *, to be like short answer questions.
|
||||
if ($result && $oldversion < 2006032201) {
|
||||
$result = set_field_select('question_answers', 'answer', '*',
|
||||
"answer = '' AND question IN (SELECT id FROM {$CFG->prefix}question WHERE qtype = '" . NUMERICAL . "')");
|
||||
sql_compare_text('answer') . " = '" . sql_empty() . "' AND question IN (SELECT id FROM {$CFG->prefix}question WHERE qtype = '" . NUMERICAL . "')");
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
Reference in New Issue
Block a user