function ft_getPropertyValues($property, $store) { $pid = $store->getSMWPropertyID($property); $db =& wfGetDB(DB_SLAVE); $result = array(); $mode = SMWSQLStore2::getStorageMode($property->getPropertyTypeID()); switch ($mode) { case SMW_SQL2_TEXT2: $res = $db->select('smw_text2', 'value_blob', 'p_id=' . $db->addQuotes($pid)); while ($row = $db->fetchObject($res)) { $dv = SMWDataValueFactory::newPropertyObjectValue($property); $dv->setOutputFormat($outputformat); $dv->setDBkeys(array($row->value_blob)); $result[] = $dv; } $db->freeResult($res); break; case SMW_SQL2_RELS2: $res = $db->select(array('smw_rels2', 'smw_ids'), 'smw_namespace, smw_title, smw_iw', 'p_id=' . $db->addQuotes($pid) . ' AND o_id=smw_id'); while ($row = $db->fetchObject($res)) { $dv = SMWDataValueFactory::newPropertyObjectValue($property); $dv->setOutputFormat($outputformat); $dv->setDBkeys(array($row->smw_title, $row->smw_namespace, $row->smw_iw)); $result[] = $dv; } $db->freeResult($res); break; case SMW_SQL2_ATTS2: if ($requestoptions !== NULL && $requestoptions->boundary !== NULL) { $value_column = $requestoptions->boundary->isNumeric() ? 'value_num' : 'value_xsd'; } else { $testval = SMWDatavalueFactory::newTypeIDValue($property->getPropertyTypeID()); $value_column = $testval->isNumeric() ? 'value_num' : 'value_xsd'; } $sql = 'p_id=' . $db->addQuotes($pid); $res = $db->select('smw_atts2', 'value_unit, value_xsd', 'p_id=' . $db->addQuotes($pid)); while ($row = $db->fetchObject($res)) { $dv = SMWDataValueFactory::newPropertyObjectValue($property); $dv->setOutputFormat($outputformat); $dv->setDBkeys(array($row->value_xsd, $row->value_unit)); $result[] = $dv; } $db->freeResult($res); break; } return $result; }
/** * Given an SMWDescription that is just a conjunction or disjunction of * SMWValueDescription objects, create a plain WHERE condition string for it. */ protected function compileAttributeWhere(SMWDescription $description, $jointable) { if ($description instanceof SMWValueDescription) { $dv = $description->getDatavalue(); if (SMWSQLStore2::getStorageMode($dv->getTypeID()) == SMW_SQL2_SPEC2) { $keys = $dv->getDBkeys(); $value = $keys[0]; $field = "{$jointable}.value_string"; } else { // should be SMW_SQL2_ATTS2 if ($dv->isNumeric()) { $value = $dv->getNumericValue(); $field = "{$jointable}.value_num"; } else { $keys = $dv->getDBkeys(); $value = $keys[0]; $field = "{$jointable}.value_xsd"; } } switch ($description->getComparator()) { case SMW_CMP_LEQ: $comp = '<='; break; case SMW_CMP_GEQ: $comp = '>='; break; case SMW_CMP_NEQ: $comp = '!='; break; case SMW_CMP_LIKE: if ($dv->getTypeID() == '_str') { $comp = ' LIKE '; $value = str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $value); } else { // LIKE only supported for strings $comp = '='; } break; case SMW_CMP_EQ: default: $comp = '='; break; } $result = "{$field}{$comp}" . $this->m_dbs->addQuotes($value); } elseif ($description instanceof SMWConjunction || $description instanceof SMWDisjunction) { $op = $description instanceof SMWConjunction ? ' AND ' : ' OR '; $result = ''; foreach ($description->getDescriptions() as $subdesc) { $result = $result . ($result != '' ? $op : '') . $this->compileAttributeWhere($subdesc, $jointable); } $result = "({$result})"; } else { $result = ''; } return $result; }