function gSQLRowCount($where, $having = "")
{
    global $gsqlFrom, $gsqlWhereExpr;
    global $gQuery;
    $sqlHead = $gQuery->HeadToSql();
    $sqlGroupBy = $gQuery->GroupByToSql();
    $oHaving = $gQuery->Having();
    $sqlHaving = $oHaving->toSql($gQuery);
    return gSQLRowCount_int($sqlHead, $gsqlFrom, $gsqlWhereExpr, $sqlGroupBy, $sqlHaving, $where, $having);
}
 /**
  * Use for count details recs number, if subQueryes not supported, or keys have different types
  *
  * @param integer $i
  * @param array $detailid
  */
 function countDetailsRecsNoSubQ($dInd, &$detailid)
 {
     global $tables_data;
     global $masterTablesData;
     global $detailsTablesData;
     $dDataSourceTable = $this->allDetailsTablesArr[$dInd]['dDataSourceTable'];
     $gQuery = GetTableData($dDataSourceTable, '.sqlquery', null);
     $dObjHaving = $gQuery->Having();
     $dSqlHaving = $dObjHaving->toSql($gQuery);
     $dSqlGroupBy = $gQuery->GroupByToSql();
     $dSqlHead = $this->allDetailsTablesArr[$dInd]['sqlHead'];
     $dSqlFrom = $this->allDetailsTablesArr[$dInd]['sqlFrom'];
     $dSqlWhere = $this->allDetailsTablesArr[$dInd]['sqlWhere'];
     //$sqlTail = $detailTableInfo['sqlTail'];
     $detailKeys = GetDetailKeysByMasterTable($this->tName, $dDataSourceTable);
     $securityClause = SecuritySQL("Search", $dDataSourceTable);
     // add where
     if (strlen($securityClause)) {
         $dSqlWhere = whereAdd($dSqlWhere, $securityClause);
     }
     $masterwhere = "";
     foreach ($this->masterKeysByD[$dInd] as $idx => $val) {
         if ($masterwhere) {
             $masterwhere .= " and ";
         }
         $masterwhere .= GetFullFieldName($detailKeys[$idx], $dDataSourceTable) . "=" . make_db_value($detailKeys[$idx], $detailid[$idx]);
     }
     return gSQLRowCount_int($dSqlHead, $dSqlFrom, $dSqlWhere, $dSqlGroupBy, $dSqlHaving, $masterwhere, "");
 }
Пример #3
0
 /**
  * Builds SQL query, for retrieve data from DB
  *
  */
 function buildSQL()
 {
     global $gQuery;
     $searchWhereClause = $this->searchClauseObj->getWhere(GetListOfFieldsByExprType(false, $this->tName));
     $searchHavingClause = $this->searchClauseObj->getWhere(GetListOfFieldsByExprType(true, $this->tName));
     $this->strWhereClause = whereAdd($this->strWhereClause, $searchWhereClause);
     $this->strHavingClause = whereAdd($this->strHavingClause, $searchHavingClause);
     $strSecuritySql = SecuritySQL("Search", $this->tName);
     $this->strWhereClause = whereAdd($this->strWhereClause, $strSecuritySql);
     if ($this->noRecordsFirstPage && !count($_GET) && !count($_POST)) {
         $this->strWhereClause = whereAdd($this->strWhereClause, "1=0");
     }
     //add where clause with foreign keys of current table and it's master table master keys
     $where = $this->addWhereWithMasterTable();
     $this->strWhereClause = whereAdd($this->strWhereClause, $where);
     if ($this->dbType == nDATABASE_DB2) {
         $this->gsqlHead .= ", ROW_NUMBER() over () as DB2_ROW_NUMBER  ";
     }
     $strSQL = gSQLWhere_having($this->gsqlHead, $this->gsqlFrom, $this->gsqlWhereExpr, $this->gsqlGroupBy, $this->gsqlHaving, $this->strWhereClause, $this->strHavingClause);
     //	order by
     $strSQL .= " " . trim($this->strOrderBy);
     //	save SQL for use in "Export" and "Printer-friendly" pages
     $_SESSION[$this->sessionPrefix . "_sql"] = $strSQL;
     $_SESSION[$this->sessionPrefix . "_where"] = $this->strWhereClause;
     $_SESSION[$this->sessionPrefix . "_having"] = $this->strHavingClause;
     $_SESSION[$this->sessionPrefix . "_order"] = $this->strOrderBy;
     $_SESSION[$this->sessionPrefix . "_arrFieldForSort"] = $this->arrFieldForSort;
     $_SESSION[$this->sessionPrefix . "_arrHowFieldSort"] = $this->arrHowFieldSort;
     //	select and display records
     $this->addMasterDetailSubQuery();
     $strSQLbak = $strSQL;
     if ($this->eventExists("BeforeQueryList")) {
         $tstrWhereClause = $this->strWhereClause;
         $tstrOrderBy = $this->strOrderBy;
         $this->eventsObject->BeforeQueryList($strSQL, $tstrWhereClause, $tstrOrderBy);
         $this->strWhereClause = $tstrWhereClause;
         $this->strOrderBy = $tstrOrderBy;
     }
     //	Rebuild SQL if needed
     if ($strSQL != $strSQLbak) {
         //	changed $strSQL - old style
         $this->numRowsFromSQL = GetRowCount($strSQL);
     } else {
         $strSQL = gSQLWhere_having($this->gsqlHead, $this->gsqlFrom, $this->gsqlWhereExpr, $this->gsqlGroupBy, $this->gsqlHaving, $this->strWhereClause, $this->strHavingClause);
         $strSQL .= " " . trim($this->strOrderBy);
         $rowcount = false;
         if ($this->eventExists("ListGetRowCount")) {
             $rowcount = $this->eventsObject->ListGetRowCount($this->searchClauseObj, $this->masterTable, $this->masterKeysReq, null);
         }
         if ($rowcount !== false) {
             $this->numRowsFromSQL = $rowcount;
         } else {
             $this->numRowsFromSQL = gSQLRowCount_int($this->gsqlHead, $this->gsqlFrom, $this->gsqlWhereExpr, $this->gsqlGroupBy, $this->gsqlHaving, $this->strWhereClause, $this->strHavingClause);
         }
     }
     LogInfo($strSQL);
     $this->querySQL = $strSQL;
 }