r24154 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24153‎ | r24154 | r24155 >
Date:08:30, 16 July 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Support for nary subject retrieval
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
@@ -317,11 +317,11 @@
318318 if ( !$value->isValid() ) {
319319 return array();
320320 }
321 - $result = array();
322321 $db =& wfGetDB( DB_SLAVE );
323322
324323 switch ($value->getTypeID()) {
325324 case '_txt': // not supported
 325+ return array();
326326 break;
327327 case '_wpg': // wikipage
328328 $sql = 'object_namespace=' . $db->addQuotes($value->getNamespace()) .
@@ -329,14 +329,42 @@
330330 ' AND relation_title=' . $db->addQuotes($property->getDBKey()) .
331331 $this->getSQLConditions($requestoptions,'subject_title','subject_title');
332332
333 - $res = $db->select( $db->tableName('smw_relations'),
 333+ $res = $db->select( 'smw_relations',
334334 'DISTINCT subject_id',
335335 $sql, 'SMW::getPropertySubjects',
336336 $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++;
339365 }
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'));
341369 break;
342370 default:
343371 $sql = 'value_xsd=' . $db->addQuotes($value->getXSDValue()) .
@@ -347,12 +375,13 @@
348376 'DISTINCT subject_id',
349377 $sql, 'SMW::getPropertySubjects',
350378 $this->getSQLOptions($requestoptions,'subject_title') );
351 - while($row = $db->fetchObject($res)) {
352 - $result[] = Title::newFromID($row->subject_id);
353 - }
354 - $db->freeResult($res);
355379 break;
356380 }
 381+ $result = array();
 382+ while($row = $db->fetchObject($res)) {
 383+ $result[] = Title::newFromID($row->subject_id);
 384+ }
 385+ $db->freeResult($res);
357386 return $result;
358387 }
359388

Status & tagging log