diff options
author | Root <development@fractureme.com> | 2012-05-28 02:07:10 +0200 |
---|---|---|
committer | Root <development@fractureme.com> | 2012-05-28 02:07:10 +0200 |
commit | e526c5a3c0c03088d9fb445d932973735d992ba3 (patch) | |
tree | fa041774010a82c3389949ec4677253df62ec23c /tests/codeigniter/database/query_builder/escape_test.php | |
parent | 3cc8502b48946f7298797393cea0a7183c325244 (diff) | |
parent | 11fd4b8759438f216318e3e1e004f918b88a56ad (diff) |
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into develop
Diffstat (limited to 'tests/codeigniter/database/query_builder/escape_test.php')
-rw-r--r-- | tests/codeigniter/database/query_builder/escape_test.php | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 50685922a..5d575a37b 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -22,15 +22,22 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_percent_sign() { - $string = '\%foo' -; - $this->db->select('value'); - $this->db->from('misc'); - $this->db->like('key', $string, 'after'); - $res = $this->db->get(); + // Escape the like string + $string = $this->db->escape_like_str('\%foo'); + 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(1, count($res->result_array())); + $this->assertEquals(1, count($res)); } // ------------------------------------------------------------------------ @@ -40,15 +47,21 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_backslash_sign() { - $string = '\\'; + // Escape the like string + $string = $this->db->escape_like_str('\\'); - $this->db->select('value'); - $this->db->from('misc'); - $this->db->like('key', $string, 'after'); - $res = $this->db->get(); + 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->result_array())); + $this->assertEquals(2, count($res)); } - }
\ No newline at end of file |