use of io.shardingjdbc.core.parsing.parser.expression.SQLNumberExpression in project sharding-jdbc by shardingjdbc.
the class OrderByClauseParser method parseSelectOrderByItem.
private OrderItem parseSelectOrderByItem(final SelectStatement selectStatement) {
SQLExpression sqlExpression = basicExpressionParser.parse(selectStatement);
OrderDirection orderDirection = OrderDirection.ASC;
if (lexerEngine.skipIfEqual(DefaultKeyword.ASC)) {
orderDirection = OrderDirection.ASC;
} else if (lexerEngine.skipIfEqual(DefaultKeyword.DESC)) {
orderDirection = OrderDirection.DESC;
}
if (sqlExpression instanceof SQLNumberExpression) {
return new OrderItem(((SQLNumberExpression) sqlExpression).getNumber().intValue(), orderDirection, getNullOrderDirection());
}
if (sqlExpression instanceof SQLIdentifierExpression) {
return new OrderItem(SQLUtil.getExactlyValue(((SQLIdentifierExpression) sqlExpression).getName()), orderDirection, getNullOrderDirection(), selectStatement.getAlias(SQLUtil.getExactlyValue(((SQLIdentifierExpression) sqlExpression).getName())));
}
if (sqlExpression instanceof SQLPropertyExpression) {
SQLPropertyExpression sqlPropertyExpression = (SQLPropertyExpression) sqlExpression;
return new OrderItem(SQLUtil.getExactlyValue(sqlPropertyExpression.getOwner().getName()), SQLUtil.getExactlyValue(sqlPropertyExpression.getName()), orderDirection, getNullOrderDirection(), selectStatement.getAlias(SQLUtil.getExactlyValue(sqlPropertyExpression.getOwner().getName()) + "." + SQLUtil.getExactlyValue(sqlPropertyExpression.getName())));
}
if (sqlExpression instanceof SQLIgnoreExpression) {
SQLIgnoreExpression sqlIgnoreExpression = (SQLIgnoreExpression) sqlExpression;
return new OrderItem(sqlIgnoreExpression.getExpression(), orderDirection, getNullOrderDirection(), selectStatement.getAlias(sqlIgnoreExpression.getExpression()));
}
throw new SQLParsingException(lexerEngine);
}
use of io.shardingjdbc.core.parsing.parser.expression.SQLNumberExpression in project sharding-jdbc by shardingjdbc.
the class SQLServerTopClauseParser method parse.
/**
* Parse top.
*
* @param selectStatement select statement
*/
public void parse(final SelectStatement selectStatement) {
if (!lexerEngine.skipIfEqual(SQLServerKeyword.TOP)) {
return;
}
int beginPosition = lexerEngine.getCurrentToken().getEndPosition();
if (!lexerEngine.skipIfEqual(Symbol.LEFT_PAREN)) {
beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
}
SQLExpression sqlExpression = basicExpressionParser.parse(selectStatement);
lexerEngine.skipIfEqual(Symbol.RIGHT_PAREN);
LimitValue rowCountValue;
if (sqlExpression instanceof SQLNumberExpression) {
int rowCount = ((SQLNumberExpression) sqlExpression).getNumber().intValue();
rowCountValue = new LimitValue(rowCount, -1, false);
selectStatement.getSqlTokens().add(new RowCountToken(beginPosition, rowCount));
} else if (sqlExpression instanceof SQLPlaceholderExpression) {
rowCountValue = new LimitValue(-1, ((SQLPlaceholderExpression) sqlExpression).getIndex(), false);
} else {
throw new SQLParsingException(lexerEngine);
}
lexerEngine.unsupportedIfEqual(SQLServerKeyword.PERCENT);
lexerEngine.skipIfEqual(DefaultKeyword.WITH, SQLServerKeyword.TIES);
if (null == selectStatement.getLimit()) {
Limit limit = new Limit(DatabaseType.SQLServer);
limit.setRowCount(rowCountValue);
selectStatement.setLimit(limit);
} else {
selectStatement.getLimit().setRowCount(rowCountValue);
}
}
Aggregations