public function checkDatabasePermissionGrant($database, $permission, $grant)
    {
        // Filter out invalid database names
        if (!$this->checkValidDatabaseName($database)) {
            return false;
        }

        // Escape all valid database patterns (permission must exist on all tables)
        $sqlDatabase = addcslashes($database, '_%'); // See http://dev.mysql.com/doc/refman/5.7/en/string-literals.html
        $dbPattern = sprintf(
            '((%s)|(%s)|(%s)|(%s))',
            preg_quote("\"$sqlDatabase\".*"), // Regexp escape sql-escaped db identifier
            preg_quote("\"$database\".*"),
            preg_quote('"%".*'),
            preg_quote('*.*')
        );
        $expression = '/GRANT[ ,\w]+((ALL PRIVILEGES)|(' . $permission . '(?! ((VIEW)|(ROUTINE)))))[ ,\w]+ON ' . $dbPattern . '/i';
        return preg_match($expression, $grant);
    }