mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-09-27 00:54:49 +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
|
# 2.0.4
|
||||||
## ⭐ New Features
|
## ⭐ New Features
|
||||||
- Support DB2 database
|
- Support DB2 database
|
||||||
|
@ -14,6 +14,7 @@ import java.util.stream.Collectors;
|
|||||||
import ai.chat2db.server.tools.base.constant.EasyToolsConstant;
|
import ai.chat2db.server.tools.base.constant.EasyToolsConstant;
|
||||||
import ai.chat2db.spi.model.*;
|
import ai.chat2db.spi.model.*;
|
||||||
|
|
||||||
|
import ai.chat2db.spi.util.ResultSetUtils;
|
||||||
import cn.hutool.core.date.TimeInterval;
|
import cn.hutool.core.date.TimeInterval;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -57,6 +58,7 @@ public class SQLExecutor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行sql
|
* 执行sql
|
||||||
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* @param sql
|
* @param sql
|
||||||
* @param function
|
* @param function
|
||||||
@ -115,7 +117,7 @@ public class SQLExecutor {
|
|||||||
headerList.add(Header.builder()
|
headerList.add(Header.builder()
|
||||||
.dataType(ai.chat2db.spi.util.JdbcUtils.resolveDataType(
|
.dataType(ai.chat2db.spi.util.JdbcUtils.resolveDataType(
|
||||||
resultSetMetaData.getColumnTypeName(i), resultSetMetaData.getColumnType(i)).getCode())
|
resultSetMetaData.getColumnTypeName(i), resultSetMetaData.getColumnType(i)).getCode())
|
||||||
.name(resultSetMetaData.getColumnName(i))
|
.name(ResultSetUtils.getColumnName(resultSetMetaData, i))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,6 +161,7 @@ public class SQLExecutor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有的数据库
|
* 获取所有的数据库
|
||||||
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -178,6 +181,7 @@ public class SQLExecutor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有的schema
|
* 获取所有的schema
|
||||||
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param schemaName
|
* @param schemaName
|
||||||
@ -217,6 +221,7 @@ public class SQLExecutor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有的数据库表
|
* 获取所有的数据库表
|
||||||
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param schemaName
|
* @param schemaName
|
||||||
@ -224,7 +229,8 @@ public class SQLExecutor {
|
|||||||
* @param types
|
* @param types
|
||||||
* @return
|
* @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();
|
List<Table> tables = Lists.newArrayList();
|
||||||
int n = 0;
|
int n = 0;
|
||||||
try (ResultSet resultSet = connection.getMetaData().getTables(databaseName, schemaName, tableName,
|
try (ResultSet resultSet = connection.getMetaData().getTables(databaseName, schemaName, tableName,
|
||||||
@ -246,6 +252,7 @@ public class SQLExecutor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有的数据库表列
|
* 获取所有的数据库表列
|
||||||
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param schemaName
|
* @param schemaName
|
||||||
@ -253,7 +260,8 @@ public class SQLExecutor {
|
|||||||
* @param columnName
|
* @param columnName
|
||||||
* @return
|
* @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();
|
List<TableColumn> tableColumns = Lists.newArrayList();
|
||||||
try (ResultSet resultSet = connection.getMetaData().getColumns(databaseName, schemaName, tableName,
|
try (ResultSet resultSet = connection.getMetaData().getColumns(databaseName, schemaName, tableName,
|
||||||
columnName)) {
|
columnName)) {
|
||||||
@ -270,6 +278,7 @@ public class SQLExecutor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有的数据库表索引
|
* 获取所有的数据库表索引
|
||||||
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param schemaName
|
* @param schemaName
|
||||||
@ -308,6 +317,7 @@ public class SQLExecutor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有的函数
|
* 获取所有的函数
|
||||||
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param schemaName
|
* @param schemaName
|
||||||
@ -328,6 +338,7 @@ public class SQLExecutor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有的存储过程
|
* 获取所有的存储过程
|
||||||
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param schemaName
|
* @param schemaName
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
package ai.chat2db.spi.util;
|
package ai.chat2db.spi.util;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import ai.chat2db.spi.model.*;
|
import ai.chat2db.spi.model.*;
|
||||||
@ -103,4 +104,12 @@ public class ResultSetUtils {
|
|||||||
return null;
|
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