From 8b02ba003b61371b4d2b9d658cf76ce05058a8cb Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Thu, 13 Aug 2026 11:18:09 +0000 Subject: [PATCH] fix(generate): recognize NUMBER columns as numeric Closes #5283 --- apps/desktop/src/lib/dataGrid/dataGenerate.ts | 2 +- packages/app-tests/dataGenerate.test.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/lib/dataGrid/dataGenerate.ts b/apps/desktop/src/lib/dataGrid/dataGenerate.ts index 72b978581e..a418ac4e07 100644 --- a/apps/desktop/src/lib/dataGrid/dataGenerate.ts +++ b/apps/desktop/src/lib/dataGrid/dataGenerate.ts @@ -1166,7 +1166,7 @@ const KnownColumnPatterns: Array<{ pattern: RegExp; generatorKey: string }> = [ export function findGeneratorKey(columnName: string, dataType: string, isAutoIncrement?: boolean): string { if (isAutoIncrement) return "sequence"; const type = dataType.toLowerCase(); - const isNumeric = type.includes("int") || type === "smallint" || type === "bigint" || type.includes("bool") || type.includes("decimal") || type.includes("numeric") || type.includes("float") || type.includes("double") || type === "real"; + const isNumeric = /^number(?:\s*\([^)]*\))?$/.test(type.trim()) || type.includes("int") || type === "smallint" || type === "bigint" || type.includes("bool") || type.includes("decimal") || type.includes("numeric") || type.includes("float") || type.includes("double") || type === "real"; const isDateTime = type.includes("date") || type.includes("timestamp") || type === "time"; const isBinary = type.includes("binary") || type.includes("blob") || type.includes("bytea"); const isBoolType = type === "bool" || type === "boolean" || type === "bit" || type === "tinyint(1)"; diff --git a/packages/app-tests/dataGenerate.test.ts b/packages/app-tests/dataGenerate.test.ts index e1facf194c..c667d32c6f 100644 --- a/packages/app-tests/dataGenerate.test.ts +++ b/packages/app-tests/dataGenerate.test.ts @@ -1,6 +1,15 @@ import { strict as assert } from "node:assert"; import { test, vi } from "vitest"; -import { defaultGeneratorParams, displayGeneratedValue, generateTableData, generateValue, supportsGeneratedMultiRowValues } from "../../apps/desktop/src/lib/dataGrid/dataGenerate.ts"; +import { defaultGeneratorParams, displayGeneratedValue, findGeneratorKey, generateTableData, generateValue, supportsGeneratedMultiRowValues } from "../../apps/desktop/src/lib/dataGrid/dataGenerate.ts"; + +test("recognizes Oracle-compatible NUMBER column types as numeric", () => { + assert.equal(findGeneratorKey("value", "NUMBER"), "number"); + assert.equal(findGeneratorKey("value", "NUMBER(10)"), "number"); + assert.equal(findGeneratorKey("value", "NUMBER(18, 2)"), "number"); + assert.equal(findGeneratorKey("value", "NUMBER(10)", true), "sequence"); + assert.equal(findGeneratorKey("value", "serial_number_code"), "text"); + assert.equal(findGeneratorKey("value", "NUMBER CODE"), "text"); +}); test("enables default values for columns with schema defaults", () => { const params = defaultGeneratorParams(