src/Data/Tools/BizDataObj_SQLHelper.php
public function buildQuerySQL($dataObj)
    {
        //echo "buildQuerySQL ".$dataObj->objectName."\n";
        // TODO: the same dataobj re-uses the same datasqlobj ...
        // build the SQL statement based on the fields and search rule
        $dataSqlObj = $this->getNewDataSqlObj($dataObj);

        if ($dataSqlObj->isfresh()) {
            // add table
            $dataSqlObj->addMainTable($dataObj->mainTableName);
            // add join table
            if ($dataObj->tableJoins) {
                foreach ($dataObj->tableJoins as $tableJoin) {
                    $tbl_col = $dataSqlObj->addJoinTable($tableJoin, $this);
                }
            }
            // add columns
            foreach ($dataObj->bizRecord as $bizField) {
                if ($bizField->ignoreInQuery) // field to be ignore in query - save memory
                    continue;
                if ($bizField->column && $bizField->type == "Blob")   // ignore blob column
                    continue;
                if ($bizField->column && !$bizField->sqlExpression && (strpos($bizField->column, ',') == 0))
                    $dataSqlObj->addTableColumn($bizField->join, $bizField->column, $bizField->aliasName);
                if ($bizField->sqlExpression) {
                    $dataSqlObj->addSqlExpression($this->_convertSqlExpression($dataObj, $bizField->sqlExpression), $bizField->aliasName);
                }
            }
        }
        $dataSqlObj->resetSQL();

        // append DataPerm in the WHERE clause
        if ($dataObj->dataPermControl == 'Y') {
            $svcObj = Openbizx::getService(OPENBIZ_DATAPERM_SERVICE);
            $hasOwnerField = $this->_hasOwnerField($dataObj);
            $dataPermSQLRule = $svcObj->buildSqlRule($dataObj, 'select', $hasOwnerField);
            $sqlSearchRule = $this->_ruleToSql($dataObj, $dataPermSQLRule);
            $dataSqlObj->addSqlWhere($sqlSearchRule);
        }

        // append QueryPameters in the WHERE clause
        foreach ($dataObj->getQueryParameters() as $fieldName => $value) {
            $queryRule = queryParamToRule($fieldName, $value, $dataObj);
            $sqlSearchRule = $this->_ruleToSql($dataObj, $queryRule);
            $dataSqlObj->addSqlWhere($sqlSearchRule);
        }

        // append SearchRule in the WHERE clause
        $sqlSearchRule = $this->_ruleToSql($dataObj, $dataObj->searchRule);
        $dataSqlObj->addSqlWhere($sqlSearchRule);

        // append SearchRule in the ORDER BY clause
        $sqlSortRule = $this->_ruleToSql($dataObj, $dataObj->sortRule);
        $dataSqlObj->addOrderBy($sqlSortRule);

        // append SearchRule in the other SQL clause
        $sqlOtherSQLRule = $this->_ruleToSql($dataObj, $dataObj->otherSQLRule);
        $dataSqlObj->addOtherSQL($sqlOtherSQLRule);

        // append SearchRule in the AccessRule clause
        $sqlAccessSQLRule = $this->_ruleToSql($dataObj, $dataObj->accessRule);
        $dataSqlObj->addSqlWhere($sqlAccessSQLRule);

        // add association to SQL
        if ($dataObj->association["AsscObjName"] != "" && $dataObj->association["FieldRefVal"] == "") {
            $asscObj = Openbizx::getObject($dataObj->association["AsscObjName"]);
            $dataObj->association["FieldRefVal"] = $asscObj->getFieldValue($dataObj->association["FieldRef"]);
        }

        if ($dataObj->association["AsscObjName"] != "" && $dataObj->association["FieldRefVal2"] == "") {
            $asscObj = Openbizx::getObject($dataObj->association["AsscObjName"]);
            $dataObj->association["FieldRefVal2"] = $asscObj->getFieldValue($dataObj->association["FieldRef2"]);
        }

        if ($dataObj->association["Relationship"] == "Self-Self") {
            $dataObj->association["ParentRecordIdColumn"] = $dataObj->getField("Id")->column;
        }
        $dataSqlObj->addAssociation($dataObj->association);

        // apply _ruleToSql to JoinCondition if any
        if ($dataSqlObj->hasJoinCondition) {
            $dataSqlObj->setTableJoinStm($this->_ruleToSql($dataObj, $dataSqlObj->getTableJoinStm()));
        }

        $querySQL = $dataSqlObj->getSqlStatement() . " ";

        //echo $querySQL."###\n";
        return $querySQL;
    }
