Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(sql): preserve leading tenant routing hints

t8y24aa36cb893d5
diff --git a/apps/desktop/src/lib/__tests__/sql/sqlStatementRanges.spec.ts b/apps/desktop/src/lib/__tests__/sql/sqlStatementRanges.spec.ts
index c71564df2a..5d450479b6 100644
--- a/apps/desktop/src/lib/__tests__/sql/sqlStatementRanges.spec.ts
+++ b/apps/desktop/src/lib/__tests__/sql/sqlStatementRanges.spec.ts
@@ -1095,6 +1095,15 @@ describe("buildExecutionCandidates", () => {
expect(candidates[0].sql).toBe(hintedSql);
});
+ it("preserves leading tenant routing hints in current statement candidates", () => {
+ const hintedSql = "/*@global:true*/\nSELECT * FROM tenant_table";
+ const sql = `SELECT 1;\n${hintedSql};`;
+ const candidates = buildExecutionCandidates(sql, indexOf(sql, "tenant_table"), "mysql");
+
+ expect(candidates[0].sql).toBe(hintedSql);
+ expect(splitSqlStatementRanges("/*@global:true*/", "mysql")).toEqual([]);
+ });
+
it("uses the cursor statement for the first candidate when there is no selection", () => {
const sql = "SELECT *\nFROM users\nWHERE active = 1";
const candidates = buildExecutionCandidates(sql, indexOf(sql, "users"));
diff --git a/apps/desktop/src/lib/sql/sqlStatementRanges.ts b/apps/desktop/src/lib/sql/sqlStatementRanges.ts
index 10d045ad6e..a1ecb87511 100644
--- a/apps/desktop/src/lib/sql/sqlStatementRanges.ts
+++ b/apps/desktop/src/lib/sql/sqlStatementRanges.ts
@@ -444,7 +444,8 @@ export function splitSqlStatementRanges(sql: string, databaseType?: DatabaseType
}
// Block comments consume until the closing */.
if (ch === "/" && next === "*") {
- if (statementStart === -1 && pendingHintStart === -1 && sql[i + 2] === "+") pendingHintStart = i;
+ const hintMarker = sql[i + 2];
+ if (statementStart === -1 && pendingHintStart === -1 && (hintMarker === "+" || hintMarker === "@")) pendingHintStart = i;
const close = sql.indexOf("*/", i + 2);
i = close === -1 ? len : close + 2;
continue;