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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(sqlserver): preserve multi-result statement mapping
t8y2876e1b38b97c
diff --git a/apps/desktop/src/stores/__tests__/queryStore.multiStatementError.spec.ts b/apps/desktop/src/stores/__tests__/queryStore.multiStatementError.spec.tsindex 20ef0ca226..d275f54cf4 100644--- a/apps/desktop/src/stores/__tests__/queryStore.multiStatementError.spec.ts+++ b/apps/desktop/src/stores/__tests__/queryStore.multiStatementError.spec.ts@@ -473,6 +473,30 @@ describe("queryStore multi-statement errors", () => {});});+ it("maps SQL Server batch result sets by source order when statement indexes are unavailable", async () => {+ mocks.getConnectionConfig.mockReturnValue({+ id: "sqlserver-1",+ name: "SQL Server",+ db_type: "sqlserver",+ database: "app",+ query_timeout_secs: 30,+ });+ mocks.executeMulti.mockResolvedValue([+ { columns: ["id"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 },+ { columns: ["id"], rows: [[2]], affected_rows: 0, execution_time_ms: 1 },+ ]);+ const { useQueryStore } = await import("@/stores/queryStore");+ const store = useQueryStore();+ const tabId = store.createTab("sqlserver-1", "app", "Query");++ await store.executeTabSql(tabId, "SELECT * FROM users; SELECT * FROM orders");++ expect(store.tabs.find((item) => item.id === tabId)?.results).toMatchObject([+ { sourceStatement: "SELECT * FROM users", sourceLabel: "app.users" },+ { sourceStatement: "SELECT * FROM orders", sourceLabel: "app.orders" },+ ]);+ });+it("uses Name comments for their indexed query results", async () => {mocks.executeMulti.mockResolvedValue([{ columns: ["id"], rows: [[2]], affected_rows: 0, execution_time_ms: 1, statement_index: 1 },diff --git a/crates/dbx-core/src/query.rs b/crates/dbx-core/src/query.rsindex 5118c48170..b5c7675ff3 100644--- a/crates/dbx-core/src/query.rs+++ b/crates/dbx-core/src/query.rs@@ -2422,6 +2422,10 @@ fn empty_query_result(execution_time_ms: u128) -> db::QueryResult {}}+fn sqlserver_batch_results(results: Vec<db::QueryResult>) -> Vec<ExecuteMultiResult> {+ results.into_iter().map(ExecuteMultiResult::from).collect()+}+async fn execute_multi_sqlserver(state: &AppState,pool_key: &str,@@ -2438,12 +2442,12 @@ async fn execute_multi_sqlserver(let query_timeout = resolve_query_timeout(options.timeout_secs);let execution_mode = options.execution_mode;- for (statement_index, batch) in batches.iter().enumerate() {+ for batch in &batches {if is_canceled(&cancel_token) {let error = canceled_error();all_results.push(ExecuteMultiResult::execution_error_with_backend(error_query_result(error.clone()),- Some(statement_index),+ None,crate::backend_error::BackendError::from_legacy_backend(&error),));break;@@ -2462,7 +2466,7 @@ async fn execute_multi_sqlserver(Err(err) => {all_results.push(ExecuteMultiResult::execution_error_with_backend(error_query_result(err.clone()),- Some(statement_index),+ None,crate::backend_error::BackendError::from_legacy_backend(&err),));break;@@ -2473,7 +2477,7 @@ async fn execute_multi_sqlserver(let error = "SQL Server connection was reset while waiting for the query lock; please retry.".to_string();all_results.push(ExecuteMultiResult::execution_error_with_backend(error_query_result(error.clone()),- Some(statement_index),+ None,crate::backend_error::BackendError::from_legacy_backend(&error),));break;@@ -2490,14 +2494,12 @@ async fn execute_multi_sqlserver(drop(client_guard);match result {- Ok(results) => all_results.extend(- results.into_iter().map(|result| ExecuteMultiResult::success_with_index(result, statement_index)),- ),+ Ok(results) => all_results.extend(sqlserver_batch_results(results)),Err(e) => {let action = pool_error_action(Some(DatabaseType::SqlServer), &e);all_results.push(ExecuteMultiResult::execution_error_with_backend(error_query_result(e.clone()),- Some(statement_index),+ None,crate::backend_error::BackendError::from_legacy_backend(&e),));if matches!(action, PoolErrorAction::Discard | PoolErrorAction::ReconnectAndRetry) {@@ -4968,6 +4970,15 @@ for line in sys.stdin:assert!(redacted.get("error").and_then(|value| value.get("detail")).is_none());}+ #[test]+ fn sqlserver_batch_results_do_not_claim_statement_indexes() {+ assert_eq!(split_sql_batches("SELECT 1; SELECT 2;").len(), 1);++ let results = sqlserver_batch_results(vec![empty_query_result(1), empty_query_result(2)]);++ assert_eq!(results.iter().map(|result| result.statement_index).collect::<Vec<_>>(), vec![None, None]);+ }+#[test]fn query_execution_error_preserves_structured_catalog_identity() {let error = QueryExecutionError::Agent(AgentCallError::Structured {