Skip to content
Browse files

Fixed several bugs when "table prefixes" was used

  • Loading branch information...
1 parent 37e1d30 commit 964bd8ed5d98211f615c611254657cd4f5b51542 @ahtih committed
Showing with 15 additions and 10 deletions.
  1. +1 −0 README.txt
  2. +14 −10 geoclustering.module
View
1 README.txt
@@ -55,6 +55,7 @@ Geo needs the following patches for Geoclustering to really work:
- http://drupal.org/files/issues/geo-filter-float.patch
- http://drupal.org/files/issues/geo-ewkb-parsing.patch
- http://drupal.org/files/issues/geo-883032.patch
+- http://drupal.org/files/issues/geo-table-prefixes-776436.patch
If using WFS module, this also needs patching to support BBOX requests:
- http://drupal.org/files/issues/wfs-filter-changes.patch
View
24 geoclustering.module
@@ -1,6 +1,8 @@
<?php
// $Id$
+//!!! Hook into "Clear all caches" operation
+
function geoclustering_extract_coords_from_node(&$node,&$params)
{
$location=$node->{$params->geofield_name}[0]['geo'];
@@ -297,7 +299,7 @@ function geoclustering_get_node_conditions(&$params)
// Check if the field is in {node} table
if (isset($node_schema['fields'][$field])) {
- $table="{node}";
+ $table="node";
$column=$field;
$column_type=$node_schema['fields'][$field]['type'];
}
@@ -306,7 +308,7 @@ function geoclustering_get_node_conditions(&$params)
$dbinfo=content_database_info(content_fields($field));
- $table="{" . $dbinfo['table'] . "}";
+ $table=$dbinfo['table'];
foreach ($dbinfo['columns'] as $col => $colinfo) {
$column=$colinfo['column'];
$column_type=$colinfo['type'];
@@ -314,7 +316,7 @@ function geoclustering_get_node_conditions(&$params)
}
$retval[]=array('table' => $table,
- 'sql' => $table . "." . $column . " = " .
+ 'sql' => "%s." . $column . " = " .
db_type_placeholder($column_type),
'param' => $required_value);
}
@@ -360,15 +362,17 @@ function geoclustering_get_nodes_sql(&$params,$summed_field_function=NULL)
$where_params=array();
foreach (geoclustering_get_node_conditions($params) as $clause) {
- if (!in_array($clause['table'],$joined_tables)) {
- $sql.=" JOIN " . $clause['table'] .
- " ON (" . $clause['table'] . ".vid={node}.vid)";
- $joined_tables[]=$clause['table'];
+ $prefixed_table="{" . $clause['table'] . "}";
+ if (!in_array($prefixed_table,$joined_tables)) {
+ $sql.=" JOIN " . $prefixed_table .
+ " ON (" . $prefixed_table . ".vid={node}.vid)";
+ $joined_tables[]=$prefixed_table;
}
if ($where_sql) {
$where_sql.=" AND ";
}
$where_sql.=$clause['sql'];
+ $where_params[]=$prefixed_table;
$where_params[]=$clause['param'];
}
@@ -475,7 +479,7 @@ function geoclustering_recalc_tree($params)
array( '{geoclustering_clusters}' => '',
'{geoclustering_uptodate_trees}' => ''),
array_merge(array_combine($tables,$tables),
- array('{geoclustering_uptodate_trees_select}' =>
+ array('geoclustering_uptodate_trees_select' =>
'{geoclustering_uptodate_trees}',
'{geo}' => '')));
@@ -999,8 +1003,8 @@ function geoclustering_views_query_alter(&$view,&$query)
/************************************************************/
foreach (geoclustering_get_node_conditions($params) as $clause) {
- $query->add_where($clause['table'],$clause['sql'],
- $clause['param']);
+ $query->add_where(NULL,$clause['sql'],
+ $query->ensure_table($clause['table']),$clause['param']);
}
//!!! add WHERE clause "geofield IS NOT NULL"

0 comments on commit 964bd8e

Please sign in to comment.
Something went wrong with that request. Please try again.