Skip to content

Commit

Permalink
Merge pull request #5464 from ytetsuro/fix/#5462/like-before-bug
Browse files Browse the repository at this point in the history
Fixed issue #5462 Query Builder LIKE BEFORE doesnt work
  • Loading branch information
narfbg authored Apr 14, 2018
2 parents c243df3 + deba4d9 commit fb61fa3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/database/DB_query_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $n
$v = "'{$v}'";
break;
case 'before':
$v = "%'{$v}'";
$v = "'%{$v}'";
break;
case 'after':
$v = "'{$v}%'";
Expand Down
23 changes: 23 additions & 0 deletions tests/codeigniter/database/query_builder/like_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,27 @@ public function test_like_spaces_and_tabs()
$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'),
);
}
}

0 comments on commit fb61fa3

Please sign in to comment.