Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The pattern '/^SELECT(.*?)FROM(.*)/is' is too aggressive and managed to match the character sequence 'from' that I had somewhere in the query. Much pain ensued.
Could it be changed to something like '/^SELECT(.*?) FROM (.*)/is' (with approprate ammendments to the replacement patterns)?
Comment | File | Size | Author |
---|---|---|---|
#6 | database2.test | 1.45 KB | alexpott |
#4 | drupal-d6-596102.patch | 1.7 KB | alexpott |
#3 | drupal-d6-596102.patch | 1.98 KB | alexpott |
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is a duplicate of #284392: db_rewrite_sql causing issues with DISTINCT.
Comment #2
curtaindog CreditAttribution: 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 CreditAttribution: thedavidmeister commenteddb_distinct_field() looks like this now in D6:
So the offending regex in the OP doesn't even exist any more.