app/src/main/java/db/juhaku/juhakudb/filter/QueryProcessor.java
/**
     * Formats WHERE clause without WHERE text appended to follow rules of database.
     *
     * <ul>
     *     <li>Formats clause's "this" prefixes as alias provided.</li>
     *     <li>Formats empty prefixed columns with alias provided.</li>
     *     <li>Formats .id fields as ._id since Android primary key field is prefixed with "_" underscore.</li>
     * </ul>
     *
     * @param clause String sql clause to format aliases.
     * @param alias String value of alias to use. Can be null if no formatting is required.
     * @return String value of clause formatted if table name was provided otherwise returns the original
     * clause.
     * @hide
     *
     * @since 1.1.2
     */
Formats WHERE clause without WHERE text appended to follow rules of database.

Formats clause's "this" prefixes as alias provided.
Formats empty prefixed columns with alias provided.
Formats .id fields as ._id since Android primary key field is prefixed with "_" underscore.


@param clause String sql clause to format aliases.
@param alias String value of alias to use. Can be null if no formatting is required.
@return String value of clause formatted if table name was provided otherwise returns the original
clause.
@hide


Formats WHERE clause without WHERE text appended to follow rules of database . Formats clause ' s " this " prefixes as alias provided . Formats empty prefixed columns with alias provided . Formats . id fields as . _id since Android primary key field is prefixed with " _ " underscore . @param clause String sql clause to format aliases . @param alias String value of alias to use . Can be null if no formatting is required . @return String value of clause formatted if table name was provided otherwise returns the original clause . @hide
private static String formatClause(String clause, String alias) {
        String formatted = clause;
        if (!StringUtils.isBlank(alias)) {
            formatted = clause.replace("this", alias);
        }
        formatted = formatted.replace(".id", ".".concat(NameResolver.ID_FIELD_SUFFIX));
        StringTokenizer tokens = new StringTokenizer(formatted, " ");
        StringBuilder formattedBuilder = new StringBuilder();
        while (tokens.hasMoreElements()) {
            String token = tokens.nextToken();
            if (!Predicate.isSymbol(token) && !ReservedWords.has(token)) {
                if (!token.contains(".") && !token.startsWith("(") && !token.startsWith(Predicate.PARAM_PLACE_HOLDER) && !StringUtils.isBlank(alias)) {
                    if (token.equals("id")) {
                        token = NameResolver.ID_FIELD_SUFFIX;
                    }
                    if (token.contains("(") && token.contains("?")) {
                        formattedBuilder.append(token);
                    } else {
                        formattedBuilder.append(alias.concat(".").concat(token));
                    }
                } else {
                    formattedBuilder.append(token); 
                }
            } else {
                formattedBuilder.append(token); 
            }
            if (tokens.hasMoreElements()) {
                formattedBuilder.append(" ");
            }
        }
        return formattedBuilder.toString();
    }
private static String formatClause ( String clause , String alias ) { String formatted = clause ; if ( ! StringUtils . isBlank ( alias ) ) { formatted = clause . replace ( "this" , alias ) ; } formatted = formatted . replace ( ".id" , "." . concat ( NameResolver . ID_FIELD_SUFFIX ) ) ; StringTokenizer tokens = new StringTokenizer ( formatted , " " ) ; StringBuilder formattedBuilder = new StringBuilder ( ) ; while ( tokens . hasMoreElements ( ) ) { String token = tokens . nextToken ( ) ; if ( ! Predicate . isSymbol ( token ) && ! ReservedWords . has ( token ) ) { if ( ! token . contains ( "." ) && ! token . startsWith ( "(" ) && ! token . startsWith ( Predicate . PARAM_PLACE_HOLDER ) && ! StringUtils . isBlank ( alias ) ) { if ( token . equals ( "id" ) ) { token = NameResolver . ID_FIELD_SUFFIX ; } if ( token . contains ( "(" ) && token . contains ( "?" ) ) { formattedBuilder . append ( token ) ; } else { formattedBuilder . append ( alias . concat ( "." ) . concat ( token ) ) ; } } else { formattedBuilder . append ( token ) ; } } else { formattedBuilder . append ( token ) ; } if ( tokens . hasMoreElements ( ) ) { formattedBuilder . append ( " " ) ; } } return formattedBuilder . toString ( ) ; }
Formats WHERE clause without WHERE text appended to follow rules of database.
Formats WHERE clause without WHERE text appended to follow rules of database .
// format "this" prefixes to use correct alias alias // format .id fields to match correct primary key by adding "_" underscore in front. // check that token is not a reserved word nor symbol // if token really is column name in database and alias is provided // otherwise add token. // just add token as it does not contain relative information // lastly add " " space to text.