src/Data/Tools/BizDataObj_SQLHelper.php
private function _ruleToSql($dataObj, $rule)
    {
        $cacheKey = $dataObj->objectName . "-" . $rule;
        if (isset($this->_doRuleCache[$cacheKey])) {
            return $this->_doRuleCache[$cacheKey];
        }
        //echo " _ruleToSql ".$dataObj->objectName." ". $rule."\n";
        $dataSqlObj = $this->getDataSqlObj();

        $rule = Expression::evaluateExpression($rule, $dataObj);

        // replace all [field] with table.column
        // use regexp to find [] parts and replace with fields
        if (!preg_match_all("/\[([0-9a-zA-Z_]+)\]/", $rule, $m)) {
            $this->_doRuleCache[$cacheKey] = $rule;
            return $rule;
        }
        foreach ($m[1] as $fld) {
            $bizField = $dataObj->getField($fld);
            if (!$bizField)
                continue;
            $fld_pattern = "[" . $bizField->objectName . "]";
            if ($bizField->column && (strpos($bizField->column, ',') != 0)) {  // handle composite key.
                if (!preg_match('/\[' . $bizField->objectName . '\].*=.*\'(.+)\'/', $rule, $matches))
                    continue; //print_r($matches);
                $keyval = $matches[1];
                // replace the matching part [compkey field]='value'
                $compkey_value = $this->_compKeyRuleToSql($bizField->column, $keyval);
                $rule = $str_replace($matches[0], $compkey_value, $rule);
            }
            else {
                if ($bizField->aliasName) {
                    $rule = str_replace($fld_pattern, $bizField->aliasName, $rule);
                } elseif ($bizField->sqlExpression) {
                    $rule = str_replace($fld_pattern, $bizField->sqlExpression, $rule);
                } else {
                    $tableColumn = $dataSqlObj->getTableColumn($bizField->join, $bizField->column);
                    $rule = str_replace($fld_pattern, $tableColumn, $rule);
                }
            }
        }

        $this->_doRuleCache[$cacheKey] = $rule;
        return $rule;
    }
private function _ruleToSql($dataObj, $rule)
    {
        $cacheKey = $dataObj->objectName . "-" . $rule;
        if (isset($this->_doRuleCache[$cacheKey])) {
            return $this->_doRuleCache[$cacheKey];
        }
        //echo " _ruleToSql ".$dataObj->objectName." ". $rule."\n";
        $dataSqlObj = $this->getDataSqlObj();

        $rule = Expression::evaluateExpression($rule, $dataObj);

        // replace all [field] with table.column
        // use regexp to find [] parts and replace with fields
        if (!preg_match_all("/\[([0-9a-zA-Z_]+)\]/", $rule, $m)) {
            $this->_doRuleCache[$cacheKey] = $rule;
            return $rule;
        }
        foreach ($m[1] as $fld) {
            $bizField = $dataObj->getField($fld);
            if (!$bizField)
                continue;
            $fld_pattern = "[" . $bizField->objectName . "]";
            if ($bizField->column && (strpos($bizField->column, ',') != 0)) {  // handle composite key.
                if (!preg_match('/\[' . $bizField->objectName . '\].*=.*\'(.+)\'/', $rule, $matches))
                    continue; //print_r($matches);
                $keyval = $matches[1];
                // replace the matching part [compkey field]='value'
                $compkey_value = $this->_compKeyRuleToSql($bizField->column, $keyval);
                $rule = $str_replace($matches[0], $compkey_value, $rule);
            }
            else {
                if ($bizField->aliasName) {
                    $rule = str_replace($fld_pattern, $bizField->aliasName, $rule);
                } elseif ($bizField->sqlExpression) {
                    $rule = str_replace($fld_pattern, $bizField->sqlExpression, $rule);
                } else {
                    $tableColumn = $dataSqlObj->getTableColumn($bizField->join, $bizField->column);
                    $rule = str_replace($fld_pattern, $tableColumn, $rule);
                }
            }
        }

        $this->_doRuleCache[$cacheKey] = $rule;
        return $rule;
    }
Convert search/sort rule to sql clause, replace [fieldName] with table.column
openbiz SQL expression as :
"[fieldName] opr 'Value' AND/OR [fieldName] opr 'Value'...". "()" is valid syntax

@param BizDataObj $dataObj
@param string $rule "[fieldName] ..."
@return string sql statement