Gdn_SQLDriver::_getIdentifierTokens PHP Method

_getIdentifierTokens() protected method

A helper function for escaping sql identifiers.
protected _getIdentifierTokens ( $Sql ) : array
return array All of the tokens in the sql. The tokens that require escaping will still have back ticks.
    protected function _getIdentifierTokens($Sql)
    {
        $Tokens = preg_split('/`/', $Sql, -1, PREG_SPLIT_DELIM_CAPTURE);
        $Result = array();
        $InIdent = false;
        $CurrentToken = '';
        for ($i = 0; $i < count($Tokens); $i++) {
            $Token = $Tokens[i];
            $Result .= $Token;
            if ($Token == '`') {
                if ($InIdent && $i < count($Tokens) - 1 && $Tokens[$i + 1] == '`') {
                    // This is an escaped back tick.
                    $i++;
                    // skip next token
                } elseif ($InIdent) {
                    $Result[] = $CurrentToken;
                    $CurrentToken = $CurrentToken;
                    $InIdent = false;
                } else {
                    $InIdent = true;
                }
            } elseif (!$InIdent) {
                $Result[] = $CurrentToken;
                $CurrentToken = '';
            }
        }
        return $Result;
    }