]> git.mjollnir.org Git - moodle.git/commitdiff
Introduced one function to calculate the proper "AS"
authorstronk7 <stronk7>
Fri, 1 Sep 2006 17:45:02 +0000 (17:45 +0000)
committerstronk7 <stronk7>
Fri, 1 Sep 2006 17:45:02 +0000 (17:45 +0000)
keyword for columns. All DB seems to support it but
PostgreSQL require it!

lib/dmllib.php

index ef350fd4afdb22ba733ffe853d750e74f452ff9e..24324d56d34fbd70ca5ba47c23d5769c41e174bb 100644 (file)
@@ -1247,6 +1247,8 @@ function sql_fullname($firstname='firstname', $lastname='lastname') {
              return ' CONCAT('. $firstname .'," ",'. $lastname .') ';
         case 'postgres7':
              return " ". $firstname ."||' '||". $lastname ." ";
+        case 'mssql':
+             return " ". $firstname ."+' '+". $lastname ." ";
         default:
              return ' '. $firstname .'||" "||'. $lastname .' ';
     }
@@ -1269,6 +1271,27 @@ function sql_isnull($fieldname) {
     }
 }
 
+/** 
+ * Returns the proper AS keyword to be used to aliase columns
+ * SQL defines the keyword as optional and nobody but PG
+ * seems to require it. This function should be used inside all
+ * the statements using column aliases.
+ * Note than the use of table aliases doesn't require the
+ * AS keyword at all, only columns for postgres.
+ * @uses $CFG
+ * @ return string the keyword
+ */
+function sql_as() {
+    global $db;
+
+    switch ($CFG->dbtype) {
+        case 'postgres7':
+            return 'AS';
+        default:
+            return '';
+    }
+}
+
 /** 
  * Prepare a SQL WHERE clause to select records where the given fields match the given values.
  * 
@@ -1321,6 +1344,7 @@ function column_type($table, $column) {
     return $rs->MetaType($field->type);
 }
 
+
 /**
  * This function, called from setup.php includes all the configuration
  * needed to properly work agains any DB. It setups connection encoding