/* Copyright 2020 Jacky Zong */
public class DatabaseQuery {
private String selectStatement;
public DatabaseQuery(String selectStatement) {
String result = selectStatement;
result = StringHelper.replace(result, "select", "SELECT");
result = StringHelper.replace(result, "from", "FROM");
result = StringHelper.replace(result, "where", "WHERE");
this.selectStatement = result;
}
public String getWhereClause() {
return StringHelper.splitAt1stOccurenceFromLeft(selectStatement, "WHERE");
}
public String getSelectStatement() {
return selectStatement;
}
public String getWhereClauseColumnValue(String columnName, String logicalDelimiter, String operator) {
String where = getWhereClause();
String[] clauses = StringHelper.split(where, logicalDelimiter.toLowerCase());
for (int i = 0; i < clauses.length; i++) {
String clause = clauses[i].trim();
if (clause.startsWith(columnName)) {
String value = StringHelper.split(clause, operator)[1].trim();
return StringHelper.replace(value, "'", "");
}
}
return null;
}
}