use of net.sf.jsqlparser.expression.Expression in project Mybatis-PageHelper by pagehelper.
the class FunctionCountTest method test.
@Test
public void test() {
Select select = select("select max(name),code,min(aa),nvl(ab,0),heh from user where a > 100");
List<SelectItem> selectItems = ((PlainSelect) select.getSelectBody()).getSelectItems();
for (SelectItem item : selectItems) {
if (item instanceof SelectExpressionItem) {
Expression exp = ((SelectExpressionItem) item).getExpression();
if (exp instanceof Function) {
System.out.println("Function:" + item.toString());
} else {
System.out.println("Not a function:" + exp.toString());
}
} else {
System.out.println("Not a function:" + item.toString());
}
}
}
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;
}
use of net.sf.jsqlparser.expression.Expression in project spanner-jdbc by olavloite.
the class CloudSpannerPreparedStatement method createUpdateMutation.
private Mutation createUpdateMutation(Update update, boolean generateParameterMetaData) throws SQLException {
if (update.getTables().isEmpty())
throw new CloudSpannerSQLException("No table found in update statement", Code.INVALID_ARGUMENT);
if (update.getTables().size() > 1)
throw new CloudSpannerSQLException("Update statements for multiple tables at once are not supported", Code.INVALID_ARGUMENT);
String table = unquoteIdentifier(update.getTables().get(0).getFullyQualifiedName());
getParameterStore().setTable(table);
List<Expression> expressions = update.getExpressions();
WriteBuilder builder = Mutation.newUpdateBuilder(table);
int index = 0;
for (Column col : update.getColumns()) {
String columnName = unquoteIdentifier(col.getFullyQualifiedName());
expressions.get(index).accept(new ValueBinderExpressionVisitorAdapter<>(getParameterStore(), builder.set(columnName), columnName));
index++;
}
visitUpdateWhereClause(update.getWhere(), builder, generateParameterMetaData);
return builder.build();
}
use of net.sf.jsqlparser.expression.Expression in project spanner-jdbc by olavloite.
the class CloudSpannerPreparedStatement method createInsertMutation.
private Mutation createInsertMutation(Insert insert, boolean generateParameterMetaData) throws SQLException {
ItemsList items = insert.getItemsList();
if (generateParameterMetaData && items == null && insert.getSelect() != null) {
// Just initialize the parameter meta data of the select statement
createSelectBuilder(insert.getSelect(), insert.getSelect().toString());
return null;
}
if (!(items instanceof ExpressionList)) {
throw new CloudSpannerSQLException("Insert statement must specify a list of values", Code.INVALID_ARGUMENT);
}
if (insert.getColumns() == null || insert.getColumns().isEmpty()) {
throw new CloudSpannerSQLException("Insert statement must specify a list of column names", Code.INVALID_ARGUMENT);
}
List<Expression> expressions = ((ExpressionList) items).getExpressions();
String table = unquoteIdentifier(insert.getTable().getFullyQualifiedName());
getParameterStore().setTable(table);
WriteBuilder builder;
if (insert.isUseDuplicate()) {
/**
* Do an insert-or-update. BUT: Cloud Spanner does not support
* supplying different values for the insert and update statements,
* meaning that only the values specified in the INSERT part of the
* statement will be considered. Anything specified in the 'ON
* DUPLICATE KEY UPDATE ...' statement will be ignored.
*/
if (this.forceUpdate)
builder = Mutation.newUpdateBuilder(table);
else
builder = Mutation.newInsertOrUpdateBuilder(table);
} else {
/**
* Just do an insert and throw an error if a row with the specified
* key alread exists.
*/
builder = Mutation.newInsertBuilder(table);
}
int index = 0;
for (Column col : insert.getColumns()) {
String columnName = unquoteIdentifier(col.getFullyQualifiedName());
expressions.get(index).accept(new ValueBinderExpressionVisitorAdapter<>(getParameterStore(), builder.set(columnName), columnName));
index++;
}
return builder.build();
}
use of net.sf.jsqlparser.expression.Expression in project spanner-jdbc by olavloite.
the class CloudSpannerPreparedStatement method createDeleteMutation.
private Mutation createDeleteMutation(Delete delete, boolean generateParameterMetaData) throws SQLException {
String table = unquoteIdentifier(delete.getTable().getFullyQualifiedName());
getParameterStore().setTable(table);
Expression where = delete.getWhere();
if (where == null) {
// Delete all
return Mutation.delete(table, KeySet.all());
} else {
// Delete one
DeleteKeyBuilder keyBuilder = new DeleteKeyBuilder(getConnection().getTable(table), generateParameterMetaData);
visitDeleteWhereClause(where, keyBuilder, generateParameterMetaData);
return Mutation.delete(table, keyBuilder.getKeyBuilder().build());
}
}
Aggregations