use of com.alibaba.druid.sql.ast.statement.SQLShowCreateTableStatement in project druid by alibaba.
the class SchemaRepository method console.
public String console(String input) {
try {
StringBuffer buf = new StringBuffer();
List<SQLStatement> stmtList = SQLUtils.parseStatements(input, dbType);
for (SQLStatement stmt : stmtList) {
if (stmt instanceof SQLShowColumnsStatement) {
SQLShowColumnsStatement showColumns = ((SQLShowColumnsStatement) stmt);
SQLName db = showColumns.getDatabase();
Schema schema;
if (db == null) {
schema = getDefaultSchema();
} else {
schema = findSchema(db.getSimpleName());
}
SQLName table = null;
SchemaObject schemaObject = null;
if (schema != null) {
table = showColumns.getTable();
schemaObject = schema.findTable(table.nameHashCode64());
}
if (schemaObject == null) {
buf.append("ERROR 1146 (42S02): Table '" + table + "' doesn't exist\n");
} else {
MySqlCreateTableStatement createTableStmt = (MySqlCreateTableStatement) schemaObject.getStatement();
createTableStmt.showCoumns(buf);
}
} else if (stmt instanceof SQLShowCreateTableStatement) {
SQLShowCreateTableStatement showCreateTableStmt = (SQLShowCreateTableStatement) stmt;
SQLName table = showCreateTableStmt.getName();
SchemaObject schemaObject = findTable(table);
if (schemaObject == null) {
buf.append("ERROR 1146 (42S02): Table '" + table + "' doesn't exist\n");
} else {
MySqlCreateTableStatement createTableStmt = (MySqlCreateTableStatement) schemaObject.getStatement();
createTableStmt.output(buf);
}
} else if (stmt instanceof MySqlRenameTableStatement) {
MySqlRenameTableStatement renameStmt = (MySqlRenameTableStatement) stmt;
for (MySqlRenameTableStatement.Item item : renameStmt.getItems()) {
renameTable(item.getName(), item.getTo());
}
} else if (stmt instanceof SQLShowTablesStatement) {
SQLShowTablesStatement showTables = (SQLShowTablesStatement) stmt;
SQLName database = showTables.getDatabase();
Schema schema;
if (database == null) {
schema = getDefaultSchema();
} else {
schema = findSchema(database.getSimpleName());
}
if (schema != null) {
for (String table : schema.showTables()) {
buf.append(table);
buf.append('\n');
}
}
} else {
stmt.accept(consoleVisitor);
}
}
if (buf.length() == 0) {
return "\n";
}
return buf.toString();
} catch (IOException ex) {
throw new FastsqlException("exeucte command error.", ex);
}
}
Aggregations