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(data-grid): preserve NULL when clearing numeric cells
Momentary_SixthSense6dbd8a133761
diff --git a/apps/desktop/src/composables/__tests__/useDataGridEditor.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridEditor.spec.tsindex 4f54899b41..7e1b3d7444 100644--- a/apps/desktop/src/composables/__tests__/useDataGridEditor.spec.ts+++ b/apps/desktop/src/composables/__tests__/useDataGridEditor.spec.ts@@ -53,6 +53,7 @@ function createEditorWithResult(quickEntry = false,editable = ref(true),resultColumnTypes?: string[],+ databaseType: import("@/types/database").DatabaseType = "postgres",) {let editor: ReturnType<typeof useDataGridEditor>;const result = ref<{ columns: string[]; rows: CellValue[][]; column_types?: string[] }>({@@ -64,7 +65,7 @@ function createEditorWithResult(editor = useDataGridEditor({result: computed(() => result.value),editable: computed(() => editable.value),- databaseType: computed(() => (mongoCollectionGrid ? "mongodb" : "postgres")),+ databaseType: computed(() => (mongoCollectionGrid ? "mongodb" : databaseType)),normalizeEditorInput: mongoCollectionGrid ? mongoDocumentGridInputValue : undefined,connectionId: computed(() => "connection-1"),database: computed(() => "app"),@@ -149,6 +150,47 @@ describe("useDataGridEditor searched replacements", () => {mocks.getConfig.mockReturnValue(undefined);});+ it("stages a cleared DB2 integer as NULL through inline edit and save preparation (#13755)", async () => {+ const editor = createEditor(+ undefined,+ true,+ undefined,+ undefined,+ [[639522, "keep", "last"]],+ undefined,+ [+ { name: "first", data_type: "INT" },+ { name: "hidden", data_type: "VARCHAR" },+ { name: "last", data_type: "VARCHAR" },+ ],+ false,+ false,+ ref(true),+ undefined,+ "db2",+ );+ editor.newRows.value = [];+ editor.startEdit(0, 0);+ editor.editValue.value = "";+ editor.commitEdit();+ expect(editor.dirtyRows.value.get(0)?.get(0)).toBeNull();+ expect(editor.hasPendingChanges.value).toBe(true);++ mocks.prepareDataGridSave.mockResolvedValue({ statements: [], rollbackStatements: [] });+ await editor.previewChanges();+ expect(mocks.prepareDataGridSave).toHaveBeenCalledWith(expect.objectContaining({ databaseType: "db2", dirtyRows: [[0, [[0, null]]]] }), undefined);++ editor.undoPendingChange();+ expect(editor.dirtyRows.value.size).toBe(0);+ editor.redoPendingChange();+ expect(editor.dirtyRows.value.get(0)?.get(0)).toBeNull();++ editor.startEdit(0, 0);+ editor.editValue.value = "0";+ editor.commitEdit();+ expect(editor.dirtyRows.value.get(0)?.get(0)).toBe(0);+ });+it.each([true, false])("blocks queued saves while row identity is pending (autoSave=%s)", async (autoSave) => {const editable = ref(true);const editor = createEditor(undefined, true, undefined, undefined, [["old", "keep", "last"]], undefined, undefined, false, false, editable);diff --git a/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.tsindex c1328f62f6..1708f5c956 100644--- a/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts+++ b/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts@@ -142,6 +142,33 @@ describe("dataGridCellDisplayText", () => {});describe("coerceDataGridCellValue", () => {+ it.each([+ ["INT", 639522],+ ["INTEGER", "639522"],+ ["SMALLINT", 12],+ ["BIGINT", "9007199254740993"],+ ["DECIMAL(31,2)", "639522.00"],+ ["DOUBLE", 1.5],+ [undefined, 639522],+ ])("clears a DB2 %s numeric cell to NULL (#13755)", (dataType, oldValue) => {+ for (const value of ["", " ", "\t\n"]) {+ expect(+ coerceDataGridCellValue({+ value,+ oldValue,+ databaseType: "db2",+ columnInfo: dataType ? { data_type: dataType } : undefined,+ preserveEmptyString: true,+ }),+ ).toBeNull();+ }+ });++ it("keeps explicit DB2 zero and empty text distinct from a cleared numeric cell", () => {+ expect(coerceDataGridCellValue({ value: "0", oldValue: 639522, databaseType: "db2", columnInfo: { data_type: "INT" } })).toBe(0);+ expect(coerceDataGridCellValue({ value: "", oldValue: "before", databaseType: "db2", columnInfo: { data_type: "VARCHAR(32)" } })).toBe("");+ });+it.each(["Integer", "Long", "int"])("keeps Neo4j %s edits as exact text for the Cypher builder", (data_type) => {for (const value of ["1001", "9007199254740999", "9223372036854775807", "-9223372036854775808"]) {expect(coerceDataGridCellValue({ value, oldValue: "1", databaseType: "neo4j", columnInfo: { data_type } })).toBe(value);diff --git a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.tsindex bf296c8815..38c7236963 100644--- a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts+++ b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts@@ -38,6 +38,9 @@ export function coerceDataGridCellValue(options: CoerceDataGridCellValueOptions)// the precision checks below so exact values survive as text.const useSampledValueType = normalizeDataType(options.columnInfo?.data_type) === "";const numericInput = isNumericColumnType(options.columnInfo?.data_type) || (useSampledValueType && typeof oldValue === "number");+ // A cleared numeric cell is SQL NULL; Number("") and Number(" ") would+ // otherwise silently turn it into zero (#13755).+ if (numericInput && value.trim() === "") return null;const numericText = normalizeGroupedNumberText(value, options.columnInfo, oldValue, options.numberFormat ?? runtimeNumberFormat());// Neo4j INTEGER is always signed 64-bit. Keep its input as text until the// Cypher builder validates it, including values outside JavaScript's range.