fix(query): single-column results editable on case-preserving engines
This commit is contained in:
5 files changed
+113
-7
No files matched your search
@@ -29,6 +29,25 @@ describe("editable query hidden primary keys", () => {
|
||||
expect(result?.projections.map((projection) => projection.alias)).toEqual(["__DBX_PK_1", "__DBX_PK_2"]);
|
||||
});
|
||||
|
||||
it("quotes the appended key with each reported engine's own dialect", () => {
|
||||
// #10233 reports OceanBase (Oracle mode), Dameng and HighGo. All three draw their
|
||||
// quoting from the dialect adapter rather than a hard-coded quote character:
|
||||
// Dameng/OceanBase Oracle mode ride the Oracle adapter, HighGo the PostgreSQL one.
|
||||
for (const databaseType of ["dameng", "oceanbase-oracle", "highgo"] as const) {
|
||||
expect(
|
||||
buildQueryWithHiddenPrimaryKeys({
|
||||
sql: "SELECT name FROM users",
|
||||
databaseType,
|
||||
primaryKeys: ["id"],
|
||||
existingResultNames: ["name"],
|
||||
}),
|
||||
).toEqual({
|
||||
sql: 'SELECT name, "id" AS "__DBX_PK_0" FROM users',
|
||||
projections: [{ sourceName: "id", alias: "__DBX_PK_0" }],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves SQL Server TOP and Oracle optimizer hints", () => {
|
||||
expect(
|
||||
buildQueryWithHiddenPrimaryKeys({
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveMetadataColumnName } from "@/lib/sql/sqlAnalysis";
|
||||
|
||||
/**
|
||||
* Dialect folding (Oracle-compatible -> upper case, PostgreSQL-compatible ->
|
||||
* lower case) is only an assumption about how the server stores an unquoted
|
||||
* identifier. Dameng keeps the case the identifier was created with, so a table
|
||||
* created as `(id int primary key, name varchar(50))` reports lowercase columns
|
||||
* while the analyzer folds the query's `name` to `NAME` (issue #10233). The
|
||||
* folded spelling must stay the primary answer, and a case-only match is only a
|
||||
* rescue when it identifies exactly one column.
|
||||
*/
|
||||
describe("metadata column name resolution tolerates server-preserved casing", () => {
|
||||
it("rescues a lowercase dameng column when the folded spelling does not exist", () => {
|
||||
expect(resolveMetadataColumnName("dameng", "name", false, ["id", "name", "amount"])).toBe("name");
|
||||
});
|
||||
|
||||
it("still prefers the folded spelling when the server stored upper case", () => {
|
||||
expect(resolveMetadataColumnName("dameng", "name", false, ["ID", "NAME"])).toBe("NAME");
|
||||
});
|
||||
|
||||
it("rescues a PostgreSQL-compatible engine that reports an upper-case column", () => {
|
||||
expect(resolveMetadataColumnName("highgo", "label", false, ["ID", "LABEL"])).toBe("LABEL");
|
||||
});
|
||||
|
||||
it("keeps PostgreSQL lower-case folding unchanged", () => {
|
||||
expect(resolveMetadataColumnName("highgo", "Label", false, ["id", "label"])).toBe("label");
|
||||
});
|
||||
|
||||
it("refuses a case-only match that is ambiguous", () => {
|
||||
expect(resolveMetadataColumnName("dameng", "value", false, ["value", "Value"])).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps quoted identifiers exact", () => {
|
||||
expect(resolveMetadataColumnName("dameng", "name", true, ["NAME"])).toBeUndefined();
|
||||
expect(resolveMetadataColumnName("dameng", "NAME", true, ["NAME"])).toBe("NAME");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user