mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
mysql select * frm aaa limit 20xxx ,limit后的字符串无法转换为数字的处理
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.parser;
|
||||
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
|
||||
import static com.alibaba.druid.sql.parser.CharTypes.isFirstIdentifierChar;
|
||||
import static com.alibaba.druid.sql.parser.CharTypes.isIdentifierChar;
|
||||
import static com.alibaba.druid.sql.parser.CharTypes.isWhitespace;
|
||||
@@ -1147,7 +1149,11 @@ public class Lexer {
|
||||
}
|
||||
|
||||
public BigDecimal decimalValue() {
|
||||
return new BigDecimal(subString(mark, bufPos).toCharArray());
|
||||
String value = subString(mark, bufPos);
|
||||
if (!StringUtils.isNumeric(value)){
|
||||
throw new ParserException(value+" is not a number!");
|
||||
}
|
||||
return new BigDecimal(value.toCharArray());
|
||||
}
|
||||
|
||||
public static interface CommentHandler {
|
||||
|
||||
@@ -95,7 +95,7 @@ public class StringUtils {
|
||||
return a.equalsIgnoreCase(b);
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String value) {
|
||||
public static boolean isEmpty(CharSequence value) {
|
||||
if (value == null || value.length() == 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -119,4 +119,18 @@ public class StringUtils {
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
public static boolean isNumeric(final CharSequence cs) {
|
||||
if (isEmpty(cs)) {
|
||||
return false;
|
||||
}
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (!Character.isDigit(cs.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.alibaba.druid.mysql;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by tianzhen.wtz on 2016/6/7.
|
||||
* 类说明:
|
||||
*/
|
||||
public class MysqlLimitTest extends TestCase{
|
||||
|
||||
|
||||
public void testLimit(){
|
||||
String sql = "select * from aaa limit 20exx";
|
||||
SQLStatementParser statementParser = SQLParserUtils.createSQLStatementParser(sql, "mysql");
|
||||
try {
|
||||
List<SQLStatement> sqlStatements = statementParser.parseStatementList();
|
||||
} catch (Exception e) {
|
||||
assertTrue(e.getMessage().contains("is not a number!"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user