There is an issue where 'closing bracket' does not appear when there is 'cached query' and 'multiple nested brackets'.
Here is the example code:
PHP Code:
// cached query
$this->db->start_cache();
$this->db->where("col_desc", 'test_inside_bracket');
$this->db->stop_cache();
// add additional 'where' using bracket (used to implement 'keyset pagination')
$this->db->bracket();
$this->db->bracket();
$this->db->where("col_name > 'test_name'");
$this->db->bracket_close();
$this->db->or_bracket();
$this->db->where("col_name = 'test_name'");
$this->db->where("col_id < 12345");
$this->db->bracket_close();
$this->db->bracket_close();
$this->db->order_by("col_name asc, col_id desc");
// check the query
$check_query = $this->db->_get_select();
die($check_query);
---
The result from code above is:
Code:
SELECT *
WHERE col_desc = 'test_inside_bracket'
AND (
(
col_name > 'test_name'
)
OR (
col_name = 'test_name'
AND col_id < 12345
)
ORDER BY col_name asc, col_id desc
The above result is missing 1 closing bracket.
The expected output should be like this:
Code:
SELECT *
WHERE col_desc = 'test_inside_bracket'
AND (
(
col_name > 'test_name'
)
OR (
col_name = 'test_name'
AND col_id < 12345
)
)
ORDER BY col_name asc, col_id desc
---
The issue above is gone when I remove the start_cache() and stop_cache() line (or one of those).
PHP Code:
// no cache, just plain where and some brackets
$this->db->where("col_desc", 'test_inside_bracket');
$this->db->bracket();
$this->db->bracket();
$this->db->where("col_name > 'test_name'");
$this->db->bracket_close();
$this->db->or_bracket();
$this->db->where("col_name = 'test_name'");
$this->db->where("col_id < 12345");
$this->db->bracket_close();
$this->db->bracket_close();
$this->db->order_by("col_name asc, col_id desc");
// check the query
$check_query = $this->db->_get_select();
die($check_query);
And the issue above is also gone when there is only one nested bracket:
PHP Code:
// cached query
$this->db->start_cache();
$this->db->where("col_desc", 'test_inside_bracket');
$this->db->stop_cache();
// add additional 'where' using bracket (used to implement 'keyset pagination')
$this->db->bracket();
$this->db->bracket();
$this->db->where("col_name > 'test_name'");
$this->db->bracket_close();
// $this->db->or_bracket(); // if this bracket (and closing bracket) is uncommented, the closing bracket will be missing
// $this->db->where("col_name = 'test_name'");
// $this->db->where("col_id < 12345");
// $this->db->bracket_close();
$this->db->bracket_close();
$this->db->order_by("col_name asc, col_id desc");
// check the query
$check_query = $this->db->_get_select();
die($check_query);
---
Please help with the issue above.
Any feedback / workaround would be greatly appreciated.
Thank you.
NB:
Temporary solusion for that issue is doing 'cache query' manually (put the query in function, then call that function to get the query. Not using start_cache()).