Skip to content

Commit

Permalink
增加对虚拟列的属性获取.
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed Jun 22, 2024
1 parent 19055a8 commit a4d6259
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ public static class MetaInfo {
*/
private String typeName;

/**
* 是否为生成列
*
* @since 3.5.8
*/
private boolean generatedColumn;

public MetaInfo(DatabaseMetaDataWrapper.Column column, TableInfo tableInfo) {
if (column != null) {
this.tableName = tableInfo.getName();
Expand All @@ -416,6 +423,7 @@ public MetaInfo(DatabaseMetaDataWrapper.Column column, TableInfo tableInfo) {
this.scale = column.getScale();
this.jdbcType = column.getJdbcType();
this.typeName = column.getTypeName();
this.generatedColumn = column.isGeneratedColumn();
}
}

Expand Down Expand Up @@ -467,6 +475,7 @@ public String toString() {
", scale=" + scale +
", jdbcType=" + jdbcType +
", typeName='" + typeName + '\'' +
", generatedColumn=" + generatedColumn +
'}';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ public Map<String, Column> getColumnsInfo(String catalog, String schema, String
column.remarks = formatComment(resultSet.getString("REMARKS"));
column.defaultValue = resultSet.getString("COLUMN_DEF");
column.nullable = resultSet.getInt("NULLABLE") == DatabaseMetaData.columnNullable;
try {
column.autoIncrement = "YES".equals(resultSet.getString("IS_AUTOINCREMENT"));
} catch (SQLException sqlException) {
//TODO 目前测试在oracle旧驱动下存在问题,降级成false.
}
column.generatedColumn = isGeneratedOrAutoIncrementColumn(resultSet, "IS_GENERATEDCOLUMN");
column.autoIncrement = isGeneratedOrAutoIncrementColumn(resultSet, "IS_AUTOINCREMENT");
columnsInfoMap.put(name.toLowerCase(), column);
}
return Collections.unmodifiableMap(columnsInfoMap);
Expand All @@ -131,6 +128,15 @@ public Map<String, Column> getColumnsInfo(String catalog, String schema, String
}
}

private boolean isGeneratedOrAutoIncrementColumn(ResultSet resultSet, String columnLabel) {
try {
return "YES".equals(resultSet.getString(columnLabel));
} catch (SQLException e) {
// ignore
}
return false;
}

public String formatComment(String comment) {
return StringUtils.isBlank(comment) ? StringPool.EMPTY : comment.replaceAll("\r\n", "\t");
}
Expand Down Expand Up @@ -214,5 +220,7 @@ public static class Column {
@Setter
private String typeName;

private boolean generatedColumn;

}
}

0 comments on commit a4d6259

Please sign in to comment.