fix(csv): stop wrapping exported dates in equals-prefixed formulas

This commit is contained in:
_Mr丶s ゛😁® authored and GitHub committed 2026-09-30 15:05:59 +08:00
1 parent 6f05afc0e6
commit ce5217bd23
7 files changed
+25 -59

No files matched your search

@@ -1704,6 +1704,21 @@ describe("useDataGridExport prepared row statements", () => {
expect(exportQueryResultCsv).toHaveBeenLastCalledWith(expect.any(String), ["_id", "value"], [["1", reservedString]], expect.anything(), expect.anything());
});
it("exports temporal CSV values without an Excel formula wrapper (#10694)", async () => {
setActivePinia(createPinia());
const timestamp = "2026-09-30 12:34:56.789";
const table: DataGridTableMeta = {
tableName: "events",
primaryKeys: [],
columns: [{ name: "created_at", data_type: "timestamp" }],
};
const state = createExportState(table, ["created_at"], undefined, [timestamp]);
await state.exportCurrentPageCsv();
expect(exportQueryResultCsv).toHaveBeenLastCalledWith(expect.any(String), ["created_at"], [[timestamp]], expect.anything(), expect.anything());
});
it("exports only visible Mongo columns from the full result set", async () => {
setActivePinia(createPinia());
const state = createMongoExportState({
@@ -30,7 +30,7 @@ import type { DatabaseType, QueryResult } from "@/types/database";
import type { QueryResultExportRequest } from "@/lib/backend/api";
import { usesSyntheticRowIdKey } from "@/lib/table/tableEditing";
import { buildXlsxSqlWorksheet } from "@/lib/export/xlsxSqlSheet";
import { forceCsvTextForTemporalColumns, formatTemporalRowsForExport } from "@/lib/dataGrid/columnFormatter";
import { formatTemporalRowsForExport } from "@/lib/dataGrid/columnFormatter";
import { translateBackendError } from "@/i18n/backend-errors";
import XlsxHeaderDialog from "@/components/export/XlsxHeaderDialog.vue";
import i18n from "@/i18n";
@@ -885,13 +885,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
};
}
});
// Hand the raw rows straight to the Rust command. Formatting (NULL→"",
// bool/number→text, etc.) happens there on a spawn_blocking thread, so
// we avoid mapping every cell synchronously on the UI thread. Temporal
// columns are the one exception: force-text them here (see
// forceCsvTextForTemporalColumns) so WPS/Excel-style CSV import can't
// re-guess and truncate/reformat a date-looking string.
const rows = forceCsvTextForTemporalColumns(result.rows, result.columnTypes);
// Let the Rust command format and write the raw values off the UI thread.
if (needsFullExport && exportProgressState) {
exportProgressState.value = {
...exportProgressState.value,
@@ -913,7 +907,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
}
outputPath = path as string;
}
await api.exportQueryResultCsv(outputPath, result.columns, rows, useSettingsStore().editorSettings.csvQuoteMode, csvNullLiteralForMode(useSettingsStore().editorSettings.csvNullMode));
await api.exportQueryResultCsv(outputPath, result.columns, result.rows, useSettingsStore().editorSettings.csvQuoteMode, csvNullLiteralForMode(useSettingsStore().editorSettings.csvNullMode));
if (needsFullExport && exportProgressState) {
exportProgressState.value = {
...exportProgressState.value,
@@ -952,8 +946,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
outputPath = path as string;
}
const result = await resultToExport(undefined, undefined, false);
const rows = forceCsvTextForTemporalColumns(result.rows, result.columnTypes);
await api.exportQueryResultCsv(outputPath, result.columns, rows, useSettingsStore().editorSettings.csvQuoteMode, csvNullLiteralForMode(useSettingsStore().editorSettings.csvNullMode));
await api.exportQueryResultCsv(outputPath, result.columns, result.rows, useSettingsStore().editorSettings.csvQuoteMode, csvNullLiteralForMode(useSettingsStore().editorSettings.csvNullMode));
toast(t("grid.exported"));
} catch (e: any) {
toast(t("grid.exportFailed", { message: translateBackendError(t, e) }), 5000);
@@ -16,7 +16,6 @@ import { joinExportedDdls } from "@/lib/export/ddlExport";
import { translateBackendError } from "@/i18n/backend-errors";
import { sidebarStructureExportTargets, sidebarTableDataExportTargets } from "@/lib/sidebar/sidebarExportRuntime";
import { fetchTableDataForExport } from "@/lib/table/tableDataExport";
import { forceCsvTextForTemporalColumns } from "@/lib/dataGrid/columnFormatter";
import XlsxHeaderDialog from "@/components/export/XlsxHeaderDialog.vue";
import { buildXlsxHeaderOverrides, hasXlsxHeaderComments, type XlsxExportOptions, type XlsxHeaderMode } from "@/lib/export/xlsxHeader";
import {
@@ -476,7 +475,7 @@ export function useSidebarTreeExportRuntime(options: SidebarTreeExportRuntimeOpt
executePage: (sql) => api.executeQuery(connectionId, database, sql),
});
if (format === "csv") {
await api.exportQueryResultCsv(outputPath, result.columns, forceCsvTextForTemporalColumns(result.rows, result.column_types ?? []), target.csvQuoteMode, target.nullLiteral);
await api.exportQueryResultCsv(outputPath, result.columns, result.rows, target.csvQuoteMode, target.nullLiteral);
} else {
const comments = result.columns.map((name) => exportColumnInfos?.find((column) => column.name.toLocaleLowerCase() === name.toLocaleLowerCase())?.comment);
const headerOverrides = buildXlsxHeaderOverrides(result.columns, comments, headerMode);