fix(sql-analysis): tolerate Oracle admin DDL in diagnostics
This commit is contained in:
9 files changed
+241
-99
No files matched your search
@@ -507,7 +507,7 @@ FROM (
|
||||
autoAliasTables: true,
|
||||
});
|
||||
|
||||
expect(items.find((item) => item.label === "order_items")?.apply).toBe("order_items AS oi2");
|
||||
expect(items.find((item) => item.label === "order_items")?.apply).toBe("order_items oi2");
|
||||
});
|
||||
|
||||
it("omits generated aliases on a DELETE target table (issue #9186)", () => {
|
||||
@@ -576,7 +576,7 @@ FROM (
|
||||
autoAliasTables: true,
|
||||
});
|
||||
|
||||
expect(items.find((item) => item.label === "order_items")?.apply).toBe("order_items AS oi");
|
||||
expect(items.find((item) => item.label === "order_items")?.apply).toBe("order_items oi");
|
||||
});
|
||||
|
||||
it("keeps generated aliases after a multi-table DELETE target list", () => {
|
||||
@@ -585,7 +585,7 @@ FROM (
|
||||
autoAliasTables: true,
|
||||
});
|
||||
|
||||
expect(items.find((item) => item.label === "order_items")?.apply).toBe("order_items AS oi");
|
||||
expect(items.find((item) => item.label === "order_items")?.apply).toBe("order_items oi");
|
||||
});
|
||||
|
||||
it("keeps generated aliases on FROM and JOIN sources", () => {
|
||||
@@ -598,8 +598,8 @@ FROM (
|
||||
autoAliasTables: true,
|
||||
});
|
||||
|
||||
expect(joined.items.find((item) => item.label === "order_items")?.apply).toBe("order_items AS oi");
|
||||
expect(queried.items.find((item) => item.label === "DH_MODEL_CAP")?.apply).toBe("DH_MODEL_CAP AS dmc");
|
||||
expect(joined.items.find((item) => item.label === "order_items")?.apply).toBe("order_items oi");
|
||||
expect(queried.items.find((item) => item.label === "DH_MODEL_CAP")?.apply).toBe("DH_MODEL_CAP dmc");
|
||||
});
|
||||
|
||||
it("preserves dialect-aware identifier quoting in apply text", () => {
|
||||
|
||||
@@ -674,7 +674,7 @@ describe("sqlCompletion table aliases", () => {
|
||||
});
|
||||
|
||||
const table = items.find((item) => item.label === "materials_order_item" && item.type === "table");
|
||||
expect(table?.apply).toBe("materials_order_item AS moi");
|
||||
expect(table?.apply).toBe("materials_order_item moi");
|
||||
});
|
||||
|
||||
it("uses every word initial for longer multi-word names", () => {
|
||||
@@ -686,7 +686,7 @@ describe("sqlCompletion table aliases", () => {
|
||||
});
|
||||
|
||||
const table = items.find((item) => item.label === "super_long_customer_order_history_archive_snapshot_daily_replica" && item.type === "table");
|
||||
expect(table?.apply).toBe("super_long_customer_order_history_archive_snapshot_daily_replica AS slcohasdr");
|
||||
expect(table?.apply).toBe("super_long_customer_order_history_archive_snapshot_daily_replica slcohasdr");
|
||||
});
|
||||
|
||||
it("applies generated aliases to table completions when enabled", () => {
|
||||
@@ -698,7 +698,7 @@ describe("sqlCompletion table aliases", () => {
|
||||
});
|
||||
|
||||
const table = items.find((item) => item.label === "order_items" && item.type === "table");
|
||||
expect(table?.apply).toBe("order_items AS oi");
|
||||
expect(table?.apply).toBe("order_items oi");
|
||||
});
|
||||
|
||||
it("omits AS from Oracle table alias completions", () => {
|
||||
@@ -772,7 +772,7 @@ describe("sqlCompletion table aliases", () => {
|
||||
});
|
||||
|
||||
const table = items.find((item) => item.label === "order_items" && item.type === "table");
|
||||
expect(table?.apply).toBe("order_items AS oi2");
|
||||
expect(table?.apply).toBe("order_items oi2");
|
||||
});
|
||||
|
||||
it("applies generated aliases in comma-separated FROM table lists", () => {
|
||||
@@ -784,7 +784,7 @@ describe("sqlCompletion table aliases", () => {
|
||||
});
|
||||
|
||||
const table = items.find((item) => item.label === "order_items" && item.type === "table");
|
||||
expect(table?.apply).toBe("order_items AS oi");
|
||||
expect(table?.apply).toBe("order_items oi");
|
||||
});
|
||||
|
||||
it("does not apply generated aliases to non-query table completions", () => {
|
||||
@@ -798,6 +798,25 @@ describe("sqlCompletion table aliases", () => {
|
||||
const table = items.find((item) => item.label === "order_items" && item.type === "table");
|
||||
expect(table?.apply).toBe("order_items");
|
||||
});
|
||||
|
||||
it("emits table aliases without AS on every dialect (issue #9525)", () => {
|
||||
// `FROM orders AS o` is rejected by Oracle and the Oracle-compatible profiles, while the
|
||||
// implicit form is accepted everywhere, so generated SQL must use it for all dialects.
|
||||
for (const databaseType of ["postgres", "mysql", "sqlserver", "oracle", "sqlite", "clickhouse"] as const) {
|
||||
const sql = "SELECT * FROM ord";
|
||||
const items = buildSqlCompletionItems(sql, sql.length, {
|
||||
databaseType,
|
||||
tables: [{ name: "order_items", type: "table" }],
|
||||
columnsByTable: new Map(),
|
||||
autoAliasTables: true,
|
||||
});
|
||||
|
||||
const table = items.find((item) => item.label === "order_items" && item.type === "table");
|
||||
// Oracle additionally double-quotes the identifier to preserve its stored case.
|
||||
expect(table?.apply, databaseType).not.toContain(" AS ");
|
||||
expect(table?.apply, databaseType).toMatch(/order_items"? oi$/);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("sqlCompletion scoped context classification", () => {
|
||||
|
||||
Reference in new issue
Block a user