fix(sql): preserve same-line TDSQL directives
This commit is contained in:
6 files changed
+145
-39
No files matched your search
@@ -1263,6 +1263,36 @@ describe("buildExecutionCandidates", () => {
|
||||
expect(splitSqlStatementRanges("/*proxy*/", "mysql")).toEqual([]);
|
||||
});
|
||||
|
||||
it.each(["/*sets:allsets */", "/*master*/", "/*slave:set_1781591902_7*/", "/*future-route:anywhere*/"])("preserves a same-line TDSQL directive without relying on a keyword allowlist: %s", (directive) => {
|
||||
const directedSql = `${directive} SELECT count(*) FROM tenant_table`;
|
||||
const sql = `SELECT 1;\n${directedSql};\nSELECT 2;`;
|
||||
const candidates = buildExecutionCandidates(sql, indexOf(sql, "tenant_table"), "mysql");
|
||||
|
||||
expect(executionCandidateForMode(candidates, "current")?.sql).toBe(directedSql);
|
||||
expect(rangeSqlTexts(executableStatementRanges(sql, "mysql"))).toEqual(["SELECT 1", directedSql, "SELECT 2"]);
|
||||
});
|
||||
|
||||
it("handles long same-line directive chains without rescanning growing prefixes", () => {
|
||||
const prefix = "/**/".repeat(80_000);
|
||||
const sql = `${prefix} SELECT 1`;
|
||||
|
||||
expect(splitSqlStatementRanges(sql, "mysql")[0]?.sql).toBe(sql);
|
||||
});
|
||||
|
||||
it("does not preserve a generic TDSQL-style directive on a separate line", () => {
|
||||
const sql = "/*sets:allsets */\nSELECT count(*) FROM tenant_table";
|
||||
const candidates = buildExecutionCandidates(sql, indexOf(sql, "tenant_table"), "mysql");
|
||||
|
||||
expect(executionCandidateForMode(candidates, "current")?.sql).toBe("SELECT count(*) FROM tenant_table");
|
||||
});
|
||||
|
||||
it("does not preserve a same-line TDSQL-style directive for other database types", () => {
|
||||
const sql = "/*sets:allsets */ SELECT count(*) FROM tenant_table";
|
||||
const candidates = buildExecutionCandidates(sql, indexOf(sql, "tenant_table"), "postgres");
|
||||
|
||||
expect(executionCandidateForMode(candidates, "current")?.sql).toBe("SELECT count(*) FROM tenant_table");
|
||||
});
|
||||
|
||||
it.each(["/* ordinary */", "/*unknown*/", "/* proxy */", "/*PROXY*/"])("keeps %s as a non-executable leading comment", (comment) => {
|
||||
const sql = `${comment}\nSHOW PROXY STATUS`;
|
||||
const candidates = buildExecutionCandidates(sql, indexOf(sql, "STATUS"), "mysql");
|
||||
|
||||
Reference in new issue
Block a user