From 59f39abc1858dfc238f0dc3d59bc02fe7df68350 Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Tue, 21 Nov 2023 18:14:55 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8B=BC=E5=86=99?= =?UTF-8?q?=E9=94=99=E8=AF=AF=20=E6=95=B0=E6=8D=AE=E5=BA=93=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BD=BF=E7=94=A8=E6=9E=9A=E4=B8=BE=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/ai/chat2db/spi/sql/SQLExecutor.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java index f3706538f..9ed899c5e 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java @@ -1,6 +1,7 @@ package ai.chat2db.spi.sql; import ai.chat2db.server.tools.base.constant.EasyToolsConstant; +import ai.chat2db.server.tools.base.enums.DataSourceTypeEnum; import ai.chat2db.server.tools.common.util.I18nUtils; import ai.chat2db.spi.ValueHandler; import ai.chat2db.spi.jdbc.DefaultValueHandler; @@ -203,11 +204,12 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li // 获取header信息 List
headerList = Lists.newArrayListWithExpectedSize(col); executeResult.setHeaderList(headerList); - int chat2dbAutoRowIdIndex = -1;// chat2db自动生成的行分页ID + // chat2db自动生成的行分页ID + int chat2dbAutoRowIdIndex = -1; for (int i = 1; i <= col; i++) { String name = ResultSetUtils.getColumnName(resultSetMetaData, i); - if ("CAHT2DB_AUTO_ROW_ID".equals(name)) { + if ("CHAT2DB_AUTO_ROW_ID".equals(name)) { chat2dbAutoRowIdIndex = i; continue; } @@ -293,9 +295,9 @@ public List databases(Connection connection) { } /** - * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEM. + * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEMA. * The schema columns are: - * TABLE_SCHEM String => schema name + * TABLE_SCHEMA String => schema name * TABLE_CATALOG String => catalog name (may be null) * Params: * catalog – a catalog name; must match the catalog name as it is stored in the database;"" retrieves those without @@ -344,7 +346,7 @@ public List tables(Connection connection, String databaseName, String sch ResultSet resultSet = metadata.getTables(databaseName, schemaName, tableName, types); // 如果connection为mysql - if ("MySQL".equalsIgnoreCase(metadata.getDatabaseProductName())) { + if (DataSourceTypeEnum.MYSQL.getCode().equalsIgnoreCase(metadata.getDatabaseProductName())) { // 获取mysql表的comment List
tables = ResultSetUtils.toObjectList(resultSet, Table.class); if (CollectionUtils.isNotEmpty(tables)) { From 37306c5bf01b49d5a269ea6f0a575c6de29c9f2f Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Tue, 21 Nov 2023 18:22:02 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9SCHEMA=E6=8B=BC=E5=86=99?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ai/chat2db/spi/model/Function.java | 4 ++-- .../src/main/java/ai/chat2db/spi/model/Procedure.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java index b111ed8f1..9d86ba907 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java @@ -17,7 +17,7 @@ @AllArgsConstructor public class Function { //FUNCTION_CAT String => function catalog (may be null) - //FUNCTION_SCHEM String => function schema (may be null) + //FUNCTION_SCHEMA String => function schema (may be null) //FUNCTION_NAME String => function name. This is the name used to invoke the function //REMARKS String => explanatory comment on the function //FUNCTION_TYPE short => kind of function: @@ -30,7 +30,7 @@ public class Function { @JsonAlias({"FUNCTION_CAT"}) private String databaseName; - @JsonAlias({"FUNCTION_SCHEM"}) + @JsonAlias({"FUNCTION_SCHEMA"}) private String schemaName; @JsonAlias({"FUNCTION_NAME"}) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java index 3c48489d7..14958dd91 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java @@ -17,7 +17,7 @@ @AllArgsConstructor public class Procedure { //PROCEDURE_CAT String => procedure catalog (may be null) - //PROCEDURE_SCHEM String => procedure schema (may be null) + //PROCEDURE_SCHEMA String => procedure schema (may be null) //PROCEDURE_NAME String => procedure name //REMARKS String => explanatory comment on the procedure //PROCEDURE_TYPE short => kind of procedure: @@ -30,7 +30,7 @@ public class Procedure { @JsonAlias({"PROCEDURE_CAT"}) private String databaseName; - @JsonAlias({"PROCEDURE_SCHEM"}) + @JsonAlias({"PROCEDURE_SCHEMA"}) private String schemaName; From c674d25d0e7089dcd50affe92ae3759b443c180c Mon Sep 17 00:00:00 2001 From: Xin Yan Date: Wed, 22 Nov 2023 00:06:57 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BD=BF=E7=94=A8=E6=9E=9A=E4=B8=BE=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ai/chat2db/spi/sql/SQLExecutor.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java index f3706538f..fce7db266 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java @@ -1,6 +1,7 @@ package ai.chat2db.spi.sql; import ai.chat2db.server.tools.base.constant.EasyToolsConstant; +import ai.chat2db.server.tools.base.enums.DataSourceTypeEnum; import ai.chat2db.server.tools.common.util.I18nUtils; import ai.chat2db.spi.ValueHandler; import ai.chat2db.spi.jdbc.DefaultValueHandler; @@ -203,7 +204,8 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li // 获取header信息 List
headerList = Lists.newArrayListWithExpectedSize(col); executeResult.setHeaderList(headerList); - int chat2dbAutoRowIdIndex = -1;// chat2db自动生成的行分页ID + // chat2db自动生成的行分页ID + int chat2dbAutoRowIdIndex = -1; for (int i = 1; i <= col; i++) { String name = ResultSetUtils.getColumnName(resultSetMetaData, i); @@ -344,7 +346,7 @@ public List
tables(Connection connection, String databaseName, String sch ResultSet resultSet = metadata.getTables(databaseName, schemaName, tableName, types); // 如果connection为mysql - if ("MySQL".equalsIgnoreCase(metadata.getDatabaseProductName())) { + if (DataSourceTypeEnum.MYSQL.getCode().equalsIgnoreCase(metadata.getDatabaseProductName())) { // 获取mysql表的comment List
tables = ResultSetUtils.toObjectList(resultSet, Table.class); if (CollectionUtils.isNotEmpty(tables)) { From 218662a2ccbb89a14c66779c743a3a2200eec40b Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Wed, 22 Nov 2023 00:11:23 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ai/chat2db/spi/model/Function.java | 4 ++-- .../src/main/java/ai/chat2db/spi/model/Procedure.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java index 9d86ba907..b111ed8f1 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java @@ -17,7 +17,7 @@ @AllArgsConstructor public class Function { //FUNCTION_CAT String => function catalog (may be null) - //FUNCTION_SCHEMA String => function schema (may be null) + //FUNCTION_SCHEM String => function schema (may be null) //FUNCTION_NAME String => function name. This is the name used to invoke the function //REMARKS String => explanatory comment on the function //FUNCTION_TYPE short => kind of function: @@ -30,7 +30,7 @@ public class Function { @JsonAlias({"FUNCTION_CAT"}) private String databaseName; - @JsonAlias({"FUNCTION_SCHEMA"}) + @JsonAlias({"FUNCTION_SCHEM"}) private String schemaName; @JsonAlias({"FUNCTION_NAME"}) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java index 14958dd91..3c48489d7 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java @@ -17,7 +17,7 @@ @AllArgsConstructor public class Procedure { //PROCEDURE_CAT String => procedure catalog (may be null) - //PROCEDURE_SCHEMA String => procedure schema (may be null) + //PROCEDURE_SCHEM String => procedure schema (may be null) //PROCEDURE_NAME String => procedure name //REMARKS String => explanatory comment on the procedure //PROCEDURE_TYPE short => kind of procedure: @@ -30,7 +30,7 @@ public class Procedure { @JsonAlias({"PROCEDURE_CAT"}) private String databaseName; - @JsonAlias({"PROCEDURE_SCHEMA"}) + @JsonAlias({"PROCEDURE_SCHEM"}) private String schemaName; From 4a5185235e01e782586db3014b7b5feadf5c0641 Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Wed, 22 Nov 2023 00:13:26 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/ai/chat2db/spi/sql/SQLExecutor.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java index 9ed899c5e..f3706538f 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java @@ -1,7 +1,6 @@ package ai.chat2db.spi.sql; import ai.chat2db.server.tools.base.constant.EasyToolsConstant; -import ai.chat2db.server.tools.base.enums.DataSourceTypeEnum; import ai.chat2db.server.tools.common.util.I18nUtils; import ai.chat2db.spi.ValueHandler; import ai.chat2db.spi.jdbc.DefaultValueHandler; @@ -204,12 +203,11 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li // 获取header信息 List
headerList = Lists.newArrayListWithExpectedSize(col); executeResult.setHeaderList(headerList); - // chat2db自动生成的行分页ID - int chat2dbAutoRowIdIndex = -1; + int chat2dbAutoRowIdIndex = -1;// chat2db自动生成的行分页ID for (int i = 1; i <= col; i++) { String name = ResultSetUtils.getColumnName(resultSetMetaData, i); - if ("CHAT2DB_AUTO_ROW_ID".equals(name)) { + if ("CAHT2DB_AUTO_ROW_ID".equals(name)) { chat2dbAutoRowIdIndex = i; continue; } @@ -295,9 +293,9 @@ public List databases(Connection connection) { } /** - * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEMA. + * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEM. * The schema columns are: - * TABLE_SCHEMA String => schema name + * TABLE_SCHEM String => schema name * TABLE_CATALOG String => catalog name (may be null) * Params: * catalog – a catalog name; must match the catalog name as it is stored in the database;"" retrieves those without @@ -346,7 +344,7 @@ public List
tables(Connection connection, String databaseName, String sch ResultSet resultSet = metadata.getTables(databaseName, schemaName, tableName, types); // 如果connection为mysql - if (DataSourceTypeEnum.MYSQL.getCode().equalsIgnoreCase(metadata.getDatabaseProductName())) { + if ("MySQL".equalsIgnoreCase(metadata.getDatabaseProductName())) { // 获取mysql表的comment List
tables = ResultSetUtils.toObjectList(resultSet, Table.class); if (CollectionUtils.isNotEmpty(tables)) { From df0b417eb5c26ef05ee509e41ec05970724ac540 Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Wed, 22 Nov 2023 00:13:26 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BD=BF=E7=94=A8=E6=9E=9A=E4=B8=BE=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ai/chat2db/spi/sql/SQLExecutor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java index 9ed899c5e..fce7db266 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java @@ -209,7 +209,7 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li for (int i = 1; i <= col; i++) { String name = ResultSetUtils.getColumnName(resultSetMetaData, i); - if ("CHAT2DB_AUTO_ROW_ID".equals(name)) { + if ("CAHT2DB_AUTO_ROW_ID".equals(name)) { chat2dbAutoRowIdIndex = i; continue; } @@ -295,9 +295,9 @@ public List databases(Connection connection) { } /** - * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEMA. + * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEM. * The schema columns are: - * TABLE_SCHEMA String => schema name + * TABLE_SCHEM String => schema name * TABLE_CATALOG String => catalog name (may be null) * Params: * catalog – a catalog name; must match the catalog name as it is stored in the database;"" retrieves those without From 1e43ec1266be5b5473f1f3178b63fa5d70f2fc22 Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Tue, 5 Dec 2023 17:59:11 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=97=B6=E5=8F=AF=E4=BB=A5=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=AD=97=E7=AC=A6=E9=9B=86=E5=AD=97=E6=AE=B5=E3=80=82?= =?UTF-8?q?=20=E7=9B=AE=E5=89=8D=E5=AE=9E=E7=8E=B0=E4=BA=86MySQL=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/CreateDatabase/index.tsx | 52 ++++++++++++++++++- chat2db-client/src/i18n/en-us/common.ts | 1 + chat2db-client/src/i18n/zh-cn/common.ts | 1 + chat2db-client/src/service/sql.ts | 9 ++++ .../chat2db/plugin/mysql/MysqlMetaData.java | 7 +++ .../domain/api/service/TableService.java | 2 + .../domain/core/impl/TableServiceImpl.java | 16 ++++++ .../api/controller/rdb/TableController.java | 13 +++++ .../main/java/ai/chat2db/spi/MetaData.java | 1 + .../chat2db/spi/jdbc/DefaultMetaService.java | 5 ++ 10 files changed, 106 insertions(+), 1 deletion(-) diff --git a/chat2db-client/src/components/CreateDatabase/index.tsx b/chat2db-client/src/components/CreateDatabase/index.tsx index 665d5b57f..bc532d862 100644 --- a/chat2db-client/src/components/CreateDatabase/index.tsx +++ b/chat2db-client/src/components/CreateDatabase/index.tsx @@ -1,7 +1,7 @@ import React, { useCallback, forwardRef, ForwardedRef, useImperativeHandle, useMemo, useState, useEffect } from 'react'; import styles from './index.less'; import classnames from 'classnames'; -import { Form, Input, Modal } from 'antd'; +import {Form, Input, Modal, Select} from 'antd'; import MonacoEditor, { IExportRefFunction } from '@/components/Console/MonacoEditor'; import { v4 as uuid } from 'uuid'; import sqlService from '@/service/sql'; @@ -15,6 +15,11 @@ interface IProps { executedCallback?: () => void; } +interface IOption { + label: string; + value: string | number | null; +} + export type CreateType = 'database' | 'schema'; export interface ICreateDatabaseRef { @@ -27,8 +32,14 @@ export interface ICreateDatabase { comment?: string; } +export interface IDatabaseCharsetList { + charsets: IOption[]; +} + // 创建database不支持注释的数据库 const noCommentDatabase = [DatabaseTypeCode.MYSQL]; +// 支持charset的数据库 +const supportCharset = [DatabaseTypeCode.MYSQL]; export default forwardRef((props: IProps, ref: ForwardedRef) => { const { className, curWorkspaceParams, executedCallback } = props; @@ -41,6 +52,9 @@ export default forwardRef((props: IProps, ref: ForwardedRef) ); const [confirmLoading, setConfirmLoading] = useState(false); const [createType, setCreateType] = useState('database'); + const [databaseCharsetList, setDatabaseCharsetList] = useState({ + charsets: [], + }); useEffect(() => { if (!open) { @@ -50,6 +64,33 @@ export default forwardRef((props: IProps, ref: ForwardedRef) } }, [open]); + useEffect(() => { + if (curWorkspaceParams.databaseType && databaseCharsetList.charsets.length === 0) { + getDatabaseCharsetList(); + } + }, [curWorkspaceParams]) + + const initialOption = { + label: '', + value: '', + }; + const getDatabaseCharsetList = () => { + sqlService + .getDatabaseCharsetList(curWorkspaceParams) + .then((res) => { + const charsets = [initialOption, + ...(res?.charsets?.map((i) => { + return { + label: i.charsetName, + value: i.charsetName, + }; + }) || [])]; + setDatabaseCharsetList({ + charsets, + }); + }); + } + const config = useMemo(() => { return createType === 'database' ? { @@ -143,6 +184,15 @@ export default forwardRef((props: IProps, ref: ForwardedRef) + + diff --git a/chat2db-client/src/i18n/en-us/common.ts b/chat2db-client/src/i18n/en-us/common.ts index 2216f71e9..f092d1b4f 100644 --- a/chat2db-client/src/i18n/en-us/common.ts +++ b/chat2db-client/src/i18n/en-us/common.ts @@ -100,6 +100,7 @@ export default { 'common.Button.addSchema': 'Add schema', 'common.label.comment': 'Comment', 'common.label.name': 'Name', + 'common.label.charset': 'Charset', 'common.title.create': 'Create', 'common.title.executiveLogging': 'Executive logging', 'common.text.executionTime': 'Affected in {1} ms', diff --git a/chat2db-client/src/i18n/zh-cn/common.ts b/chat2db-client/src/i18n/zh-cn/common.ts index 3d59bf3c6..a46f2fbec 100644 --- a/chat2db-client/src/i18n/zh-cn/common.ts +++ b/chat2db-client/src/i18n/zh-cn/common.ts @@ -99,6 +99,7 @@ export default { 'common.Button.addSchema': '添加Schema', 'common.label.comment': '备注', 'common.label.name': '名称', + 'common.label.charset': '字符集', 'common.title.create': '创建', 'common.title.executiveLogging': '执行记录', 'common.text.executionTime': '{1}ms 执行完毕', diff --git a/chat2db-client/src/service/sql.ts b/chat2db-client/src/service/sql.ts index 8754246fa..6a1c903a2 100644 --- a/chat2db-client/src/service/sql.ts +++ b/chat2db-client/src/service/sql.ts @@ -301,6 +301,14 @@ const getCreateSchemaSql = createRequest<{ schemaName?: string; }, {sql:string}>('/api/rdb/schema/create_schema_sql', { method: 'post' }); +const getDatabaseCharsetList = createRequest<{ + dataSourceId: number; + databaseName: string; +}, IDatabaseSupportField>( + '/api/rdb/table/table_charset', + { method: 'get' }, +); + export default { getCreateSchemaSql, getCreateDatabaseSql, @@ -339,4 +347,5 @@ export default { // exportResultTable getAllTableList, getAllFieldByTable, + getDatabaseCharsetList, }; diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java index 40a291955..30189959e 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java @@ -297,4 +297,11 @@ public String getMetaDataName(String... names) { public ValueHandler getValueHandler() { return new MysqlValueHandler(); } + + @Override + public TableMeta getTableCharset(String databaseName, String schemaName, String tableName) { + return TableMeta.builder() + .charsets(MysqlCharsetEnum.getCharsets()) + .build(); + } } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java index 93f245af2..45555bbe4 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java @@ -129,4 +129,6 @@ public interface TableService { * @return */ DataResult checkTableVector(TableVectorParam param); + + TableMeta queryTableCharset(TypeQueryParam param); } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java index 5fd24c465..60e3de509 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java @@ -577,4 +577,20 @@ public DataResult checkTableVector(TableVectorParam param) { } return DataResult.of(false); } + + @Override + public TableMeta queryTableCharset(TypeQueryParam param) { + MetaData metaSchema = Chat2DBContext.getMetaData(); + TableMeta tableMeta = metaSchema.getTableCharset(null, null, null); + if (tableMeta != null) { + //filter primary key + List indexTypes = tableMeta.getIndexTypes(); + if (CollectionUtils.isNotEmpty(indexTypes)) { + List types = indexTypes.stream().filter(indexType -> !"Primary".equals(indexType.getTypeName())).collect(Collectors.toList()); + tableMeta.setIndexTypes(types); + } + } + return tableMeta; + } + } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java index 131a6bf6c..4148a449f 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java @@ -250,4 +250,17 @@ public ActionResult delete(@Valid @RequestBody TableDeleteRequest request) { DropParam dropParam = rdbWebConverter.tableDelete2dropParam(request); return tableService.drop(dropParam); } + + /** + * 数据库支持的字符集 + * @param request + * @return + */ + @GetMapping("/table_charset") + public DataResult tableCharset(@Valid TypeQueryRequest request) { + TypeQueryParam typeQueryParam = TypeQueryParam.builder().dataSourceId(request.getDataSourceId()).build(); + TableMeta tableMeta = tableService.queryTableCharset(typeQueryParam); + return DataResult.of(tableMeta); + } + } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java index 02fab4057..af1aed623 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java @@ -214,4 +214,5 @@ List indexes(Connection connection, @NotEmpty String databaseName, S */ ValueHandler getValueHandler(); + TableMeta getTableCharset(String databaseName, String schemaName, String tableName); } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java index 624814080..6065f027a 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java @@ -136,4 +136,9 @@ public String getMetaDataName(String... names) { public ValueHandler getValueHandler() { return new DefaultValueHandler(); } + + @Override + public TableMeta getTableCharset(String databaseName, String schemaName, String tableName) { + return null; + } } \ No newline at end of file