Files
MyGoNavi/frontend/src/components/tableDesignerExecutionSql.ts
Syngnat 56b3112a07 🐛 fix(oracle): 修复表结构注释读取与保存报错
- 补齐 Oracle 表字段注释元数据读取

- 在表结构 DDL 中追加表和字段注释信息

- 规范表设计器 Oracle DDL 执行前的分号处理

Refs #482
2026-05-23 17:41:46 +08:00

38 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { isOracleLikeDialect } from '../utils/sqlDialect';
export const splitSchemaExecutionStatements = (sqlText: string): string[] => (
String(sqlText || '')
.replace(//g, ';')
.split(/;\s*\n/)
.map(statement => statement.trim())
.filter(Boolean)
);
export const normalizeSchemaStatementForExecution = (statement: string, dbType: string): string => {
const trimmed = String(statement || '').trim();
if (!trimmed) return '';
if (isOracleLikeDialect(dbType)) {
return trimmed.replace(/;+\s*$/, '').trim();
}
return trimmed.endsWith(';') ? trimmed : `${trimmed};`;
};
const unescapeSqlComment = (text: string, mysqlBackslashEscapes = false): string => {
const unescaped = text.replace(/''/g, "'");
return mysqlBackslashEscapes ? unescaped.replace(/\\'/g, "'") : unescaped;
};
export const parseTableCommentFromDDL = (ddlText: string): string => {
const ddl = String(ddlText || '').replace(/\r?\n/g, ' ');
const mysqlMatch = ddl.match(/COMMENT\s*=\s*'((?:\\'|''|[^'])*)'/i);
if (mysqlMatch) {
return unescapeSqlComment(mysqlMatch[1], true);
}
const commentOnTableMatch = ddl.match(/\bCOMMENT\s+ON\s+TABLE\s+.+?\s+IS\s+(NULL|'((?:''|[^'])*)')/i);
if (!commentOnTableMatch || commentOnTableMatch[1].toUpperCase() === 'NULL') {
return '';
}
return unescapeSqlComment(commentOnTableMatch[2] || '');
};