io.ebeaninternal.server.util.DSelectColumnsParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ebean Show documentation
Show all versions of ebean Show documentation
composite of common runtime dependencies for all platforms
package io.ebeaninternal.server.util;
import java.util.ArrayList;
import java.util.List;
/**
* Splits a select clause into 'logical columns' taking into account functions and quotes.
*/
public final class DSelectColumnsParser {
private final int end;
private final String selectClause;
private int pos;
public static List parse(String sqlSelect) {
return new DSelectColumnsParser(sqlSelect).parse();
}
private DSelectColumnsParser(String selectClause) {
this.selectClause = selectClause;
this.end = selectClause.length();
}
private List parse() {
ArrayList columns = new ArrayList<>();
while (pos <= end) {
columns.add(nextColumnInfo());
}
return columns;
}
private String nextColumnInfo() {
int start = pos;
nextComma();
return selectClause.substring(start, pos++).trim();
}
private void nextComma() {
boolean inQuote = false;
int inBrackets = 0;
while (pos < end) {
char c = selectClause.charAt(pos);
if (c == '\'') inQuote = !inQuote;
else if (c == '(') inBrackets++;
else if (c == ')') inBrackets--;
else if (!inQuote && inBrackets == 0 && c == ',') {
return;
}
pos++;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy