{"action":"created","issue":{"url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/1071","labels_url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/1071/labels{/name}","comments_url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/1071/comments","events_url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/1071/events","html_url":"https://github.com/backdrop/backdrop-issues/issues/1071","id":97485264,"number":1071,"title":"SQL subquery not always properly bracketed","user":{"login":"lugray","id":6557101,"avatar_url":"https://avatars.githubusercontent.com/u/6557101?v=3","gravatar_id":"","url":"https://api.github.com/users/lugray","html_url":"https://github.com/lugray","followers_url":"https://api.github.com/users/lugray/followers","following_url":"https://api.github.com/users/lugray/following{/other_user}","gists_url":"https://api.github.com/users/lugray/gists{/gist_id}","starred_url":"https://api.github.com/users/lugray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lugray/subscriptions","organizations_url":"https://api.github.com/users/lugray/orgs","repos_url":"https://api.github.com/users/lugray/repos","events_url":"https://api.github.com/users/lugray/events{/privacy}","received_events_url":"https://api.github.com/users/lugray/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-27T15:05:45Z","updated_at":"2015-07-27T15:13:37Z","closed_at":null,"body":"This is ported from Drupal.\r\n\r\nWhen $sub​_query is an instance of ​​SelectInterface the following code generates invalid SQL.\r\n```php\r\n<?php\r\n​​$query->condition('t.somefield', $sub​_query)​;\r\n?>\r\n```\r\nThe following code however, generates valid, working SQL:\r\n```php\r\n<?php\r\n​​$query->condition('t.somefield', $sub​_query, 'IN')​;\r\n?>\r\n```\r\nThe second example works because brackets are added around the sub-​query because it's understood that there are multiple values to test against​. If however, your sub-query ​is designed to return a single value, it would make more sense to use the first example (defaulting to an '=' operator), or you may even wish to use something like\r\n```php\r\n<?php\r\n​$query->condition('t.somefield', $sub​_query, '<'​);​\r\n?>\r\n```\r\nIn which case brackets are not added around the sub-query resulting in the SQL syntax error. At the moment condition values only get bracketed based on the operator used. They also need to be bracketed regardless of operator when the condition value is an instance of ​SelectInterface​."},"comment":{"url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/comments/125241179","html_url":"https://github.com/backdrop/backdrop-issues/issues/1071#issuecomment-125241179","issue_url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/1071","id":125241179,"user":{"login":"quicksketch","id":100206,"avatar_url":"https://avatars.githubusercontent.com/u/100206?v=3","gravatar_id":"","url":"https://api.github.com/users/quicksketch","html_url":"https://github.com/quicksketch","followers_url":"https://api.github.com/users/quicksketch/followers","following_url":"https://api.github.com/users/quicksketch/following{/other_user}","gists_url":"https://api.github.com/users/quicksketch/gists{/gist_id}","starred_url":"https://api.github.com/users/quicksketch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quicksketch/subscriptions","organizations_url":"https://api.github.com/users/quicksketch/orgs","repos_url":"https://api.github.com/users/quicksketch/repos","events_url":"https://api.github.com/users/quicksketch/events{/privacy}","received_events_url":"https://api.github.com/users/quicksketch/received_events","type":"User","site_admin":false},"created_at":"2015-07-27T15:13:37Z","updated_at":"2015-07-27T15:13:37Z","body":"Hi @lugray! Excellent. Could you provide the URL to the Drupal issue for reference? Normally we'll port everything from Drupal when the next release comes out, reapplying every patch if needed.\r\n\r\nOverall though, everything makes sense to me. The PR at https://github.com/backdrop/backdrop/pull/1005 looks good. Are there any tests for this new functionality? It seems like an ideal candidate to have a test to prevent future regressions."}}