Since the orderby fix for postgre the rand() feature is broken (with mysql)

This caused the problem:
http://drupal.org/node/91665
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/views/views_q...

Presumable the same bug is in the 5.x branch.

Comments

gordon’s picture

Assigned: Unassigned » gordon
Status: Active » Needs review
StatusFileSize
new617 bytes

I have applied this fix to my sites, and it seems to be working.

However I do not know it this will break pgsql again.

sammys’s picture

Tested this on PostgreSQL in 4.7 and all is good. RTBC as far as PostgreSQL is concerned.

--
Sammy Spets
Synerger
http://synerger.com

thsutton’s picture

I've applied this patch and its working fine with PostgreSQL 8.1.4 and Drupal 5.0 beta 2. The only thing that tripped me up was forgetting to edit and re-save the view using random to get it to re-generate the query sans '()'.

merlinofchaos’s picture

Status: Needs review » Fixed

I applied what I think is a better patch. I believe this works in all circumstances, but time will tell! Anyone using PGSQL, I invite you to try out HEAD and see if it works.

fago’s picture

Status: Fixed » Needs review
StatusFileSize
new593 bytes

I've just updated to the latest to the latest 4.7 version and unfortunately the rand() feature is still broken for mysql, because there is an extra point in the query..

ORDER BY .rand()

a fix is attached, which only includes the point if there is something in front of..

merlinofchaos’s picture

Status: Needs review » Fixed

Ok the proper fix should be backported from 5 in the 4.7.x-1.x-dev branch.

fago’s picture

Status: Fixed » Needs review
StatusFileSize
new689 bytes

I'm afraid, it still doesn't work. (tested with 4.7 and mysql)

1. it doesn't insert the rand() in the order by, because there is no alias.
2. it added an invalid select for the rand() statement, I changed it to only add a field if it has a table.

fix for 4.7 attached, hopefully it's still working with postgresql, however I think so as I've made no changes for usual add_orderby() calls.

merlinofchaos’s picture

Argh I left out the bit that gives the random sort an alias. Sigh.

Since this has only been 3 hours I redid the release to include the missing alias. (It's been in the drupal 5 version for days but I'm apparently getting worse and worse with branch management =)

If you downloaded Views 4.7.x-1.2 between 10am and 1pm pacific time today, download it again.

fago’s picture

Status: Needs review » Fixed

yep, seems to work now.
thanks!

strooltz’s picture

StatusFileSize
new21.27 KB

I'm still having this problem. I patched my views_query.inc and couldn't get it to work...

this is the error:

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '() FROM node node LEFT JOIN term_node term_node ON node.nid = term_node.nid WHE' at line 1 query: SELECT node.nid, rand() AS _rand() FROM node node LEFT JOIN term_node term_node ON node.nid = term_node.nid WHERE (node.status = '1') AND (node.type IN ('image')) AND (term_node.tid IN ('8')) ORDER BY _rand() ASC LIMIT 0, 1 in

I've also attached the views_query.inc im using...

thanks

s

dkashen’s picture

Version: 4.7.x-1.x-dev » 4.7.x-1.2

Hello,

I'm transferring a drupal SQL database between two different hosts (and
hosting companies) via a backup and restore sequence.

The old host WB-hosting runs MySQL version 5.0.24-standard
while the KB says that site5.com runs sql v 4.1.21

and I'm getting an error I believe relates to the different SQL versions,
but it gives an error that is similar to one cited in this thread.

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '() FROM node node LEFT JOIN node_revisions node_revisions ON node.vid = node_re' at line 1 query: SELECT DISTINCT(node.nid), rand() AS _rand() FROM node node LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid WHERE (node.type IN ('forum')) AND (UPPER(node_revisions.body) LIKE UPPER('%Thank%')) ORDER BY _rand() ASC LIMIT 0, 1 in /home/kettleb/public_html/KS88/includes/database.mysql.inc on line 120.

Let me know if there is any more info that would be useful.

Thank you,

Anonymous’s picture

Status: Fixed » Closed (fixed)
Bèr Kessels’s picture

Status: Closed (fixed) » Active

according to last two reports not fixed.

Here is my query output, using "views_query.inc,v 1.48.2.12 2007/01/16 04:21:55"
SELECT node.nid, rand(), node.title AS node_title, node.changed AS node_changed, node_data_field_salary_sought.field_salary_sought_value AS node_data_field_salary_sought_field_salary_sought_value, node_data_field_current_location.field_current_location_value AS node_data_field_current_location_field_current_location_value FROM node node LEFT JOIN node_data_field_salary_sought node_data_field_salary_sought ON node.vid = node_data_field_salary_sought.vid LEFT JOIN node_data_field_current_location node_data_field_current_location ON node.vid = node_data_field_current_location.vid WHERE (node.status = '1') AND (node.type IN ('content_job_listing_entry')) ORDER BY ASC LIMIT 0, 5

Bèr Kessels’s picture

Status: Active » Postponed (maintainer needs more info)

Fiddling a bit with the views solved the weird bug. I removed and added the view entirely. Seems some combination of a broken view and a stale cache.

Can strooltz and dkashen please confirm that removing + re-adding the view solves their Database error too?

setting this to 'needs more info'

merlinofchaos’s picture

I was going to ask if you had resaved the view; the view you exported is cachable, and Views currently caches the query on the view. (Yes, this has been creating alarming side effects, but I was concerned about caching it in the cache tables. Clearly I should have, and in the future I will.

Bèr Kessels’s picture

merely re-saving did not help. I really had to remove the old one entirely and add a new one (by hand).

catch’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)