public function buildQuerySQL($dataObj)
    {
        //echo "buildQuerySQL ".$dataObj->objectName."\n";
        // TODO: the same dataobj re-uses the same datasqlobj ...
        // build the SQL statement based on the fields and search rule
        $dataSqlObj = $this->getNewDataSqlObj($dataObj);

        if ($dataSqlObj->isfresh()) {
            // add table
            $dataSqlObj->addMainTable($dataObj->mainTableName);
            // add join table
            if ($dataObj->tableJoins) {
                foreach ($dataObj->tableJoins as $tableJoin) {
                    $tbl_col = $dataSqlObj->addJoinTable($tableJoin, $this);
                }
            }
            // add columns
            foreach ($dataObj->bizRecord as $bizField) {
                if ($bizField->ignoreInQuery) // field to be ignore in query - save memory
                    continue;
                if ($bizField->column && $bizField->type == "Blob")   // ignore blob column
                    continue;
                if ($bizField->column && !$bizField->sqlExpression && (strpos($bizField->column, ',') == 0))
                    $dataSqlObj->addTableColumn($bizField->join, $bizField->column, $bizField->aliasName);
                if ($bizField->sqlExpression) {
                    $dataSqlObj->addSqlExpression($this->_convertSqlExpression($dataObj, $bizField->sqlExpression), $bizField->aliasName);
                }
            }
        }
        $dataSqlObj->resetSQL();

        // append DataPerm in the WHERE clause
        if ($dataObj->dataPermControl == 'Y') {
            $svcObj = Openbizx::getService(OPENBIZ_DATAPERM_SERVICE);
            $hasOwnerField = $this->_hasOwnerField($dataObj);
            $dataPermSQLRule = $svcObj->buildSqlRule($dataObj, 'select', $hasOwnerField);
            $sqlSearchRule = $this->_ruleToSql($dataObj, $dataPermSQLRule);
            $dataSqlObj->addSqlWhere($sqlSearchRule);
        }

        // append QueryPameters in the WHERE clause
        foreach ($dataObj->getQueryParameters() as $fieldName => $value) {
            $queryRule = queryParamToRule($fieldName, $value, $dataObj);
            $sqlSearchRule = $this->_ruleToSql($dataObj, $queryRule);
            $dataSqlObj->addSqlWhere($sqlSearchRule);
        }

        // append SearchRule in the WHERE clause
        $sqlSearchRule = $this->_ruleToSql($dataObj, $dataObj->searchRule);
        $dataSqlObj->addSqlWhere($sqlSearchRule);

        // append SearchRule in the ORDER BY clause
        $sqlSortRule = $this->_ruleToSql($dataObj, $dataObj->sortRule);
        $dataSqlObj->addOrderBy($sqlSortRule);

        // append SearchRule in the other SQL clause
        $sqlOtherSQLRule = $this->_ruleToSql($dataObj, $dataObj->otherSQLRule);
        $dataSqlObj->addOtherSQL($sqlOtherSQLRule);

        // append SearchRule in the AccessRule clause
        $sqlAccessSQLRule = $this->_ruleToSql($dataObj, $dataObj->accessRule);
        $dataSqlObj->addSqlWhere($sqlAccessSQLRule);

        // add association to SQL
        if ($dataObj->association["AsscObjName"] != "" && $dataObj->association["FieldRefVal"] == "") {
            $asscObj = Openbizx::getObject($dataObj->association["AsscObjName"]);
            $dataObj->association["FieldRefVal"] = $asscObj->getFieldValue($dataObj->association["FieldRef"]);
        }

        if ($dataObj->association["AsscObjName"] != "" && $dataObj->association["FieldRefVal2"] == "") {
            $asscObj = Openbizx::getObject($dataObj->association["AsscObjName"]);
            $dataObj->association["FieldRefVal2"] = $asscObj->getFieldValue($dataObj->association["FieldRef2"]);
        }

        if ($dataObj->association["Relationship"] == "Self-Self") {
            $dataObj->association["ParentRecordIdColumn"] = $dataObj->getField("Id")->column;
        }
        $dataSqlObj->addAssociation($dataObj->association);

        // apply _ruleToSql to JoinCondition if any
        if ($dataSqlObj->hasJoinCondition) {
            $dataSqlObj->setTableJoinStm($this->_ruleToSql($dataObj, $dataSqlObj->getTableJoinStm()));
        }

        $querySQL = $dataSqlObj->getSqlStatement() . " ";

        //echo $querySQL."###\n";
        return $querySQL;
    }
Build the Select SQL statement based on the fields and search/sort rule

@param BizDataObj $dataObj
@return void