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 d2cff939a..7e0a6023b 100644 --- a/src/common/datasource/index.tsx +++ b/src/common/datasource/index.tsx @@ -30,6 +30,7 @@ import DM from './dm'; import Hana from './hana'; import MongoDB from './mongodb'; import Hive from './hive'; +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'; @@ -58,6 +59,8 @@ import { ReactComponent as DMSvg } from '@/svgr/dm.svg'; import { ReactComponent as DBDMSvg } from '@/svgr/database_dm.svg'; import { ReactComponent as MongoDBSvg } from '@/svgr/command.svg'; import { ReactComponent as DBMongoDBSvg } from '@/svgr/database.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< @@ -221,6 +224,15 @@ const _styles = { dbIcon: { component: DBMongoDBSvg } + }, + [IDataSourceType.DB2]: { + icon: { + component: DB2Svg, + color: '#0F62FE' + }, + dbIcon: { + component: DBDB2Svg + } } }; @@ -240,7 +252,8 @@ const _gruops = { [IDataSourceType.DM]: DatasourceGroup.OtherDatabase, [IDataSourceType.HANA]: DatasourceGroup.OtherDatabase, [IDataSourceType.MongoDB]: DatasourceGroup.OtherDatabase, - [IDataSourceType.HIVE]: DatasourceGroup.OtherDatabase + [IDataSourceType.HIVE]: DatasourceGroup.OtherDatabase, + [IDataSourceType.DB2]: DatasourceGroup.OtherDatabase }; export const connectType2Ds: Map = new Map(); @@ -303,6 +316,7 @@ function initDatasource() { register(IDataSourceType.HANA, Hana); register(IDataSourceType.MongoDB, MongoDB); register(IDataSourceType.HIVE, Hive); + register(IDataSourceType.DB2, DB2); } function getAllConnectTypes(ds?: IDataSourceType): ConnectType[] { diff --git a/src/constant/label.ts b/src/constant/label.ts index 4380499e0..0c3cb0da7 100644 --- a/src/constant/label.ts +++ b/src/constant/label.ts @@ -151,7 +151,8 @@ export const ConnectTypeText = (type: ConnectType) => { id: 'src.constant.DM_LABEL', defaultMessage: '达梦(DM)' }), - [ConnectType.HANA]: 'SAP HANA' + [ConnectType.HANA]: 'SAP HANA', + [ConnectType.DB2]: 'DB2' }; return textMap?.[type]; }; diff --git a/src/d.ts/datasource.ts b/src/d.ts/datasource.ts index a918187a9..7183b8d7d 100644 --- a/src/d.ts/datasource.ts +++ b/src/d.ts/datasource.ts @@ -60,5 +60,6 @@ export enum IDataSourceType { DM = 'DM', HANA = 'HANA', MongoDB = 'mongodb', - HIVE = 'HIVE' + HIVE = 'HIVE', + DB2 = 'DB2' } diff --git a/src/d.ts/index.ts b/src/d.ts/index.ts index 5801565b9..6c007d069 100644 --- a/src/d.ts/index.ts +++ b/src/d.ts/index.ts @@ -774,6 +774,7 @@ export enum ConnectionMode { SQL_SERVER = 'SQL_SERVER', DM = 'DM', HANA = 'HANA', + DB2 = 'DB2', ALL = 'ALL', UNKNOWN = 'UNKNOWN' } @@ -3568,7 +3569,8 @@ export enum ConnectType { DM = 'DM', HANA = 'HANA', MONGODB = 'MONGODB', - HIVE = 'HIVE' + HIVE = 'HIVE', + 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 59744e85d..e8c075574 100644 --- a/src/page/Workspace/SideBar/ResourceTree/DatabaseSearchModal/constant.ts +++ b/src/page/Workspace/SideBar/ResourceTree/DatabaseSearchModal/constant.ts @@ -90,6 +90,7 @@ export const objectTypeConfig = { [ConnectType.SQL_SERVER]: sqlServerObjectType, [ConnectType.HANA]: hanaObjectType, [ConnectType.HIVE]: [DbObjectType.table, DbObjectType.column], + [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 +