MDL-17408 DML: new sql_modulo() method + test

This commit is contained in:
skodak 2008-11-26 08:19:45 +00:00
parent d85e995ab6
commit e6df37346f
2 changed files with 18 additions and 0 deletions

View 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.
*

View File

@ -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();