diff --git a/src/common/datasource/db2/index.tsx b/src/common/datasource/db2/index.tsx new file mode 100644 index 000000000..74f3b0c59 --- /dev/null +++ b/src/common/datasource/db2/index.tsx @@ -0,0 +1,123 @@ +/* + * Copyright 2023 OceanBase + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ConnectType, TaskType } from '@/d.ts'; +import { IDataSourceModeConfig } from '../interface'; +import { haveOCP } from '@/util/env'; + +// fix_report_20260529_100416 issue (Issue dms-ee#839): DB2 LUW expresses identity columns via +// `GENERATED ALWAYS AS IDENTITY` rather than MySQL's AUTO_INCREMENT keyword. Leaving +// enableAutoIncrement=true causes the table designer to surface an "自增" checkbox that the +// backend has no way to round-trip into DB2 grammar — the front-end now hides the affordance. +const tableConfig = { + enableAutoIncrement: false, + type2ColumnType: { + id: 'integer', + name: 'varchar', + date: 'date', + time: 'timestamp' + } +}; + +const functionConfig: IDataSourceModeConfig['schema']['func'] = { + params: ['paramName', 'dataType', 'dataLength'], + defaultValue: { + dataLength: 45 + }, + dataNature: true, + sqlSecurity: true, + deterministic: true +}; + +const procedureConfig: IDataSourceModeConfig['schema']['proc'] = { + params: ['paramName', 'paramMode', 'dataType', 'dataLength'], + defaultValue: { + dataLength: 45 + }, + dataNature: true, + sqlSecurity: true, + deterministic: true +}; + +const items: Record = { + [ConnectType.DB2]: { + connection: { + address: { + items: ['ip', 'port', 'catalogName'] + }, + account: true, + sys: false, + ssl: false, + jdbcDoc: 'https://www.ibm.com/docs/en/db2/11.5?topic=java-jdbc-overview', + disableURLParse: true + }, + features: { + task: [TaskType.DATA_ARCHIVE, TaskType.DATA_DELETE], + obclient: false, + recycleBin: false, + plRun: false, + sessionManage: true, + sessionParams: false, + sqlconsole: true, + sqlExplain: false, + groupResourceTree: true, + export: { + fileLimit: false, + snapshot: false + } + }, + schema: { + table: tableConfig, + func: functionConfig, + proc: procedureConfig, + innerSchema: [ + 'SYSCAT', + 'SYSIBM', + 'SYSIBMADM', + 'SYSIBMINTERNAL', + 'SYSIBMTS', + 'SYSFUN', + 'SYSPROC', + 'SYSSTAT', + 'SYSTOOLS', + 'SYSPUBLIC', + 'NULLID' + ] + }, + sql: { + language: 'mysql', + escapeChar: '"', + // fix_report_20260601_031142 (Issue dms-ee#839, P0-1): caseSensitivity drives the + // CaseInput/CaseTextEditor force-upper-case behavior on the table designer. Setting it to + // false made the column-name input mutate "my_col" into "MY_COL" on every keystroke, + // making lower-case column names impossible to enter (DB2 will still upper-case the + // identifier server-side if the user submits without double quotes — that semantic is + // unchanged). Aligning with SQL Server (also `"` quoted, also `true`): the workbench's + // table designer accepts the user's input verbatim; users who need to preserve mixed + // case can wrap the identifier in "..." themselves, which the editor already supports. + // The previous comment blaming SQL-editor auto-complete was incorrect: caseSensitivity + // is only consumed by CaseInput / CaseTextEditor and does not flow into the SQL editor + // completion pipeline. + caseSensitivity: true + } + } +}; + +if (haveOCP()) { + delete items[ConnectType.DB2]; +} + +export default items; diff --git a/src/common/datasource/index.tsx b/src/common/datasource/index.tsx index 547364d07..11fdb7b4a 100644 --- a/src/common/datasource/index.tsx +++ b/src/common/datasource/index.tsx @@ -26,6 +26,7 @@ import Doris from './doris'; import TiDB from './tidb'; import PG from './pg'; import DM from './dm'; +import DB2 from './db2'; import FileSystem from './fileSystem'; import { ReactComponent as OBSvg } from '@/svgr/source_ob.svg'; import { ReactComponent as DBOBSvg } from '@/svgr/database_oceanbase.svg'; @@ -52,6 +53,8 @@ import { ReactComponent as DBSqlServerSvg } from '@/svgr/database_sqlserver.svg' import { ReactComponent as SqlServerSvg } from '@/svgr/sqlserver.svg'; import { ReactComponent as DMSvg } from '@/svgr/dm.svg'; import { ReactComponent as DBDMSvg } from '@/svgr/database_dm.svg'; +import { ReactComponent as DB2Svg } from '@/svgr/db2.svg'; +import { ReactComponent as DBDB2Svg } from '@/svgr/database_db2.svg'; import odc from '@/plugins/odc'; export const _types: Map< @@ -172,6 +175,15 @@ const _styles = { dbIcon: { component: DBDMSvg } + }, + [IDataSourceType.DB2]: { + icon: { + component: DB2Svg, + color: '#0F62FE' + }, + dbIcon: { + component: DBDB2Svg + } } }; @@ -187,7 +199,8 @@ const _gruops = { [IDataSourceType.HUAWEI]: DatasourceGroup.FileSystem, [IDataSourceType.QCLOUD]: DatasourceGroup.FileSystem, [IDataSourceType.SQL_SERVER]: DatasourceGroup.OtherDatabase, - [IDataSourceType.DM]: DatasourceGroup.OtherDatabase + [IDataSourceType.DM]: DatasourceGroup.OtherDatabase, + [IDataSourceType.DB2]: DatasourceGroup.OtherDatabase }; export const connectType2Ds: Map = new Map(); @@ -246,6 +259,7 @@ function initDatasource() { register(IDataSourceType.QCLOUD, FileSystem.QCLOUD); register(IDataSourceType.SQL_SERVER, SqlServer); register(IDataSourceType.DM, DM); + register(IDataSourceType.DB2, DB2); } function getAllConnectTypes(ds?: IDataSourceType): ConnectType[] { diff --git a/src/constant/label.ts b/src/constant/label.ts index adf38797f..d7e29fbb0 100644 --- a/src/constant/label.ts +++ b/src/constant/label.ts @@ -150,7 +150,8 @@ export const ConnectTypeText = (type: ConnectType) => { [ConnectType.DM]: formatMessage({ id: 'src.constant.DM_LABEL', defaultMessage: '达梦(DM)' - }) + }), + [ConnectType.DB2]: 'DB2' }; return textMap?.[type]; }; diff --git a/src/d.ts/datasource.ts b/src/d.ts/datasource.ts index 6e704930d..f655b9191 100644 --- a/src/d.ts/datasource.ts +++ b/src/d.ts/datasource.ts @@ -56,5 +56,6 @@ export enum IDataSourceType { HUAWEI = 'HUAWEI', AWSS3 = 'AWSS3', SQL_SERVER = 'SQL_SERVER', - DM = 'DM' + DM = 'DM', + DB2 = 'DB2' } diff --git a/src/d.ts/index.ts b/src/d.ts/index.ts index 610c03008..0c69eee3c 100644 --- a/src/d.ts/index.ts +++ b/src/d.ts/index.ts @@ -771,6 +771,7 @@ export enum ConnectionMode { OB_ORACLE = 'OB_ORACLE', SQL_SERVER = 'SQL_SERVER', DM = 'DM', + DB2 = 'DB2', ALL = 'ALL', UNKNOWN = 'UNKNOWN' } @@ -3560,7 +3561,8 @@ export enum ConnectType { OBS = 'OBS', S3A = 'S3A', SQL_SERVER = 'SQL_SERVER', - DM = 'DM' + DM = 'DM', + DB2 = 'DB2' } export enum DatasourceGroup { diff --git a/src/page/Workspace/SideBar/ResourceTree/DatabaseSearchModal/constant.ts b/src/page/Workspace/SideBar/ResourceTree/DatabaseSearchModal/constant.ts index 33e969d1e..cbf485ee7 100644 --- a/src/page/Workspace/SideBar/ResourceTree/DatabaseSearchModal/constant.ts +++ b/src/page/Workspace/SideBar/ResourceTree/DatabaseSearchModal/constant.ts @@ -70,6 +70,7 @@ export const objectTypeConfig = { [ConnectType.OB_ORACLE]: oracleObjectType, [ConnectType.ORACLE]: oracleObjectType, [ConnectType.SQL_SERVER]: sqlServerObjectType, + [ConnectType.DB2]: mysqlObjectType, SEARCH_OBJECT_FROM_ALL_DATABASE: oracleObjectType }; diff --git a/src/svgr/database_db2.svg b/src/svgr/database_db2.svg new file mode 100644 index 000000000..30a44c917 --- /dev/null +++ b/src/svgr/database_db2.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/svgr/db2.svg b/src/svgr/db2.svg new file mode 100644 index 000000000..3372eea19 --- /dev/null +++ b/src/svgr/db2.svg @@ -0,0 +1,4 @@ + + + DB2 +