{"action":"created","issue":{"url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/131","labels_url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/131/labels{/name}","comments_url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/131/comments","events_url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/131/events","html_url":"https://github.com/greenlion/PHP-SQL-Parser/issues/131","id":89108147,"number":131,"title":"processOrderBy exception when Order By Clause is a function","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":2,"created_at":"2015-06-17T19:48:56Z","updated_at":"2015-06-17T19:49:10Z","closed_at":null,"body":"_From [ljwilson...@gmail.com](https://code.google.com/u/114859493305067387206/) on December 17, 2013 19:12:48_\n\nWhat steps will reproduce the problem? 1. This sql:\r\nSELECT users0.user_name AS 'CIS UserName'\r\n\t,calls.description AS 'Description'\r\n\t,contacts2.first_name AS 'Contacts First Name'\r\n\t,contacts2.last_name AS 'Contacts Last Name'\r\n\t,calls_cstm.date_logged_c AS 'Date'\r\n\t,calls_cstm.contact_type_c AS 'Contact Type'\r\n\t,dbo.fn_GetAccountName(calls.parent_id) AS 'Account Name'\r\nFROM calls\r\nLEFT JOIN calls_cstm ON calls.id = calls_cstm.id_c\r\nLEFT JOIN users users0 ON calls.assigned_user_id = users0.id\r\nLEFT JOIN contacts contacts2 ON calls.contact_id = contacts2.id\r\nWHERE calls.deleted = 0\r\n\tAND (\r\n\t\tDATEADD(SECOND, 0, calls_cstm.date_logged_c) BETWEEN '2013-01-01'\r\n\t\t\tAND '2013-12-31'\r\n\t\t)\r\nORDER BY dbo.fn_GetAccountName(calls.parent_id) ASC LIMIT 0\r\n\t,15 What is the expected output? What do you see instead? Expect successful parse, but instead get:\r\nFatal error: Uncaught exception 'UnableToCreateSQLException' with message 'unknown expr_type in ORDER[0] function' in C:\\php-sql-parser-20131130\\PHP-SQL-Parser\\php-sql-creator.php:250\r\nStack trace:\r\n\\#0 C:\\php-sql-parser-20131130\\PHP-SQL-Parser\\php-sql-creator.php(166): PHPSQLCreator->processORDER(Array)\r\n\\#1 C:\\php-sql-parser-20131130\\PHP-SQL-Parser\\php-sql-creator.php(53): PHPSQLCreator->processSelectStatement(Array)\r\n\\#2 C:\\php-sql-parser-20131130\\PHP-SQL-Parser\\php-sql-creator.php(40): PHPSQLCreator->create(Array)\r\n\\#3 C:\\php-sql-parser-20131130\\PHP-SQL-Parser\\php-limit-test.php(41): PHPSQLCreator->__construct(Array)\r\n\\#4 {main}\r\n  thrown in C:\\php-sql-parser-20131130\\PHP-SQL-Parser\\php-sql-creator.php on line 250 What version of the product are you using? On what operating system? Using version php-sql-parser-20131130 on Windows 7. Please provide any additional information below. Adding one line (after line 246) in php-sql-creator.php fixes it for me:\r\n\r\n        protected function processORDER($parsed) {\r\n            $sql = \"\";\r\n            foreach ($parsed as $k => $v) {\r\n                $len = strlen($sql);\r\n                $sql .= $this->processOrderByAlias($v);\r\n                $sql .= $this->processColRef($v);\r\n                $sql .= $this->processFunction($v); //NEW LINE\r\n\r\n                if ($len == strlen($sql)) {\r\n                    throw new UnableToCreateSQLException('ORDER', $k, $v, 'expr_type');\r\n                }\r\n\r\n                $sql .= \",\";\r\n            }\r\n            $sql = substr($sql, 0, -1);\r\n            return \"ORDER BY \" . $sql;\r\n        }\n\n_Original issue: http://code.google.com/p/php-sql-parser/issues/detail?id=105_"},"comment":{"url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/comments/112926453","html_url":"https://github.com/greenlion/PHP-SQL-Parser/issues/131#issuecomment-112926453","issue_url":"https://api.github.com/repos/greenlion/PHP-SQL-Parser/issues/131","id":112926453,"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-17T19:49:10Z","updated_at":"2015-06-17T19:49:10Z","body":"_From [pho...@gmx.de](https://code.google.com/u/109317404671582518013/) on December 17, 2013 13:11:14_\n\nFixed in r827 .\n\n**Status:** Fixed  \n"}}