I had a problem with this query from Taxonomy Access:

SELECT t.tid AS tid, t.vid AS vid FROM {term_data} t
         INNER JOIN {term_access_defaults} tdg ON tdg.vid=0
         LEFT JOIN {term_access_defaults} td ON td.vid=t.vid AND td.rid=tdg.rid
         LEFT JOIN {term_access} ta ON ta.tid=t.tid AND ta.rid=tdg.rid
         WHERE tdg.rid IN (%d)
         GROUP BY t.tid, t.vid
         HAVING BIT_OR(COALESCE(
                                ta.grant_list,
                                td.grant_list,
                                tdg.grant_list
                               )) > 0

It got translated like this:

SELECT t.tid AS tid, t.vid AS vid FROM "TERM_DATA" t
         INNER JOIN "TERM_ACCESS_DEFAULTS" tdg ON tdg.vid=0
         LEFT JOIN "TERM_ACCESS_DEFAULTS" td ON td.vid=t.vid AND td.rid=tdg.rid
         LEFT JOIN "TERM_ACCESS" ta ON ta.tid=t.tid AND ta.rid=tdg.rid
         WHERE tdg.rid IN (:d0)
         GROUP BY t.t.tid, t., t.vid
         HAVING BIT_OR(COALESCE(
                                ta.grant_list,
                                td.grant_list,
                                tdg.grant_list
                               )) > 0

Note that nonsense in the GROUP BY section: t.t.tid, t., t.vid.

That's because the oracle_escape_group_by_alias function was too simplistic. This query has t.tid aliased to tid. The function did a simple string-replace for tid, replacing it with the original column name, t.tid. So the GROUP BY section had t.tid, where tid was replaced with t.tid, so we end up with t.t.tid. With vid, it's the same thing except that the regular expression is wrong too, so it thought that ", t.vid" was aliased to vid. So it replaced t.vid with t., t.vid.

Here's a patch where I wrote a more thorough translator for GROUP BY.

CommentFileSizeAuthor
groupby.diff2.39 KBgalaxor

Comments

aaaristo’s picture

Assigned: Unassigned » aaaristo

Thanks galaxor, no time now to test it, but i hope do be able to do it in first days of june

aaaristo’s picture

i don't like this fix... itested it a while ago with some complex queries and does not work...

we need somenthing like:

1. GROUB BY (....matchA.....)

2. parse matchA to find aliases

3. lookup aliases in the query.

trying to match the whole query is not going to win... IMUO

aaaristo’s picture

Status: Needs review » Needs work
bohart’s picture

Version: 6.x-1.0 » 7.x-1.x-dev
Assigned: aaaristo » Unassigned
Status: Needs work » Closed (won't fix)
Issue tags: +LutskGCW20

Drupal 6 is no longer supported.