Ticket #204 (assigned Patch)
Parenthesis Support
| Reported by: | sasan | Owned by: | zombor |
|---|---|---|---|
| Priority: | critical | Milestone: | 2.2 |
| Component: | Libraries:Database | Version: | SVN HEAD |
| Keywords: | Cc: |
Description
This patch will help you to put parentheses in your SQL queries. Imagine the following query:
SELECT `username`, `lastname`, `appname`, `id`, `name` ,`group_name` FROM arag_users JOIN `arag_groups` ON arag_groups.id = arag_users.group_id WHERE `group_name` LIKE '%admin%' AND (username LIKE '%admin%' OR name LIKE '%admin%' OR lastname LIKE '%admin%') AND `appname` = 'arag' ORDER BY `appname` ASC, `lastname` ASC, `group_name` ASC
In the above example you can make groups of your where conditions that return a whole boolean result. In this way you can have more flexible where or like clauses. like the following:
if ($user != NULL) {
$row = explode(" ", $user);
foreach ($row as $tag) {
$this->db->like('(username', $tag);
$this->db->orlike($this->tablePrefix.$this->tableNameUsers.".name", $tag);
$this->db->orlike('lastname)', $tag);
}
}
if ($appName != NULL) {
if ($flagappname) {
$this->db->like('appname', $appName);
} else {
$this->db->where('appname', $appName);
}
}
You can even use operators and there will be no conflict, e.g. :
where('id>)', $id)
Change History
Note: See
TracTickets for help on using
tickets.
