Hi there,

I have many sites and everything worked just fine on all of them except one. That one has many features including a couple of modules to limit access to some nodes. When I upgraded to Drupal 6.16, I started getting an error because of a missing field in the SELECT list in comparison to the list of fields in the ORDER BY field.

If you are not aware of it, the Core database.inc & MYSQL/PGSQL files have changed. The db_distinct_field() was moved to the main database file and does not do as thorough a test as the old pgsql version.

So, I had to tweak your SQL (and no, it is not really like you could predict this one!) to get it to work.

  $result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, sn.s_status, n.created'
    . ' FROM {node} n INNER JOIN {term_node} t ON n.vid = t.vid'
    . ' INNER JOIN {simplenews_newsletters} sn ON n.nid = sn.nid'
    . ' WHERE (t.tid = %d AND n.status = %d)'
    . ' ORDER BY n.created DESC'), $tid, 1, 0, $count);

I had to add n.created to the SELECT. That works great for pgsql. I hope you can add that to your code too (even though you don't use that field...)

FYI, this is part of simplenews/simplenews.module around line 1263. The culprit is the db_rewrite_sql() which transforms the SELECT statement dramatically.

Thank you.
Alexis

CommentFileSizeAuthor
#3 simplenews.734196.patch2.29 KBSutharsan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AlexisWilke’s picture

FYI,

I found a Core issue (why did they publish 6.16 with such a bug?!) that mentions this problem. I still would suggest you add that field because there is no way Core will be fixed any time soon (as you may know.)

#284392: db_rewrite_sql causing issues with DISTINCT

Thank you.
Alexis

Sutharsan’s picture

Assigned: Unassigned » Sutharsan
Sutharsan’s picture

Assigned: Sutharsan » Unassigned
Status: Active » Fixed
FileSize
2.29 KB

Attached patch is now committed and will be available in the next dev release of 6.x-1.x-dev and 6.x-2.x-dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.