fix(editor): locate SQL errors after pagination rewriting

This commit is contained in:
zipg authored and GitHub committed 2026-09-08 01:43:13 +08:00
1 parent 3ae1548de0
commit 2e72bee9a1
4 files changed
+55 -3

No files matched your search

+24 -1
View File
@@ -1,6 +1,6 @@
import { strict as assert } from "node:assert";
import { test } from "vitest";
import { parseSqlErrorLocation, sqlErrorDecorationRange } from "../../apps/desktop/src/lib/sql/sqlDiagnostics.ts";
import { parseSqlErrorLocation, sqlErrorDecorationRange, sqlErrorSqlMatchesEditor } from "../../apps/desktop/src/lib/sql/sqlDiagnostics.ts";
test("locates the Oracle invalid identifier reported by the Agent", () => {
const sql = "select x.* from si_price_adjust_task t;";
@@ -44,6 +44,29 @@ test("rejects malformed or out-of-range Oracle Agent positions", () => {
test("keeps existing line-column and PostgreSQL caret parsing", () => {
assert.deepEqual(parseSqlErrorLocation("syntax error at line 2, column 4"), { line: 1, column: 3 });
assert.deepEqual(parseSqlErrorLocation("ERROR 1064: syntax error near 'LIMIT 100' at line 3"), { line: 2, column: 0 });
assert.deepEqual(parseSqlErrorLocation('ERROR: column "bad" does not exist\nLINE 3: SELECT bad\n ^'), { line: 2, column: 15 });
assert.deepEqual(sqlErrorDecorationRange("SELECT 1\nFROM bad", "syntax error at line 2, column 2"), { from: 10, to: 11 });
});
test("matches DBX pagination rewrites without accepting unrelated stale SQL", () => {
const editorSql = "SELECT *\nFROM projects\nWHERE ;";
const executedSql = "SELECT *\nFROM projects\nWHERE LIMIT 100;";
assert.equal(sqlErrorSqlMatchesEditor(editorSql, executedSql), true);
assert.equal(sqlErrorSqlMatchesEditor(editorSql, "SELECT *\nFROM other_table\nWHERE LIMIT 100;"), false);
});
test("matches the user's own LIMIT when the SQL differs only by a semicolon", () => {
const editorSql = "SELECT *\nFROM projects\nLIMIT 10";
const executedSql = "SELECT *\nFROM projects\nLIMIT 10;";
assert.equal(sqlErrorSqlMatchesEditor(editorSql, executedSql), true);
});
test("strips the generated OFFSET ROWS FETCH FIRST suffix fully", () => {
const editorSql = "SELECT *\nFROM projects";
const executedSql = "SELECT *\nFROM projects OFFSET 10 ROWS FETCH FIRST 5 ROWS ONLY;";
assert.equal(sqlErrorSqlMatchesEditor(editorSql, executedSql), true);
});