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(grid): load full PostgreSQL preview values before building rollback SQL (#13024)
Jeff022bd4fb45d6
diff --git a/apps/desktop/src/composables/__tests__/useDataGridLargeValues.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridLargeValues.spec.tsindex 24a0045122..b707b977ed 100644--- a/apps/desktop/src/composables/__tests__/useDataGridLargeValues.spec.ts+++ b/apps/desktop/src/composables/__tests__/useDataGridLargeValues.spec.ts@@ -64,7 +64,7 @@ function mountLargeValues(databaseType: DatabaseType, result: Ref<QueryResult>,databaseType: computed(() => databaseType),connectionId: computed(() => `${databaseType}-1`),executionDatabase: computed(() => "MAXIMO"),- resultSourceColumns: computed(() => ["ID", "APP"]),+ resultSourceColumns: computed(() => result.value.columns),allColumnTypes: computed(() => result.value.column_types ?? []),renderedGridColumns: computed(() => []),showTranspose: ref(false),@@ -371,6 +371,66 @@ describe("useDataGridLargeValues", () => {expect(mocks.readLargeValueChunk).toHaveBeenCalledWith(expect.objectContaining({ valueRef: "original-locator", connectionId: "oracle-1", clientSessionId: "original-session" }));});+ it("loads full PostgreSQL preview values before clear SQL generation so rollback keeps the original", async () => {+ const full = JSON.stringify(Array.from({ length: 50 }, (_, n) => ({ date: "2026-10-15", n })));+ const result = previewResult("json", `${full.slice(0, 18)}...`, full.length);+ const { largeValues } = mountLargeValues("postgres", result);+ const first = result.value.rows[0];+ const dirtyRows = new Map([[0, new Map([[1, null]])]]);+ mocks.buildDataGridContextFilterCondition.mockResolvedValue('"ID" = 1');+ mocks.buildTableSelectSql.mockResolvedValue('SELECT * FROM "public"."APP_DATA" WHERE ("ID" = 1) LIMIT 1');+ mocks.executeMulti.mockResolvedValue([{ columns: ["ID", "APP"], rows: [[1, full]], affected_rows: 0, execution_time_ms: 1 }]);++ await largeValues.prepareSaveBaseline({ dirtyRows, deletedRows: new Set() });++ expect(result.value.rows[0]).toBe(first);+ expect(result.value.rows[0]![1]).toBe(full);+ expect(dirtyRows.get(0)!.get(1)).toBeNull();+ expect(result.value.large_value_cells).toEqual([]);+ expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(expect.not.objectContaining({ largeValuePreviewSize: expect.anything() }));+ expect(mocks.readLargeValueChunk).not.toHaveBeenCalled();+ });++ it("loads every PostgreSQL preview of a deleted row and leaves untouched previews alone", async () => {+ const result = previewResult("jsonb", "[1, 2...", 4096);+ result.value.columns.push("DOC");+ result.value.column_types!.push("json");+ result.value.rows[0]!.push('{"a"...');+ result.value.rows.push([2, "[3, 4...", '{"b"...']);+ result.value.large_value_cells = [+ { row_index: 0, column_index: 1, original_bytes: 4096 },+ { row_index: 0, column_index: 2, original_bytes: 4096 },+ { row_index: 1, column_index: 1, original_bytes: 4096 },+ { row_index: 1, column_index: 2, original_bytes: 4096 },+ ];+ const { largeValues } = mountLargeValues("postgres", result);+ mocks.buildDataGridContextFilterCondition.mockResolvedValue('"ID" = 1');+ mocks.buildTableSelectSql.mockResolvedValue('SELECT * FROM "public"."APP_DATA" WHERE ("ID" = 1) LIMIT 1');+ mocks.executeMulti.mockResolvedValue([{ columns: ["ID", "APP", "DOC"], rows: [[1, "[1, 2, 3]", '{"a": 1}']], affected_rows: 0, execution_time_ms: 1 }]);++ await largeValues.prepareSaveBaseline({ dirtyRows: new Map(), deletedRows: new Set([0]) });++ expect(result.value.rows[0]).toEqual([1, "[1, 2, 3]", '{"a": 1}']);+ expect(result.value.rows[1]).toEqual([2, "[3, 4...", '{"b"...']);+ expect(result.value.large_value_cells).toEqual([+ { row_index: 1, column_index: 1, original_bytes: 4096 },+ { row_index: 1, column_index: 2, original_bytes: 4096 },+ ]);+ });++ it("blocks save and keeps the PostgreSQL preview when its full value cannot be loaded", async () => {+ const result = previewResult("json", '{"date":"2026-10-1...', 4096);+ const { largeValues } = mountLargeValues("postgres", result);+ mocks.buildDataGridContextFilterCondition.mockResolvedValue('"ID" = 1');+ mocks.buildTableSelectSql.mockResolvedValue('SELECT * FROM "public"."APP_DATA" WHERE ("ID" = 1) LIMIT 1');+ mocks.executeMulti.mockResolvedValue([{ columns: ["ID", "APP"], rows: [], affected_rows: 0, execution_time_ms: 1 }]);++ await expect(largeValues.prepareSaveBaseline({ dirtyRows: new Map([[0, new Map([[1, null]])]]), deletedRows: new Set() })).rejects.toThrow("grid.largeValueRowUnavailable");++ expect(result.value.rows[0]).toEqual([1, '{"date":"2026-10-1...']);+ expect(result.value.large_value_cells).toHaveLength(1);+ });+it("blocks save on expired snapshots and keeps every original preview for retry", async () => {const result = previewResult("CLOB", "preview", 1);result.value.large_value_context = { connectionId: "oracle-1", database: "MAXIMO" };diff --git a/apps/desktop/src/composables/useDataGridLargeValues.ts b/apps/desktop/src/composables/useDataGridLargeValues.tsindex d625c197ca..1f80924ddd 100644--- a/apps/desktop/src/composables/useDataGridLargeValues.ts+++ b/apps/desktop/src/composables/useDataGridLargeValues.ts@@ -94,7 +94,7 @@ export interface LargeValueSnapshotDownloadTarget {}const materializedSnapshotBytes = new WeakMap<QueryResult, Map<string, number>>();type LargeValueCellRequest = {- item: LargeValueRowItem;+ rowId: number;sourceIndex: number;columnIndex: number;originalBytes: number;@@ -331,7 +331,7 @@ export function useDataGridLargeValues(options: UseDataGridLargeValuesOptions) {if (sourceColumn && !selectedColumns.some((column) => column.toLocaleLowerCase() === sourceColumn.toLocaleLowerCase())) selectedColumns.push(sourceColumn);}const selectedColumnTypes = selectedColumns.map((column) => tableMeta.columns.find((candidate) => candidate.name.toLocaleLowerCase() === column.toLocaleLowerCase())?.data_type ?? "");- const predicates = await Promise.all([...requests.values()].map((request) => largeValueRowPredicate(request.item, primaryKeyIndexes)));+ const predicates = await Promise.all([...requests.values()].map((request) => largeValueRowPredicate(request.sourceIndex, primaryKeyIndexes)));if (!visibleLargeValuePreviewActive || generation !== visibleLargeValuePreviewRequestedGeneration || options.result.value !== sourceResult) return;const sql = await buildTableSelectSql({databaseType: options.databaseType.value,@@ -480,8 +480,8 @@ export function useDataGridLargeValues(options: UseDataGridLargeValuesOptions) {return chunks;}- async function largeValueRowPredicate(item: LargeValueRowItem, primaryKeyIndexes: number[]): Promise<string> {- const originalRow = item.sourceIndex === undefined ? undefined : options.result.value.rows[item.sourceIndex];+ async function largeValueRowPredicate(sourceIndex: number, primaryKeyIndexes: number[]): Promise<string> {+ const originalRow = options.result.value.rows[sourceIndex];if (!originalRow) throw new Error(options.translate("grid.largeValueRowUnavailable"));const tableMeta = options.tableMeta.value!;const conditions = await Promise.all(@@ -504,7 +504,7 @@ export function useDataGridLargeValues(options: UseDataGridLargeValuesOptions) {const tableMeta = options.tableMeta.value!;const sourceColumn = options.resultSourceColumns.value[columnIndex];if (!sourceColumn) throw new Error(options.translate("grid.largeValueColumnUnavailable"));- const predicates = await Promise.all(requests.map((request) => largeValueRowPredicate(request.item, primaryKeyIndexes)));+ const predicates = await Promise.all(requests.map((request) => largeValueRowPredicate(request.sourceIndex, primaryKeyIndexes)));const selectedColumns = [...new Set([...tableMeta.primaryKeys, sourceColumn])];const sql = await buildTableSelectSql({databaseType: options.databaseType.value,@@ -545,9 +545,9 @@ export function useDataGridLargeValues(options: UseDataGridLargeValuesOptions) {const originalRow = options.result.value.rows[request.sourceIndex];const identity = originalRow ? largeValueIdentityKey(originalRow, primaryKeyIndexes) : "";if (!valuesByIdentity.has(identity)) throw new Error(options.translate("grid.largeValueRowUnavailable"));- const rowValues = resolved.get(request.item.id) ?? new Map<number, CellValue>();+ const rowValues = resolved.get(request.rowId) ?? new Map<number, CellValue>();rowValues.set(columnIndex, valuesByIdentity.get(identity) ?? null);- resolved.set(request.item.id, rowValues);+ resolved.set(request.rowId, rowValues);}}@@ -589,7 +589,7 @@ export function useDataGridLargeValues(options: UseDataGridLargeValuesOptions) {continue;}const requests = requestsByColumn.get(columnIndex) ?? [];- requests.push({ item, sourceIndex: item.sourceIndex, columnIndex, originalBytes: metadata.original_bytes });+ requests.push({ rowId: item.id, sourceIndex: item.sourceIndex, columnIndex, originalBytes: metadata.original_bytes });requestsByColumn.set(columnIndex, requests);}}@@ -722,8 +722,57 @@ export function useDataGridLargeValues(options: UseDataGridLargeValuesOptions) {});}+ /**+ * Rollback statements are built from the baseline rows, so a changed or deleted+ * cell that still holds a truncated server preview (no `value_ref`, e.g.+ * PostgreSQL json/text) must be replaced with its full value first. Otherwise+ * the recorded rollback SQL carries the `...`-suffixed preview (issue #12964).+ */+ async function preparePreviewSaveBaseline(changes: { dirtyRows: ReadonlyMap<number, ReadonlyMap<number, CellValue>>; deletedRows: ReadonlySet<number> }, signal: AbortSignal): Promise<void> {+ const source = options.result.value;+ const cells = (source.large_value_cells ?? []).filter((cell) => !cell.value_ref && (changes.deletedRows.has(cell.row_index) || changes.dirtyRows.get(cell.row_index)?.has(cell.column_index)));+ if (!cells.length) return;+ const connectionId = options.connectionId.value;+ const database = options.executionDatabase.value;+ const tableMeta = options.tableMeta.value;+ if (!connectionId || !tableMeta?.tableName || tableMeta.primaryKeys.length === 0) throw new Error(options.translate("grid.largeValueNeedsRowIdentifier"));+ const primaryKeyIndexes = tableMeta.primaryKeys.map(largeValueSourceColumnIndex);+ if (primaryKeyIndexes.some((index) => index < 0)) throw new Error(options.translate("grid.largeValueNeedsRowIdentifier"));+ const operation = options.resultLifecycle.beginOperation();+ const isCurrent = () => !signal.aborted && options.result.value === source && options.connectionId.value === connectionId && options.executionDatabase.value === database && options.resultLifecycle.isCurrent(operation);+ const requestsByColumn = new Map<number, LargeValueCellRequest[]>();+ for (const cell of cells) {+ const requests = requestsByColumn.get(cell.column_index) ?? [];+ // Keyed by source index: this map never leaves the function.+ requests.push({ rowId: cell.row_index, sourceIndex: cell.row_index, columnIndex: cell.column_index, originalBytes: cell.original_bytes });+ requestsByColumn.set(cell.column_index, requests);+ }+ const resolved: ResolvedLargeValueCells = new Map();+ for (const [columnIndex, requests] of requestsByColumn) {+ for (const chunk of chunkLargeValueRequests(requests)) {+ await fetchLargeValueRequestChunk(columnIndex, chunk, primaryKeyIndexes, resolved);+ if (!isCurrent()) throw new Error("LOB result context changed");+ }+ }+ // Preserve row identity so the editor keeps pending edits, deletes and undo history.+ for (const [sourceIndex, values] of resolved) {+ const row = source.rows[sourceIndex];+ if (!row) throw new Error(options.translate("grid.largeValueRowUnavailable"));+ for (const [columnIndex, value] of values) {+ row[columnIndex] = value;+ visibleLargeValuePreviewCaches.get(source)?.forget(sourceIndex, columnIndex);+ }+ }+ const resolvedKeys = new Set(cells.map((cell) => largeValueCellKey(cell.row_index, cell.column_index)));+ source.large_value_cells = source.large_value_cells?.filter((cell) => !resolvedKeys.has(largeValueCellKey(cell.row_index, cell.column_index)));+ options.largeValueResolutionVersion.value += 1;+ options.clearCellFormatCache();+ options.invalidateResultEstimate(source);+ }+async function prepareSaveBaseline(changes: { dirtyRows: ReadonlyMap<number, ReadonlyMap<number, CellValue>>; deletedRows: ReadonlySet<number> }): Promise<void> {const snapshotSignal = snapshotController.signal;+ await preparePreviewSaveBaseline(changes, snapshotSignal);const source = options.result.value;const cells = (source.large_value_cells ?? []).filter((cell) => cell.value_ref && (changes.deletedRows.has(cell.row_index) || changes.dirtyRows.get(cell.row_index)?.has(cell.column_index)));const context = source.large_value_context;