{"action":"opened","number":4431,"pull_request":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter/pulls/4431","id":58293981,"html_url":"https://github.com/bcit-ci/CodeIgniter/pull/4431","diff_url":"https://github.com/bcit-ci/CodeIgniter/pull/4431.diff","patch_url":"https://github.com/bcit-ci/CodeIgniter/pull/4431.patch","issue_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4431","number":4431,"state":"open","locked":false,"title":"Fix bug in query builder join method (not complete solution)","user":{"login":"rbcpl","id":17065710,"avatar_url":"https://avatars.githubusercontent.com/u/17065710?v=3","gravatar_id":"","url":"https://api.github.com/users/rbcpl","html_url":"https://github.com/rbcpl","followers_url":"https://api.github.com/users/rbcpl/followers","following_url":"https://api.github.com/users/rbcpl/following{/other_user}","gists_url":"https://api.github.com/users/rbcpl/gists{/gist_id}","starred_url":"https://api.github.com/users/rbcpl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbcpl/subscriptions","organizations_url":"https://api.github.com/users/rbcpl/orgs","repos_url":"https://api.github.com/users/rbcpl/repos","events_url":"https://api.github.com/users/rbcpl/events{/privacy}","received_events_url":"https://api.github.com/users/rbcpl/received_events","type":"User","site_admin":false},"body":"If there are curved brackets in the join query, then the first bracket is removed and the second one is kept in some cases, which leads to an incorrect SQL statement. E.g.: \r\n```\r\n\r\n\t// Replace with a meaningful statement.\r\n\t$this->db->select(\"table2.field\");\r\n\t$this->db->from(\"table1\");\r\n\t$this->db->join(\"table2\", \"table1.id = table2.id  AND (table1.id = table2.id OR table1.id = table2.id)\");\r\n\t$this->db->where(\"table1.id = 1\");\r\n\t\t        \r\n\t$query = $this->db->get();\r\n\t\t\r\n\tprint_r($query->row_array());\r\n```\r\n\r\ngenerates the incorrect query: \r\n```\r\n... ON `table1`.`id` = `table2`.`id` AND `table1`.`id` = `table2`.`id` OR `table1`.`id` = table2.id) WHERE ...\r\n```\r\n\r\nIf the join is written like this\r\n\r\n`\t$this->db->join(\"table2\", \"table1.id = table2.id  AND( table1.id = table2.id OR table1.id = table2.id)\");`\r\n\r\nit works. \r\n\r\nThe given solution is only a temporary solution! The given code now works. However, the following join\r\n\r\n`\t$this->db->join(\"table2\", \"table1.id = table2.id  AND ( table1.id = table2.id OR table1.id = table2.id)\");`\r\n\r\ndoes still not work as it generates the following query:\r\n```\r\n\r\nON `table1`.`id` = `table2`.`id` AND ( `table1`.`id =` `table2`.`id` OR `table1`.`id` = table2.id)\r\n\r\n```\r\n(error here: `id =`) Furthermore, the last table2.id is always not embraced by \"`\".\r\n\r\nTo solve the problem, the first added \\( would be enough. However, I also added a \\) and a second \\( in the regex. It has be evaluated, if the the last two addtions are required. One has to dig deeper, to resolve the issue as an whole. I found the bug when migrating from CI 2 to CI 3. In CI2 the query is build co","created_at":"2016-02-04T14:33:02Z","updated_at":"2016-02-04T14:33:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/pulls/4431/commits","review_comments_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/pulls/4431/comments","review_comment_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4431/comments","statuses_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/statuses/bb31891c076df83b3ffdb627c2f1e2449ca3af67","head":{"label":"rbcpl:rbcpl-query-builder","ref":"rbcpl-query-builder","sha":"bb31891c076df83b3ffdb627c2f1e2449ca3af67","user":{"login":"rbcpl","id":17065710,"avatar_url":"https://avatars.githubusercontent.com/u/17065710?v=3","gravatar_id":"","url":"https://api.github.com/users/rbcpl","html_url":"https://github.com/rbcpl","followers_url":"https://api.github.com/users/rbcpl/followers","following_url":"https://api.github.com/users/rbcpl/following{/other_user}","gists_url":"https://api.github.com/users/rbcpl/gists{/gist_id}","starred_url":"https://api.github.com/users/rbcpl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbcpl/subscriptions","organizations_url":"https://api.github.com/users/rbcpl/orgs","repos_url":"https://api.github.com/users/rbcpl/repos","events_url":"https://api.github.com/users/rbcpl/events{/privacy}","received_events_url":"https://api.github.com/users/rbcpl/received_events","type":"User","site_admin":false},"repo":{"id":51076647,"name":"CodeIgniter","full_name":"rbcpl/CodeIgniter","owner":{"login":"rbcpl","id":17065710,"avatar_url":"https://avatars.githubusercontent.com/u/17065710?v=3","gravatar_id":"","url":"https://api.github.com/users/rbcpl","html_url":"https://github.com/rbcpl","followers_url":"https://api.github.com/users/rbcpl/followers","following_url":"https://api.github.com/users/rbcpl/following{/other_user}","gists_url":"https://api.github.com/users/rbcpl/gists{/gist_id}","starred_url":"https://api.github.com/users/rbcpl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbcpl/subscriptions","organizations_url":"https://api.github.com/users/rbcpl/orgs","repos_url":"https://api.github.com/users/rbcpl/repos","events_url":"https://api.github.com/users/rbcpl/events{/privacy}","received_events_url":"https://api.github.com/users/rbcpl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rbcpl/CodeIgniter","description":"Open Source PHP Framework (originally from EllisLab)","fork":true,"url":"https://api.github.com/repos/rbcpl/CodeIgniter","forks_url":"https://api.github.com/repos/rbcpl/CodeIgniter/forks","keys_url":"https://api.github.com/repos/rbcpl/CodeIgniter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rbcpl/CodeIgniter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rbcpl/CodeIgniter/teams","hooks_url":"https://api.github.com/repos/rbcpl/CodeIgniter/hooks","issue_events_url":"https://api.github.com/repos/rbcpl/CodeIgniter/issues/events{/number}","events_url":"https://api.github.com/repos/rbcpl/CodeIgniter/events","assignees_url":"https://api.github.com/repos/rbcpl/CodeIgniter/assignees{/user}","branches_url":"https://api.github.com/repos/rbcpl/CodeIgniter/branches{/branch}","tags_url":"https://api.github.com/repos/rbcpl/CodeIgniter/tags","blobs_url":"https://api.github.com/repos/rbcpl/CodeIgniter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rbcpl/CodeIgniter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rbcpl/CodeIgniter/git/refs{/sha}","trees_url":"https://api.github.com/repos/rbcpl/CodeIgniter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rbcpl/CodeIgniter/statuses/{sha}","languages_url":"https://api.github.com/repos/rbcpl/CodeIgniter/languages","stargazers_url":"https://api.github.com/repos/rbcpl/CodeIgniter/stargazers","contributors_url":"https://api.github.com/repos/rbcpl/CodeIgniter/contributors","subscribers_url":"https://api.github.com/repos/rbcpl/CodeIgniter/subscribers","subscription_url":"https://api.github.com/repos/rbcpl/CodeIgniter/subscription","commits_url":"https://api.github.com/repos/rbcpl/CodeIgniter/commits{/sha}","git_commits_url":"https://api.github.com/repos/rbcpl/CodeIgniter/git/commits{/sha}","comments_url":"https://api.github.com/repos/rbcpl/CodeIgniter/comments{/number}","issue_comment_url":"https://api.github.com/repos/rbcpl/CodeIgniter/issues/comments{/number}","contents_url":"https://api.github.com/repos/rbcpl/CodeIgniter/contents/{+path}","compare_url":"https://api.github.com/repos/rbcpl/CodeIgniter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rbcpl/CodeIgniter/merges","archive_url":"https://api.github.com/repos/rbcpl/CodeIgniter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rbcpl/CodeIgniter/downloads","issues_url":"https://api.github.com/repos/rbcpl/CodeIgniter/issues{/number}","pulls_url":"https://api.github.com/repos/rbcpl/CodeIgniter/pulls{/number}","milestones_url":"https://api.github.com/repos/rbcpl/CodeIgniter/milestones{/number}","notifications_url":"https://api.github.com/repos/rbcpl/CodeIgniter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rbcpl/CodeIgniter/labels{/name}","releases_url":"https://api.github.com/repos/rbcpl/CodeIgniter/releases{/id}","deployments_url":"https://api.github.com/repos/rbcpl/CodeIgniter/deployments","created_at":"2016-02-04T13:10:01Z","updated_at":"2016-02-04T13:10:04Z","pushed_at":"2016-02-04T14:22:11Z","git_url":"git://github.com/rbcpl/CodeIgniter.git","ssh_url":"git@github.com:rbcpl/CodeIgniter.git","clone_url":"https://github.com/rbcpl/CodeIgniter.git","svn_url":"https://github.com/rbcpl/CodeIgniter","homepage":"https://codeigniter.com/","size":41811,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"bcit-ci:develop","ref":"develop","sha":"e54c461d77ffce9f10999ca51bb2e3932304639b","user":{"login":"bcit-ci","id":8863432,"avatar_url":"https://avatars.githubusercontent.com/u/8863432?v=3","gravatar_id":"","url":"https://api.github.com/users/bcit-ci","html_url":"https://github.com/bcit-ci","followers_url":"https://api.github.com/users/bcit-ci/followers","following_url":"https://api.github.com/users/bcit-ci/following{/other_user}","gists_url":"https://api.github.com/users/bcit-ci/gists{/gist_id}","starred_url":"https://api.github.com/users/bcit-ci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcit-ci/subscriptions","organizations_url":"https://api.github.com/users/bcit-ci/orgs","repos_url":"https://api.github.com/users/bcit-ci/repos","events_url":"https://api.github.com/users/bcit-ci/events{/privacy}","received_events_url":"https://api.github.com/users/bcit-ci/received_events","type":"Organization","site_admin":false},"repo":{"id":2234102,"name":"CodeIgniter","full_name":"bcit-ci/CodeIgniter","owner":{"login":"bcit-ci","id":8863432,"avatar_url":"https://avatars.githubusercontent.com/u/8863432?v=3","gravatar_id":"","url":"https://api.github.com/users/bcit-ci","html_url":"https://github.com/bcit-ci","followers_url":"https://api.github.com/users/bcit-ci/followers","following_url":"https://api.github.com/users/bcit-ci/following{/other_user}","gists_url":"https://api.github.com/users/bcit-ci/gists{/gist_id}","starred_url":"https://api.github.com/users/bcit-ci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcit-ci/subscriptions","organizations_url":"https://api.github.com/users/bcit-ci/orgs","repos_url":"https://api.github.com/users/bcit-ci/repos","events_url":"https://api.github.com/users/bcit-ci/events{/privacy}","received_events_url":"https://api.github.com/users/bcit-ci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bcit-ci/CodeIgniter","description":"Open Source PHP Framework (originally from EllisLab)","fork":false,"url":"https://api.github.com/repos/bcit-ci/CodeIgniter","forks_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/forks","keys_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/teams","hooks_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/hooks","issue_events_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/events{/number}","events_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/events","assignees_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/assignees{/user}","branches_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/branches{/branch}","tags_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/tags","blobs_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/git/refs{/sha}","trees_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/statuses/{sha}","languages_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/languages","stargazers_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/stargazers","contributors_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/contributors","subscribers_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/subscribers","subscription_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/subscription","commits_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/commits{/sha}","git_commits_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/git/commits{/sha}","comments_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/comments{/number}","issue_comment_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/comments{/number}","contents_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/contents/{+path}","compare_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/merges","archive_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/downloads","issues_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues{/number}","pulls_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/pulls{/number}","milestones_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/milestones{/number}","notifications_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/labels{/name}","releases_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/releases{/id}","deployments_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/deployments","created_at":"2011-08-19T13:34:00Z","updated_at":"2016-02-04T12:07:43Z","pushed_at":"2016-02-04T13:45:19Z","git_url":"git://github.com/bcit-ci/CodeIgniter.git","ssh_url":"git@github.com:bcit-ci/CodeIgniter.git","clone_url":"https://github.com/bcit-ci/CodeIgniter.git","svn_url":"https://github.com/bcit-ci/CodeIgniter","homepage":"https://codeigniter.com/","size":85584,"stargazers_count":11616,"watchers_count":11616,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5922,"mirror_url":null,"open_issues_count":66,"forks":5922,"open_issues":66,"watchers":11616,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/bcit-ci/CodeIgniter/pulls/4431"},"html":{"href":"https://github.com/bcit-ci/CodeIgniter/pull/4431"},"issue":{"href":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4431"},"comments":{"href":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4431/comments"},"review_comments":{"href":"https://api.github.com/repos/bcit-ci/CodeIgniter/pulls/4431/comments"},"review_comment":{"href":"https://api.github.com/repos/bcit-ci/CodeIgniter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bcit-ci/CodeIgniter/pulls/4431/commits"},"statuses":{"href":"https://api.github.com/repos/bcit-ci/CodeIgniter/statuses/bb31891c076df83b3ffdb627c2f1e2449ca3af67"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":4,"deletions":2,"changed_files":1}}