diff --git a/src/page/Workspace/components/SQLPage/index.tsx b/src/page/Workspace/components/SQLPage/index.tsx index 10093dff..8d4864de 100644 --- a/src/page/Workspace/components/SQLPage/index.tsx +++ b/src/page/Workspace/components/SQLPage/index.tsx @@ -18,6 +18,7 @@ import { getDataSourceModeConfigByConnectionMode } from '@/common/datasource'; import { newScript, updateScript } from '@/common/network'; import { executeSQL, runSQLLint } from '@/common/network/sql'; import { executeTaskManager } from '@/common/network/sql/executeSQL'; +import { IExecuteTaskResult } from '@/common/network/sql/preHandle'; import { batchGetDataModifySQL } from '@/common/network/table'; import { ProfileType } from '@/component/ExecuteSqlDetailModal/constant'; import ExecuteSQLModal from '@/component/ExecuteSQLModal'; @@ -51,10 +52,11 @@ import SessionStore from '@/store/sessionManager/session'; import setting, { SettingStore } from '@/store/setting'; import type { SQLStore } from '@/store/sql'; import { isConnectionModeBeMySQLType } from '@/util/connection'; +import { isLogicalDatabase } from '@/util/database'; import utils, { EHighLight } from '@/util/editor'; import { formatMessage } from '@/util/intl'; import notification from '@/util/notification'; -import { splitSql } from '@/util/sql'; +import { splitSqlForHighlight } from '@/util/sql'; import { generateAndDownloadFile, getCurrentSQL } from '@/util/utils'; import { message, Spin } from 'antd'; import { debounce, isNil } from 'lodash'; @@ -68,8 +70,6 @@ import Trace from '../Trace'; import ExecDetail from './ExecDetail'; import ExecPlan from './ExecPlan'; import styles from './index.less'; -import { isLogicalDatabase } from '@/util/database'; -import { IExecuteTaskResult } from '@/common/network/sql/preHandle'; interface ISQLPageState { resultHeight: number; @@ -1344,7 +1344,7 @@ export class SQLPage extends Component { for (let i = 0; i < results?.length; i++) { const result = results[i]; if (result.status !== ISqlExecuteResultStatus.SUCCESS) { - const sqlIndexs = await splitSql( + const sqlIndexs = await splitSqlForHighlight( this.editor.getValue(), session.connection?.dialectType === ConnectionMode.MYSQL, session?.params?.delimiter, diff --git a/src/util/sql.ts b/src/util/sql.ts index 8910901f..e8684b7a 100644 --- a/src/util/sql.ts +++ b/src/util/sql.ts @@ -14,12 +14,12 @@ * limitations under the License. */ +import { getDataSourceModeConfig } from '@/common/datasource'; import { PLType } from '@/constant/plType'; -import { ConnectType, ConnectionMode, DbObjectType, IFormatPLSchema, IPLParam } from '@/d.ts'; +import { ConnectionMode, ConnectType, DbObjectType, IFormatPLSchema, IPLParam } from '@/d.ts'; import moment from 'moment'; import { Oracle } from './dataType'; import { getQuoteTableName } from './utils'; -import { getDataSourceModeConfig } from '@/common/datasource'; /** * 把一段输入多行注释掉,并且在首行添加comment信息。 @@ -264,6 +264,23 @@ export async function splitSql( }); } +export async function splitSqlForHighlight( + sql: string, + isOracle: boolean = false, + delimiter, +): Promise { + const { SQLDocument } = await import('@oceanbase-odc/ob-parser-js'); + const doc = new SQLDocument({ + text: sql, + delimiter: delimiter, + }); + return doc?.statements + ?.filter((stmt) => !stmt.isDelimiter) + .map((stmt) => { + return stmt.stop + (stmt.delimiter?.length || 0); + }); +} + export function getRealTableName(tableName: string, isOracle: boolean = true) { return getRealNameInDatabase(tableName, isOracle, false); }