Home » Database » SQL_Parser » Bug #272
Parser does not handle parentheses in where clause
Details
| Submitted | 2003-11-18 16:44 UTC |
|---|---|
| From | young at sl dot com dot ua |
| Assigned | busterb |
| Status | Closed |
| Package | SQL_Parser |
| PHP Version | 0.4 |
| Roadmaps | (Not assigned) |
Comments
[2003-11-18 16:44 UTC] young at sl dot com dot ua
Description:
------------
Valid query: SELECT CLIENTS_TRANSLATION.ID_CLIENTS_PREFIX, CLIENTS_TRANSLATION.RULE_NUMBER, CLIENTS_TRANSLATION.PATTERN, CLIENTS_TRANSLATION.RULE FROM CLIENTS, CLIENTS_PREFIX, CLIENTS_TRANSLATION WHERE (CLIENTS.ID_SOFTSWITCH = 5) AND (CLIENTS.ID_CLIENTS = CLIENTS_PREFIX.ID_CLIENTS) and CLIENTS.ENABLE='Y' and CLIENTS.UNUSED='N' and (CLIENTS_TRANSLATION.ID_CLIENTS_PREFIX = CLIENTS_PREFIX.ID_CLIENTS_PREFIX) ORDER BY CLIENTS_TRANSLATION.ID_CLIENTS_PREFIX,CLIENTS_TRANSLATION.RULE_NUMBER
Result: Parse error: Expected an operator on line 1
[2003-11-21 04:58 UTC] busterb at php dot net
Thanks for the report. It looks like the parser does not
understand parenthesis in where clauses (though
subselects do work in CVS). I will have a look to see if
this can be implmented. Try your query without the
extra parenthesis. Don't worry; order of operations in
SQL makes them unnecessary anyway.
[2003-12-02 23:59 UTC] webmaster at kryptronic dot com
I am a user of the Perl SQL::Statement module which has it's own issues with parens, but does provide support for them (just not embedded). An example of what works in SQL::Statement follows:
SELECT column1,column2
FROM table1
WHERE (column1='1' AND column2='1') OR (column3='1' AND column4='1')
In this statement parens are necessary.
I am looking to use SQL_Parser as a basis for a driver module to tie into the DB package for managing CSV files via SQL. Whether support can be added into SQL_Parser or a true SQL::Statement module is needed really depends on when and what updates can be made to SQL_Parser.
I'm willing to help get SQL_Parser working if needed.
[2003-12-15 20:37 UTC] none at none dot com
Was this error fixed in verison 4.3.4? If not when is the expected date to fix this problem?
[2003-12-28 05:35 UTC] busterb at php dot net
I need to restructure how parseSearchClause handles
parentheses. Give me a few more days to sort it out; there
may be a patch in my queue.
[2004-01-22 17:27 UTC] busterb at php dot net
There is a partial fix in CVS. It doesn't fix these test cases, but is the beginning; essentially, parseSearchOptions needs to do a recursive call when finding parentheses. There is a bug in how I implemented this, but you are welcome to take a look.
[2004-01-22 17:29 UTC] busterb at php dot net
I meant parseSearchClause.
[2005-04-03 00:07 UTC] epte at ruffdogs dot com
Uh.. correct me if I'm wrong, but this seems fixed. At least it seems to be behaving correctly in CVS.
[2005-04-03 00:09 UTC] epte at ruffdogs dot com
Oh. I see. I was taking the simpler query farther down the page and not the original one. The issue still remains.
[2005-04-03 00:19 UTC] epte at ruffdogs dot com
Actually... now that I realize that the parser only had difficulty with my whitespace at the end of the query, it seems to work fine, even for the hard initial case. My choice of where to put the parentheses in the resultant parse tree would have been a bit different, but the parse tree that is returned does work.