Closed (fixed)
Project:
Drupal core
Version:
6.x-dev
Component:
database system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
5 Oct 2009 at 08:35 UTC
Updated:
18 Jun 2013 at 15:16 UTC
Jump to comment: Most recent file
Comments
Comment #1
damien tournoud commentedThis is a duplicate of #284392: db_rewrite_sql causing issues with DISTINCT.
Comment #2
curtaindog commentedWell, its a different (and edge) case... but I accept that db_distinct_field needs review so I'm happy to wait and see what comes out of that.
Comment #3
alexpottI had exactly the same thing... and didn't see this post until after I'd spent a good while tracking it down... learnt lots of good stuff :)
In the function db_distinct_field a query is broken apart using sql keywords. The pattern used would match the first from in a select even if it was part of a cck fieldname - any field containing the characters from will do.
For example a I have view which creates the following SQL query
this is changed to
This sql fails with the error "user warning: Unknown column 'node_data_field_FROMtext.field_fromtext_value'"
To recreate this problem (using Drupal 6)
1. Install CCK and Views and some access control module
2. Create a field called field_fromtext on a node type
3. Create a view on the nodes and sort the view by this field
4. Then look at the view will some user that's not allow to see every node...
The line of code that seems to be causing the problem is
... not so sure this is a edge case as plenty of words contain the letter sequence "from"
Plus I don't think this is a duplicate of #284392: db_rewrite_sql causing issues with DISTINCT as that concerns the regular expression that inserts the distinct clause.
I attach a patch which seems to solve the issue on my site
Comment #4
alexpottUploading a better patch which uses regular expressions \b to find a word boundary instead of the space character.
So the only change is from
to this...
in both the mysql versions of db_distinct_field
Comment #5
gábor hojtsyLooks useful, needs more testing.
Comment #6
alexpott@Gabor
Here's a test that'll prove the patch works... a perhaps provide real-life scenario for french cheese lovers ;)!
Obviously this patch will be influenced by whatever is decided on this issue http://drupal.org/node/284392... but even the latest patch #365 would fail because the regex is still '/^SELECT(.*?)FROM(.*)/is' when it should be '/^SELECT(.*?)\bFROM\b(.*)/is'
Comment #7
thedavidmeister commenteddb_distinct_field() looks like this now in D6:
So the offending regex in the OP doesn't even exist any more.