Skip to content

Commit

Permalink
MDL-15837 Finished sql_ helper unit tests for mysql and postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Aug 8, 2008
1 parent 0b0bfa9 commit 06a546b
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions lib/dml/simpletest/test_postgres7_adodb_moodle_database.php
Expand Up @@ -13,24 +13,15 @@ class postgres7_adodb_moodle_database_test extends dbspecific_test {
function test_ilike() {
$DB = $this->tdb;

$dbman = $DB->get_manager();

$table = new xmldb_table("testtable");
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, '0');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table);
$this->tables[$table->getName()] = $table;

$id = $DB->insert_record('testtable', array('name' => 'SuperDuperREcord'));

$wheresql = "name " . $DB->sql_ilike() . " '%per%'";
$record = $DB->get_record_select('testtable', $wheresql);
$this->assertEqual('SuperDuperREcord', $record->name);
$sql = "SELECT 'SuperDuperRecord' " . $DB->sql_ilike() . " '%per%' AS result";
$record = $DB->get_record_sql($sql);
$this->assertEqual('t', $record->result);

$wheresql = "name " . $DB->sql_ilike() . " 'per'";
$record = $DB->get_record_select('testtable', $wheresql);
$this->assertFalse($record);
$sql = "SELECT 'SuperDuperRecord' " . $DB->sql_ilike() . " 'per' AS result";
$record = $DB->get_record_sql($sql);
$this->assertEqual('f',$record->result);
}

function test_concat() {
Expand All @@ -47,12 +38,27 @@ function test_bitxor() {

function test_cast_char2int() {
$DB = $this->tdb;
$field = $DB->get_field_sql("SELECT " . $DB->sql_cast_char2int("'two'"));
$this->assertFalse($field);
$field = $DB->get_field_sql("SELECT " . $DB->sql_cast_char2int("'74971.4901'"));
$this->assertFalse($field);
$field = $DB->get_field_sql("SELECT " . $DB->sql_cast_char2int("'74971'"));
$this->assertEqual(74971, $field);
}

function test_cast_char2real() {
$DB = $this->tdb;
$field = $DB->get_field_sql("SELECT " . $DB->sql_cast_char2real("'74971.55'"));
$this->assertEqual(74971.5, $field);
$field = $DB->get_field_sql("SELECT " . $DB->sql_cast_char2real("'74971.59'"));
$this->assertEqual(74971.6, $field);
}

function test_regex() {
$DB = $this->tdb;
$name = 'something or another';

$sql = "SELECT '$name' ".$DB->sql_regex()." 'th'";
$this->assertEqual('t', $DB->get_field_sql($sql));

$sql = "SELECT '$name' ".$DB->sql_regex(false)." 'th'";
$this->assertEqual('f', $DB->get_field_sql($sql));
}
}
?>

0 comments on commit 06a546b

Please sign in to comment.