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
feat(grid): text preview and in-cell editing for postgres bytea
lxk955509b1de6fa95
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex a1effced56..e09cc40cf1 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -188,7 +188,7 @@ import {formatBinaryCellByteSize,binaryCellUtf8Text,hasUnsafeOpaqueAggregateStatePredicate,- isBlobCellColumnType,+ isBinaryCellTextEditable,isBinaryCellColumnType,isOpaqueAggregateStateColumnType,mergeOpaqueReadonlyColumnIndexes,@@ -11570,7 +11570,7 @@ function detailClipboardText(detail: DataGridCellDetail): string {if (detail.value === null) return "";const binaryText = binaryCellClipboardText(detail.value, detail.type, resolvedDatabaseType.value);if (binaryText !== null) return binaryText;- if (isBlobCellColumnType(detail.type)) return binaryCellUtf8Text(detail.value, detail.type, resolvedDatabaseType.value) ?? displayCellValue(detail.value);+ if (isBinaryCellTextEditable(detail.type, resolvedDatabaseType.value)) return binaryCellUtf8Text(detail.value, detail.type, resolvedDatabaseType.value) ?? displayCellValue(detail.value);return displayCellValue(detail.value);}diff --git a/apps/desktop/src/components/grid/DataGridCellDetailDialog.vue b/apps/desktop/src/components/grid/DataGridCellDetailDialog.vueindex 4069608e34..23a04d5380 100644--- a/apps/desktop/src/components/grid/DataGridCellDetailDialog.vue+++ b/apps/desktop/src/components/grid/DataGridCellDetailDialog.vue@@ -11,7 +11,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popoverimport { useCellDetailEditor, type UseCellDetailEditorReturn } from "@/composables/useCellDetailEditor";import { useTheme } from "@/composables/useTheme";import { useSettingsStore } from "@/stores/settingsStore";-import { BINARY_CELL_DOWNLOAD_MODES, isBinaryCellColumnType, binaryCellUtf8Text, isBlobCellColumnType, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";+import { BINARY_CELL_DOWNLOAD_MODES, isBinaryCellColumnType, binaryCellUtf8Text, isBinaryCellTextEditable, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";import { canPreviewCellGeometry, cellDetailPreviewText } from "@/lib/dataGrid/cellDetailPresentation";import { renderWktOnCanvas } from "@/lib/dataGrid/geometryPreview";import type { DataGridCellDetail } from "@/lib/dataGrid/dataGridDetail";@@ -30,7 +30,7 @@ const props = defineProps<{downloadBinaryValue: (detail: DataGridCellDetail | null, mode: BinaryCellDownloadMode) => void | Promise<void>;canImportBinaryValue: (detail: DataGridCellDetail | null) => boolean;importBinaryValue: (detail: DataGridCellDetail | null) => void | Promise<void>;- /** BLOB 文本预览与编辑写回一致,在 MySQL / Oracle(含 OceanBase-Oracle)连接开启。 */+ /** BLOB / BYTEA 文本预览与编辑写回一致,在 MySQL / Oracle(含 OceanBase-Oracle)或 PostgreSQL 连接开启。 */databaseType?: DatabaseType;}>();@@ -48,7 +48,7 @@ let jsonPreviewEditor: UseCellDetailEditorReturn | null = null;const jsonFormatted = computed(() => settingsStore.editorSettings.cellDetailJsonFormatted);const jsonView = computed(() => jsonFormatted.value && !!props.detail?.formattedJson);const wordWrapEnabled = computed(() => settingsStore.editorSettings.wordWrap);-const binaryTextPreview = computed(() => (props.detail && isBlobCellColumnType(props.detail.type) ? binaryCellUtf8Text(props.detail.value, props.detail.type, props.databaseType) : null));+const binaryTextPreview = computed(() => (props.detail && isBinaryCellTextEditable(props.detail.type, props.databaseType) ? binaryCellUtf8Text(props.detail.value, props.detail.type, props.databaseType) : null));const presentedValuePreview = computed(() => (binaryTextPreview.value === null && props.detail ? cellDetailPreviewText(props.detail, props.databaseType) : props.detail?.displayValuePreview) ?? "");function toggleWordWrap() {diff --git a/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue b/apps/desktop/src/components/grid/DataGridCellDetailPanel.vueindex 222ff5415e..f590d31936 100644--- a/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue+++ b/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue@@ -10,7 +10,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popoverimport { TabsContent } from "@/components/ui/tabs";import TemporalCellEditor from "@/components/grid/TemporalCellEditor.vue";import { useDataGridCellDetail } from "@/composables/useDataGridCellDetail";-import { BINARY_CELL_DOWNLOAD_MODES, isBinaryCellColumnType, binaryCellUtf8Text, isBlobCellColumnType, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";+import { BINARY_CELL_DOWNLOAD_MODES, isBinaryCellColumnType, binaryCellUtf8Text, isBinaryCellTextEditable, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";import { canPreviewCellGeometry, cellDetailPreviewText } from "@/lib/dataGrid/cellDetailPresentation";import type { DataGridCellDetail } from "@/lib/dataGrid/dataGridDetail";import type { TemporalCellEditorConfig } from "@/lib/dataGrid/dataGridTemporalEditor";@@ -38,7 +38,7 @@ const props = defineProps<{importBinaryValue: (detail: DataGridCellDetail | null) => void | Promise<void>;openImagePreview: (src: string, title: string) => void;canCopySqlCondition: () => boolean;- /** BLOB 文本预览与编辑写回一致,在 MySQL / Oracle(含 OceanBase-Oracle)连接开启。 */+ /** BLOB / BYTEA 文本预览与编辑写回一致,在 MySQL / Oracle(含 OceanBase-Oracle)或 PostgreSQL 连接开启。 */databaseType?: DatabaseType;}>();@@ -76,7 +76,7 @@ void geometryCanvas;void detailsEditorContainer;void sideJsonPreviewContainer;-const binaryTextPreview = computed(() => (isBlobCellColumnType(props.detail.type) ? binaryCellUtf8Text(props.detail.value, props.detail.type, props.databaseType) : null));+const binaryTextPreview = computed(() => (isBinaryCellTextEditable(props.detail.type, props.databaseType) ? binaryCellUtf8Text(props.detail.value, props.detail.type, props.databaseType) : null));const presentedValuePreview = computed(() => (binaryTextPreview.value === null ? cellDetailPreviewText(props.detail, props.databaseType) : props.detail.displayValuePreview));const transformOpen = ref(false);// 底部面板横向空间充足:有图片预览时与值文本左右并排,侧栏窄面板保持上下堆叠。diff --git a/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.tsindex bd26196d0b..5e5027f2df 100644--- a/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts+++ b/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts@@ -2151,6 +2151,57 @@ describe("cell detail surfaces", () => {expect(copyText).toHaveBeenCalledWith("Hello");});+ it("presents printable PostgreSQL BYTEA bytes as text and copies the presented value (#11987)", async () => {+ const copyText = vi.fn();+ const byteaDetail = detail({+ type: "BYTEA",+ value: "0x48656c6c6f",+ rawValue: "0x48656c6c6f",+ rawValuePreview: "0x48656c6c6f",+ displayValue: "Hello",+ displayValuePreview: "Hello",+ formattedJson: "",+ });+ const dialog = mountComponent(DataGridCellDetailDialog, {+ open: true,+ detail: byteaDetail,+ typeColorClass: () => "",+ openImagePreview: vi.fn(),+ copyText,+ canDownloadBinaryValue: () => true,+ downloadBinaryValue: vi.fn(),+ canImportBinaryValue: () => true,+ importBinaryValue: vi.fn(),+ databaseType: "postgres",+ });+ const panel = mountComponent(DataGridCellDetailPanel, {+ detail: byteaDetail,+ panelIsBottom: true,+ metadataCollapsed: false,+ valueFillsHeight: false,+ editing: false,+ sideJsonView: false,+ showCompactJson: false,+ canCompactJson: false,+ typeColorClass: () => "",+ canDownloadBinaryValue: () => true,+ downloadBinaryValue: vi.fn(),+ canImportBinaryValue: () => true,+ importBinaryValue: vi.fn(),+ openImagePreview: vi.fn(),+ canCopySqlCondition: () => true,+ databaseType: "postgres",+ });++ expect(hostText(dialog.root)).toContain("Hello");+ expect(hostText(panel.root)).toContain("Hello");+ dispatch(+ findOne(dialog.root, (node) => node.props.title === "grid.copyValue"),+ "click",+ );+ expect(copyText).toHaveBeenCalledWith("Hello");+ });+it("keeps non-MySQL BLOB detail previews in hex", () => {const panel = mountComponent(DataGridCellDetailPanel, {detail: detail({ type: "BLOB", value: "0x2332303035383035", rawValue: "0x2332303035383035", rawValuePreview: "0x2332303035383035", displayValue: "BLOB [8 bytes]", displayValuePreview: "BLOB [8 bytes]", formattedJson: "" }),diff --git a/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridExport.spec.tsindex 5384aac8f4..8218b39895 100644--- a/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts+++ b/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts@@ -3007,6 +3007,25 @@ describe("useDataGridExport MySQL BLOB 文本复制 (#12413)", () => {expect(extractDataGridSelection).toHaveBeenLastCalledWith(expect.objectContaining({ extractor: "sql-inserts", rows: [[1, "0x616263"]] }));});+ it("copies text-like PostgreSQL bytea as text, matching the grid preview (#11987)", async () => {+ const byteaTable: DataGridTableMeta = {+ tableName: "test_bytea",+ primaryKeys: ["id"],+ columns: [+ { name: "id", data_type: "int4", is_nullable: false, is_primary_key: true },+ { name: "payload", data_type: "bytea", is_nullable: false },+ ],+ };+ const matrix: CellSelectionMatrix = { rowIndexes: [0], columnIndexes: [1], columns: ["payload"], rows: [["0x616263"]] };+ vi.mocked(extractDataGridSelection).mockResolvedValueOnce({ text: "abc", mimeType: "text/plain", fileExtension: "txt", rowCount: 1, columnCount: 1 });+ const state = createExportState(byteaTable, ["id", "payload"], matrix, [1, "0x616263"], undefined, undefined, [], DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS, false, undefined, false, 1, 1, "postgres");++ await expect(state.copyWithPreference("smart")).resolves.toBe(true);++ expect(extractDataGridSelection).toHaveBeenCalledWith(expect.objectContaining({ extractor: "raw", rows: [["abc"]] }));+ expect(copyToClipboard).toHaveBeenCalledWith("abc");+ });+it("copies HTML with both rich and plain clipboard flavors", async () => {const matrix: CellSelectionMatrix = { rowIndexes: [0], columnIndexes: [0], columns: ["name"], rows: [["Ada"]] };vi.mocked(extractDataGridSelection).mockResolvedValueOnce({ text: "<table><tr><td>Ada</td></tr></table>", mimeType: "text/html", fileExtension: "html", rowCount: 1, columnCount: 1 });diff --git a/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts b/apps/desktop/src/lib/dataGrid/binaryCellDownload.tsindex 88bdfad300..54311f948b 100644--- a/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts+++ b/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts@@ -120,6 +120,7 @@ const FIXED_BINARY_TYPE_RE = /^binary(?:\b|\()/i;const BINARY_STRING_TYPE_RE = /^(?:binary|varbinary)(?:\b|\()/i;const VARBINARY_TYPE_RE = /^varbinary(?:\b|\()/i;const BLOB_TYPE_RE = /^(?:blob|tinyblob|mediumblob|longblob)(?:\b|\()/i;+const BYTEA_TYPE_RE = /^(?:[a-zA-Z0-9_]+\.)?bytea(?:\b|\()/i;const MYSQL_FILE_IMPORT_TYPE_RE = /^(?:blob|tinyblob|mediumblob|longblob|binary|varbinary)(?:\b|\()/i;const OPAQUE_AGG_STATE_TYPE_RE = /^agg_state\s*<\s*[^>\s][^>]*>$/i;@@ -237,9 +238,14 @@ export function isBlobCellColumnType(columnType?: string): boolean {return !!type && BLOB_TYPE_RE.test(type);}+export function isByteaCellColumnType(columnType?: string): boolean {+ const type = (columnType ?? "").trim();+ return !!type && !type.endsWith("[]") && !type.startsWith("_") && BYTEA_TYPE_RE.test(type);+}+export function canImportBinaryCellFile(databaseType?: DatabaseType, columnType?: string): boolean {const type = (columnType ?? "").trim();- if (databaseType === "postgres") return /^bytea(?:\b|\()/i.test(type);+ if (databaseType === "postgres") return isByteaCellColumnType(type);if (databaseType === "mysql") return MYSQL_FILE_IMPORT_TYPE_RE.test(type);return false;}@@ -328,14 +334,15 @@ export function binaryCellClipboardText(value: unknown, columnType?: string, datif (uuidText !== null) return uuidText;// 覆盖上方注释里「严格限于 VARBINARY」的旧范围(#12413):网格已经对文本型 BLOB// 显示文本预览(MySQL 与 Oracle 家族;AES_DECRYPT 这类表达式的结果列常报成 BLOB),- // 显示 `secret` 却复制出 hex 与预览自相矛盾,因此并入同一闸门;严格往返校验与 hex- // 回退保持不变,MySQL BINARY、Oracle RAW、非预览库的 blob/bytea 等现有语义不受影响。- const blobColumn = isBlobCellColumnType(columnType);+ // 以及 PostgreSQL BYTEA(#11987),显示 `secret` 却复制出 hex 与预览自相矛盾,因此并入同一闸门;+ // 严格往返校验与 hex 回退保持不变,MySQL BINARY、Oracle RAW、非预览库的 blob/bytea 等现有语义不受影响。+ const editableBinary = isBinaryCellTextEditable(columnType, databaseType);// Blob columns follow the grid's inline text-preview gate: MySQL and the- // Oracle family preview text-like blobs as text, so copying hex from such a- // cell contradicts what the cell shows (#12413). MySQL VARBINARY keeps its- // #7471 contract; every other column stays lossless hex.- const decodableType = (databaseType === "mysql" && VARBINARY_TYPE_RE.test((columnType ?? "").trim())) || (blobColumn && isBlobTextPreviewDatabase(databaseType));+ // Oracle family preview text-like blobs as text, and PostgreSQL previews+ // text-like bytea (#11987), so copying hex from such a cell contradicts what+ // the cell shows (#12413). MySQL VARBINARY keeps its #7471 contract; every+ // other column stays lossless hex.+ const decodableType = (databaseType === "mysql" && VARBINARY_TYPE_RE.test((columnType ?? "").trim())) || editableBinary;if (!decodableType) return null;// MySQL QueryResult 的 binary canonical form 是 `0x<hex>`;不要把普通的偶数长度// 文本(例如 "abcd")猜测成 hex bytes。@@ -348,8 +355,8 @@ export function binaryCellClipboardText(value: unknown, columnType?: string, dat// 与 GBK 回退无关,沿用 hex。return encoded.length === bytes.length && encoded.every((byte, index) => byte === bytes[index]) ? text : null;}- // BLOB 家族与显示/编辑路径共用同一闸门:只解严格 UTF-8,不参与 GBK 回退。- if (blobColumn) return null;+ // BLOB 与 BYTEA 家族与显示/编辑路径共用同一闸门:只解严格 UTF-8,不参与 GBK 回退。+ if (editableBinary) return null;return printableGbkText(binaryPreviewBytes(bytes, columnType));}@@ -357,14 +364,19 @@ export function isBlobTextPreviewDatabase(databaseType?: DatabaseType): booleanreturn databaseType === "mysql" || databaseType === "oracle" || databaseType === "oceanbase-oracle";}-// MySQL 与 Oracle(含 OceanBase-Oracle)BLOB 的文本预览必须与编辑写回路径(coerceBlobTextValue)走同一闸门:+export function isBinaryCellTextEditable(columnType?: string, databaseType?: DatabaseType): boolean {+ if (databaseType === "postgres" && isByteaCellColumnType(columnType)) return true;+ return isBlobCellColumnType(columnType) && isBlobTextPreviewDatabase(databaseType);+}++// MySQL 与 Oracle(含 OceanBase-Oracle)BLOB,以及 PostgreSQL BYTEA 的文本预览必须与编辑写回路径(coerceBlobTextValue)走同一闸门:// SQLite/DuckDB/H2/Firebird 等库同样暴露 `blob` 列,若一律按文本预览会出现-// “显示是文本、编辑器却是十六进制”的不一致,故 blob 文本预览仅在支持的连接开启。+// “显示是文本、编辑器却是十六进制”的不一致,故 blob / bytea 文本预览仅在支持的连接开启。// binary/varbinary 的文本预览早于该特性存在(如 TDengine BINARY 文本),保持全库通用。-function isBinaryCellTextPreviewColumn(columnType: string | undefined, databaseType: DatabaseType | undefined): boolean {+export function isBinaryCellTextPreviewColumn(columnType: string | undefined, databaseType: DatabaseType | undefined): boolean {if (isOpaqueAggregateStateColumnType(columnType)) return false;if (BINARY_STRING_TYPE_RE.test((columnType ?? "").trim())) return true;- return isBlobCellColumnType(columnType) && isBlobTextPreviewDatabase(databaseType);+ return isBinaryCellTextEditable(columnType, databaseType);}// 显示/复制路径的解码链:先严格 UTF-8,仅 MySQL 连接的 binary/varbinary 再回退严格diff --git a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.tsindex db9977d8b2..bf296c8815 100644--- a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts+++ b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts@@ -1,6 +1,6 @@import type { GridCellValue } from "@/lib/dataGrid/dataGridSql";import type { DatabaseType, ColumnInfo } from "@/types/database";-import { binaryCellBytesToHexValue, binaryCellUtf8Text, decodeBinaryUuidText, isBlobCellColumnType, isBlobTextPreviewDatabase } from "@/lib/dataGrid/binaryCellDownload";+import { binaryCellBytesToHexValue, binaryCellUtf8Text, decodeBinaryUuidText, isBinaryCellTextEditable } from "@/lib/dataGrid/binaryCellDownload";import { isNumericColumnType, isUuidColumnType, resolveDataGridTypeVisualKind } from "@/lib/dataGrid/dataGridColumnType";import { isBooleanColumnType } from "@/lib/dataGrid/dataGridBooleanColumn";@@ -96,7 +96,7 @@ export function dataGridCellEditorText(options: { value: GridCellValue | undefinif (value === null) return "";const uuidText = decodeBinaryUuidText(value, options.columnInfo?.data_type);if (uuidText !== null) return uuidText;- if (isBlobTextPreviewDatabase(options.databaseType) && isBlobCellColumnType(options.columnInfo?.data_type)) {+ if (isBinaryCellTextEditable(options.columnInfo?.data_type, options.databaseType)) {const text = binaryCellUtf8Text(value, options.columnInfo?.data_type, options.databaseType);if (text !== null) return text;}@@ -124,7 +124,7 @@ function coerceUuidTextValue(options: CoerceDataGridCellValueOptions): GridCellV}function coerceBlobTextValue(options: CoerceDataGridCellValueOptions): GridCellValue | undefined {- if (!isBlobTextPreviewDatabase(options.databaseType) || !isBlobCellColumnType(options.columnInfo?.data_type)) return undefined;+ if (!isBinaryCellTextEditable(options.columnInfo?.data_type, options.databaseType)) return undefined;const originalText = binaryCellUtf8Text(options.oldValue, options.columnInfo?.data_type, options.databaseType);if (originalText === null) return undefined;if (options.value === originalText) return options.oldValue;diff --git a/crates/dbx-sql-data/src/data_grid_sql.rs b/crates/dbx-sql-data/src/data_grid_sql.rsindex 824bd50412..c82ba968d7 100644--- a/crates/dbx-sql-data/src/data_grid_sql.rs+++ b/crates/dbx-sql-data/src/data_grid_sql.rs@@ -3372,7 +3372,13 @@ fn is_postgres_binary_literal_column(column_info: Option<&DataGridColumnInfo>,) -> bool {database_type == Some(DatabaseType::Postgres)- && column_info.is_some_and(|column| column.data_type.trim().eq_ignore_ascii_case("bytea"))+ && column_info.is_some_and(|column| {+ let data_type = column.data_type.trim();+ // accept an optional single schema qualifier (pg_catalog.bytea) so the write-back+ // literal path stays aligned with the frontend BYTEA_TYPE_RE edit gate+ let bytea_name = data_type.split_once('.').map_or(data_type, |(_, name)| name);+ bytea_name.eq_ignore_ascii_case("bytea")+ })}fn format_postgres_binary_literal_text(text: &str) -> Option<String> {@@ -11130,6 +11136,25 @@ mod tests {assert_eq!(format_grid_sql_literal(&json!("0x00ab"), Some(DatabaseType::Postgres), Some(&text)), "'0x00ab'");}+ #[test]+ fn postgres_bytea_literal_gate_accepts_schema_qualified_and_rejects_arrays() {+ let qualified = column("payload", "pg_catalog.bytea", true, None);+ let array = column("payload", "bytea[]", true, None);++ assert_eq!(+ format_grid_sql_literal(&json!("0x00aBff"), Some(DatabaseType::Postgres), Some(&qualified)),+ "decode('00aBff', 'hex')"+ );+ assert_eq!(+ format_grid_sql_literal(&json!("0x00aBff"), Some(DatabaseType::Postgres), Some(&array)),+ "'0x00aBff'"+ );+ assert_eq!(+ format_grid_sql_literal(&json!("0x00aBff"), Some(DatabaseType::Gaussdb), Some(&qualified)),+ "'0x00aBff'"+ );+ }+#[test]fn sqlite_family_literals_do_not_double_escape_backslashes() {let value = json!(r#"{"json_raw":"{\"foo\":1,\"bar\":\"sometext\"}"}"#);diff --git a/packages/app-tests/binaryCellDownload.test.ts b/packages/app-tests/binaryCellDownload.test.tsindex 8e083bbe8d..59de63d41d 100644--- a/packages/app-tests/binaryCellDownload.test.ts+++ b/packages/app-tests/binaryCellDownload.test.ts@@ -14,6 +14,9 @@ import {binaryCellUtf8Text,isBlobCellColumnType,isBlobTextPreviewDatabase,+ isByteaCellColumnType,+ isBinaryCellTextEditable,+ isBinaryCellTextPreviewColumn,MAX_BINARY_CELL_IMPORT_BYTES,parseBinaryCellBytes,parseBinaryCellHexValue,@@ -51,13 +54,22 @@ test("TDengine BINARY text is not treated as unprefixed hex", () => {assert.equal(binaryCellDisplayText("0x3636", "BINARY(16)", undefined, "tdengine"), "66");});-test("binary cell download detects common blob column types", () => {+test("binary cell download detects common blob and bytea column types", () => {assert.equal(isBinaryCellColumnType("BLOB"), true);assert.equal(isBinaryCellColumnType("RAW(2000)"), true);assert.equal(isBinaryCellColumnType("long raw"), true);+ assert.equal(isBinaryCellColumnType("bytea"), true);assert.equal(isBinaryCellColumnType("varchar"), false);assert.equal(isBlobCellColumnType("longblob"), true);assert.equal(isBlobCellColumnType("varbinary(255)"), false);+ assert.equal(isBlobCellColumnType("bytea"), false);+ assert.equal(isByteaCellColumnType("bytea"), true);+ assert.equal(isByteaCellColumnType("BYTEA"), true);+ assert.equal(isByteaCellColumnType("pg_catalog.bytea"), true);+ assert.equal(isByteaCellColumnType("public.bytea"), true);+ assert.equal(isByteaCellColumnType("bytea[]"), false);+ assert.equal(isByteaCellColumnType("_bytea"), false);+ assert.equal(isByteaCellColumnType("blob"), false);});test("binary cell download menu closes when hover moves to another cell", () => {@@ -251,7 +263,11 @@ test("binaryCellClipboardText decodes textual MySQL varbinary and preserves arbiassert.equal(binaryCellClipboardText("0x616263", "RAW", "oracle"), null);assert.equal(binaryCellClipboardText("0x616263", "BINARY(8)", "mysql"), null); // MySQL BINARY 不跟随assert.equal(binaryCellClipboardText("0x616263", "VARBINARY(128)", "sqlserver"), null); // SQL Server varbinary 不改- assert.equal(binaryCellClipboardText("0x616263", "bytea", "postgres"), null); // Postgres bytea 不改+ // PostgreSQL bytea 文本复制(#11987):与显示预览/编辑写回保持同一闸门+ assert.equal(binaryCellClipboardText("0x616263", "bytea", "postgres"), "abc");+ assert.equal(binaryCellClipboardText("\\x616263", "bytea", "postgres"), "abc");+ assert.equal(binaryCellClipboardText("0x89504e47", "bytea", "postgres"), null);+ assert.equal(binaryCellClipboardText("0x616263", "bytea", "sqlite"), null);assert.equal(binaryCellClipboardText("0x616263", "BINARY(16)", "tdengine"), null); // 非 MySQL BINARY 不改assert.equal(binaryCellClipboardText("0x616263", "varchar", "mysql"), null); // 非二进制列不改assert.equal(binaryCellClipboardText("abcd", "VARBINARY(4)", "mysql"), null); // 普通文本不猜测为裸 hex@@ -259,7 +275,7 @@ test("binaryCellClipboardText decodes textual MySQL varbinary and preserves arbi// 回归:SQLite/DuckDB 等库同样有 `blob` 列,文本预览必须与编辑写回路径一样仅对 mysql 开启,// 否则出现“单元格/详情显示文本、编辑器却是十六进制”的不一致。-test("BLOB text preview stays limited to MySQL and Oracle family connections", () => {+test("BLOB and BYTEA text preview stays limited to supported database connections", () => {assert.equal(isBlobTextPreviewDatabase("mysql"), true);assert.equal(isBlobTextPreviewDatabase("oracle"), true);assert.equal(isBlobTextPreviewDatabase("oceanbase-oracle"), true);@@ -267,6 +283,15 @@ test("BLOB text preview stays limited to MySQL and Oracle family connections", (assert.equal(isBlobTextPreviewDatabase("duckdb"), false);assert.equal(isBlobTextPreviewDatabase(undefined), false);+ assert.equal(isBinaryCellTextEditable("blob", "mysql"), true);+ assert.equal(isBinaryCellTextEditable("blob", "oracle"), true);+ assert.equal(isBinaryCellTextEditable("bytea", "postgres"), true);+ assert.equal(isBinaryCellTextEditable("bytea", "sqlite"), false);+ assert.equal(isBinaryCellTextEditable("bytea[]", "postgres"), false);++ assert.equal(isBinaryCellTextPreviewColumn("bytea", "postgres"), true);+ assert.equal(isBinaryCellTextPreviewColumn("bytea", "sqlite"), false);+assert.equal(binaryCellUtf8Text("0x2332303035383035", "LONGBLOB", "sqlite"), null);assert.equal(binaryCellUtf8Text("0x2332303035383035", "BLOB", "duckdb"), null);assert.equal(binaryCellUtf8Text("0x2332303035383035", "LONGBLOB", undefined), null);@@ -282,6 +307,16 @@ test("BLOB text preview stays limited to MySQL and Oracle family connections", (assert.equal(binaryCellDisplayText("0x48656c6c6f", "BLOB", undefined, "oceanbase-oracle"), "Hello");assert.equal(binaryCellDisplayText("0x89504e47", "BLOB", undefined, "oracle"), "BLOB [4 bytes]");+ // PostgreSQL 的 BYTEA 文本预览(#11987)+ assert.equal(binaryCellUtf8Text("0x48656c6c6f", "bytea", "postgres"), "Hello");+ assert.equal(binaryCellUtf8Text("\\x48656c6c6f", "bytea", "postgres"), "Hello");+ assert.equal(binaryCellDisplayText("0x48656c6c6f", "bytea", undefined, "postgres"), "Hello");+ assert.equal(binaryCellDisplayText("\\x48656c6c6f", "bytea", undefined, "postgres"), "Hello");+ assert.equal(binaryCellDisplayText("0x89504e47", "bytea", undefined, "postgres"), "BYTEA [4 bytes]");+ assert.equal(binaryCellDisplayText("\\x89504e47", "bytea", undefined, "postgres"), "BYTEA [4 bytes]");+ assert.equal(binaryCellUtf8Text("0x48656c6c6f", "bytea", "sqlite"), null);+ assert.equal(binaryCellDisplayText("0x48656c6c6f", "bytea", undefined, "sqlite"), "BYTEA [5 bytes]");+// binary/varbinary 的文本预览是既有行为(如 TDengine BINARY 文本),不受 mysql 闸门影响。assert.equal(binaryCellDisplayText("0x534e2d4130303031", "VARBINARY(8)", undefined, "sqlite"), "SN-A0001");});diff --git a/packages/app-tests/dataGridCellCoercion.test.ts b/packages/app-tests/dataGridCellCoercion.test.tsindex 212691837f..92f5900f3e 100644--- a/packages/app-tests/dataGridCellCoercion.test.ts+++ b/packages/app-tests/dataGridCellCoercion.test.ts@@ -223,3 +223,35 @@ test("Oracle and OceanBase-Oracle text BLOB editor decodes UTF-8 and writes edit}});+test("PostgreSQL text BYTEA editor decodes UTF-8 and writes edited bytes as hex (#11987)", () => {+ const oldValueHex = "0x48656c6c6f";+ const oldValuePgEscape = "\\x48656c6c6f";+ const columnInfo = { data_type: "bytea" };++ for (const oldValue of [oldValueHex, oldValuePgEscape]) {+ assert.equal(dataGridCellEditorText({ value: oldValue, databaseType: "postgres", columnInfo }), "Hello");+ assert.strictEqual(coerceDataGridCellValue({ value: "Hello", oldValue, databaseType: "postgres", columnInfo }), oldValue);+ assert.equal(coerceDataGridCellValue({ value: "新内容", oldValue, databaseType: "postgres", columnInfo }), "0xe696b0e58685e5aeb9");+ assert.equal(coerceDataGridCellValue({ value: "", oldValue, databaseType: "postgres", columnInfo }), "0x");+ assert.equal(coerceDataGridCellValue({ value: "", oldValue, databaseType: "postgres", columnInfo, emptyStringAsNull: true }), null);+ }+});++test("PostgreSQL binary BYTEA editor keeps non-text bytes in hex (#11987)", () => {+ const oldValueHex = "0x89504e470d0a1a0a";+ const oldValuePgEscape = "\\x89504e470d0a1a0a";+ const columnInfo = { data_type: "bytea" };++ for (const oldValue of [oldValueHex, oldValuePgEscape]) {+ assert.equal(dataGridCellEditorText({ value: oldValue, databaseType: "postgres", columnInfo }), oldValue);+ assert.equal(coerceDataGridCellValue({ value: oldValue, oldValue, databaseType: "postgres", columnInfo }), oldValue);+ }+});++test("non-PostgreSQL BYTEA editor keeps bytes in hex", () => {+ const oldValue = "0x48656c6c6f";+ const columnInfo = { data_type: "bytea" };++ assert.equal(dataGridCellEditorText({ value: oldValue, databaseType: "sqlite", columnInfo }), oldValue);+ assert.equal(coerceDataGridCellValue({ value: "Hello", oldValue, databaseType: "sqlite", columnInfo }), "Hello");+});