Beispiel #1
0
 /**
  *   Executes multiple SQL queries and returns an array
  *   of results.
  *
  *   @param array $arSqls     Array of SQL queries
  *   @return array   Array of query results
  */
 protected function queryMultiple($arSqls)
 {
     $arSM = $this->query->getSolutionModifier();
     if ($arSM['limit'] === null && $arSM['offset'] === null) {
         $nOffset = 0;
         $nLimit = null;
         $nSql = 0;
     } else {
         $offsetter = new SparqlEngineDb_Offsetter($this->dbConn, $this->query);
         list($nSql, $nOffset) = $offsetter->determineOffset($arSqls);
         $nLimit = $arSM['limit'];
     }
     $nCount = 0;
     $arResults = array();
     foreach ($arSqls as $nId => $arSql) {
         if ($nId < $nSql) {
             continue;
         }
         if ($nLimit != null) {
             $nCurrentLimit = $nLimit - $nCount;
         } else {
             $nCurrentLimit = null;
         }
         $dbResult = $this->queryDb($arSql, $nOffset, $nCurrentLimit);
         $nCount += $dbResult->RowCount();
         $arResults[] = $dbResult;
         $nOffset = 0;
         if ($nLimit !== null && $nCount >= $nLimit) {
             break;
         }
     }
     return $arResults;
     //return array_map(array($this, 'queryDb'), $arSql);
 }
Beispiel #2
0
 /**
  *   Creates a sql LIMIT statement if the sparql query needs one.
  *   This method is needed because AdoDb does not support limits with
  *   prepared statements. It's a pity.
  *
  *   @return string  SQL command to be appended to a query, to limit
  *                   the number of result rows returned.
  */
 public static function getLimitSql(Query $query, ADOConnection $dbConn)
 {
     $arSM = $query->getSolutionModifier();
     if ($arSM['limit'] === null && $arSM['offset'] === null) {
         return '';
     }
     //this here is mysql syntax. if anyone has problems, write it
     //dependent on $dbConn's type
     if ($arSM['offset'] === null) {
         return ' LIMIT ' . $arSM['limit'];
     } else {
         if ($arSM['limit'] === null) {
             return ' LIMIT ' . $arSM['offset'] . ', 18446744073709551615';
         } else {
             return ' LIMIT ' . $arSM['offset'] . ', ' . $arSM['limit'];
         }
     }
 }
Beispiel #3
0
 /**
  * Sorts the results.
  *
  * @param  Array  $vartable List containing the unsorted result vars
  * @return Array  List containing the sorted result vars
  */
 protected function sortVars($vartable)
 {
     $newTable = array();
     $mod = $this->query->getSolutionModifier();
     // if no ORDER BY solution modifier return vartable
     if ($mod['order by'] != null) {
         $order = $mod['order by'];
         $map = $this->buildVarmap($order, $vartable);
         foreach ($map as $val) {
             $newTable[] = $vartable[$val];
         }
     } else {
         $newTable = $vartable;
     }
     if ($mod['offset'] != null) {
         $newTable = array_slice($newTable, $mod['offset']);
     }
     if ($mod['limit'] != null) {
         $newTable = array_slice($newTable, 0, $mod['limit']);
     }
     return $newTable;
 }