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:
@@ -182,6 +182,19 @@ public class Schema {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLAlterTableStatement x) {
|
||||
SQLName table = x.getName();
|
||||
SchemaObject object = repository.findTable(table);
|
||||
if (object != null) {
|
||||
SQLCreateTableStatement stmt = (SQLCreateTableStatement) object.getStatement();
|
||||
if (stmt != null) {
|
||||
stmt.apply(x);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class MySqlSchemaVisitor extends MySqlASTVisitorAdapter {
|
||||
@@ -248,6 +261,19 @@ public class Schema {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLAlterTableStatement x) {
|
||||
SQLName table = x.getName();
|
||||
SchemaObject object = repository.findTable(table);
|
||||
if (object != null) {
|
||||
SQLCreateTableStatement stmt = (SQLCreateTableStatement) object.getStatement();
|
||||
if (stmt != null) {
|
||||
stmt.apply(x);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public SchemaObject findTable(SQLTableSource tableSource, String alias) {
|
||||
|
||||
@@ -213,15 +213,17 @@ public class SchemaRepository {
|
||||
if (stmt instanceof MySqlShowColumnsStatement) {
|
||||
MySqlShowColumnsStatement showColumns = ((MySqlShowColumnsStatement) stmt);
|
||||
SQLName table = showColumns.getTable();
|
||||
SchemaObject schemaObject = findSchemaObject(table);
|
||||
SchemaObject schemaObject = findTable(table);
|
||||
MySqlCreateTableStatement createTableStmt = (MySqlCreateTableStatement) schemaObject.getStatement();
|
||||
createTableStmt.showCoumns(buf);
|
||||
} else if (stmt instanceof MySqlShowCreateTableStatement) {
|
||||
MySqlShowCreateTableStatement showCreateTableStmt = (MySqlShowCreateTableStatement) stmt;
|
||||
SQLName table = showCreateTableStmt.getName();
|
||||
SchemaObject schemaObject = findSchemaObject(table);
|
||||
SchemaObject schemaObject = findTable(table);
|
||||
MySqlCreateTableStatement createTableStmt = (MySqlCreateTableStatement) schemaObject.getStatement();
|
||||
createTableStmt.output(buf);
|
||||
} else {
|
||||
this.getDefaultSchema().accept(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +233,7 @@ public class SchemaRepository {
|
||||
}
|
||||
}
|
||||
|
||||
private SchemaObject findSchemaObject(SQLName name) {
|
||||
public SchemaObject findTable(SQLName name) {
|
||||
if (name instanceof SQLIdentifierExpr) {
|
||||
return findTable(((SQLIdentifierExpr) name).getName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user