Source for file Offsetter.php

Documentation is available at Offsetter.php

  1. <?php
  2. require_once RDFAPI_INCLUDE_DIR 'sparql/SparqlEngineDb/SqlMerger.php';
  3.  
  4. /**
  5. *   Determines the offset in a row of sql queries.
  6. *
  7. *   @author Christian Weiske <cweiske@cweiske.de>
  8. *
  9. *   @package sparql
  10. */
  11. {
  12.     public function __construct(ADOConnection $dbConnQuery $query)
  13.     {
  14.         $this->dbConn   $dbConn;
  15.         $this->query    $query;
  16.     }//public function __construct(ADOConnection $dbConn, Query $query)
  17.  
  18.  
  19.  
  20.     /**
  21.     *   Determines the offset in the sqls, the position to start form.
  22.     *
  23.     *   @param array $arSqls    Array of SQL query parts as returned by
  24.     *                            SparqlEngine_TypeSorter::getOrderifiedSqls()
  25.     *   @return array   Array of two values: The first determines the
  26.     *                    index of the sql query to begin with, the second
  27.     *                    is the row offset that should be used in the final
  28.     *                    SQL query.
  29.     */
  30.     public function determineOffset($arSqls)
  31.     {
  32.         $arSM $this->query->getSolutionModifier();
  33.         if ($arSM['offset'=== null{
  34.             return array(00);
  35.         }
  36.  
  37.         $nCount 0;
  38.         foreach ($arSqls as $nId => $arSql{
  39.             $nCurrentCount $this->getCount($arSql);
  40.             if ($nCurrentCount $nCount $arSM['offset']{
  41.                 return array($nId$arSM['offset'$nCount);
  42.             }
  43.             $nCount += $nCurrentCount;
  44.         }
  45.         //nothing found - no results for this offset
  46.         return array(count($arSqls)0);
  47.     }//public function determineOffset($arSql)
  48.  
  49.  
  50.  
  51.     /**
  52.     *   Returns the number of rows that the given query will return.
  53.     *
  54.     *   @param array $arSql Array with sql parts and at least keys
  55.     *                 'from' and 'where' set.
  56.     *   @return int     Number of rows returned.
  57.     */
  58.     protected function getCount($arSql)
  59.     {
  60.         $sql SparqlEngineDb_SqlMerger::getCount($this->query$arSql);
  61.         $dbResult $this->dbConn->execute($sql);
  62.  
  63.         $nCount 0;
  64.         foreach ($dbResult as $row{
  65.             $nCount intval($row[0]);
  66.             break;
  67.         }
  68.         return $nCount;
  69.     }//protected function getCount($arSql)
  70.  
  71.  
  72.  
  73.     /**
  74.     *   Creates a sql LIMIT statement if the sparql query needs one.
  75.     *   This method is needed because AdoDb does not support limits with
  76.     *   prepared statements. It's a pity.
  77.     *
  78.     *   @return string  SQL command to be appended to a query, to limit
  79.     *                    the number of result rows returned.
  80.     */
  81.     public static function getLimitSql(Query $queryADOConnection $dbConn)
  82.     {
  83.         $arSM $query->getSolutionModifier();
  84.         if ($arSM['limit'=== null && $arSM['offset'=== null{
  85.             return '';
  86.         }
  87.         //this here is mysql syntax. if anyone has problems, write it
  88.         //dependent on $dbConn's type
  89.         if ($arSM['offset'=== null{
  90.             return ' LIMIT ' $arSM['limit'];
  91.         else if ($arSM['limit'=== null{
  92.             return ' LIMIT ' $arSM['offset'', 18446744073709551615';
  93.         else {
  94.             return ' LIMIT ' $arSM['offset'', ' $arSM['limit'];
  95.         }
  96.     }//public static function getLimitSql(Query $query, ADOConnection $dbConn)
  97.  
  98. }//class SparqlEngineDb_Offsetter
  99.  
  100. ?>

Documentation generated on Fri, 1 Jun 2007 16:50:05 +0200 by phpDocumentor 1.3.2