{"action":"created","issue":{"url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/176","labels_url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/176/labels{/name}","comments_url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/176/comments","events_url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/176/events","html_url":"https://github.com/greenlion/PHP-SQL-Parser/issues/176","id":89120429,"number":176,"title":"Can not calculate position of query exception","user":{"login":"witchi","id":5766508,"avatar_url":"https://avatars.githubusercontent.com/u/5766508?v=3","gravatar_id":"","url":"https://api.github.com/users/witchi","html_url":"https://github.com/witchi","followers_url":"https://api.github.com/users/witchi/followers","following_url":"https://api.github.com/users/witchi/following{/other_user}","gists_url":"https://api.github.com/users/witchi/gists{/gist_id}","starred_url":"https://api.github.com/users/witchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/witchi/subscriptions","organizations_url":"https://api.github.com/users/witchi/orgs","repos_url":"https://api.github.com/users/witchi/repos","events_url":"https://api.github.com/users/witchi/events{/privacy}","received_events_url":"https://api.github.com/users/witchi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/labels/imported","name":"imported","color":"FFFFFF"},{"url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/labels/Priority-Medium","name":"Priority-Medium","color":"FFFFFF"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-17T20:39:54Z","updated_at":"2015-06-17T20:40:08Z","closed_at":null,"body":"_From [abi...@owasp.org](https://code.google.com/u/100796709490792794235/) on September 25, 2014 22:28:45_\n\nWhat steps will reproduce the problem? 1. Parse the following query with keyword positions true\r\n2. Error happens What is the expected output? What do you see instead? PHP Fatal error:  Uncaught exception 'UnableToCalculatePositionException' with message 'cannot calculate position of as dec within ,\r\ncast(dec*30 as int)/30.0 \r\n-- now build mask grid. \r\n-- This is a separate query if no temp tables can be made ' in /Users/abiusx/Desktop/PHP-SQL-Parser/src/positions/PositionCalculator.php:199 What version of the product are you using? On what operating system? php-sql-parser-20140108 OS X Yosemite Please provide any additional information below. SQL Query:\r\n$sql1=<<<XXX\r\nSELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,\r\ncast(dec*30 as int)/30.0 as dec,\r\ncount(*) as pop\r\nFROM Galaxy as G,\r\nfHTM_Cover('CONVEX J2000 6 175 -5 175 5 185 5 185 -5') as T\r\nWHERE htmID between T.HTMIDstart* power(2,28)and T. HTMIDend*power(2,28)\r\nand ra between 175 and 185\r\nand dec between -5 and 5\r\nand u-g > 1\r\nand r \\< 21.5\r\nGROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,\r\ncast(dec*30 as int)/30.0 \r\n-- now build mask grid. \r\n-- This is a separate query if no temp tables can be made \r\nXXX;\n\n_Original issue: http://code.google.com/p/php-sql-parser/issues/detail?id=150_"},"comment":{"url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/comments/112943084","html_url":"https://github.com/greenlion/PHP-SQL-Parser/issues/176#issuecomment-112943084","issue_url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/176","id":112943084,"user":{"login":"witchi","id":5766508,"avatar_url":"https://avatars.githubusercontent.com/u/5766508?v=3","gravatar_id":"","url":"https://api.github.com/users/witchi","html_url":"https://github.com/witchi","followers_url":"https://api.github.com/users/witchi/followers","following_url":"https://api.github.com/users/witchi/following{/other_user}","gists_url":"https://api.github.com/users/witchi/gists{/gist_id}","starred_url":"https://api.github.com/users/witchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/witchi/subscriptions","organizations_url":"https://api.github.com/users/witchi/orgs","repos_url":"https://api.github.com/users/witchi/repos","events_url":"https://api.github.com/users/witchi/events{/privacy}","received_events_url":"https://api.github.com/users/witchi/received_events","type":"User","site_admin":false},"created_at":"2015-06-17T20:40:08Z","updated_at":"2015-06-17T20:40:08Z","body":"_From [pho...@gmx.de](https://code.google.com/u/109317404671582518013/) on September 26, 2014 10:11:13_\n\nAh, I have found it. \r\n\r\n\r\nIn the first \"cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec\" you use a column name \"dec\", which is recognized as reserved keyword. The following \"*\" is a column-ref instead of an operator, so the PositionCalculator doesn't allow \"30\" after a column-ref and looks forward in the statement to find a better position. By a rare fluke it finds a similar string on position 115. So it calculates forward starting a wrong position. At the end of the string it runs into an exception because there is no more statement left.\r\n\r\nSo the problem is not the PositionCalculator, the reason is the Parser itself. I'll see, what I can do..."}}