Index: views.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/views.module,v retrieving revision 1.154 diff -u -r1.154 views.module --- views.module 7 Sep 2006 05:54:53 -0000 1.154 +++ views.module 7 Sep 2006 11:11:33 -0000 @@ -846,7 +846,7 @@ */ function _views_is_cacheable(&$view) { // views with arguments are immediately not cacheable. - if (!empty($view->argument) || !empty($view->exposed_filter)) { + if (!empty($view->argument) || !empty($view->exposed_filter) || !empty($view->no_cache)) { return false; } Index: views_query.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/views_query.inc,v retrieving revision 1.45 diff -u -r1.45 views_query.inc --- views_query.inc 7 Sep 2006 05:40:26 -0000 1.45 +++ views_query.inc 7 Sep 2006 11:11:34 -0000 @@ -6,6 +6,10 @@ */ function _views_build_query(&$view, $args = array()) { $query = new _views_query(); + + if (!empty($view->use_alias_prefix)) { + $query->set_table_alias_prefix($view->use_alias_prefix); + } // Process static filters _views_view_build_filters($query, $view); @@ -90,6 +94,10 @@ foreach($view->exposed_filter as $count => $expose) { if ($filter['id'] == $expose['id']) { $id = $expose['id']; + + if (isset($view->exposed_filter_offset)) { + $count += $view->exposed_filter_offset; + } if (!$expose['operator'] && $_GET["op$count"]) { $filter['operator'] = check_plain($_GET["op$count"]); @@ -129,7 +137,7 @@ else if (is_array($filter['value']) && count($filter['value'])) { if ($filter['operator'] == 'OR' || $filter['operator'] == 'NOR') { $query->ensure_table($table); - $where_args = array_merge(array($table, $field), $filter['value']); + $where_args = array_merge(array($query->use_alias_prefix . $table, $field), $filter['value']); $placeholder = array_fill(0, count($filter['value']), '%s'); if ($filter['operator'] == 'OR') { $query->add_where("%s.%s IN ('". implode("','", $placeholder) ."')", $where_args); @@ -157,7 +165,7 @@ } else { $query->ensure_table("$table"); - $query->add_where("%s.%s %s '%s'", $table, $field, $filter['operator'], $filter['value']); + $query->add_where("%s.%s %s '%s'", $query->use_alias_prefix . $table, $field, $filter['operator'], $filter['value']); } } } @@ -272,6 +280,7 @@ */ function _views_query($views_get_title_table = 'node', $views_get_title_field = 'nid') { $this->views_get_title_table = $views_get_title_table; + $this->joins = array(); $this->where = array(); $this->orderby = array(); $this->groupby = array(); @@ -285,6 +294,7 @@ } $this->count_field = "$views_get_title_table.$views_get_title_field"; $this->header = array(); + $this->use_alias_prefix = ''; } /* @@ -303,9 +313,9 @@ $table .= "."; } if ($alias) { - $a = " AS $alias"; + $a = " AS $this->use_alias_prefix$alias"; } - $this->fields[] = "$table$field$a"; + $this->fields[] = "$this->use_alias_prefix$table$field$a"; } /* @@ -334,6 +344,13 @@ } /* + * Set a prefix for table aliases + */ + function set_table_alias_prefix($prefix) { + $this->use_alias_prefix = $prefix; + } + + /* * Add a simple WHERE clause to the query. The caller is responsible for * ensuring that all fields are fully qualified (TABLE.FIELD) and that * the table already exists in the query. @@ -451,7 +468,7 @@ else { $this->tables[$table]++; } - $this->tablequeue[] = array('table' => $table, 'num' => $this->tables[$table]); + $this->tablequeue[] = array('table' => $table, 'num' => $this->tables[$table], 'alias_prefix' => $this->use_alias_prefix); } /* @@ -511,9 +528,11 @@ * The name of the table in the global table array. * @param $table_num * The instance number of the table. + * @param $alias_prefix + * An optional prefix for the table alias. */ - function get_table_name($table, $table_num) { - return ($table_num < 2 ? $table : $table . $table_num); + function get_table_name($table, $table_num, $alias_prefix = '') { + return ($table_num < 2 ? $alias_prefix . $table : $alias_prefix . $table . $table_num); } /* @@ -534,15 +553,18 @@ $table_real = (isset($table_data[$table]['name']) ? $table_data[$table]['name'] : $table); $table_num = $tinfo['num']; - $table_alias = $this->get_table_name($table, $table_num); + $table_alias = $this->get_table_name($table, $table_num, $tinfo['alias_prefix']); $joininfo = (!$this->joins[$table][$table_num] ? $table_data[$table]['join'] : $this->joins[$table][$table_num]); + + $left_table_alias = isset($joininfo['left']['alias']) ? $joininfo['left']['alias'] : $tinfo['alias_prefix']; + $left_table_alias .= $joininfo['left']['table']; // the { is a special character which seems to be treated differently // in PHP5 than PHP4 so we do this a little oddly. $join_type = $joininfo['type'] == 'inner' ? 'INNER' : 'LEFT'; - $joins .= " $join_type JOIN {" . $table_real . "} $table_alias ON " . $joininfo['left']['table'] . "." . + $joins .= " $join_type JOIN {" . $table_real . "} $table_alias ON " . $left_table_alias .".". $joininfo['left']['field'] . " = $table_alias." . $joininfo['right']['field']; if (isset($joininfo['extra'])) {