mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-08-02 21:50:43 +08:00
Fix bug with invalid schema specification
This commit is contained in:
@ -87,12 +87,42 @@ public class DatabaseServiceImpl implements DatabaseService {
|
||||
(key) -> param.isRefresh(), (key) -> {
|
||||
Connection connection = param.getConnection() == null ? Chat2DBContext.getConnection()
|
||||
: param.getConnection();
|
||||
MetaData metaData = Chat2DBContext.getMetaData();
|
||||
return metaData.schemas(connection, param.getDataBaseName());
|
||||
return getSchemaList(param.getDataBaseName(), connection);
|
||||
});
|
||||
return ListResult.of(schemas);
|
||||
}
|
||||
|
||||
|
||||
private List<Schema> getSchemaList(String databaseName, Connection connection) {
|
||||
MetaData metaData = Chat2DBContext.getMetaData();
|
||||
List<Schema> schemas = metaData.schemas(connection,databaseName);
|
||||
sortSchema(schemas,connection);
|
||||
return schemas;
|
||||
}
|
||||
|
||||
private void sortSchema(List<Schema> schemas,Connection connection) {
|
||||
if (CollectionUtils.isEmpty(schemas)) {
|
||||
return;
|
||||
}
|
||||
String ulr = null;
|
||||
try {
|
||||
ulr = connection.getMetaData().getURL();
|
||||
} catch (SQLException e) {
|
||||
log.error("get url error", e);
|
||||
}
|
||||
// If the database name contains the name of the current database, the current database is placed in the first place
|
||||
int num = -1;
|
||||
for (int i = 0; i < schemas.size(); i++) {
|
||||
if (StringUtils.isNotBlank(ulr) && ulr.contains(schemas.get(i).getName())) {
|
||||
num = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (num != -1 && num != 0) {
|
||||
Collections.swap(schemas, num, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataResult<MetaSchema> queryDatabaseSchema(MetaDataQueryParam param) {
|
||||
MetaSchema metaSchema = new MetaSchema();
|
||||
|
Reference in New Issue
Block a user