代码自动生成工具,当表注释为空时,根据SQL导入失败问题修复

This commit is contained in:
chaocloud 2021-11-24 15:08:01 +08:00
parent 7991d68586
commit b66d845354

View File

@ -64,10 +64,17 @@ public class ToolCodegenSQLParser {
private static ToolSchemaTableDO parseTable(SQLCreateTableStatement statement) { private static ToolSchemaTableDO parseTable(SQLCreateTableStatement statement) {
return ToolSchemaTableDO.builder() return ToolSchemaTableDO.builder()
.tableName(statement.getTableSource().getTableName(true)) .tableName(statement.getTableSource().getTableName(true))
.tableComment(((SQLCharExpr) statement.getComment()).getText()) .tableComment(getCommentText(statement))
.build(); .build();
} }
private static String getCommentText(SQLCreateTableStatement statement) {
if (statement == null || statement.getComment() == null) {
return "";
}
return ((SQLCharExpr) statement.getComment()).getText();
}
private static List<ToolSchemaColumnDO> parseColumns(SQLCreateTableStatement statement) { private static List<ToolSchemaColumnDO> parseColumns(SQLCreateTableStatement statement) {
List<ToolSchemaColumnDO> columns = new ArrayList<>(); List<ToolSchemaColumnDO> columns = new ArrayList<>();
statement.getTableElementList().forEach(element -> parseColumn(columns, element)); statement.getTableElementList().forEach(element -> parseColumn(columns, element));