Example #1
0
 /**
  * Query the database with the given SPARQL query.
  *
  * @param Erfurt_SparqlQuery $query Parsed SPARQL query.
  * @param string $resultform Result form. If set to 'xml' the result will be
  * SPARQL Query Results XML Format as described in @link http://www.w3.org/TR/rdf-sparql-XMLres/.
  *
  * @return array/string  array of triple arrays, or XML. 
  * Format depends on $resultform parameter.
  */
 public function queryModel(Erfurt_Sparql_Query $query, $resultform = 'plain')
 {
     $this->query = $query;
     require_once 'Erfurt/Sparql/EngineDb/QuerySimplifier.php';
     $qsimp = new Erfurt_Sparql_EngineDb_QuerySimplifier();
     $qsimp->simplify($this->query);
     require_once 'Erfurt/Sparql/EngineDb/QueryOptimizer.php';
     $queryOptimizer = new Erfurt_Sparql_EngineDb_QueryOptimizer($this);
     $result = $queryOptimizer->optimize($this->query);
     if ($result instanceof Erfurt_Sparql_Query) {
         $this->query = $result;
     }
     $resultform = strtolower($resultform);
     switch ($resultform) {
         case 'xml':
             require_once 'Erfurt/Sparql/EngineDb/ResultRenderer/Xml.php';
             $rc = new Erfurt_Sparql_EngineDb_ResultRenderer_Xml();
             break;
             //require_once 'Erfurt/Exception.php';
             //throw new Erfurt_Exception('XML result format not supported yet.');
             //require_once 'Erfurt/Sparql/EngineDb/ResultRenderer/EfZendDb/Xml.php';
             //$this->rc = new Erfurt_Sparql_EngineDb_ResultRenderer_RapZendDb_Xml();
             //break;
         //require_once 'Erfurt/Exception.php';
         //throw new Erfurt_Exception('XML result format not supported yet.');
         //require_once 'Erfurt/Sparql/EngineDb/ResultRenderer/EfZendDb/Xml.php';
         //$this->rc = new Erfurt_Sparql_EngineDb_ResultRenderer_RapZendDb_Xml();
         //break;
         case 'extended':
             require_once 'Erfurt/Sparql/EngineDb/ResultRenderer/Extended.php';
             $rc = new Erfurt_Sparql_EngineDb_ResultRenderer_Extended();
             break;
         case 'json':
             require_once 'Erfurt/Sparql/EngineDb/ResultRenderer/Json.php';
             $rc = new Erfurt_Sparql_EngineDb_ResultRenderer_Json();
             break;
         case 'plain':
         default:
             require_once 'Erfurt/Sparql/EngineDb/ResultRenderer/Plain.php';
             $rc = new Erfurt_Sparql_EngineDb_ResultRenderer_Plain();
     }
     if (is_array($result)) {
         $result = $rc->convertFromDbResults($result['data'], $this->query, $this, $result['vars']);
         return $result;
     }
     require_once 'Erfurt/Sparql/EngineDb/SqlGenerator/Adapter/Ef.php';
     $this->sg = new Erfurt_Sparql_EngineDb_SqlGenerator_Adapter_Ef($this->query, $this->arModelIdMapping);
     require_once 'Erfurt/Sparql/EngineDb/TypeSorter.php';
     $this->ts = new Erfurt_Sparql_EngineDb_TypeSorter($this->query, $this);
     $this->_setOptions();
     $arSqls = $this->sg->createSql();
     #var_dump($arSqls);exit;
     $this->ts->setData($this->sg);
     return $rc->convertFromDbResults($this->_queryMultiple($this->ts->getOrderifiedSqls($arSqls)), $this->query, $this, $this->sg->arVarAssignments);
 }
Example #2
0
 /**
  *   Execute a prepared statement by filling it with variables
  *
  *   @param array $arVariables   Array with (variable name => value) pairs
  *   @param string $resultform   Which form the result should have
  *
  *   @return mixed   Result according to $resultform
  */
 public function execute($arVariables, $resultform = false)
 {
     if ($this->arPrepared === null) {
         throw new Exception('You need to prepare() the query first.');
     }
     if ($this->bRealPrepared) {
         return SparqlEngineDb_ResultConverter::convertFromDbResults($this->pr->execute($this->arDbStatements, $arVariables), $this, $resultform);
     } else {
         list($strSelect, $strFrom, $strWhere) = $this->arPrepared;
         return SparqlEngineDb_ResultConverter::convertFromDbResults($this->queryMultiple($this->ts->getOrderifiedSqls($strSelect, $strFrom, $this->pr->replacePlaceholdersWithVariables($strWhere, $this->sg->getPlaceholders(), $arVariables))), $this, $resultform);
     }
 }