summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/database
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2012-05-26 13:09:11 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2012-05-26 13:09:11 +0200
commit8f24b1c9ad93365d5e2d20de9f89468e26ebbe34 (patch)
treef4553ae815f16696fd1e36c03f8a2d247881ab4a /tests/codeigniter/database
parentf33e2ff30b0a9c54d6e8adbe88662838b9bd525e (diff)
parent1af5b47ad6f95f805d9f411ce020f2e2fa88b302 (diff)
Merge pull request #1400 from toopay/db-test-suite
Escape test
Diffstat (limited to 'tests/codeigniter/database')
-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