fix(sql): preserve Oracle identifier semantics in star expansion
This commit is contained in:
1 parent
3597a00759
commit
aa4ed91c40
3 files changed
+81
-11
No files matched your search
@@ -334,7 +334,76 @@ describe("SELECT star expansion", () => {
|
||||
qualifierSql,
|
||||
databaseType,
|
||||
),
|
||||
).toBe(`id, ${qualifierSql}.${quotedColumn}`);
|
||||
).toBe(`${databaseType === "oracle" ? '"id"' : "id"}, ${qualifierSql}.${quotedColumn}`);
|
||||
});
|
||||
|
||||
it("does not quote all-uppercase Oracle columns when expanding alias.* (regression #9163)", () => {
|
||||
const sql = "SELECT t.* FROM device_table AS t";
|
||||
const cursor = sql.indexOf("*") + 1;
|
||||
const context = sqlCompletionContextFromSemantic(buildSqlSemanticModel(sql, cursor, { databaseType: "oracle", dialect: "mysql" }), getSqlCompletionContext(sql, cursor, { databaseType: "oracle", dialect: "mysql" }));
|
||||
|
||||
expect(
|
||||
buildSelectStarExpansion(
|
||||
context,
|
||||
new Map([
|
||||
[
|
||||
"device_table",
|
||||
[
|
||||
{ name: "AGENT_NAME", table: "device_table" },
|
||||
{ name: "PROTOCOL", table: "device_table" },
|
||||
{ name: "created at", table: "device_table" },
|
||||
],
|
||||
],
|
||||
]),
|
||||
"mysql",
|
||||
"t",
|
||||
"oracle",
|
||||
),
|
||||
).toBe('AGENT_NAME, t.PROTOCOL, t."created at"');
|
||||
});
|
||||
|
||||
it("does not quote all-uppercase Oracle columns for an unqualified star when only databaseType is set", () => {
|
||||
const sql = "SELECT * FROM device_table";
|
||||
const cursor = "SELECT *".length;
|
||||
const context = sqlCompletionContextFromSemantic(buildSqlSemanticModel(sql, cursor, { databaseType: "oracle" }), getSqlCompletionContext(sql, cursor, { databaseType: "oracle" }));
|
||||
|
||||
expect(
|
||||
buildSelectStarExpansion(
|
||||
context,
|
||||
new Map([
|
||||
[
|
||||
"device_table",
|
||||
[
|
||||
{ name: "AGENT_NAME", table: "device_table" },
|
||||
{ name: "SPARE1", table: "device_table" },
|
||||
],
|
||||
],
|
||||
]),
|
||||
undefined,
|
||||
undefined,
|
||||
"oracle",
|
||||
),
|
||||
).toBe("AGENT_NAME, SPARE1");
|
||||
});
|
||||
|
||||
it.each([
|
||||
["oracle", "mysql"],
|
||||
["oracle", undefined],
|
||||
[undefined, "oracle"],
|
||||
] as const)("preserves required Oracle column quotes with databaseType %s and dialect %s", (databaseType, dialect) => {
|
||||
const columnsByTable = new Map([["orders", ["OrderId", "order_id", "AGENT_NAME", "SELECT", "created at", "ACCOUNT$SYS"].map((name) => ({ name, table: "orders" }))]]);
|
||||
const contextOptions = { databaseType, dialect: "mysql" as const };
|
||||
|
||||
for (const [sql, expected] of [
|
||||
["SELECT o.* FROM orders o", '"OrderId", o."order_id", o.AGENT_NAME, o."SELECT", o."created at", o.ACCOUNT$SYS'],
|
||||
["SELECT * FROM orders", '"OrderId", "order_id", AGENT_NAME, "SELECT", "created at", ACCOUNT$SYS'],
|
||||
]) {
|
||||
const cursor = sql.indexOf("*") + 1;
|
||||
const context = sqlCompletionContextFromSemantic(buildSqlSemanticModel(sql, cursor, contextOptions), getSqlCompletionContext(sql, cursor, contextOptions));
|
||||
|
||||
expect(buildSelectStarExpansion(context, columnsByTable, dialect, context.qualifier, databaseType)).toBe(expected);
|
||||
expect(buildSelectStarExpansion(context, new Map(), dialect, context.qualifier, databaseType)).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it("expands an unqualified star from result columns when the table has an alias", () => {
|
||||
|
||||
Reference in new issue
Block a user