{"action":"created","issue":{"url":"https://api.github.com/repos/requery/requery/issues/62","repository_url":"https://api.github.com/repos/requery/requery","labels_url":"https://api.github.com/repos/requery/requery/issues/62/labels{/name}","comments_url":"https://api.github.com/repos/requery/requery/issues/62/comments","events_url":"https://api.github.com/repos/requery/requery/issues/62/events","html_url":"https://github.com/requery/requery/issues/62","id":144345506,"number":62,"title":"Allow safe raw queries ","user":{"login":"cbruegg","id":175421,"avatar_url":"https://avatars.githubusercontent.com/u/175421?v=3","gravatar_id":"","url":"https://api.github.com/users/cbruegg","html_url":"https://github.com/cbruegg","followers_url":"https://api.github.com/users/cbruegg/followers","following_url":"https://api.github.com/users/cbruegg/following{/other_user}","gists_url":"https://api.github.com/users/cbruegg/gists{/gist_id}","starred_url":"https://api.github.com/users/cbruegg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbruegg/subscriptions","organizations_url":"https://api.github.com/users/cbruegg/orgs","repos_url":"https://api.github.com/users/cbruegg/repos","events_url":"https://api.github.com/users/cbruegg/events{/privacy}","received_events_url":"https://api.github.com/users/cbruegg/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/requery/requery/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":{"login":"npurushe","id":4143434,"avatar_url":"https://avatars.githubusercontent.com/u/4143434?v=3","gravatar_id":"","url":"https://api.github.com/users/npurushe","html_url":"https://github.com/npurushe","followers_url":"https://api.github.com/users/npurushe/followers","following_url":"https://api.github.com/users/npurushe/following{/other_user}","gists_url":"https://api.github.com/users/npurushe/gists{/gist_id}","starred_url":"https://api.github.com/users/npurushe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/npurushe/subscriptions","organizations_url":"https://api.github.com/users/npurushe/orgs","repos_url":"https://api.github.com/users/npurushe/repos","events_url":"https://api.github.com/users/npurushe/events{/privacy}","received_events_url":"https://api.github.com/users/npurushe/received_events","type":"User","site_admin":false},"milestone":null,"comments":6,"created_at":"2016-03-29T18:16:56Z","updated_at":"2016-04-13T16:25:27Z","closed_at":"2016-04-13T05:29:59Z","body":"As mentioned in a reddit thread a few hours ago, it would be great if requery would support safe raw queries. For example:\r\n\r\n`List<Book> books = [...].queryRaw(\"SELECT * FROM books WHERE title = ?\", \"Harry Potter\");`\r\n\r\nArguments should be escaped properly. Requery should not make assumptions about the structure of the query, so that any SQL statement that returns rows compatible with the type argument (`Book` in this case). \r\n\r\nAnother nice feature would be to have a similar method returning the result of an aggregate function, for example `Count(*)`/`Sum(price)`. \r\n\r\nI haven't taken a look at the structure of this project yet, but if you could give me a brief description of steps to be taken to implement this, I could try to work on this and submit a PR. \r\n\r\n**Edit:** \r\nIn order to support `IN`-statements, the methods should apply the following transformations:\r\n\r\n`List<Book> books = [...].queryRaw(\"SELECT * FROM books WHERE title IN ?\", Arrays.asList(\"Harry Potter\", \"Another Book\"));`\r\nbecomes the following SQL statement behind the scenes: `SELECT * FROM books WHERE title IN (?, ?)` and the iterable or array is 'inlined' into the other arguments.\r\n\r\nTo make dealing with `null`-values easier, `List<Book> books = [...].queryRaw(\"SELECT * FROM books WHERE title = ?\", null);`\r\ncould become `SELECT * FROM books WHERE title IS NULL` behind the scenes for conveniece. I couldn't come up with a case where this wouldn't be desirable behavior.\r\n"},"comment":{"url":"https://api.github.com/repos/requery/requery/issues/comments/209531355","html_url":"https://github.com/requery/requery/issues/62#issuecomment-209531355","issue_url":"https://api.github.com/repos/requery/requery/issues/62","id":209531355,"user":{"login":"cbruegg","id":175421,"avatar_url":"https://avatars.githubusercontent.com/u/175421?v=3","gravatar_id":"","url":"https://api.github.com/users/cbruegg","html_url":"https://github.com/cbruegg","followers_url":"https://api.github.com/users/cbruegg/followers","following_url":"https://api.github.com/users/cbruegg/following{/other_user}","gists_url":"https://api.github.com/users/cbruegg/gists{/gist_id}","starred_url":"https://api.github.com/users/cbruegg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbruegg/subscriptions","organizations_url":"https://api.github.com/users/cbruegg/orgs","repos_url":"https://api.github.com/users/cbruegg/repos","events_url":"https://api.github.com/users/cbruegg/events{/privacy}","received_events_url":"https://api.github.com/users/cbruegg/received_events","type":"User","site_admin":false},"created_at":"2016-04-13T16:25:26Z","updated_at":"2016-04-13T16:25:26Z","body":"I see, thanks for explaining. Too bad \"WHERE Col = null\" doesn't behave like a Java programmer would expect in SQL. "}}