mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-09-28 01:24:44 +08:00
- Default return alias for returned results [Issue #270](https://github.com/chat2db/Chat2DB/issues/270)
This commit is contained in:
@ -1,3 +1,11 @@
|
||||
# 2.0.4
|
||||
|
||||
## 🐞 Bug Fixes
|
||||
- Default return alias for returned results [Issue #270](https://github.com/chat2db/Chat2DB/issues/270)
|
||||
|
||||
## 🐞 问题修复
|
||||
- 返回结果默认返回别名 [Issue #270](https://github.com/chat2db/Chat2DB/issues/270)
|
||||
|
||||
# 2.0.4
|
||||
## ⭐ New Features
|
||||
- Support DB2 database
|
||||
|
@ -14,6 +14,7 @@ import java.util.stream.Collectors;
|
||||
import ai.chat2db.server.tools.base.constant.EasyToolsConstant;
|
||||
import ai.chat2db.spi.model.*;
|
||||
|
||||
import ai.chat2db.spi.util.ResultSetUtils;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -57,6 +58,7 @@ public class SQLExecutor {
|
||||
|
||||
/**
|
||||
* 执行sql
|
||||
*
|
||||
* @param connection
|
||||
* @param sql
|
||||
* @param function
|
||||
@ -115,7 +117,7 @@ public class SQLExecutor {
|
||||
headerList.add(Header.builder()
|
||||
.dataType(ai.chat2db.spi.util.JdbcUtils.resolveDataType(
|
||||
resultSetMetaData.getColumnTypeName(i), resultSetMetaData.getColumnType(i)).getCode())
|
||||
.name(resultSetMetaData.getColumnName(i))
|
||||
.name(ResultSetUtils.getColumnName(resultSetMetaData, i))
|
||||
.build());
|
||||
}
|
||||
|
||||
@ -159,6 +161,7 @@ public class SQLExecutor {
|
||||
|
||||
/**
|
||||
* 获取所有的数据库
|
||||
*
|
||||
* @param connection
|
||||
* @return
|
||||
*/
|
||||
@ -178,6 +181,7 @@ public class SQLExecutor {
|
||||
|
||||
/**
|
||||
* 获取所有的schema
|
||||
*
|
||||
* @param connection
|
||||
* @param databaseName
|
||||
* @param schemaName
|
||||
@ -217,6 +221,7 @@ public class SQLExecutor {
|
||||
|
||||
/**
|
||||
* 获取所有的数据库表
|
||||
*
|
||||
* @param connection
|
||||
* @param databaseName
|
||||
* @param schemaName
|
||||
@ -224,7 +229,8 @@ public class SQLExecutor {
|
||||
* @param types
|
||||
* @return
|
||||
*/
|
||||
public List<Table> tables(Connection connection,String databaseName, String schemaName, String tableName, String types[]) {
|
||||
public List<Table> tables(Connection connection, String databaseName, String schemaName, String tableName,
|
||||
String types[]) {
|
||||
List<Table> tables = Lists.newArrayList();
|
||||
int n = 0;
|
||||
try (ResultSet resultSet = connection.getMetaData().getTables(databaseName, schemaName, tableName,
|
||||
@ -246,6 +252,7 @@ public class SQLExecutor {
|
||||
|
||||
/**
|
||||
* 获取所有的数据库表列
|
||||
*
|
||||
* @param connection
|
||||
* @param databaseName
|
||||
* @param schemaName
|
||||
@ -253,7 +260,8 @@ public class SQLExecutor {
|
||||
* @param columnName
|
||||
* @return
|
||||
*/
|
||||
public List<TableColumn> columns(Connection connection,String databaseName, String schemaName, String tableName, String columnName) {
|
||||
public List<TableColumn> columns(Connection connection, String databaseName, String schemaName, String tableName,
|
||||
String columnName) {
|
||||
List<TableColumn> tableColumns = Lists.newArrayList();
|
||||
try (ResultSet resultSet = connection.getMetaData().getColumns(databaseName, schemaName, tableName,
|
||||
columnName)) {
|
||||
@ -270,6 +278,7 @@ public class SQLExecutor {
|
||||
|
||||
/**
|
||||
* 获取所有的数据库表索引
|
||||
*
|
||||
* @param connection
|
||||
* @param databaseName
|
||||
* @param schemaName
|
||||
@ -308,6 +317,7 @@ public class SQLExecutor {
|
||||
|
||||
/**
|
||||
* 获取所有的函数
|
||||
*
|
||||
* @param connection
|
||||
* @param databaseName
|
||||
* @param schemaName
|
||||
@ -328,6 +338,7 @@ public class SQLExecutor {
|
||||
|
||||
/**
|
||||
* 获取所有的存储过程
|
||||
*
|
||||
* @param connection
|
||||
* @param databaseName
|
||||
* @param schemaName
|
||||
|
@ -2,6 +2,7 @@
|
||||
package ai.chat2db.spi.util;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import ai.chat2db.spi.model.*;
|
||||
@ -103,4 +104,12 @@ public class ResultSetUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getColumnName(ResultSetMetaData resultSetMetaData, int column) throws SQLException {
|
||||
String columnLabel = resultSetMetaData.getColumnLabel(column);
|
||||
if (columnLabel != null) {
|
||||
return columnLabel;
|
||||
}
|
||||
return resultSetMetaData.getColumnName(column);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user