summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/codeigniter/database/query_builder/escape_test.php41
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