]> git.mjollnir.org Git - moodle.git/commitdiff
Adding two helper functions and modify upgrade to
authorstronk7 <stronk7>
Fri, 26 Jan 2007 21:27:44 +0000 (21:27 +0000)
committerstronk7 <stronk7>
Fri, 26 Jan 2007 21:27:44 +0000 (21:27 +0000)
work properly under MSSQL and Oracle. MDL-8303

Added one simple hack to execute_sql() in order
to avoid and debug about trailing ;

lib/dmllib.php

index 17a206d7b51b9447c2445c048631ea24b08fa3b9..5c3dabb3a9567ed271e1ab21f0be70109a226f2b 100644 (file)
@@ -68,6 +68,15 @@ function execute_sql($command, $feedback=true) {
         $db->debug = false;
     }
 
+    if ($CFG->version >= 2006101007) { //Look for trailing ; from Moodle 1.7.0
+        $command = trim($command);
+    /// If the trailing ; is there, fix and warn!
+        if (substr($command, strlen($command)-1, 1) == ';') {
+            $command = trim($command, ';');
+            debugging('Warning. Avoid to end your SQL commands with a trailing ";".', DEBUG_DEVELOPER);
+        }
+    }
+
     $empty_rs_cache = array();  // Clear out the cache, just in case changes were made to table structures
 
     if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
@@ -1620,6 +1629,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->dbfamily) {
+        case 'oracle':
+            return ' '; //Only Oracle uses 1 white-space
+        default:
+            return '';
+    }
+}
+
 /**
  * Returns the proper substr() function for each DB
  * Relies on ADOdb $db->substr property
@@ -1631,6 +1656,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.