Gdn_SQLDriver::_parseExpr PHP Method

_parseExpr() protected method

Parses an expression for use in where clauses.
protected _parseExpr ( string $Expr, string $Name = null, $EscapeExpr = false ) : string
$Expr string The expression to parse.
$Name string A name to give the parameter if $Expr becomes a named parameter.
return string The parsed expression.
    protected function _parseExpr($Expr, $Name = null, $EscapeExpr = false)
    {
        $Result = '';
        $C = substr($Expr, 0, 1);
        if ($C === '=' && $EscapeExpr === false) {
            // This is a function call. Each parameter has to be parsed.
            $FunctionArray = preg_split('/(\\[[^\\]]+\\])/', substr($Expr, 1), -1, PREG_SPLIT_DELIM_CAPTURE);
            for ($i = 0; $i < count($FunctionArray); $i++) {
                $Part = $FunctionArray[$i];
                if (substr($Part, 1) == '[') {
                    // Translate the part of the function call.
                    $Part = $this->_fieldExpr(substr($Part, 1, strlen($Part) - 2), $Name);
                    $FunctionArray[$i] = $Part;
                }
            }
            // Combine the array back to the original function call.
            $Result = join('', $FunctionArray);
        } elseif ($C === '@' && $EscapeExpr === false) {
            // This is a literal. Don't do anything.
            $Result = substr($Expr, 1);
        } else {
            // This is a column reference.
            if (is_null($Name)) {
                $Result = $this->escapeIdentifier($Expr);
            } else {
                // This is a named parameter.
                // Check to see if the named parameter is valid.
                if (in_array(substr($Expr, 0, 1), array('=', '@'))) {
                    // The parameter has to be a default name.
                    $Result = $this->namedParameter('Param', true);
                } else {
                    $Result = $this->namedParameter($Name, true);
                }
                $this->_NamedParameters[$Result] = $Expr;
            }
        }
        return $Result;
    }