Tried to use ViewsOR with arguments

In the argument "Views Or: Next alternative" setting "Share arguments" does not work. In the query user/%/support i got an SQL errors:

* 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 ') count_alias' at line 8 query: SELECT COUNT(*) FROM (SELECT node.nid AS nid FROM issue_node node INNER JOIN issue_node_comment_statistics node_comment_statistics ON node.nid = node_comment_statistics.nid INNER JOIN issue_users users ON node.uid = users.uid LEFT JOIN issue_users ncs_users ON node_comment_statistics.last_comment_uid = ncs_users.uid AND ncs_users.uid != '0' LEFT JOIN issue_content_type_test_case node_data_field_in_charge ON node.vid = node_data_field_in_charge.vid WHERE ) count_alias in Y:\home\drupal6\www\sites\all\modules\views\includes\view.inc on line 739.
* 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 'ORDER BY node_comment_statistics_last_updated DESC LIMIT 0, 25' at line 21 query: SELECT node.nid AS nid, node.title AS node_title, GREATEST(node.changed, node_comment_statistics.last_comment_timestamp) AS node_comment_statistics_last_updated, users.name AS users_name, users.uid AS users_uid, COALESCE(ncs_users.name, node_comment_statistics.last_comment_name) AS node_comment_statistics_last_comment_name, ncs_users.name AS ncs_users_name, node_comment_statistics.last_comment_uid AS node_comment_statistics_last_comment_uid, node_data_field_in_charge.field_in_charge_uid AS node_data_field_in_charge_field_in_charge_uid, node.type AS node_type, node.vid AS node_vid, node_data_field_in_charge.field_priority_value AS node_data_field_in_charge_field_priority_value, node_data_field_in_charge.field_category_value AS node_data_field_in_charge_field_category_value, node_data_field_in_charge.field_status_value AS node_data_field_in_charge_field_status_value FROM issue_node node INNER JOIN issue_node_comment_statistics node_comment_statistics ON node.nid = node_comment_statistics.nid INNER JOIN issue_users users ON node.uid = users.uid LEFT JOIN issue_users ncs_users ON node_comment_statistics.last_comment_uid = ncs_users.uid AND ncs_users.uid != '0' LEFT JOIN issue_content_type_test_case node_data_field_in_charge ON node.vid = node_data_field_in_charge.vid WHERE ORDER BY node_comment_statistics_last_updated DESC LIMIT 0, 25 in Y:\home\drupal6\www\sites\all\modules\views\includes\view.inc on line 765.

I see this with zero or one argument. Views OR works only if both arguments are set trgardless of "share argument" option set.

Arguments used:
Node: user is author or commented - default settings
Content: userreferrence field - default settings

other arguments settings work as AND or won't work at all

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

that0n3guy’s picture

I can second this bug....

benone’s picture

the same here.
need to give both arguments, even if they are the same..
subscribe.

inforeto’s picture

Got the same errors when setting shared arguments.
Be it with or without shared arguments the second argument is expected.

The whole where clause seems missing if either argument is not set.
The sql error points to the "WHERE ORDER BY " where theres no where clause added.

pontus_nilsson’s picture

I get the same error.

I have
Views Or: Begin alternatives (share argument)
Nid
Views Or: Next alternative (share argument)
Nid
Views Or: Next alternative (share argument)
Nid
Views Or: Next alternative (share argument)
Nid
Views Or: End alternatives

When I enter argument 11 the SQL clause ends with only WHERE
When I enter 11/11/11/11 as argument the WHERE clause is written correctly in views UI preview.

When I remove the setting share argument in the next alternative setting, the same problem occurs.

Josh Benner’s picture

I am seeing the same error.

Josh Benner’s picture

Preliminarily, I'm having luck with a one-character edit on line 215 of views_or_handler_argument.inc, changing the != to a ==

I've not done much testing on this change, yet, and I don't have a full understanding of how the module operates to know for sure if this is an appropriate fix.

