I'm using CCK and have a content type with a column that is displayed using a select list control (dropdown). I'm populating the control using PHP and the user wants to see the data listed alphabetically, thus I must use "order by". When passing the sql through db_rewrite_sql, the sql gets corrupted. Perhaps fix is to check for existence of "order by" clause and then move the clause to the end of the additional sql that gets appended to the original sql. I suggest also updating db_rewrite docs to tell developers to join to table {node} and use alias "n" for it, and mention other accepted alias' to prevent ambiguity.
Comments
Comment #1
ao2 commentedHi, I am not sure if I hit the same bug you have, but I am reusing this report because the symptoms look pretty much the same.
Is your
ORDER BYin a nestedSELECTstatement?I made a brief analisys and I have a possible explanation, can anyone confirm it?
If we have a nested query with an
ORDER BYin it, and noORDER BYin the main query, then db_rewrite_sql picks the one in the nested query and adds a spurious parenthesis breaking SQL syntax.Here a sample query that shows the problem (exposed also by #436868: Improve query)
It gets rewritten to:
note the misplaced parenthesis near
ORDER BY.The problem should be caused by db_rewrite_sql logic, it picks the last
ORDER BY, which might not be enough in case of nested queries. The example is withORDER BY, but it will happen also withGROUP BYandLIMIT.Regards,
Antonio
Comment #2
multiplextor commentedClosed. The reason: expired.