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。

feat(dataGrid): fix temporal cell editor precision

二丫讲梵90276464b273
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index 83f2de1301..f6a0ec7ebf 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -115,7 +115,7 @@ import { canFormatCellDetailJson, cellDetailEditorText, compactJsonText, default
import { renderWktOnCanvas, isHexGeometry } from "@/lib/dataGrid/geometryPreview";
import { buildDataGridCellDetail, buildDataGridColumnDetail, buildDataGridRowDetail, dataGridColumnDetailJson, dataGridColumnDetailTsv, dataGridRowDetailJson, dataGridRowDetailTsv, filterDataGridDetailFields, type DataGridCellDetail } from "@/lib/dataGrid/dataGridDetail";
import { applyColumnFormatter, buildColumnFormatterKey, normalizeColumnFormatter, resolveColumnFormatter, type ColumnFormatterConfig, type DateTimeFormatterUnit, DateTimePatterns } from "@/lib/dataGrid/columnFormatter";
-import { temporalCellEditorKind, type TemporalCellEditorKind } from "@/lib/dataGrid/dataGridTemporalEditor";
+import { temporalCellEditorConfig, type TemporalCellEditorConfig } from "@/lib/dataGrid/dataGridTemporalEditor";
import { isCancelSearchShortcut, isCopyCurrentRowShortcut, isDeleteCurrentRowShortcut, isFocusSearchShortcut, isModRShortcut, isSaveShortcut, isToggleTransposeShortcut } from "@/lib/editor/keyboardShortcuts";
import { dataGridHeaderContentWidth, scrollbarGutterWidth } from "@/lib/dataGrid/dataGridScrollGutter";
import { canGoNextDataGridPage } from "@/lib/dataGrid/dataGridPagination";
@@ -4066,8 +4066,8 @@ function resultColumnInfoForGridColumn(columnIndex: number): Pick<ColumnInfo, "d
return dataType ? { data_type: dataType } : undefined;
}
-function temporalEditorKindForColumn(columnIndex: number): TemporalCellEditorKind | undefined {
- return temporalCellEditorKind(tableColumnForGridColumn(columnIndex)?.data_type, props.databaseType);
+function temporalEditorConfigForColumn(columnIndex: number): TemporalCellEditorConfig | undefined {
+ return temporalCellEditorConfig(tableColumnForGridColumn(columnIndex), props.databaseType);
}
function enumValuesForGridColumn(columnIndex: number): string[] {
@@ -4928,9 +4928,9 @@ watch(activeCellDetail, (detail) => {
const detailEditValue = ref("");
const isEditingDetail = ref(false);
-const detailTemporalEditorKind = computed(() => {
+const detailTemporalEditorConfig = computed(() => {
const detail = activeCellDetail.value;
- return detail ? temporalEditorKindForColumn(detail.colIndex) : undefined;
+ return detail ? temporalEditorConfigForColumn(detail.colIndex) : undefined;
});
const sideDetailPrioritizesValue = computed(() => !cellDetailPanelIsBottom.value && !isEditingDetail.value && !!activeCellDetail.value?.formattedJson);
const sideDetailValueFillsHeight = computed(() => cellDetailPanelIsBottom.value || isEditingDetail.value || (!cellDetailPanelIsBottom.value && !activeCellDetail.value?.imagePreviewUrl));
@@ -9197,7 +9197,15 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
@dblclick.stop="canEditCellItem(displayItems[cell.recordIndex], cell.valueIndex) && startDomCellEdit(displayItems[cell.recordIndex].id, cell.valueIndex, cell.display, $event)"
>
<template v-if="editingCell?.rowId === displayItems[cell.recordIndex]?.id && editingCell?.col === cell.valueIndex">
- <TemporalCellEditor v-if="temporalEditorKindForColumn(cell.valueIndex)" v-model="editValue" :kind="temporalEditorKindForColumn(cell.valueIndex)!" cell-layout="transpose" @cancel="cancelEdit" @commit="commitGridEdit" />
+ <TemporalCellEditor
+ v-if="temporalEditorConfigForColumn(cell.valueIndex)"
+ v-model="editValue"
+ :kind="temporalEditorConfigForColumn(cell.valueIndex)!.kind"
+ :fraction-precision="temporalEditorConfigForColumn(cell.valueIndex)!.fractionPrecision"
+ cell-layout="transpose"
+ @cancel="cancelEdit"
+ @commit="commitGridEdit"
+ />
<EnumCellEditor v-else-if="isEnumGridColumn(cell.valueIndex)" v-model="editValue" :values="enumValuesForGridColumn(cell.valueIndex)" :nullable="isEnumGridColumnNullable(cell.valueIndex)" cell-layout="transpose" @cancel="cancelEdit" @commit="commitGridEdit" />
<textarea
v-else-if="cellUsesExpandedEditor(displayItems[cell.recordIndex]?.id, cell.valueIndex)"
@@ -9672,7 +9680,14 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
/>
<div ref="canvasOverlayRef" class="canvas-grid-overlay dbx-data-grid-font-family sticky left-0 top-0 z-10 overflow-visible" :style="canvasOverlayStyle">
<div v-if="canvasEditingCell" class="absolute pointer-events-auto z-20 tabular-nums" :style="canvasEditingCellStyle" @mousedown.stop @click.stop>
- <TemporalCellEditor v-if="temporalEditorKindForColumn(canvasEditingCell.actualColIdx)" v-model="editValue" :kind="temporalEditorKindForColumn(canvasEditingCell.actualColIdx)!" @cancel="cancelEdit" @commit="commitGridEdit" />
+ <TemporalCellEditor
+ v-if="temporalEditorConfigForColumn(canvasEditingCell.actualColIdx)"
+ v-model="editValue"
+ :kind="temporalEditorConfigForColumn(canvasEditingCell.actualColIdx)!.kind"
+ :fraction-precision="temporalEditorConfigForColumn(canvasEditingCell.actualColIdx)!.fractionPrecision"
+ @cancel="cancelEdit"
+ @commit="commitGridEdit"
+ />
<EnumCellEditor
v-else-if="isEnumGridColumn(canvasEditingCell.actualColIdx)"
v-model="editValue"
@@ -9815,7 +9830,14 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
@contextmenu="onCellContext(item.id, item.displayIndex, col.actualColIdx, col.visibleColIdx, $event)"
>
<template v-if="editingCell?.rowId === item.id && editingCell?.col === col.actualColIdx">
- <TemporalCellEditor v-if="temporalEditorKindForColumn(col.actualColIdx)" v-model="editValue" :kind="temporalEditorKindForColumn(col.actualColIdx)!" @cancel="cancelEdit" @commit="commitGridEdit" />
+ <TemporalCellEditor
+ v-if="temporalEditorConfigForColumn(col.actualColIdx)"
+ v-model="editValue"
+ :kind="temporalEditorConfigForColumn(col.actualColIdx)!.kind"
+ :fraction-precision="temporalEditorConfigForColumn(col.actualColIdx)!.fractionPrecision"
+ @cancel="cancelEdit"
+ @commit="commitGridEdit"
+ />
<EnumCellEditor v-else-if="isEnumGridColumn(col.actualColIdx)" v-model="editValue" :values="enumValuesForGridColumn(col.actualColIdx)" :nullable="isEnumGridColumnNullable(col.actualColIdx)" @cancel="cancelEdit" @commit="commitGridEdit" />
<textarea
v-else-if="cellUsesExpandedEditor(item.id, col.actualColIdx)"
@@ -10238,7 +10260,16 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
</div>
<template v-if="isEditingDetail">
<div class="min-h-0 flex-1" :style="sideDetailEditorStyle">
- <TemporalCellEditor v-if="detailTemporalEditorKind" v-model="detailEditValue" :kind="detailTemporalEditorKind" variant="inline" :commit-on-close="false" @cancel="cancelDetailEdit" @commit="commitDetailEdit" />
+ <TemporalCellEditor
+ v-if="detailTemporalEditorConfig"
+ v-model="detailEditValue"
+ :kind="detailTemporalEditorConfig.kind"
+ :fraction-precision="detailTemporalEditorConfig.fractionPrecision"
+ variant="inline"
+ :commit-on-close="false"
+ @cancel="cancelDetailEdit"
+ @commit="commitDetailEdit"
+ />
<div v-else ref="detailsEditorContainer" data-cell-detail-editor-root class="min-h-0 h-full w-full rounded border overflow-hidden" />
</div>
<div v-if="!cellDetailPanelIsBottom" class="flex shrink-0 gap-1 py-0.5">
@@ -10316,7 +10347,16 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
<TabsContent v-if="activeCellDetailTabs.includes('valueEditor')" value="valueEditor" class="m-0 min-h-0 flex-1 flex flex-col p-3 text-xs">
<div class="flex min-h-0 flex-1 flex-col">
- <TemporalCellEditor v-if="detailTemporalEditorKind" v-model="detailEditValue" :kind="detailTemporalEditorKind" variant="inline" :commit-on-close="false" @cancel="cancelValueEditorEdit" @commit="commitValueEditorEdit" />
+ <TemporalCellEditor
+ v-if="detailTemporalEditorConfig"
+ v-model="detailEditValue"
+ :kind="detailTemporalEditorConfig.kind"
+ :fraction-precision="detailTemporalEditorConfig.fractionPrecision"
+ variant="inline"
+ :commit-on-close="false"
+ @cancel="cancelValueEditorEdit"
+ @commit="commitValueEditorEdit"
+ />
<div v-else ref="valueEditorContainer" data-cell-detail-editor-root class="min-h-0 flex-1 w-full rounded border overflow-auto" />
</div>
<div class="flex gap-1 mt-2 shrink-0">
diff --git a/apps/desktop/src/components/grid/TemporalCellEditor.vue b/apps/desktop/src/components/grid/TemporalCellEditor.vue
index 0aac5ed15c..e8d9faf355 100644
--- a/apps/desktop/src/components/grid/TemporalCellEditor.vue
+++ b/apps/desktop/src/components/grid/TemporalCellEditor.vue
@@ -13,11 +13,13 @@ const props = withDefaults(
variant?: "cell" | "inline";
cellLayout?: "grid" | "transpose";
commitOnClose?: boolean;
+ fractionPrecision?: number;
}>(),
{
variant: "cell",
cellLayout: "grid",
commitOnClose: true,
+ fractionPrecision: 0,
},
);
@@ -37,6 +39,14 @@ let skipCommitOnClose = false;
const hasDate = computed(() => props.kind !== "time");
const hasTime = computed(() => props.kind !== "date");
+const normalizedFractionPrecision = computed(() => Math.max(0, Math.min(9, props.fractionPrecision || 0)));
+const existingFractionDigits = computed(() => parseFractionDigits(timeValue.value));
+const fractionInputLength = computed(() => normalizedFractionPrecision.value || existingFractionDigits.value.length);
+const fractionInputMaxLength = computed(() => Math.max(1, fractionInputLength.value));
+const showFractionInput = computed(() => hasTime.value && (normalizedFractionPrecision.value > 0 || existingFractionDigits.value.length > 0));
+const timeGridStyle = computed(() => ({
+ gridTemplateColumns: showFractionInput.value ? "3.5rem 0.5rem 3.5rem 0.5rem 3.5rem 0.5rem 5rem" : "3.5rem 0.5rem 3.5rem 0.5rem 3.5rem",
+}));
const editorRootClass = computed(() => (props.variant === "inline" ? "relative h-9 w-full" : "absolute inset-0 z-10"));
const inputClass = computed(() =>
props.variant === "inline"
@@ -64,7 +74,9 @@ const timeValue = computed(() => {
});
const timeParts = computed(() => {
- const [hour = "00", minute = "00", second = "00"] = timeValue.value.split(":");
+ const match = /^(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?$/.exec(timeValue.value);
+ if (!match) return { hour: "00", minute: "00", second: "00" };
+ const [, hour = "00", minute = "00", second = "00"] = match;
return { hour, minute, second };
});
@@ -118,7 +130,7 @@ function stepDate(part: "day" | "month" | "year", delta: number) {
function updateTime(part: "hour" | "minute" | "second", rawValue: string | number) {
const parts = { ...timeParts.value, [part]: normalizeTimePart(rawValue, part === "hour" ? 23 : 59) };
- const nextTime = `${parts.hour}:${parts.minute}:${parts.second}`;
+ const nextTime = `${parts.hour}:${parts.minute}:${parts.second}${fractionSuffix.value}`;
if (props.kind === "time") {
setModelValue(nextTime);
return;
@@ -134,6 +146,26 @@ function stepTime(part: "hour" | "minute" | "second", delta: number) {
setModelValue(stepTemporalInputValue(localValue.value, props.kind, part, delta));
}
+const fractionSuffix = computed(() => {
+ const digits = existingFractionDigits.value;
+ return digits ? `.${digits}` : "";
+});
+
+function updateFraction(event: Event) {
+ updateFractionValue((event.target as HTMLInputElement).value);
+}
+
+function updateFractionValue(rawValue: string) {
+ const maxLength = Math.max(1, fractionInputLength.value);
+ const digits = rawValue.replace(/\D/g, "").slice(0, maxLength);
+ const nextTime = `${timeParts.value.hour}:${timeParts.value.minute}:${timeParts.value.second}${digits ? `.${digits}` : ""}`;
+ if (props.kind === "time") {
+ setModelValue(nextTime);
+ return;
+ }
+ setDateTimeValue(dateParts.value.year, dateParts.value.month, dateParts.value.day, nextTime);
+}
+
function flushInputValue(target: EventTarget | null) {
if (!(target instanceof HTMLInputElement)) return;
const part = target.dataset.temporalPart;
@@ -141,6 +173,8 @@ function flushInputValue(target: EventTarget | null) {
updateDate(part, target.value);
} else if (part === "hour" || part === "minute" || part === "second") {
updateTime(part, target.value);
+ } else if (part === "fraction") {
+ updateFractionValue(target.value);
}
}
@@ -155,7 +189,7 @@ function setNull() {
function setNow() {
const now = new Date();
const dateText = [String(now.getFullYear()).padStart(4, "0"), String(now.getMonth() + 1).padStart(2, "0"), String(now.getDate()).padStart(2, "0")].join("-");
- const nextTime = [String(now.getHours()).padStart(2, "0"), String(now.getMinutes()).padStart(2, "0"), String(now.getSeconds()).padStart(2, "0")].join(":");
+ const nextTime = [String(now.getHours()).padStart(2, "0"), String(now.getMinutes()).padStart(2, "0"), String(now.getSeconds()).padStart(2, "0")].join(":") + nowFractionSuffix(now);
if (props.kind === "date") setModelValue(dateText);
else if (props.kind === "time") setModelValue(nextTime);
else setModelValue(`${dateText} ${nextTime}`);
@@ -234,6 +268,16 @@ function setDateTimeValue(year: number, month: number, day: number, time: string
else setModelValue(`${dateText} ${time}`);
}
+function parseFractionDigits(value: string): string {
+ return value.match(/\.(\d{1,9})/)?.[1] ?? "";
+}
+
+function nowFractionSuffix(now: Date): string {
+ const precision = normalizedFractionPrecision.value;
+ if (precision <= 0) return "";
+ return `.${String(now.getMilliseconds()).padStart(3, "0").padEnd(precision, "0").slice(0, precision)}`;
+}
+
function daysInMonth(year: number, month: number): number {
return new Date(year, month, 0).getDate();
}
@@ -295,7 +339,7 @@ function twoDigit(value: string | number): string {
</div>
</div>
- <div v-if="hasTime" class="grid grid-cols-[3.5rem_0.5rem_3.5rem_0.5rem_3.5rem] items-center gap-1.5">
+ <div v-if="hasTime" class="grid items-center gap-1.5" :style="timeGridStyle">
<div class="grid h-7 min-w-0 grid-cols-[1fr_1.35rem] overflow-hidden rounded-md border border-input bg-background">
<input :value="twoDigit(timeParts.hour)" data-temporal-part="hour" inputmode="numeric" class="min-w-0 bg-transparent px-1 text-center text-[13px] tabular-nums outline-none" @input="updateTimeFromInput('hour', $event)" />
<div class="grid border-l">
@@ -331,6 +375,12 @@ function twoDigit(value: string | number): string {
</button>
</div>
</div>
+ <template v-if="showFractionInput">
+ <span class="text-center text-xs text-muted-foreground">.</span>
+ <div class="grid h-7 min-w-0 overflow-hidden rounded-md border border-input bg-background">
+ <input :value="existingFractionDigits" data-temporal-part="fraction" inputmode="numeric" :maxlength="fractionInputMaxLength" class="min-w-0 bg-transparent px-1 text-center text-[13px] tabular-nums outline-none" placeholder="0" @input="updateFraction" />
+ </div>
+ </template>
</div>
<div class="flex items-center justify-between gap-1">
diff --git a/apps/desktop/src/lib/__tests__/dataGrid/dataGridTemporalEditor.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/dataGridTemporalEditor.spec.ts
new file mode 100644
index 0000000000..e545585960
--- /dev/null
+++ b/apps/desktop/src/lib/__tests__/dataGrid/dataGridTemporalEditor.spec.ts
@@ -0,0 +1,48 @@
+import { describe, expect, it } from "vitest";
+import { formatTemporalInputValue, parseTemporalInputValue, stepTemporalInputValue, temporalCellEditorConfig, temporalCellEditorKind } from "@/lib/dataGrid/dataGridTemporalEditor";
+
+describe("dataGridTemporalEditor", () => {
+ it("resolves temporal editor configs with fractional precision", () => {
+ expect(temporalCellEditorConfig("datetime(3)")).toEqual({ kind: "datetime", fractionPrecision: 3 });
+ expect(temporalCellEditorConfig("datetime2(7)")).toEqual({ kind: "datetime", fractionPrecision: 7 });
+ expect(temporalCellEditorConfig("timestamp(6)")).toEqual({ kind: "datetime", fractionPrecision: 6 });
+ expect(temporalCellEditorConfig("time(6)")).toEqual({ kind: "time", fractionPrecision: 6 });
+ expect(temporalCellEditorConfig("DateTime64(3)")).toEqual({ kind: "datetime", fractionPrecision: 3 });
+ });
+
+ it("uses column numeric scale for temporal fractional precision", () => {
+ expect(temporalCellEditorConfig({ data_type: "timestamp", numeric_scale: 6 })).toEqual({ kind: "datetime", fractionPrecision: 6 });
+ expect(temporalCellEditorConfig({ data_type: "time", numeric_scale: 3 })).toEqual({ kind: "time", fractionPrecision: 3 });
+ expect(temporalCellEditorConfig({ data_type: "timestamp(6)", numeric_scale: 2 })).toEqual({ kind: "datetime", fractionPrecision: 2 });
+ });
+
+ it("keeps the legacy kind-only helper", () => {
+ expect(temporalCellEditorKind("datetime(6)")).toBe("datetime");
+ expect(temporalCellEditorKind("date")).toBe("date");
+ expect(temporalCellEditorKind("varchar(64)")).toBeUndefined();
+ });
+
+ it("preserves fractional seconds when formatting and parsing datetime input", () => {
+ expect(formatTemporalInputValue("2026-07-09 12:34:56.123456", "datetime")).toBe("2026-07-09T12:34:56.123456");
+ expect(parseTemporalInputValue("2026-07-09T12:34:56.123456", "datetime")).toBe("2026-07-09 12:34:56.123456");
+ });
+
+ it("preserves fractional seconds when formatting and parsing time input", () => {
+ expect(formatTemporalInputValue("12:34:56.123456", "time")).toBe("12:34:56.123456");
+ expect(parseTemporalInputValue("12:34:56.123456", "time")).toBe("12:34:56.123456");
+ });
+
+ it("preserves fractional seconds while stepping date and time parts", () => {
+ const value = "2026-07-09 12:34:56.123456";
+
+ expect(stepTemporalInputValue(value, "datetime", "day", 1)).toBe("2026-07-10 12:34:56.123456");
+ expect(stepTemporalInputValue(value, "datetime", "hour", 1)).toBe("2026-07-09 13:34:56.123456");
+ expect(stepTemporalInputValue(value, "datetime", "second", 1)).toBe("2026-07-09 12:34:57.123456");
+ });
+
+ it("keeps ordinary datetime values at second precision", () => {
+ expect(temporalCellEditorConfig("datetime")).toEqual({ kind: "datetime", fractionPrecision: 0 });
+ expect(formatTemporalInputValue("2026-07-09 12:34:56", "datetime")).toBe("2026-07-09T12:34:56");
+ expect(parseTemporalInputValue("2026-07-09T12:34:56", "datetime")).toBe("2026-07-09 12:34:56");
+ });
+});
diff --git a/apps/desktop/src/lib/dataGrid/dataGridTemporalEditor.ts b/apps/desktop/src/lib/dataGrid/dataGridTemporalEditor.ts
index d2b208bda1..e03d92e7e9 100644
--- a/apps/desktop/src/lib/dataGrid/dataGridTemporalEditor.ts
+++ b/apps/desktop/src/lib/dataGrid/dataGridTemporalEditor.ts
@@ -1,18 +1,38 @@
-import type { DatabaseType } from "@/types/database";
+import type { ColumnInfo, DatabaseType } from "@/types/database";
export type TemporalCellEditorKind = "date" | "time" | "datetime";
+export type TemporalCellEditorColumn = Pick<ColumnInfo, "data_type" | "numeric_scale">;
-export function temporalCellEditorKind(dataType: string | undefined, _databaseType?: DatabaseType): TemporalCellEditorKind | undefined {
+export interface TemporalCellEditorConfig {
+ kind: TemporalCellEditorKind;
+ fractionPrecision: number;
+}
+
+export function temporalCellEditorConfig(columnOrDataType: string | TemporalCellEditorColumn | undefined, _databaseType?: DatabaseType): TemporalCellEditorConfig | undefined {
+ const dataType = temporalColumnDataType(columnOrDataType);
+ const numericScale = temporalColumnNumericScale(columnOrDataType);
const normalized = normalizeTemporalType(dataType);
if (!normalized) return undefined;
if (/\b(?:datetime|datetime2|datetime64|smalldatetime|datetimeoffset|timestamp|timestamptz)\b/.test(normalized)) {
- return "datetime";
+ return {
+ kind: "datetime",
+ fractionPrecision: normalized.includes("smalldatetime") ? 0 : temporalFractionPrecision(dataType, numericScale),
+ };
+ }
+ if (/\bdate(?:32)?\b/.test(normalized)) return { kind: "date", fractionPrecision: 0 };
+ if (/\b(?:time|timetz|time64)\b/.test(normalized)) {
+ return {
+ kind: "time",
+ fractionPrecision: temporalFractionPrecision(dataType, numericScale),
+ };
}
- if (/\bdate(?:32)?\b/.test(normalized)) return "date";
- if (/\b(?:time|timetz|time64)\b/.test(normalized)) return "time";
return undefined;
}
+export function temporalCellEditorKind(dataType: string | undefined, databaseType?: DatabaseType): TemporalCellEditorKind | undefined {
+ return temporalCellEditorConfig(dataType, databaseType)?.kind;
+}
+
export function formatTemporalInputValue(value: string | number | boolean | null, kind: TemporalCellEditorKind): string {
if (value === null || value === undefined) return "";
const text = String(value).trim();
@@ -27,9 +47,9 @@ export function formatTemporalInputValue(value: string | number | boolean | null
return normalizeTimeInput(text);
}
- const datetime = text.match(/^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2})(?::(\d{2}))?/);
+ const datetime = text.match(/^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2})(?::(\d{2})(\.\d{1,9})?)?/);
if (!datetime) return "";
- return `${datetime[1]}T${datetime[2]}:${datetime[3] ?? "00"}`;
+ return `${datetime[1]}T${datetime[2]}:${datetime[3] ?? "00"}${datetime[4] ?? ""}`;
}
export function parseTemporalInputValue(value: string, kind: TemporalCellEditorKind): string | null {
@@ -38,9 +58,9 @@ export function parseTemporalInputValue(value: string, kind: TemporalCellEditorK
if (kind === "date") return text;
if (kind === "time") return normalizeTimeInput(text) || text;
- const datetime = text.match(/^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2})(?::(\d{2}))?$/);
+ const datetime = text.match(/^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2})(?::(\d{2})(\.\d{1,9})?)?$/);
if (!datetime) return text;
- return `${datetime[1]} ${datetime[2]}:${datetime[3] ?? "00"}`;
+ return `${datetime[1]} ${datetime[2]}:${datetime[3] ?? "00"}${datetime[4] ?? ""}`;
}
export type TemporalCellEditorPart = "year" | "month" | "day" | "hour" | "minute" | "second";
@@ -59,7 +79,7 @@ export function stepTemporalInputValue(value: string, kind: TemporalCellEditorKi
dateParts.day = Math.max(1, Math.min(daysInMonth(dateParts.year, dateParts.month), dateParts.day));
const dateText = [String(dateParts.year).padStart(4, "0"), String(dateParts.month).padStart(2, "0"), String(dateParts.day).padStart(2, "0")].join("-");
- const timeText = [timeParts.hour, timeParts.minute, timeParts.second].map((item) => String(item).padStart(2, "0")).join(":");
+ const timeText = [timeParts.hour, timeParts.minute, timeParts.second].map((item) => String(item).padStart(2, "0")).join(":") + timeParts.fraction;
if (kind === "date") return dateText;
if (kind === "time") return timeText;
@@ -70,10 +90,30 @@ function normalizeTemporalType(dataType: string | undefined): string {
return (dataType ?? "").toLowerCase().replace(/_/g, "").replace(/[(),]/g, " ").replace(/\s+/g, " ").trim();
}
+function temporalColumnDataType(columnOrDataType: string | TemporalCellEditorColumn | undefined): string | undefined {
+ return typeof columnOrDataType === "string" ? columnOrDataType : columnOrDataType?.data_type;
+}
+
+function temporalColumnNumericScale(columnOrDataType: string | TemporalCellEditorColumn | undefined): number | null | undefined {
+ return typeof columnOrDataType === "string" ? undefined : columnOrDataType?.numeric_scale;
+}
+
+function temporalFractionPrecision(dataType: string | undefined, numericScale?: number | null): number {
+ if (numericScale !== null && numericScale !== undefined) return clampFractionPrecision(numericScale);
+ const precision = dataType?.match(/\((\d{1,2})/)?.[1];
+ if (!precision) return 0;
+ return clampFractionPrecision(Number(precision));
+}
+
+function clampFractionPrecision(value: number): number {
+ if (!Number.isFinite(value)) return 0;
+ return Math.max(0, Math.min(9, Math.trunc(value)));
+}
+
function normalizeTimeInput(text: string): string {
- const match = text.match(/^(\d{2}:\d{2})(?::(\d{2}))?/);
+ const match = text.match(/^(\d{2}:\d{2})(?::(\d{2})(\.\d{1,9})?)?/);
if (!match) return "";
- return `${match[1]}:${match[2] ?? "00"}`;
+ return `${match[1]}:${match[2] ?? "00"}${match[3] ?? ""}`;
}
function temporalDateParts(value: string): { year: number; month: number; day: number } {
@@ -86,10 +126,11 @@ function temporalDateParts(value: string): { year: number; month: number; day: n
return { year: Number(match[1]), month: Number(match[2]), day: Number(match[3]) };
}
-function temporalTimeParts(value: string, kind: TemporalCellEditorKind): { hour: number; minute: number; second: number } {
+function temporalTimeParts(value: string, kind: TemporalCellEditorKind): { hour: number; minute: number; second: number; fraction: string } {
const time = kind === "time" ? formatTemporalInputValue(value, "time") || "00:00:00" : formatTemporalInputValue(value, "datetime").split("T")[1] || "00:00:00";
- const [hour = "00", minute = "00", second = "00"] = time.split(":");
- return { hour: Number(hour) || 0, minute: Number(minute) || 0, second: Number(second) || 0 };
+ const match = /^(\d{2}):(\d{2}):(\d{2})(\.\d{1,9})?$/.exec(time);
+ if (!match) return { hour: 0, minute: 0, second: 0, fraction: "" };
+ return { hour: Number(match[1]) || 0, minute: Number(match[2]) || 0, second: Number(match[3]) || 0, fraction: match[4] ?? "" };
}
function daysInMonth(year: number, month: number): number {
diff --git a/crates/dbx-core/src/data_grid_sql.rs b/crates/dbx-core/src/data_grid_sql.rs
index 63134abc1e..cbbdbb44aa 100644
--- a/crates/dbx-core/src/data_grid_sql.rs
+++ b/crates/dbx-core/src/data_grid_sql.rs
@@ -2602,6 +2602,10 @@ mod tests {
format_grid_sql_literal(&json!("2026-05-12T00:00:00.123456Z"), Some(DatabaseType::Mysql), None),
"'2026-05-12 00:00:00.123456'"
);
+ assert_eq!(
+ format_grid_sql_literal(&json!("2026-05-12 00:00:00.123456"), Some(DatabaseType::Mysql), None),
+ "'2026-05-12 00:00:00.123456'"
+ );
}
#[test]
@@ -2626,6 +2630,14 @@ mod tests {
),
"N'2026-06-29 10:11:12.8966666'"
);
+ assert_eq!(
+ format_grid_sql_literal(
+ &json!("2026-06-29 10:11:12.123456"),
+ Some(DatabaseType::SqlServer),
+ Some(&datetime2)
+ ),
+ "N'2026-06-29 10:11:12.1234560'"
+ );
assert_eq!(
format_grid_sql_literal(
&json!("2026-06-29 10:11:12.896666666"),
@@ -2683,6 +2695,10 @@ mod tests {
format_grid_sql_literal(&json!("2022-08-25 09:58:43.123456"), Some(DatabaseType::Oracle), Some(&timestamp)),
"TO_TIMESTAMP('2022-08-25 09:58:43.123456', 'YYYY-MM-DD HH24:MI:SS.FF')"
);
+ assert_eq!(
+ format_grid_sql_literal(&json!("2022-08-25 09:58:43.654321"), Some(DatabaseType::Oracle), Some(&timestamp)),
+ "TO_TIMESTAMP('2022-08-25 09:58:43.654321', 'YYYY-MM-DD HH24:MI:SS.FF')"
+ );
assert_eq!(
format_grid_sql_literal(&json!("2022-08-25 09:58:43"), Some(DatabaseType::Oracle), Some(&date)),
"TO_DATE('2022-08-25 09:58:43', 'YYYY-MM-DD HH24:MI:SS')"