From 06a546bdae1fa1ae2dd9e7ac61f5501bb688f197 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Fri, 8 Aug 2008 11:03:03 +0000 Subject: [PATCH] MDL-15837 Finished sql_ helper unit tests for mysql and postgres --- .../test_postgres7_adodb_moodle_database.php | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/dml/simpletest/test_postgres7_adodb_moodle_database.php b/lib/dml/simpletest/test_postgres7_adodb_moodle_database.php index 2213e79d80..367dc1e6a8 100644 --- a/lib/dml/simpletest/test_postgres7_adodb_moodle_database.php +++ b/lib/dml/simpletest/test_postgres7_adodb_moodle_database.php @@ -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() { @@ -47,12 +38,27 @@ class postgres7_adodb_moodle_database_test extends dbspecific_test { 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)); + } } ?> -- 2.39.5