{"action":"created","issue":{"url":"https://api.github.com/repos/mybatis/mybatis-3/issues/415","labels_url":"https://api.github.com/repos/mybatis/mybatis-3/issues/415/labels{/name}","comments_url":"https://api.github.com/repos/mybatis/mybatis-3/issues/415/comments","events_url":"https://api.github.com/repos/mybatis/mybatis-3/issues/415/events","html_url":"https://github.com/mybatis/mybatis-3/issues/415","id":81657475,"number":415,"title":"<foreach> does not properly close IN-clause if the collection is empty.","user":{"login":"gitolathe","id":5220396,"avatar_url":"https://avatars.githubusercontent.com/u/5220396?v=3","gravatar_id":"","url":"https://api.github.com/users/gitolathe","html_url":"https://github.com/gitolathe","followers_url":"https://api.github.com/users/gitolathe/followers","following_url":"https://api.github.com/users/gitolathe/following{/other_user}","gists_url":"https://api.github.com/users/gitolathe/gists{/gist_id}","starred_url":"https://api.github.com/users/gitolathe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gitolathe/subscriptions","organizations_url":"https://api.github.com/users/gitolathe/orgs","repos_url":"https://api.github.com/users/gitolathe/repos","events_url":"https://api.github.com/users/gitolathe/events{/privacy}","received_events_url":"https://api.github.com/users/gitolathe/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-27T22:43:52Z","updated_at":"2015-05-28T07:15:46Z","closed_at":"2015-05-28T03:47:20Z","body":"The `<foreach>` tag changed behavior between version 3.2.7 and 3.2.8. Having a `<select>` like below in a mapper file:\r\n\r\n```xml\r\n<select id=\"getReports\" parameterType=\"list\" resultMap=\"reportResultMap\">\r\n    select * from REPORTS where reportId IN\r\n    <foreach item=\"item\" index=\"index\" collection=\"list\" open=\"(\" separator=\",\" close=\")\">\r\n        #{item.id}\r\n    </foreach>\r\n</select>\r\n```\r\nthe `IN`-clause is rendered invalid with version 3.2.8 but works just fine with 3.2.7.\r\n\r\nIt seems quite likely that the changed behavior is caused by the fix for #195 which issued the `if`-statement \r\n```java\r\n    if (!iterable.iterator().hasNext()) {\r\n      return true;\r\n    }\r\n```\r\nto be added to `ForEachSqlNode.apply()` in commit [abf2ef3616](https://github.com/mybatis/mybatis-3/blob/abf2ef361641221be092008b90c74e4f0d510528/src/main/java/org/apache/ibatis/scripting/xmltags/ForEachSqlNode.java) at row 55.\r\n\r\n**3.2.7**\r\nThe `IN` clause is properly closed with an empty collection:\r\n```sql\r\nselect * from REPORTS where REPORTID IN ( ) \r\n```\r\nwhich is valid SQL.\r\n\r\n**3.2.8**\r\nThe `open` and `close` attributes are not applied thus the SQL is not valid since there are no opening and ending parenthesis following the `IN`:\r\n```\r\n### Error querying database.  Cause: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement \"SELECT * FROM REPORTS WHERE REPORTID IN [*]\"; expected \"(\"; SQL statement:\r\n```"},"comment":{"url":"https://api.github.com/repos/mybatis/mybatis-3/issues/comments/106205201","html_url":"https://github.com/mybatis/mybatis-3/issues/415#issuecomment-106205201","issue_url":"https://api.github.com/repos/mybatis/mybatis-3/issues/415","id":106205201,"user":{"login":"gitolathe","id":5220396,"avatar_url":"https://avatars.githubusercontent.com/u/5220396?v=3","gravatar_id":"","url":"https://api.github.com/users/gitolathe","html_url":"https://github.com/gitolathe","followers_url":"https://api.github.com/users/gitolathe/followers","following_url":"https://api.github.com/users/gitolathe/following{/other_user}","gists_url":"https://api.github.com/users/gitolathe/gists{/gist_id}","starred_url":"https://api.github.com/users/gitolathe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gitolathe/subscriptions","organizations_url":"https://api.github.com/users/gitolathe/orgs","repos_url":"https://api.github.com/users/gitolathe/repos","events_url":"https://api.github.com/users/gitolathe/events{/privacy}","received_events_url":"https://api.github.com/users/gitolathe/received_events","type":"User","site_admin":false},"created_at":"2015-05-28T07:15:46Z","updated_at":"2015-05-28T07:15:46Z","body":"Hi Harawata,\r\n\r\nThanks for the response and it seems like you're correct. Apparently at least one value expression must be provided [ (Second Informal Review Draft) ISO/IEC 9075:1992, Database\r\n         Language SQL- July 30, 1992](http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt) so I've learned something :smile: :\r\n\r\n```\r\n8.4  <in predicate>\r\n\r\nFunction\r\n\r\nSpecify a quantified comparison.\r\n\r\nFormat\r\n\r\n<in predicate> ::=\r\n    <row value constructor>\r\n      [ NOT ] IN <in predicate value>\r\n\r\n<in predicate value> ::=\r\n      <table subquery>\r\n    | <left paren> <in value list> <right paren>\r\n\r\n<in value list> ::=\r\n    <value expression> { <comma> <value expression> }...\r\n```"}}