From 45516d902ca2dfd5a061123d152e2ed92c86bd9b Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sat, 28 Jun 2008 18:15:38 +0000 Subject: [PATCH] Added sql_ceil() helper function. MDL-15336 --- lib/dmllib.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/dmllib.php b/lib/dmllib.php index 12818a8259a..2f4d29a9c44 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -2160,6 +2160,23 @@ function sql_null_from_clause() { } } +/** + * Returns the correct CEIL expression applied to fieldname + * @param string fieldname the field (or expression) we are going to ceil + * @return string the piece of SQL code to be used in your ceiling statement + */ +function sql_ceil($fieldname) { + global $CFG; + + switch ($CFG->dbfamily) { + case 'mssql': + return ' CEILING(' . $fieldname . ')'; + break; + default: + return ' CEIL(' . $fieldname . ')'; + } +} + /** * Prepare a SQL WHERE clause to select records where the given fields match the given values. *