use of net.sf.jsqlparser.JSQLParserException in project dbeaver by serge-rider.
the class SQLQueryTransformerCount method transformQuery.
@Override
public SQLQuery transformQuery(SQLDataSource dataSource, SQLQuery query) throws DBException {
try {
Statement statement = CCJSqlParserUtil.parse(query.getQuery());
if (statement instanceof Select && ((Select) statement).getSelectBody() instanceof PlainSelect) {
PlainSelect select = (PlainSelect) ((Select) statement).getSelectBody();
List<SelectItem> selectItems = new ArrayList<>();
Function countFunc = new Function();
countFunc.setName("count");
countFunc.setParameters(new ExpressionList(Collections.<Expression>singletonList(new Column("*"))));
SelectItem countItem = new SelectExpressionItem(countFunc);
selectItems.add(countItem);
select.setSelectItems(selectItems);
return new SQLQuery(dataSource, select.toString(), query, false);
} else {
throw new DBException("Query [" + query.getQuery() + "] can't be modified");
}
} catch (JSQLParserException e) {
throw new DBException("Can't transform query to SELECT count(*)", e);
}
}
use of net.sf.jsqlparser.JSQLParserException in project dbeaver by serge-rider.
the class SQLSemanticProcessor method addWhereToSelect.
public static void addWhereToSelect(PlainSelect select, String condString) throws JSQLParserException {
Expression filterWhere;
try {
filterWhere = CCJSqlParserUtil.parseCondExpression(condString);
} catch (JSQLParserException e) {
throw new JSQLParserException("Bad query condition: [" + condString + "]", e);
}
addWhereToSelect(select, filterWhere);
}
Aggregations