summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/DB_query_builder.php2
-rw-r--r--tests/codeigniter/database/query_builder/like_test.php23
2 files changed, 24 insertions, 1 deletions
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 744c4970e..41148f63b 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -1042,7 +1042,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$v = "'{$v}'";
break;
case 'before':
- $v = "%'{$v}'";
+ $v = "'%{$v}'";
break;
case 'after':
$v = "'{$v}%'";
diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php
index 3672afae3..4d8673d99 100644
--- a/tests/codeigniter/database/query_builder/like_test.php
+++ b/tests/codeigniter/database/query_builder/like_test.php
@@ -103,4 +103,27 @@ class Like_test extends CI_TestCase {
$this->assertCount(1, $tabs);
}
+ /**
+ * GitHub issue #5462
+ *
+ * @see ./mocks/schema/skeleton.php
+ *
+ * @dataProvider like_set_side_provider
+ */
+ public function test_like_set_side($str, $side, $expected_name)
+ {
+ $actual = $this->db->like('name', $str, $side)->get('job')->result_array();
+ $this->assertCount(1, $actual);
+ $this->assertEquals($expected_name, $actual[0]['name']);
+ }
+
+ public function like_set_side_provider()
+ {
+ return array(
+ array('Developer', 'none', 'Developer'),
+ array('tician', 'before', 'Politician'),
+ array('Accou', 'after', 'Accountant'),
+ array('usicia', 'both', 'Musician'),
+ );
+ }
}