Esempio n. 1
0
 /**
  * tests if equals() works according to the RDF specifications
  *
  */
 function testEquals()
 {
     $_SESSION['test'] = 'Litras Equals test';
     $literal1 = new Literal('test');
     $literal2 = new Literal('test');
     $this->assertTrue($literal1->equals($literal2));
     $literal2->setLanguage('DE');
     $this->assertFalse($literal1->equals($literal2));
     $literal1->setLanguage('FR');
     $this->assertFalse($literal1->equals($literal2));
     $literal1->setLanguage('DE');
     $this->assertTrue($literal1->equals($literal2));
     $literal1->setDatatype("http://www.w3.org/TR/xmlschema-2/integer");
     $this->assertFalse($literal1->equals($literal2));
     $literal2->setDatatype("http://www.w3.org/TR/xmlschema-2/integer1");
     $this->assertFalse($literal1->equals($literal2));
     $literal2->setDatatype("http://www.w3.org/TR/xmlschema-2/integer");
     $this->assertTrue($literal1->equals($literal2));
 }
Esempio n. 2
0
 /**
  * Filter tuples containing variables matching all patterns from the WHERE clause
  * of an RDQL query. As a result of a database query using ADOdb these tuples
  * are returned as an ADORecordSet object, which is then passed to this function.
  *
  * @param   object ADORecordSet &$recordSet
  * @return  array  [][?VARNAME]['value']   = string
  *                             ['nType']   = string
  *                             ['l_lang']  = string
  *                             ['l_dtype'] = string
  * @access	private
  */
 function filterQueryResult(&$recordSet)
 {
     $queryResult = array();
     if (isset($this->parsedQuery['filters'])) {
         while (!$recordSet->EOF) {
             foreach ($this->parsedQuery['filters'] as $filter) {
                 $evalFilterStr = $filter['evalFilterStr'];
                 // evaluate regex equality expressions of each filter
                 foreach ($filter['regexEqExprs'] as $i => $expr) {
                     preg_match($expr['regex'], $recordSet->fields[$this->rsIndexes[$expr['var']]['value']], $match);
                     $op = substr($expr['operator'], 0, 1);
                     if ($op != '!' && !isset($match[0]) || $op == '!' && isset($match[0])) {
                         $evalFilterStr = str_replace("##RegEx_{$i}##", 'FALSE', $evalFilterStr);
                     } else {
                         $evalFilterStr = str_replace("##RegEx_{$i}##", 'TRUE', $evalFilterStr);
                     }
                 }
                 // evaluate string equality expressions
                 foreach ($filter['strEqExprs'] as $i => $expr) {
                     $exprBoolVal = 'FALSE';
                     switch ($expr['value_type']) {
                         case 'variable':
                             if ($recordSet->fields[$this->rsIndexes[$expr['var']]['value']] == $recordSet->fields[$this->rsIndexes[$expr['value']]['value']] && $expr['operator'] == 'eq' || $recordSet->fields[$this->rsIndexes[$expr['var']]['value']] != $recordSet->fields[$this->rsIndexes[$expr['value']]['value']] && $expr['operator'] == 'ne') {
                                 $exprBoolVal = 'TRUE';
                             }
                             break;
                         case 'URI':
                             if (isset($this->rsIndexes[$expr['var']]['nType']) && $recordSet->fields[$this->rsIndexes[$expr['var']]['nType']] == 'l') {
                                 if ($expr['operator'] == 'ne') {
                                     $exprBoolVal = 'TRUE';
                                 }
                                 break;
                             }
                             if ($recordSet->fields[$this->rsIndexes[$expr['var']]['value']] == $expr['value'] && $expr['operator'] == 'eq' || $recordSet->fields[$this->rsIndexes[$expr['var']]['value']] != $expr['value'] && $expr['operator'] == 'ne') {
                                 $exprBoolVal = 'TRUE';
                             }
                             break;
                         case 'Literal':
                             if (!isset($this->rsIndexes[$expr['var']]['nType']) || $recordSet->fields[$this->rsIndexes[$expr['var']]['nType']] != 'l') {
                                 if ($expr['operator'] == 'ne') {
                                     $exprBoolVal = 'TRUE';
                                 }
                                 break;
                             }
                             $filterLiteral = new Literal($expr['value'], $expr['value_lang']);
                             $filterLiteral->setDatatype($expr['value_dtype']);
                             $resultLiteral = new Literal($recordSet->fields[$this->rsIndexes[$expr['var']]['value']]);
                             $resultLiteral->setDatatype($recordSet->fields[$this->rsIndexes[$expr['var']]['l_dtype']]);
                             $resultLiteral->setLanguage($recordSet->fields[$this->rsIndexes[$expr['var']]['l_lang']]);
                             $equal = $resultLiteral->equals($filterLiteral);
                             if ($equal && $expr['operator'] == 'eq' || !$equal && $expr['operator'] == 'ne') {
                                 $exprBoolVal = 'TRUE';
                             } else {
                                 $exprBoolVal = 'FALSE';
                             }
                     }
                     $evalFilterStr = str_replace("##strEqExpr_{$i}##", $exprBoolVal, $evalFilterStr);
                 }
                 // evaluate numerical expressions
                 foreach ($filter['numExprVars'] as $varName) {
                     $varValue = "'" . $recordSet->fields[$this->rsIndexes[$varName]['value']] . "'";
                     $evalFilterStr = str_replace($varName, $varValue, $evalFilterStr);
                 }
                 eval("\$filterBoolVal = {$evalFilterStr}; \$eval_filter_ok = TRUE;");
                 if (!isset($eval_filter_ok)) {
                     trigger_error(RDQL_AND_ERR . "'" . htmlspecialchars($filter['string']) . "'", E_USER_ERROR);
                 }
                 if (!$filterBoolVal) {
                     $recordSet->MoveNext();
                     continue 2;
                 }
             }
             $queryResult[] = $this->_convertRsRowToQueryResultRow($recordSet->fields);
             $recordSet->MoveNext();
         }
     } else {
         while (!$recordSet->EOF) {
             $queryResult[] = $this->_convertRsRowToQueryResultRow($recordSet->fields);
             $recordSet->MoveNext();
         }
     }
     return $queryResult;
 }