]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17408 DML: new sql_modulo() method + test
authorskodak <skodak>
Wed, 26 Nov 2008 08:19:45 +0000 (08:19 +0000)
committerskodak <skodak>
Wed, 26 Nov 2008 08:19:45 +0000 (08:19 +0000)
lib/dml/moodle_database.php
lib/dml/simpletest/testdml.php

index 479b1ccda04edef250a50a8b83b539d7800e03d0..13b11d28cefc694c4f62a3f4cf7aae283615b91f 100644 (file)
@@ -1421,6 +1421,18 @@ abstract class moodle_database {
         return '((' . $int1 . ') ^ (' . $int2 . '))';
     }
 
+    /**
+     * Returns the SQL text to be used in order to perform module '%'
+     * opration - remainder after division
+     *
+     * @param integer int1 first integer in the operation
+     * @param integer int2 second integer in the operation
+     * @return string the piece of SQL code to be used in your statement.
+     */
+    public function sql_modulo($int1, $int2) {
+        return '((' . $int1 . ') % (' . $int2 . '))';
+    }
+
     /**
      * Returns the correct CEIL expression applied to fieldname.
      *
index d2561b615b12cfe48e913f5f9ba05b4db33e0911..13d9dc071bfb9c696a6566fd3b26e6b00e32cd65 100755 (executable)
@@ -1405,6 +1405,12 @@ class dml_test extends UnitTestCase {
         $this->assertEqual($DB->get_field_sql($sql), 9);
     }
 
+    function test_sql_modulo() {
+        $DB = $this->tdb;
+        $sql = "SELECT ".$DB->sql_modulo(10, 7)." AS number ".$DB->sql_null_from_clause();
+        $this->assertEqual($DB->get_field_sql($sql), 3);
+    }
+
     function test_sql_ceil() {
         $DB = $this->tdb;
         $sql = "SELECT ".$DB->sql_ceil(665.666)." AS number ".$DB->sql_null_from_clause();