🐛 fix(oracle): 修复DDL注释拼接缺少分号与换行

- 为 Oracle 建表 DDL 追加注释前补齐语句结束符并保留空行分隔
- 修复 COMMENT ON TABLE/COLUMN 与 CREATE TABLE 粘连导致复制后无法直接执行的问题
- 补充后端 Oracle 建表语句与前端 DDL 格式化回归测试
This commit is contained in:
Syngnat
2026-06-24 11:40:18 +08:00
committed by tianqijiuyun-latiao
parent d2c4160c6d
commit 32c3ba017e
3 changed files with 29 additions and 1 deletions

View File

@@ -19,4 +19,18 @@ describe('formatDdlForDisplay', () => {
expect(formatDdlForDisplay(raw, 'duckdb')).toBe(raw);
});
it('keeps Oracle comment statements separated from create table DDL', () => {
const raw = `CREATE TABLE "H2"."S_BUSI" (
"ID" NUMBER
) TABLESPACE "H2DB";
COMMENT ON TABLE "H2"."S_BUSI" IS '业务机构信息';
COMMENT ON COLUMN "H2"."S_BUSI"."ID" IS '主键';`;
const formatted = formatDdlForDisplay(raw, 'oracle');
expect(formatted).toContain('TABLESPACE "H2DB";\n\nCOMMENT ON TABLE "H2"."S_BUSI"');
expect(formatted).toContain(`COMMENT ON COLUMN "H2"."S_BUSI"."ID" IS '主键';`);
});
});

View File

@@ -317,4 +317,7 @@ ORDER BY c.column_id`] = oracleRecordingQueryResult{
t.Fatalf("expected DDL to contain %q, got: %s", want, ddl)
}
}
if !strings.Contains(ddl, ");\n\nCOMMENT ON TABLE") {
t.Fatalf("expected Oracle DDL comments to be separated by a statement terminator and blank line, got: %s", ddl)
}
}

View File

@@ -589,7 +589,18 @@ func (o *OracleDB) appendOracleCommentDDL(baseDDL string, dbName string, tableNa
if len(commentLines) == 0 {
return baseDDL
}
return strings.TrimRight(baseDDL, " \t\r\n") + "\n" + strings.Join(commentLines, "\n")
return ensureOracleDDLStatementTerminator(baseDDL) + "\n\n" + strings.Join(commentLines, "\n")
}
func ensureOracleDDLStatementTerminator(ddl string) string {
trimmed := strings.TrimRight(ddl, " \t\r\n")
if trimmed == "" {
return trimmed
}
if strings.HasSuffix(trimmed, ";") || strings.HasSuffix(trimmed, "/") {
return trimmed
}
return trimmed + ";"
}
func (o *OracleDB) fetchOracleTableComment(schema string, table string) string {