mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
fix MySqlSchemaStatVisitor think index as column
This commit is contained in:
@@ -69,6 +69,8 @@ public class Lexer {
|
||||
private int varIndex = -1;
|
||||
|
||||
protected CommentHandler commentHandler;
|
||||
|
||||
protected boolean hasComment = false;
|
||||
|
||||
public Lexer(String input){
|
||||
this(input, true);
|
||||
@@ -747,6 +749,7 @@ public class Lexer {
|
||||
|
||||
stringVal = subString(mark, bufPos);
|
||||
token = Token.MULTI_LINE_COMMENT;
|
||||
hasComment = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -777,6 +780,7 @@ public class Lexer {
|
||||
|
||||
stringVal = subString(mark + 1, bufPos);
|
||||
token = Token.LINE_COMMENT;
|
||||
hasComment = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1045,4 +1049,8 @@ public class Lexer {
|
||||
|
||||
boolean handle(Token lastToken, String comment);
|
||||
}
|
||||
|
||||
public boolean isHasComment() {
|
||||
return hasComment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.alibaba.druid.sql.ast.expr.SQLAnyExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBetweenExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBooleanExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCaseExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCastExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
@@ -554,6 +555,14 @@ public class SQLExprParser extends SQLParser {
|
||||
break;
|
||||
case EOF:
|
||||
throw new EOFParserException();
|
||||
case TRUE:
|
||||
lexer.nextToken();
|
||||
sqlExpr = new SQLBooleanExpr(true);
|
||||
break;
|
||||
case FALSE:
|
||||
lexer.nextToken();
|
||||
sqlExpr = new SQLBooleanExpr(false);
|
||||
break;
|
||||
default:
|
||||
throw new ParserException("ERROR. token : " + tok + ", pos : " + lexer.pos());
|
||||
}
|
||||
@@ -714,6 +723,7 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public final void exprList(Collection<SQLExpr> exprCol) {
|
||||
exprList(exprCol, null);
|
||||
}
|
||||
@@ -878,10 +888,10 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
if (lexer.token() == (Token.LPAREN)) {
|
||||
lexer.nextToken();
|
||||
exprList(over.getPartitionBy());
|
||||
exprList(over.getPartitionBy(), over);
|
||||
accept(Token.RPAREN);
|
||||
} else {
|
||||
exprList(over.getPartitionBy());
|
||||
exprList(over.getPartitionBy(), over);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1359,29 +1369,19 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
charType.setCharSetName(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
if (lexer.stringVal().equalsIgnoreCase("COLLATE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() != Token.IDENTIFIER) {
|
||||
throw new ParserException();
|
||||
}
|
||||
charType.setCollate(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
}
|
||||
}else if(identifierEquals("COLLATE")){
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() != Token.IDENTIFIER) {
|
||||
throw new ParserException();
|
||||
}
|
||||
|
||||
charType.setCollate(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
if (lexer.stringVal().equalsIgnoreCase("COLLATE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() != Token.IDENTIFIER) {
|
||||
throw new ParserException();
|
||||
}
|
||||
charType.setCollate(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
}
|
||||
return charType;
|
||||
}
|
||||
|
||||
@@ -1539,7 +1539,7 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
SQLPrimaryKeyImpl pk = new SQLPrimaryKeyImpl();
|
||||
accept(Token.LPAREN);
|
||||
exprList(pk.getColumns());
|
||||
exprList(pk.getColumns(), pk);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
return pk;
|
||||
@@ -1550,7 +1550,7 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
SQLUnique unique = new SQLUnique();
|
||||
accept(Token.LPAREN);
|
||||
exprList(unique.getColumns());
|
||||
exprList(unique.getColumns(), unique);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
return unique;
|
||||
|
||||
@@ -166,7 +166,10 @@ public class SQLParser {
|
||||
} else if (lexer.token() == Token.CASE) {
|
||||
alias = lexer.token.name();
|
||||
lexer.nextToken();
|
||||
}
|
||||
} else if (lexer.token() == Token.USER) {
|
||||
alias = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
switch (lexer.token()) {
|
||||
case KEY:
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnionOperator;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnionQueryTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause;
|
||||
|
||||
public class SQLSelectParser extends SQLParser {
|
||||
@@ -316,8 +317,12 @@ public class SQLSelectParser extends SQLParser {
|
||||
if (lexer.token() == Token.SELECT || lexer.token() == Token.WITH) {
|
||||
SQLSelect select = select();
|
||||
accept(Token.RPAREN);
|
||||
queryRest(select.getQuery());
|
||||
tableSource = new SQLSubqueryTableSource(select);
|
||||
SQLSelectQuery query = queryRest(select.getQuery());
|
||||
if (query instanceof SQLUnionQuery) {
|
||||
tableSource = new SQLUnionQueryTableSource((SQLUnionQuery) query);
|
||||
} else {
|
||||
tableSource = new SQLSubqueryTableSource(select);
|
||||
}
|
||||
} else if (lexer.token() == Token.LPAREN) {
|
||||
tableSource = parseTableSource();
|
||||
accept(Token.RPAREN);
|
||||
@@ -418,7 +423,7 @@ public class SQLSelectParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
this.exprParser.exprList(join.getUsing());
|
||||
this.exprParser.exprList(join.getUsing(), join);
|
||||
accept(Token.RPAREN);
|
||||
} else {
|
||||
join.getUsing().add(this.expr());
|
||||
|
||||
@@ -1062,7 +1062,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
if (lexer.token() == (Token.LPAREN)) {
|
||||
lexer.nextToken();
|
||||
this.exprParser.exprList(insertStatement.getColumns());
|
||||
this.exprParser.exprList(insertStatement.getColumns(), insertStatement);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
@@ -1070,7 +1070,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause();
|
||||
this.exprParser.exprList(values.getValues());
|
||||
this.exprParser.exprList(values.getValues(), values);
|
||||
insertStatement.setValues(values);
|
||||
accept(Token.RPAREN);
|
||||
} else if (acceptSubQuery && (lexer.token() == Token.SELECT || lexer.token() == Token.LPAREN)) {
|
||||
@@ -1135,7 +1135,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
exprParser.exprList(stmt.getParameters());
|
||||
exprParser.exprList(stmt.getParameters(), stmt);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
@@ -1392,7 +1392,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (lexer.token() == (Token.LPAREN)) {
|
||||
lexer.nextToken();
|
||||
SQLListExpr list = new SQLListExpr();
|
||||
this.exprParser.exprList(list.getItems());
|
||||
this.exprParser.exprList(list.getItems(), list);
|
||||
accept(Token.RPAREN);
|
||||
item.setColumn(list);
|
||||
} else {
|
||||
@@ -1466,7 +1466,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
this.exprParser.exprList(createView.getColumns());
|
||||
this.exprParser.exprList(createView.getColumns(), createView);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user