use of net.sf.jsqlparser.expression.Expression in project spanner-jdbc by olavloite.
the class AbstractSpannerExpressionVisitorAdapter method visit.
@Override
public void visit(SignedExpression value) {
Expression underlyingValue = value.getExpression();
if (underlyingValue instanceof DoubleValue) {
DoubleValue doubleValue = (DoubleValue) underlyingValue;
doubleValue.setValue(value.getSign() == '-' ? -doubleValue.getValue() : doubleValue.getValue());
visit(doubleValue);
} else if (underlyingValue instanceof LongValue) {
LongValue longValue = (LongValue) underlyingValue;
longValue.setValue(value.getSign() == '-' ? -longValue.getValue() : longValue.getValue());
visit(longValue);
} else {
super.visit(value);
}
}
use of net.sf.jsqlparser.expression.Expression in project dbeaver by dbeaver.
the class SQLSemanticProcessor method patchSelectQuery.
private static boolean patchSelectQuery(DBRProgressMonitor monitor, DBPDataSource dataSource, PlainSelect select, DBDDataFilter filter) throws JSQLParserException, DBException {
// WHERE
if (filter.hasConditions()) {
for (DBDAttributeConstraint co : filter.getConstraints()) {
if (co.hasCondition()) {
Table table = getConstraintTable(select, co);
if (!isValidTableColumn(monitor, dataSource, table, co)) {
table = null;
}
if (table != null) {
if (table.getAlias() != null) {
co.setEntityAlias(table.getAlias().getName());
} else {
co.setEntityAlias(table.getName());
}
} else {
co.setEntityAlias(null);
}
}
}
StringBuilder whereString = new StringBuilder();
SQLUtils.appendConditionString(filter, dataSource, null, whereString, true);
String condString = whereString.toString();
addWhereToSelect(select, condString);
}
// ORDER
if (filter.hasOrdering()) {
List<OrderByElement> orderByElements = select.getOrderByElements();
if (orderByElements == null) {
orderByElements = new ArrayList<>();
select.setOrderByElements(orderByElements);
}
for (DBDAttributeConstraint co : filter.getOrderConstraints()) {
String columnName = co.getAttributeName();
boolean forceNumeric = filter.hasNameDuplicates(columnName) || !SQLUtils.PATTERN_SIMPLE_NAME.matcher(columnName).matches();
Expression orderExpr = getOrderConstraintExpression(monitor, dataSource, select, co, forceNumeric);
OrderByElement element = new OrderByElement();
element.setExpression(orderExpr);
if (co.isOrderDescending()) {
element.setAsc(false);
element.setAscDescPresent(true);
}
orderByElements.add(element);
}
}
return true;
}
use of net.sf.jsqlparser.expression.Expression in project dbeaver by dbeaver.
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);
}
use of net.sf.jsqlparser.expression.Expression in project dbeaver by dbeaver.
the class SQLSemanticProcessor method getOrderConstraintExpression.
private static Expression getOrderConstraintExpression(DBRProgressMonitor monitor, DBPDataSource dataSource, PlainSelect select, DBDAttributeConstraint co, boolean forceNumeric) throws JSQLParserException, DBException {
Expression orderExpr;
String attrName = DBUtils.getQuotedIdentifier(dataSource, co.getAttributeName());
if (forceNumeric || attrName.isEmpty()) {
orderExpr = new LongValue(co.getOrderPosition());
} else if (CommonUtils.isJavaIdentifier(attrName)) {
// Use column table only if there are multiple source tables (joins)
Table orderTable = CommonUtils.isEmpty(select.getJoins()) ? null : getConstraintTable(select, co);
if (!isValidTableColumn(monitor, dataSource, orderTable, co)) {
orderTable = null;
}
orderExpr = new Column(orderTable, attrName);
} else {
// TODO: set tableAlias for all column references in expression
orderExpr = CCJSqlParserUtil.parseExpression(attrName);
// orderExpr = new CustomExpression(attrName);
// orderExpr = new LongValue(co.getAttribute().getOrdinalPosition() + 1);
}
return orderExpr;
}
use of net.sf.jsqlparser.expression.Expression in project dbeaver by serge-rider.
the class SQLSemanticProcessor method getConstraintExpression.
private static Expression getConstraintExpression(PlainSelect select, DBDAttributeConstraint co) throws JSQLParserException {
Expression orderExpr;
String attrName = co.getAttribute().getName();
if (attrName.isEmpty()) {
orderExpr = new LongValue(co.getAttribute().getOrdinalPosition() + 1);
} else if (CommonUtils.isJavaIdentifier(attrName)) {
// Use column table only if there are multiple source tables (joins)
Table orderTable = CommonUtils.isEmpty(select.getJoins()) ? null : getConstraintTable(select, co);
orderExpr = new Column(orderTable, attrName);
} else {
// TODO: set tableAlias for all column references in expression
orderExpr = CCJSqlParserUtil.parseExpression(attrName);
//orderExpr = new CustomExpression(attrName);
//orderExpr = new LongValue(co.getAttribute().getOrdinalPosition() + 1);
}
return orderExpr;
}
Aggregations