RDF_RDQL
[ class tree: RDF_RDQL ] [ index: RDF_RDQL ] [ all elements ]

Source for file RDQL.php

Documentation is available at RDQL.php

  1. <?php 
  2.  
  3. require_once 'RDF.php';
  4.  
  5. // ----------------------------------------------------------------------------------
  6. // RDQL Error Messages
  7. // ----------------------------------------------------------------------------------
  8. define('RDF_RDQL_ERROR',        -1);
  9. define('RDF_RDQL_ERROR_SYNTAX'-2);
  10. define('RDF_RDQL_ERROR_SELECT'-3);
  11. define('RDF_RDQL_ERROR_SOURCE'-4);
  12. define('RDF_RDQL_ERROR_WHERE',  -5);
  13. define('RDF_RDQL_ERROR_AND',    -6);
  14. define('RDF_RDQL_ERROR_USING',  -7);
  15. // ----------------------------------------------------------------------------------
  16. // RDQL default namespace prefixes
  17. // ----------------------------------------------------------------------------------
  18. $GLOBALS['_RDF_RDQL_default_prefixes'= array(
  19.     'rdf'  => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
  20.     'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
  21.     'xsd'  => 'http://www.w3.org/2001/XMLSchema#'
  22. );
  23.  
  24. class RDF_RDQL
  25. {
  26.     // }}}
  27.     // {{{ raiseError()
  28.  
  29.     /**
  30.      * This method is used to communicate an error and invoke error
  31.      * callbacks etc.  Basically a wrapper for PEAR::raiseError
  32.      * without the message string.
  33.      *
  34.      * @param mixed    integer error code, or a PEAR error object (all
  35.      *                  other parameters are ignored if this parameter is
  36.      *                  an object
  37.      *
  38.      * @param int      error mode, see PEAR_Error docs
  39.      *
  40.      * @param mixed    If error mode is PEAR_ERROR_TRIGGER, this is the
  41.      *                  error level (E_USER_NOTICE etc).  If error mode is
  42.      *                  PEAR_ERROR_CALLBACK, this is the callback function,
  43.      *                  either as a function name, or as an array of an
  44.      *                  object and method name.  For other error modes this
  45.      *                  parameter is ignored.
  46.      *
  47.      * @param string   Extra debug information.  Defaults to the last
  48.      *                  query and native error code.
  49.      *
  50.      * @return object  PEAR error object
  51.      *
  52.      * @see PEAR_Error
  53.      */
  54.     function &raiseError($code = null$mode = null$options = null$userinfo = null)
  55.     {
  56.         // The error is yet a MDB error object
  57.         if (is_object($code)) {
  58.             // because we the static PEAR::raiseError, our global
  59.             // handler should be used if it is set
  60.             if ($mode === null && !empty($this->_default_error_mode)) {
  61.                 $mode    $this->_default_error_mode;
  62.                 $options $this->_default_error_options;
  63.             }
  64.             return PEAR::raiseError($codenull$mode$optionsnullnulltrue);
  65.         }
  66.  
  67.         return PEAR::raiseError(null$code$mode$options$userinfo'RDF_RDQL_Error'true);
  68.     }
  69.     /**
  70.      * Return a textual error message for a RAP error code.
  71.      *
  72.      * @access  public
  73.      * @param   int     error code
  74.      * @return  string  error message
  75.      */
  76.     function errorMessage($value)
  77.     {
  78.         // make the variable static so that it only has to do the defining on the first call
  79.         static $errorMessages;
  80.  
  81.         // define the varies error messages
  82.         if (!isset($errorMessages)) {
  83.             $errorMessages = array(
  84.                 RDF_RDQL_ERROR              => 'Unknown error',
  85.                 RDF_RDQL_ERROR_SYNTAX       => 'Syntax error',
  86.                 RDF_RDQL_ERROR_SELECT       => 'Error in the SELECT clause',
  87.                 RDF_RDQL_ERROR_SOURCE       => 'Error in the SOURCE clause',
  88.                 RDF_RDQL_ERROR_WHERE        => 'Error in the WHERE clause',
  89.                 RDF_RDQL_ERROR_AND          => 'Error in the AND clause',
  90.                 RDF_RDQL_ERROR_USING        => 'Error in the USING clause',
  91.             );
  92.         }
  93.  
  94.         // If this is an error object, then grab the corresponding error code
  95.         if (RDF_RDQL::isError($value)) {
  96.             $value $value->getCode();
  97.         }
  98.  
  99.         // return the textual error message corresponding to the code
  100.         return isset($errorMessages[$value]$errorMessages[$value$errorMessages[RDF_RDQL_ERROR];
  101.     // end func errorMessage
  102.  
  103.     function isError($error)
  104.     {
  105.         return is_a($value'RDF_RDQL_Error');
  106.     }
  107.  
  108.     /**
  109.      * Perform an RDQL query on this Model_MDB.
  110.      * This method returns an associative array of variable bindings.
  111.      * The values of the query variables can either be RAP's objects (instances of Node)
  112.      * if $returnNodes set to TRUE, or their string serialization.
  113.      *
  114.      * @access public
  115.      * @param object model 
  116.      * @param string $queryString 
  117.      * @param boolean $returnNodes 
  118.      * @return array [][?VARNAME] = object Node  (if $returnNodes = TRUE)
  119.      *        OR  array   [][?VARNAME] = string
  120.      */
  121.     function RDQLQuery(&$model$queryString$returnNodes = true)
  122.     {
  123.         if (!is_a($model'RDF_Model')) {
  124.             $errmsg 'Parameter is not an RDF_Model';
  125.             return RDF_RDQL::raiseError(RDF_RDQL_ERRORnullnull$errmsg);
  126.         }
  127.         $parser =new RDF_RDQL_Parser();
  128.         $parsedQuery =$parser->parseQuery($queryString);
  129.         $model_class get_class($model);
  130.         // this method can only query this model
  131.         // if another model was specified in the from clause throw an error
  132.         if (strtolower($model_class== 'rdf_model_mdb'{
  133.             if (isset($parsedQuery['sources'][0])
  134.                 && $parsedQuery['sources'][0!= $model->modelURI
  135.             {
  136.                 $errmsg 'Method can only query this Model_MDB';
  137.                 return RDF_RDQL::raiseError(RDF_RDQL_ERRORnullnull$errmsg);
  138.             }
  139.             $engine =new RDF_RDQL_Engine_MDB();
  140.         elseif (strtolower($model_class== 'rdf_model_memory'{
  141.             if (isset($parsedQuery['sources'][1])) {
  142.                 $errmsg 'Method can only query this Model_Memory';
  143.                 return RDF_RDQL::raiseError(RDF_ERROR_MISMATCHnullnull$errmsg);
  144.             }
  145.             $engine =new RDF_RDQL_Engine_Memory();
  146.         else {
  147.             $errmsg 'Model type is not supported: ' $model_class;
  148.             return RDF_RDQL::raiseError(RDF_RDQL_ERRORnullnull$errmsg);
  149.         }
  150.  
  151.         $res =$engine->queryModel($model$parsedQuery$returnNodes);
  152.  
  153.         return $res;
  154.     }
  155.  
  156.  
  157.     /**
  158.      * Perform an RDQL query on this Model_MDB.
  159.      * This method returns an RDQLResultIterator of variable bindings.
  160.      * The values of the query variables can either be RAP's objects (instances of Node)
  161.      * if $returnNodes set to TRUE, or their string serialization.
  162.      *
  163.      * @access public
  164.      * @param object model 
  165.      * @param string $queryString 
  166.      * @param boolean $returnNodes 
  167.      * @return object RDQLResultIterator = with values as object Node  (if $returnNodes = TRUE)
  168.      *        OR  object RDQLResultIterator = with values as strings if (if $returnNodes = FALSE)
  169.      */
  170.     function RDQLQueryAsIterator(&$model$queryString$returnNodes = true)
  171.     {
  172.         if (!is_a($model'RDF_Model')) {
  173.             $errmsg 'Parameter is not an RDF_Model';
  174.             return RDF_RDQL::raiseError(RDF_RDQL_ERRORnullnull$errmsg);
  175.         }
  176.  
  177.         $result =RDF_RDQL::RDQLQuery($model$queryString$returnNodes);
  178.         if (PEAR::isError($result)) {
  179.             return $result;
  180.         }
  181.         return new RDF_RDQL_ResultIterator($result);
  182.     }
  183. }
  184.  
  185. /**
  186.  * RDF_RDQL_Error implements a class for reporting RDF RDQL error
  187.  * messages.
  188.  *
  189.  * @package RDF_RDQL
  190.  * @category RDF
  191.  * @author  Stig Bakken <ssb@fast.no>
  192.  */
  193. class RDF_RDQL_Error extends PEAR_Error
  194. {
  195.     // }}}
  196.     // {{{ constructor
  197.  
  198.     /**
  199.      * RDF_Error constructor.
  200.      *
  201.      * @param mixed   $code      RDF error code, or string with error message.
  202.      * @param integer $mode      what 'error mode' to operate in
  203.      * @param integer $level     what error level to use for
  204.      *                            $mode & PEAR_ERROR_TRIGGER
  205.      * @param smixed  $debuginfo additional debug info, such as the last query
  206.      */
  207.     function RDF_RDQL_Error($code = RDF_RDQL_ERROR$mode = PEAR_ERROR_RETURN,
  208.               $level = E_USER_NOTICE$debuginfo = null)
  209.     {
  210.         if (is_int($code)) {
  211.             $this->PEAR_Error('RDF RDQL Error: '.RDF_RDQL::errorMessage($code)$code,
  212.                 $mode$level$debuginfo);
  213.         else {
  214.             $this->PEAR_Error("RDF RDQL Error: $code"RDF_RDQL_ERROR$mode$level,
  215.                 $debuginfo);
  216.         }
  217.     }
  218. }
  219.  
  220. // Include RQQL classes
  221. require_once 'RDF/RDQL/Parser.php';
  222. require_once 'RDF/RDQL/Engine/MDB.php';
  223. require_once 'RDF/RDQL/Engine/Memory.php';
  224. require_once 'RDF/RDQL/ResultIterator.php';
  225.  
  226. ?>

Documentation generated on Mon, 11 Mar 2019 15:39:50 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.