From 872569265d7903a7f48b75f7bd26da07bde6c3a0 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Sun, 24 May 2026 10:28:01 +0800 Subject: [PATCH] fix(sql): add databaseType parameter to findStatementAtCursor function --- apps/desktop/src/App.vue | 1 + apps/desktop/src/lib/http.ts | 8 ++++++-- apps/desktop/src/lib/sqlExecutionTarget.ts | 5 +++-- apps/desktop/src/lib/tauri.ts | 8 ++++++-- packages/app-tests/sqlStatementBackend.test.ts | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue index 7d8925c639..fee10312b6 100644 --- a/apps/desktop/src/App.vue +++ b/apps/desktop/src/App.vue @@ -173,6 +173,7 @@ async function resolveActiveExecutableSql() { ? await resolveExecutableSqlWithBackend(tab.sql, selectedSql.value, { mode: settingsStore.editorSettings.executeMode, cursorPos: cursorPos.value, + databaseType: activeConnection.value?.db_type, }) : ""; } diff --git a/apps/desktop/src/lib/http.ts b/apps/desktop/src/lib/http.ts index 5bce01dd66..b7c83a7633 100644 --- a/apps/desktop/src/lib/http.ts +++ b/apps/desktop/src/lib/http.ts @@ -462,8 +462,12 @@ export async function analyzeSqlReferences(sql: string, dialect?: string): Promi return post("/api/query/analyze-sql-references", { sql, dialect }); } -export async function findStatementAtCursor(sql: string, cursorPos: number): Promise { - return post("/api/query/find-statement-at-cursor", { sql, cursorPos }); +export async function findStatementAtCursor( + sql: string, + cursorPos: number, + databaseType?: DatabaseType, +): Promise { + return post("/api/query/find-statement-at-cursor", { sql, cursorPos, databaseType }); } export async function prepareQueryPaginationExecutionPlan( diff --git a/apps/desktop/src/lib/sqlExecutionTarget.ts b/apps/desktop/src/lib/sqlExecutionTarget.ts index d687dbc283..2e5e861258 100644 --- a/apps/desktop/src/lib/sqlExecutionTarget.ts +++ b/apps/desktop/src/lib/sqlExecutionTarget.ts @@ -1,4 +1,5 @@ import * as api from "./api"; +import type { DatabaseType } from "@/types/database"; export type ExecuteMode = "all" | "current"; @@ -20,13 +21,13 @@ export function resolveExecutableSql( export async function resolveExecutableSqlWithBackend( fullSql: string, selectedSql: string, - options?: { mode?: ExecuteMode; cursorPos?: number }, + options?: { mode?: ExecuteMode; cursorPos?: number; databaseType?: DatabaseType }, ): Promise { const trimmedSelection = selectedSql.trim(); if (trimmedSelection) return trimmedSelection; if (options?.mode === "current" && options.cursorPos !== undefined) { - return await api.findStatementAtCursor(fullSql, options.cursorPos); + return await api.findStatementAtCursor(fullSql, options.cursorPos, options.databaseType); } return fullSql; diff --git a/apps/desktop/src/lib/tauri.ts b/apps/desktop/src/lib/tauri.ts index a4a3746eda..2c627d7441 100644 --- a/apps/desktop/src/lib/tauri.ts +++ b/apps/desktop/src/lib/tauri.ts @@ -416,8 +416,12 @@ export async function analyzeSqlReferences(sql: string, dialect?: string): Promi return invoke("analyze_sql_references", { sql, dialect }); } -export async function findStatementAtCursor(sql: string, cursorPos: number): Promise { - return invoke("find_statement_at_cursor", { sql, cursorPos }); +export async function findStatementAtCursor( + sql: string, + cursorPos: number, + databaseType?: DatabaseType, +): Promise { + return invoke("find_statement_at_cursor", { sql, cursorPos, databaseType }); } export async function prepareQueryPaginationExecutionPlan( diff --git a/packages/app-tests/sqlStatementBackend.test.ts b/packages/app-tests/sqlStatementBackend.test.ts index 4fcd18b3df..a9cfe0c04a 100644 --- a/packages/app-tests/sqlStatementBackend.test.ts +++ b/packages/app-tests/sqlStatementBackend.test.ts @@ -19,7 +19,7 @@ test("shared API exposes backend current statement resolution", () => { }); test("execution target prefers backend current statement resolution", () => { - assert.match(executionTargetSource, /api\.findStatementAtCursor\(fullSql, options\.cursorPos\)/); + assert.match(executionTargetSource, /api\.findStatementAtCursor\(fullSql, options\.cursorPos, options\.databaseType\)/); assert.doesNotMatch(executionTargetSource, /sqlStatementSplit/); assert.doesNotMatch(executionTargetSource, /return findStatementAtCursor\(fullSql, options\.cursorPos\)/); });