mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
MDL-17408 DML: new sql_modulo() method + test
This commit is contained in:
parent
d85e995ab6
commit
e6df37346f
@ -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.
|
||||
*
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user