After installing i18n module I found that add_where function accepts clause parameter to be empty string. It will result sql error such as this:

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 term_data_weight ASC, node_promote DESC LIMIT 0, 100' at line 12 query: SELECT node.nid AS nid, node.title AS node_title, term_data.name AS term_data_name, term_data.vid AS term_data_vid, term_data.tid AS term_data_tid, term_data.weight AS term_data_weight, node.promote AS node_promote FROM node node LEFT JOIN og_ancestry og_ancestry ON node.nid = og_ancestry.nid LEFT JOIN term_node term_node ON node.vid = term_node.vid LEFT JOIN term_data term_data ON term_node.tid = term_data.tid WHERE (og_ancestry.group_nid = -1) AND (node.type in ('page', 'story', 'story_wide', 'timeline_page')) AND (term_data.vid in ('1')) AND (node.status <> 0) AND () ORDER BY term_data_weight ASC, node_promote DESC LIMIT 0, 100 in /Applications/MAMP/htdocs/drupal/sites/all/modules/views/includes/view.inc on line 755.

The view exported:

function hkicontent_views_default_views() {
  /*
   * View 'group_navi'
   */
  $view = new view;
  $view->name = 'group_navi';
  $view->description = 'Navigation for selected group';
  $view->tag = 'HOO';
  $view->view_php = '';
  $view->base_table = 'node';
  $view->is_cacheable = FALSE;
  $view->api_version = 2;
  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  $handler = $view->new_display('default', 'Defaults', 'default');
  $handler->override_option('fields', array(
    'title' => array(
      'label' => '',
      'alter' => array(
        'alter_text' => 0,
        'text' => '',
        'make_link' => 0,
        'path' => '',
        'alt' => '',
        'prefix' => '',
        'suffix' => '',
        'help' => '',
        'trim' => 0,
        'max_length' => '',
        'word_boundary' => 1,
        'ellipsis' => 1,
        'strip_tags' => 0,
        'html' => 0,
      ),
      'link_to_node' => 1,
      'exclude' => 0,
      'id' => 'title',
      'table' => 'node',
      'field' => 'title',
      'relationship' => 'none',
    ),
    'name' => array(
      'label' => '',
      'alter' => array(
        'alter_text' => 0,
        'text' => '',
        'make_link' => 0,
        'path' => '',
        'alt' => '',
        'prefix' => '',
        'suffix' => '',
        'help' => '',
        'trim' => 0,
        'max_length' => '',
        'word_boundary' => 1,
        'ellipsis' => 1,
        'strip_tags' => 0,
        'html' => 0,
      ),
      'link_to_taxonomy' => 0,
      'exclude' => 1,
      'id' => 'name',
      'table' => 'term_data',
      'field' => 'name',
      'relationship' => 'none',
    ),
  ));
  $handler->override_option('sorts', array(
    'weight' => array(
      'order' => 'ASC',
      'id' => 'weight',
      'table' => 'term_data',
      'field' => 'weight',
      'relationship' => 'none',
    ),
    'promote' => array(
      'order' => 'DESC',
      'id' => 'promote',
      'table' => 'node',
      'field' => 'promote',
      'relationship' => 'none',
    ),
  ));
  $handler->override_option('filters', array(
    'picg' => array(
      'operator' => '=',
      'value' => '',
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => 'picg_op',
        'label' => 'Organic groups: OG: Posts in current group',
        'use_operator' => FALSE,
        'identifier' => 'picg',
        'remember' => FALSE,
        'single' => TRUE,
        'optional' => TRUE,
      ),
      'id' => 'picg',
      'table' => 'og_ancestry',
      'field' => 'picg',
      'relationship' => 'none',
    ),
    'type' => array(
      'operator' => 'in',
      'value' => array(
        'page' => 'page',
        'story' => 'story',
        'story_wide' => 'story_wide',
        'timeline_page' => 'timeline_page',
      ),
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'type',
      'table' => 'node',
      'field' => 'type',
      'relationship' => 'none',
      'override' => array(
        'button' => 'Override',
      ),
    ),
    'vid' => array(
      'operator' => 'in',
      'value' => array(
        '1' => '1',
      ),
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'vid',
      'table' => 'term_data',
      'field' => 'vid',
      'relationship' => 'none',
    ),
    'status' => array(
      'operator' => '=',
      'value' => '1',
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'status',
      'table' => 'node',
      'field' => 'status',
      'relationship' => 'none',
    ),
    'content_negotiation' => array(
      'operator' => '',
      'value' => '',
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'content_negotiation',
      'table' => 'node',
      'field' => 'content_negotiation',
      'relationship' => 'none',
    ),
  ));
  $handler->override_option('access', array(
    'type' => 'none',
  ));
  $handler->override_option('cache', array(
    'type' => 'none',
  ));
  $handler->override_option('items_per_page', 100);
  $handler->override_option('style_plugin', 'list');
  $handler->override_option('style_options', array(
    'grouping' => 'name',
    'type' => 'ul',
  ));
  $handler = $view->new_display('block', 'HOO Navigation', 'block_1');
  $handler->override_option('block_description', '');
  $handler->override_option('block_caching', -1);
  $views[$view->name] = $view;

  return $views;
}

Preview view of the block display:

SELECT node.nid AS nid,
   node.title AS node_title,
   term_data.name AS term_data_name,
   term_data.vid AS term_data_vid,
   term_data.tid AS term_data_tid,
   term_data.weight AS term_data_weight,
   node.promote AS node_promote
 FROM node node 
 LEFT JOIN og_ancestry og_ancestry ON node.nid = og_ancestry.nid
 LEFT JOIN term_node term_node ON node.vid = term_node.vid
 LEFT JOIN term_data term_data ON term_node.tid = term_data.tid
 WHERE (og_ancestry.group_nid  = ***CURRENT_GID***) AND (node.type in ('page', 'story', 'story_wide', 'timeline_page')) AND (term_data.vid in ('1')) AND (node.status <> 0) AND (node.language ='fi' OR node.language ='' OR node.language IS NULL)
   ORDER BY term_data_weight ASC, node_promote DESC

In the preview i18n module's i18n_db_rewrite_where function will return correctly "node.language = ...." where as in the real world in admin pages only empty string is returned. Thus technically this could be a issue for i18n module, but to be more general fix I submitted the given patch for views module. Hope it helps someone else too!

CommentFileSizeAuthor
dont-accept-empty-clause.patch821 bytestomimikola

Comments

tomimikola’s picture

Status: Patch (to be ported) » Needs review

Fixed the incorrect status value.

merlinofchaos’s picture

isset() is always preferred to is_null() as it is faster.

victorcoder’s picture

Someone has notice this same issue in 2.6?

I can't find no reports about this in 2.6, can anyone point me to the issue for 2.6 if it's reported already?

merlinofchaos’s picture

I've been thinking about this, and I am not convinced Views *should* perform this validation. Handlers shoudl not be passing empty add_where() clauses, and should be fully capable of making sure they don't.

merlinofchaos’s picture

Status: Needs review » Closed (won't fix)