fix(sql): respect PostgreSQL ARRAY brackets

This commit is contained in:
jearhe authored and GitHub committed 2026-08-22 14:01:46 +08:00
1 parent 11179676ed
commit f274a599ed
6 files changed
+282 -57

No files matched your search

+16
View File
@@ -60,6 +60,22 @@ describe("expandSqlVariables", () => {
expect(expandSqlVariables(sql)).toEqual({ sql, expanded: false });
});
it("keeps PostgreSQL ARRAY literals from corrupting later variable references", () => {
const sql = ["@set selected = 7;", "select ARRAY[']']::varchar[], @selected, ${missing}"].join("\n");
expect(expandSqlVariables(sql, { databaseType: "postgres" }).sql).toBe("select ARRAY[']']::varchar[], 7, ${missing}");
});
it("keeps multiline PostgreSQL ARRAY values in @set declarations", () => {
const sql = ["@set values = ARRAY[", " 'first',", " 'second'", "];", "select @values;"].join("\n");
expect(expandSqlVariables(sql, { databaseType: "postgres" }).sql).toBe("select ARRAY[\n 'first',\n 'second'\n];");
});
it.each(["sqlserver", "sqlite", "jdbc"] as const)("preserves %s bracket identifiers during variable expansion", (databaseType) => {
const sql = ["@set selected = 7;", "select [column:@ignored], @selected"].join("\n");
expect(expandSqlVariables(sql, { databaseType }).sql).toBe("select [column:@ignored], 7");
});
it("keeps a value's own quotes and parentheses intact", () => {
const sql = ["@set filter = (status = 'drafted' and deleted_at is null);", "select * from t where @filter"].join("\n");
expect(expandSqlVariables(sql).sql).toBe("select * from t where (status = 'drafted' and deleted_at is null)");