mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve parser ddl support
This commit is contained in:
@@ -53,25 +53,27 @@ import com.alibaba.druid.support.logging.LogFactory;
|
||||
*/
|
||||
public class DruidPooledConnection extends PoolableWrapper implements javax.sql.PooledConnection, Connection {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(DruidPooledConnection.class);
|
||||
private final static Log LOG = LogFactory.getLog(DruidPooledConnection.class);
|
||||
|
||||
public static final int MAX_RECORD_SQL_COUNT = 10;
|
||||
|
||||
protected Connection conn;
|
||||
protected volatile DruidConnectionHolder holder;
|
||||
protected TransactionInfo transactionInfo;
|
||||
private final boolean dupCloseLogEnable;
|
||||
private volatile boolean traceEnable = false;
|
||||
private boolean disable = false;
|
||||
private boolean closed = false;
|
||||
private volatile boolean traceEnable = false;
|
||||
private boolean disable = false;
|
||||
private boolean closed = false;
|
||||
private final Thread ownerThread;
|
||||
|
||||
private long connectedTimeNano;
|
||||
private volatile boolean running = false;
|
||||
private volatile boolean running = false;
|
||||
|
||||
private volatile boolean abandoned = false;
|
||||
private volatile boolean abandoned = false;
|
||||
|
||||
private StackTraceElement[] connectStackTrace;
|
||||
|
||||
private Throwable disableError = null;
|
||||
private Throwable disableError = null;
|
||||
|
||||
public DruidPooledConnection(DruidConnectionHolder holder){
|
||||
super(holder.getConnection());
|
||||
@@ -686,7 +688,10 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
|
||||
}
|
||||
|
||||
if (transactionInfo != null) {
|
||||
transactionInfo.getSqlList().add(sql);
|
||||
List<String> sqlList = transactionInfo.getSqlList();
|
||||
if (sqlList.size() < MAX_RECORD_SQL_COUNT) {
|
||||
sqlList.add(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
public class SQLCreateViewStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean orReplace = false;
|
||||
protected SQLName name;
|
||||
protected SQLSelect subQuery;
|
||||
|
||||
@@ -37,6 +38,14 @@ public class SQLCreateViewStatement extends SQLStatementImpl implements SQLDDLSt
|
||||
|
||||
}
|
||||
|
||||
public boolean isOrReplace() {
|
||||
return orReplace;
|
||||
}
|
||||
|
||||
public void setOrReplace(boolean orReplace) {
|
||||
this.orReplace = orReplace;
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -284,11 +284,24 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
public SQLStatement parseCreate() {
|
||||
char markChar = lexer.current();
|
||||
int markBp = lexer.bp();
|
||||
|
||||
accept(Token.CREATE);
|
||||
|
||||
boolean replace = false;
|
||||
if (lexer.token() == Token.OR) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("REPLACE");
|
||||
replace = true;
|
||||
}
|
||||
|
||||
List<SQLCommentHint> hints = this.exprParser.parseHints();
|
||||
|
||||
if (lexer.token() == Token.TABLE || identifierEquals(TEMPORARY)) {
|
||||
if (replace) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
MySqlCreateTableParser parser = new MySqlCreateTableParser(this.exprParser);
|
||||
MySqlCreateTableStatement stmt = parser.parseCrateTable(false);
|
||||
stmt.setHints(hints);
|
||||
@@ -296,19 +309,32 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.DATABASE) {
|
||||
if (replace) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
return parseCreateDatabase();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.UNIQUE || lexer.token() == Token.INDEX || identifierEquals(FULLTEXT)
|
||||
|| identifierEquals(SPATIAL)) {
|
||||
if (replace) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
return parseCreateIndex();
|
||||
}
|
||||
|
||||
if (identifierEquals(USER)) {
|
||||
if (replace) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
return parseCreateUser();
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == Token.VIEW) {
|
||||
if (replace) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
|
||||
return parseCreateView();
|
||||
}
|
||||
|
||||
@@ -1494,7 +1520,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == Token.VALUES || identifierEquals("VALUE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
parseValueClause(stmt.getValuesList(), 0);
|
||||
} else if (lexer.token() == Token.SELECT) {
|
||||
SQLQueryExpr queryExpr = (SQLQueryExpr) this.exprParser.expr();
|
||||
@@ -1871,7 +1897,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause(valueExprList);
|
||||
valueClauseList.add(values);
|
||||
} else {
|
||||
@@ -2222,11 +2248,11 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
if (identifierEquals("COLUMN")) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
|
||||
SQLAlterTableAlterColumn alterColumn = new SQLAlterTableAlterColumn();
|
||||
SQLColumnDefinition columnDef = this.exprParser.parseColumn();
|
||||
alterColumn.setColumn(columnDef);
|
||||
|
||||
|
||||
stmt.getItems().add(alterColumn);
|
||||
} else if (identifierEquals("CHANGE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -1078,6 +1078,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlDropViewStatement x) {
|
||||
setMode(x, Mode.Drop);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,11 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.PERCENT) {
|
||||
lexer.nextToken();
|
||||
top.setPercent(true);
|
||||
}
|
||||
|
||||
return top;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ public class SQLServerLexer extends Lexer {
|
||||
map.put("TOP", Token.TOP);
|
||||
map.put("USE", Token.USE);
|
||||
map.put("WITH", Token.WITH);
|
||||
map.put("PERCENT", Token.PERCENT);
|
||||
|
||||
DEFAULT_SQL_SERVER_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
+2
-4
@@ -76,9 +76,7 @@ public class SQLServerSelectParser extends SQLSelectParser {
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.TOP) {
|
||||
SQLServerTop top = new SQLServerTop();
|
||||
lexer.nextToken();
|
||||
top.setExpr(createExprParser().primary());
|
||||
SQLServerTop top = this.createExprParser().parseTop();
|
||||
queryBlock.setTop(top);
|
||||
}
|
||||
|
||||
@@ -101,7 +99,7 @@ public class SQLServerSelectParser extends SQLSelectParser {
|
||||
return queryRest(queryBlock);
|
||||
}
|
||||
|
||||
protected SQLExprParser createExprParser() {
|
||||
protected SQLServerExprParser createExprParser() {
|
||||
return new SQLServerExprParser(lexer);
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -96,6 +96,10 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
print(")");
|
||||
}
|
||||
|
||||
if (x.isPercent()) {
|
||||
print(" PERCENT");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -644,6 +644,12 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (lexer.token() == Token.CREATE) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.OR) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("REPLACE");
|
||||
createView.setOrReplace(true);
|
||||
}
|
||||
|
||||
this.accept(Token.VIEW);
|
||||
|
||||
|
||||
@@ -808,6 +808,9 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
case Merge:
|
||||
stat.incrementMergeCount();
|
||||
break;
|
||||
case Drop:
|
||||
stat.incrementDropCount();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -445,7 +445,14 @@ public class TableStat {
|
||||
}
|
||||
|
||||
public static enum Mode {
|
||||
Insert(1), Update(2), Delete(4), Select(8), Merge(16), Truncate(32), Alter(64);
|
||||
Insert(1), //
|
||||
Update(2), //
|
||||
Delete(4), //
|
||||
Select(8), //
|
||||
Merge(16), //
|
||||
Truncate(32), //
|
||||
Alter(64), //
|
||||
Drop(128);
|
||||
|
||||
public final int mark;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user