jsenich’s picture

The fix in 6 works for me, thanks!

not_Dries_Buytaert’s picture

So, I guess that line 215 (as mentioned in post #6) is if ($this->view->args[$this->position] != '') {, quoted from

  function query() {
    $this->finish_alternative();
    $alt = &$this->query_current_alternative();
    if ($this->view->args[$this->position] != '') {
      if ($this->options['share_arguments']) {
        array_splice($this->view->args, $this->position, 0, array_slice($this->view->args, $alt['position'], $this->position - $alt['position']));
        $alt['position'] = $this->position;
      }
      else {
        array_splice($this->view->args, $this->position, 0, '');
      }
    }
  }
liquidcms’s picture

fix works for me as well.. any chance of getting this committed?

thadwheeler’s picture

I tried the fix in #6 and it was not working for me. I get no query run when I enter a single argument or all 4 that I need

liquidcms’s picture

not sure if it helps.. but this is a screen of my View setup http://screencast.com/t/BbZSzOuFMu0B

and i only pass a single arg

WorldFallz’s picture

Status: Active » Needs review
FileSize
907 bytes

yep, I can confirm this fixes the problem. Here's a patch in the hopes of getting it committed. If someone could try it and then RTBC this issue it might help move things along.

elliotttf’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed the patch in #12 works.

ZechariahStover’s picture

Confirmed the patch in #12 works for me.

stevehuk’s picture

Confirmed the patch in #12 works for me.

alienatix’s picture

Confirmed the patch in #12 works for me.

allain’s picture

Confirmed patch in #12 works for me too.

skylord’s picture

Hm. With this patch view fails when "Share arguments" is set and there are two arguments. So, this solution is not correct... I.e. view can have more arguments not used in OR block....

skylord’s picture

Status: Reviewed & tested by the community » Needs review

As i think removing the whole condition is the best choice. Test on misc configs - works as expected - uses first arg for all alternatives when "share" is set no matter of args number. Please, test and confirm...

# diff -u views_or_handler_argument.inc.orig views_or_handler_argument.inc
--- views_or_handler_argument.inc.orig  2011-02-25 05:09:04.000000000 +0300
+++ views_or_handler_argument.inc       2011-05-07 17:04:21.000000000 +0400
@@ -211,14 +211,12 @@
   function query() {
     $this->finish_alternative();
     $alt = &$this->query_current_alternative();
-    if ($this->view->args[$this->position] != '') {
-      if ($this->options['share_arguments']) {
-        array_splice($this->view->args, $this->position, 0, array_slice($this->view->args, $alt['position'], $this->position - $alt['position']));
-        $alt['position'] = $this->position;
-      }
-      else {
-        array_splice($this->view->args, $this->position, 0, '');
-      }
+    if ($this->options['share_arguments']) {
+      array_splice($this->view->args, $this->position, 0, array_slice($this->view->args, $alt['position'], $this->position - $alt['position']));
+      $alt['position'] = $this->position;
+    }
+    else {
+      array_splice($this->view->args, $this->position, 0, '');
     }
   }
 }

seandunaway’s picture

I've tested both of these and they both work well. I am running into some issues when not passing any arguments at all but that can be restructured in the view. Can we get this in dev before it gets lost forever in issueland? You wouldn't believe the hacks I was doing before for similar functionality.

Here is a git re-roll of #19 for easy commit.

Jim Kirkpatrick’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

#20 works for me, please commit!

Darren Oh’s picture

Status: Reviewed & tested by the community » Fixed

Fixed in commit c3294b8. Thanks to rump and Jim Kirkpatrick for reviewing skylord’s patch!

Status: Fixed » Closed (fixed)

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

Darren Oh’s picture

Status: Closed (fixed) » Needs work

This patch broke functionality when arguments are not shared: #1340590: Default arguments not respected (and query broken?) when "Share arguments" is NOT indicated. It has been reversed until a safe patch is provided.