Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php |
— | — | @@ -317,11 +317,11 @@ |
318 | 318 | if ( !$value->isValid() ) { |
319 | 319 | return array(); |
320 | 320 | } |
321 | | - $result = array(); |
322 | 321 | $db =& wfGetDB( DB_SLAVE ); |
323 | 322 | |
324 | 323 | switch ($value->getTypeID()) { |
325 | 324 | case '_txt': // not supported |
| 325 | + return array(); |
326 | 326 | break; |
327 | 327 | case '_wpg': // wikipage |
328 | 328 | $sql = 'object_namespace=' . $db->addQuotes($value->getNamespace()) . |
— | — | @@ -329,14 +329,42 @@ |
330 | 330 | ' AND relation_title=' . $db->addQuotes($property->getDBKey()) . |
331 | 331 | $this->getSQLConditions($requestoptions,'subject_title','subject_title'); |
332 | 332 | |
333 | | - $res = $db->select( $db->tableName('smw_relations'), |
| 333 | + $res = $db->select( 'smw_relations', |
334 | 334 | 'DISTINCT subject_id', |
335 | 335 | $sql, 'SMW::getPropertySubjects', |
336 | 336 | $this->getSQLOptions($requestoptions,'subject_title') ); |
337 | | - while($row = $db->fetchObject($res)) { |
338 | | - $result[] = Title::newFromID($row->subject_id); |
| 337 | + break; |
| 338 | + case '__nry': |
| 339 | + $values = $value->getDVs(); |
| 340 | + $narytable = $db->tableName('smw_nary'); |
| 341 | + $where = "$narytable.attribute_title=" . $db->addQuotes($property->getDBKey()); |
| 342 | + $from = $narytable; |
| 343 | + $count = 0; |
| 344 | + foreach ($values as $dv) { |
| 345 | + if ( ($dv === NULL) || (!$dv->isValid()) ) { |
| 346 | + $count++; |
| 347 | + continue; |
| 348 | + } |
| 349 | + switch ($dv->getTypeID()) { |
| 350 | + case '_txt': // not supported |
| 351 | + break; |
| 352 | + case '_wpg': |
| 353 | + $from .= ' INNER JOIN ' . $db->tableName('smw_nary_relations') . ' AS nary' . $count . |
| 354 | + " ON ($narytable.subject_id=nary$count.subject_id AND $narytable.nary_key=nary$count.nary_key)"; |
| 355 | + $where .= " AND nary$count.object_title=" . $db->addQuotes($dv->getDBKey()) . |
| 356 | + " AND nary$count.object_namespace=" . $db->addQuotes($dv->getNamespace()); |
| 357 | + break; |
| 358 | + default: |
| 359 | + $from .= ' INNER JOIN ' . $db->tableName('smw_nary_attributes') . ' AS nary' . $count . |
| 360 | + " ON ($narytable.subject_id=nary$count.subject_id AND $narytable.nary_key=nary$count.nary_key)"; |
| 361 | + $where .= " AND nary$count.value_xsd=" . $db->addQuotes($dv->getXSDValue()) . |
| 362 | + " AND nary$count.value_unit=" . $db->addQuotes($dv->getUnit()); |
| 363 | + } |
| 364 | + $count++; |
339 | 365 | } |
340 | | - $db->freeResult($res); |
| 366 | + $res = $db->query("SELECT DISTINCT $narytable.subject_id FROM $from WHERE $where", |
| 367 | + 'SMW::getPropertySubjects', |
| 368 | + $this->getSQLOptions($requestoptions,'subject_title')); |
341 | 369 | break; |
342 | 370 | default: |
343 | 371 | $sql = 'value_xsd=' . $db->addQuotes($value->getXSDValue()) . |
— | — | @@ -347,12 +375,13 @@ |
348 | 376 | 'DISTINCT subject_id', |
349 | 377 | $sql, 'SMW::getPropertySubjects', |
350 | 378 | $this->getSQLOptions($requestoptions,'subject_title') ); |
351 | | - while($row = $db->fetchObject($res)) { |
352 | | - $result[] = Title::newFromID($row->subject_id); |
353 | | - } |
354 | | - $db->freeResult($res); |
355 | 379 | break; |
356 | 380 | } |
| 381 | + $result = array(); |
| 382 | + while($row = $db->fetchObject($res)) { |
| 383 | + $result[] = Title::newFromID($row->subject_id); |
| 384 | + } |
| 385 | + $db->freeResult($res); |
357 | 386 | return $result; |
358 | 387 | } |
359 | 388 | |