fix(sql): keep set operation statements together across newlines
Co-authored-by: zipg <4047349+zipg@users.noreply.github.com>
This commit is contained in:
1 parent
f2c429afd9
commit
bc16f784ad
2 files changed
+196
No files matched your search
@@ -205,6 +205,21 @@ describe("statementRangeAtCursor", () => {
|
||||
expect(range?.sql.trim()).toBe("SELECT 2");
|
||||
});
|
||||
|
||||
it("keeps newline set-operation SELECT operands with the cursor statement", () => {
|
||||
const sql = "select * from tbA\nunion\nselect * from tbB";
|
||||
const expected = "select * from tbA\nunion\nselect * from tbB";
|
||||
|
||||
expect(statementRangeAtCursor(sql, indexOf(sql, "tbA"))?.sql.trim()).toBe(expected);
|
||||
expect(statementRangeAtCursor(sql, indexOf(sql, "tbB"))?.sql.trim()).toBe(expected);
|
||||
});
|
||||
|
||||
it("keeps newline set-operation operands with ALL modifiers together", () => {
|
||||
const sql = "select * from tbA\nunion all\nselect * from tbB\nSELECT * FROM logs;";
|
||||
const range = statementRangeAtCursor(sql, indexOf(sql, "tbA"));
|
||||
|
||||
expect(range?.sql.trim()).toBe("select * from tbA\nunion all\nselect * from tbB");
|
||||
});
|
||||
|
||||
it("keeps a multi-line select together when continuation lines do not start statements", () => {
|
||||
const sql = "SELECT id,\n name\nFROM users\nWHERE active = 1\nSELECT * FROM logs;";
|
||||
const range = statementRangeAtCursor(sql, indexOf(sql, "name"));
|
||||
@@ -416,6 +431,13 @@ describe("buildExecutionCandidates", () => {
|
||||
expect(candidates[0].kind).toBe("all");
|
||||
});
|
||||
|
||||
it("uses the whole set-operation statement for cursor execution candidates", () => {
|
||||
const sql = "select * from tbA\nunion\nselect * from tbB\nSELECT * FROM logs;";
|
||||
const candidates = buildExecutionCandidates(sql, indexOf(sql, "tbA"));
|
||||
|
||||
expect(candidateSummaries(candidates)).toEqual(["cursor:select * from tbA\nunion\nselect * from tbB", "all:select * from tbA\nunion\nselect * from tbB\nSELECT * FROM logs;"]);
|
||||
});
|
||||
|
||||
it("uses the current command line for Redis cursor candidates", () => {
|
||||
const sql = "GET user:1\nDEL user:2\nHGETALL user:3";
|
||||
const candidates = buildExecutionCandidates(sql, indexOf(sql, "user:2"), "redis");
|
||||
|
||||
Reference in new issue
Block a user