diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index 479b1ccda04..13b11d28cef 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -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. * diff --git a/lib/dml/simpletest/testdml.php b/lib/dml/simpletest/testdml.php index d2561b615b1..13d9dc071bf 100755 --- a/lib/dml/simpletest/testdml.php +++ b/lib/dml/simpletest/testdml.php @@ -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();