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(grid): preserve MySQL tinyint numeric edits

t8y20047d79974a8
diff --git a/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts
index 6bd30f2751..742414768c 100644
--- a/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts
+++ b/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts
@@ -77,6 +77,17 @@ describe("coerceDataGridCellValue", () => {
).toBe(true);
});
+ it.each(["0", "1"])("keeps numeric MySQL TINYINT(1) edits numeric for %s", (value) => {
+ expect(
+ coerceDataGridCellValue({
+ value,
+ oldValue: 0,
+ databaseType: "mysql",
+ columnInfo: { data_type: "TINYINT(1)" },
+ }),
+ ).toBe(Number(value));
+ });
+
it.each([
["missing numeric metadata", 1, undefined, "2", 2],
["empty numeric metadata", 1, { data_type: "" }, "2", 2],
diff --git a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
index e9a1dfa346..4e5a0cd8c3 100644
--- a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
+++ b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
@@ -27,7 +27,9 @@ export function coerceDataGridCellValue(options: CoerceDataGridCellValueOptions)
const numericInput = isNumericColumnType(options.columnInfo?.data_type) || (useSampledValueType && typeof oldValue === "number");
const numericText = normalizeGroupedNumberText(value, options.columnInfo, oldValue);
if (isBooleanInputColumn(options) || (useSampledValueType && typeof oldValue === "boolean")) {
- const booleanValue = parseBooleanInput(numericText);
+ // MySQL exposes TINYINT(1) as an integer in the grid. Keep its numeric
+ // 0/1 edits numeric while still accepting explicit TRUE/FALSE aliases.
+ const booleanValue = parseBooleanInput(numericText, !isMysqlTinyintOneColumn(options));
if (booleanValue !== undefined) return booleanValue;
}
if (numericInput) {
@@ -50,10 +52,16 @@ function isBooleanInputColumn(options: CoerceDataGridCellValueOptions): boolean
return options.databaseType === "mysql" && options.columnInfo?.data_type.trim().toLowerCase() === "tinyint(1)";
}
-function parseBooleanInput(value: string): boolean | undefined {
+function isMysqlTinyintOneColumn(options: CoerceDataGridCellValueOptions): boolean {
+ return options.databaseType === "mysql" && options.columnInfo?.data_type.trim().toLowerCase() === "tinyint(1)";
+}
+
+function parseBooleanInput(value: string, allowNumericAliases: boolean): boolean | undefined {
const normalized = value.trim().toLowerCase();
- if (normalized === "true" || normalized === "1") return true;
- if (normalized === "false" || normalized === "0") return false;
+ if (normalized === "true") return true;
+ if (normalized === "false") return false;
+ if (allowNumericAliases && normalized === "1") return true;
+ if (allowNumericAliases && normalized === "0") return false;
return undefined;
}