mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -27,11 +27,11 @@ import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class SQLCreateTableParser extends SQLDDLParser {
|
||||
|
||||
public SQLCreateTableParser(String sql){
|
||||
public SQLCreateTableParser(String sql) {
|
||||
super(sql);
|
||||
}
|
||||
|
||||
public SQLCreateTableParser(SQLExprParser exprParser){
|
||||
public SQLCreateTableParser(SQLExprParser exprParser) {
|
||||
super(exprParser);
|
||||
}
|
||||
|
||||
@@ -40,22 +40,26 @@ public class SQLCreateTableParser extends SQLDDLParser {
|
||||
if (lexer.isKeepComments() && lexer.hasComment()) {
|
||||
comments = lexer.readAndResetComments();
|
||||
}
|
||||
|
||||
|
||||
SQLCreateTableStatement stmt = parseCrateTable(true);
|
||||
if (comments != null) {
|
||||
stmt.addBeforeComment(comments);
|
||||
}
|
||||
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLCreateTableStatement parseCrateTable(boolean acceptCreate) {
|
||||
SQLCreateTableStatement createTable = newCreateStatement();
|
||||
|
||||
if (acceptCreate) {
|
||||
if (lexer.hasComment() && lexer.isKeepComments()) {
|
||||
createTable.addBeforeComment(lexer.readAndResetComments());
|
||||
}
|
||||
|
||||
accept(Token.CREATE);
|
||||
}
|
||||
|
||||
SQLCreateTableStatement createTable = newCreateStatement();
|
||||
|
||||
if (identifierEquals("GLOBAL")) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -82,21 +86,21 @@ public class SQLCreateTableParser extends SQLDDLParser {
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
Token token = lexer.token();
|
||||
if (token == Token.IDENTIFIER
|
||||
&& lexer.stringVal().equalsIgnoreCase("SUPPLEMENTAL")
|
||||
&& JdbcConstants.ORACLE.equals(dbType)) {
|
||||
this.parseCreateTableSupplementalLogingProps(createTable);
|
||||
} else if (token == Token.IDENTIFIER //
|
||||
|| token == Token.LITERAL_ALIAS) {
|
||||
|| token == Token.LITERAL_ALIAS) {
|
||||
SQLColumnDefinition column = this.exprParser.parseColumn();
|
||||
createTable.getTableElementList().add(column);
|
||||
} else if (token == Token.PRIMARY //
|
||||
|| token == Token.UNIQUE //
|
||||
|| token == Token.CHECK //
|
||||
|| token == Token.CONSTRAINT
|
||||
|| token == Token.FOREIGN) {
|
||||
|| token == Token.UNIQUE //
|
||||
|| token == Token.CHECK //
|
||||
|| token == Token.CONSTRAINT
|
||||
|| token == Token.FOREIGN) {
|
||||
SQLConstraint constraint = this.exprParser.parseConstaint();
|
||||
constraint.setParent(createTable);
|
||||
createTable.getTableElementList().add((SQLTableElement) constraint);
|
||||
@@ -149,5 +153,4 @@ public class SQLCreateTableParser extends SQLDDLParser {
|
||||
protected SQLCreateTableStatement newCreateStatement() {
|
||||
return new SQLCreateTableStatement(getDbType());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user