From 1af5b47ad6f95f805d9f411ce020f2e2fa88b302 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 26 May 2012 16:04:39 +0700 Subject: Remove ternary --- .../database/query_builder/escape_test.php | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'tests/codeigniter/database/query_builder') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 5df812ca6..5d575a37b 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -13,9 +13,6 @@ class Escape_test extends CI_TestCase { Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); - - $this->pre = (strpos(DB_DRIVER, 'pgsql') === FALSE) ? '`' : '"'; - $this->esc = (strpos(DB_DRIVER, 'mysql') === FALSE) ? '!' : ''; } // ------------------------------------------------------------------------ @@ -25,9 +22,17 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_percent_sign() { + // Escape the like string $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT {$this->pre}value{$this->pre} FROM {$this->pre}misc{$this->pre} WHERE {$this->pre}key{$this->pre} LIKE '$string%' ESCAPE '$this->esc';"; + if (strpos(DB_DRIVER, 'mysql') !== FALSE) + { + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';"; + } + else + { + $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';'; + } $res = $this->db->query($sql)->result_array(); @@ -42,14 +47,21 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_backslash_sign() { + // Escape the like string $string = $this->db->escape_like_str('\\'); - $sql = "SELECT {$this->pre}value{$this->pre} FROM {$this->pre}misc{$this->pre} WHERE {$this->pre}key{$this->pre} LIKE '$string%' ESCAPE '$this->esc';"; + if (strpos(DB_DRIVER, 'mysql') !== FALSE) + { + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';"; + } + else + { + $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';'; + } $res = $this->db->query($sql)->result_array(); // Check the result $this->assertEquals(2, count($res)); } - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b