Adding two helper functions and modify upgrade to

work properly under MSSQL and Oracle. MDL-8303
This commit is contained in:
stronk7
2007-01-26 20:44:57 +00:00
parent 4ca9e54f7f
commit 14da408e08
2 changed files with 30 additions and 1 deletions
+29
View File
@@ -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.
+1 -1
View File
@@ -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;