r40392 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40391‎ | r40392 | r40393 >
Date:20:28, 3 September 2008
Author:yaron
Status:old
Tags:
Comment:
Fixed handling of 'none' value and other fixes for SMWSQLStore2, general
SQL formatting improvements
Modified paths:
  • /trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php
@@ -204,11 +204,11 @@
205205 $cat_ns = NS_CATEGORY;
206206 $sql .= "AND p.page_namespace != $cat_ns ";
207207 foreach ($applied_filters as $i => $af) {
208 - // if any of these filter's values are 'none',
 208+ // if any of this filter's values is 'none',
209209 // include another table to get this information
210210 $includes_none = false;
211211 foreach ($af->values as $fv) {
212 - if ($af->values[0]->text === '_none' || $af->values[0]->text === ' none') {
 212+ if ($fv->text === '_none' || $fv->text === ' none') {
213213 $includes_none = true;
214214 break;
215215 }
@@ -236,7 +236,7 @@
237237 }
238238 foreach ($applied_filters as $i => $af) {
239239 if ($af->filter->is_relation) {
240 - $sql .= "JOIN $smw_relations r$i
 240+ $sql .= "LEFT OUTER JOIN $smw_relations r$i
241241 ON p.page_id = r$i.subject_id ";
242242 } else {
243243 $sql .= "JOIN $smw_attributes a$i
@@ -283,11 +283,11 @@
284284 ON ids.smw_id = insts.s_id
285285 AND ids.smw_namespace != $cat_ns ";
286286 foreach ($applied_filters as $i => $af) {
287 - // if any of these filter's values are 'none',
 287+ // if any of this filter's values is 'none',
288288 // include another table to get this information
289289 $includes_none = false;
290290 foreach ($af->values as $fv) {
291 - if ($af->values[0]->text === '_none' || $af->values[0]->text === ' none') {
 291+ if ($fv->text === '_none' || $fv->text === ' none') {
292292 $includes_none = true;
293293 break;
294294 }
@@ -297,26 +297,31 @@
298298 $property_table_name = $smw_rels;
299299 $property_table_nickname = "nr$i";
300300 $property_field = 'p_id';
301 - $value_field = "o_ids$i.smw_title";
302301 } else {
303302 $property_table_name = $smw_atts;
304303 $property_table_nickname = "na$i";
305304 $property_field = 'p_id';
306 - $value_field = 'value_xsd';
307305 }
308306 $property_value = str_replace(' ', '_', $af->filter->property);
309307 $property_value = str_replace("'", "\'", $property_value);
310308 $sql .= "LEFT OUTER JOIN
311 - (SELECT s_id, $value_field
 309+ (SELECT s_id
312310 FROM $property_table_name
313 - WHERE $property_field = '$property_value') $property_table_nickname
 311+ WHERE $property_field = (SELECT smw_id FROM $smw_ids WHERE smw_title = '$property_value' AND smw_namespace = $prop_ns)) $property_table_nickname
314312 ON ids.smw_id = $property_table_nickname.s_id ";
315313 }
316314 }
317315 foreach ($applied_filters as $i => $af) {
 316+ $sql .= "\n ";
318317 if ($af->filter->is_relation) {
319 - $sql .= "JOIN $smw_rels r$i ON ids.smw_id = r$i.s_id
320 - JOIN $smw_ids o_ids$i ON r$i.o_id = o_ids$i.smw_id ";
 318+ if ($includes_none) {
 319+ $sql .= "LEFT OUTER ";
 320+ }
 321+ $sql .= "JOIN $smw_rels r$i ON ids.smw_id = r$i.s_id\n ";
 322+ if ($includes_none) {
 323+ $sql .= "LEFT OUTER ";
 324+ }
 325+ $sql .= "JOIN $smw_ids o_ids$i ON r$i.o_id = o_ids$i.smw_id ";
321326 } else {
322327 $sql .= "JOIN $smw_atts a$i ON ids.smw_id = a$i.s_id ";
323328 }
@@ -338,11 +343,15 @@
339344 $property_value = str_replace(' ', '_', $af->filter->property);
340345 if ($af->filter->is_relation) {
341346 $property_field = "r$i.p_id";
342 - $sql .= "AND $property_field = (SELECT smw_id FROM $smw_ids WHERE smw_title = '$property_value' AND smw_namespace = $prop_ns) AND ";
 347+ $sql .= "\n AND ($property_field = (SELECT smw_id FROM $smw_ids WHERE smw_title = '$property_value' AND smw_namespace = $prop_ns)";
 348+ if ($includes_none) {
 349+ $sql .= " OR $property_field IS NULL";
 350+ }
 351+ $sql .= ")\n AND ";
343352 $value_field = "o_ids$i.smw_title";
344353 } else {
345354 $property_field = "a$i.p_id";
346 - $sql .= "AND $property_field = (SELECT smw_id FROM $smw_ids WHERE smw_title = '$property_value' AND smw_namespace = $prop_ns) AND ";
 355+ $sql .= "\n AND $property_field = (SELECT smw_id FROM $smw_ids WHERE smw_title = '$property_value' AND smw_namespace = $prop_ns) AND ";
347356 $value_field = "a$i.value_xsd";
348357 }
349358 $sql .= $af->checkSQL($value_field);
@@ -989,12 +998,12 @@
990999 $sql = "SELECT DISTINCT ids.smw_title AS title,
9911000 ids.smw_title AS value,
9921001 ids.smw_namespace AS namespace,
993 - ids.smw_sortkey AS sortkey ";
 1002+ ids.smw_sortkey AS sortkey\n";
9941003 } else {
9951004 $sql = "SELECT DISTINCT p.page_title AS title,
9961005 p.page_title AS value,
9971006 p.page_namespace AS namespace,
998 - c.cl_sortkey AS sortkey ";
 1007+ c.cl_sortkey AS sortkey\n";
9991008 }
10001009 $sql .= $this->getSQLFromClause($this->category, $this->subcategory, $this->all_subcategories, $this->applied_filters);
10011010 return $sql;

Status & tagging log