From f52301b30f32366814e7d5fd2185de526a156e7c Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sat, 15 Jul 2017 13:23:52 +0800 Subject: [PATCH] fixed #292 --- .../parsing/parser/dialect/sqlserver/SQLServerParser.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/sqlserver/SQLServerParser.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/sqlserver/SQLServerParser.java index 2439baf6f32e4..a9513a0abf4b7 100755 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/sqlserver/SQLServerParser.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/sqlserver/SQLServerParser.java @@ -66,15 +66,17 @@ protected boolean isRowNumberCondition(final SelectStatement selectStatement, fi */ public void parseTop(final SelectStatement selectStatement) { if (skipIfEqual(SQLServerKeyword.TOP)) { - skipIfEqual(Symbol.LEFT_PAREN); + int beginPosition = getLexer().getCurrentToken().getEndPosition(); + if (!skipIfEqual(Symbol.LEFT_PAREN)) { + beginPosition = getLexer().getCurrentToken().getEndPosition() - getLexer().getCurrentToken().getLiterals().length(); + } SQLExpression sqlExpression = parseExpression(); skipIfEqual(Symbol.RIGHT_PAREN); LimitValue rowCountValue; if (sqlExpression instanceof SQLNumberExpression) { int rowCount = ((SQLNumberExpression) sqlExpression).getNumber().intValue(); rowCountValue = new LimitValue(rowCount, -1); - selectStatement.getSqlTokens().add( - new RowCountToken(getLexer().getCurrentToken().getEndPosition() - String.valueOf(rowCount).length() - getLexer().getCurrentToken().getLiterals().length(), rowCount)); + selectStatement.getSqlTokens().add(new RowCountToken(beginPosition, rowCount)); } else if (sqlExpression instanceof SQLPlaceholderExpression) { rowCountValue = new LimitValue(-1, ((SQLPlaceholderExpression) sqlExpression).getIndex()); } else {