Example #1
0
 /**
  *   Returns the number of rows that the given query will return.
  *
  *   @param array $arSql Array with sql parts and at least keys
  *                'from' and 'where' set.
  *   @return int     Number of rows returned.
  */
 protected function getCount($arSql)
 {
     $sql = SparqlEngineDb_SqlMerger::getCount($this->query, $arSql);
     $dbResult = $this->dbConn->execute($sql);
     $nCount = 0;
     foreach ($dbResult as $row) {
         $nCount = intval($row[0]);
         break;
     }
     return $nCount;
 }
Example #2
0
 /**
  *   Sends the sql to the database and returns the results.
  *
  *   @internal Switches between ADOConnection::Execute() and
  *    ADOConnection::SelectLimit() depending on the $query parameter's
  *    $solutionModifier "limit" and "offset" settings.
  *   Uses $query variable.
  *
  *   @param array $arSql     Array that gets a SQL query string once imploded
  *
  *   @return mixed           Anything ADOConnection::Execute() may return
  *   @throws Exception       If Database query does not work
  */
 function queryDb($arSql, $nOffset, $nLimit)
 {
     $strSql = SparqlEngineDb_SqlMerger::getSelect($this->query, $arSql);
     if ($strSql == '()') {
         return new ADORecordSet(false);
     }
     // I want associative arrays.
     $oldmode = $this->dbConn->SetFetchMode(ADODB_FETCH_ASSOC);
     if (isset($GLOBALS['debugSparql']) && $GLOBALS['debugSparql']) {
         echo 'SQL query: ' . $strSql . "\n";
     }
     if ($nLimit === null && $nOffset == 0) {
         $ret = $this->dbConn->execute($strSql);
     } else {
         if ($nLimit === null) {
             $ret = $this->dbConn->SelectLimit($strSql, -1, $nOffset);
         } else {
             $ret = $this->dbConn->SelectLimit($strSql, $nLimit, $nOffset);
         }
     }
     //... but others maybe not
     $this->dbConn->SetFetchMode($oldmode);
     if (!$ret) {
         //Error occured
         throw new Exception('ADOdb error: ' . $this->dbConn->ErrorMsg() . "\n" . $strSql);
     }
     return $ret;
 }