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(grid): preview text stored in MySQL BLOB cells

zipgf45fcdb69d51
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index 1d343bd61d..e0408d99e2 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -141,6 +141,8 @@ import {
canDownloadBinaryCellValue,
downloadBinaryCellPayload,
formatBinaryCellByteSize,
+ binaryCellUtf8Text,
+ isBlobCellColumnType,
isBinaryCellColumnType,
openBinaryCellFile,
parseBinaryCellBytes,
@@ -4120,8 +4122,8 @@ function cellEditContentNeedsExpandedEditor(options: { displayText: string; edit
function cellEditorTextForValue(value: CellValue | undefined, columnIndex: number): string {
return dataGridCellEditorText({
value: value ?? null,
- databaseType: props.databaseType,
- columnInfo: tableColumnForGridColumn(columnIndex),
+ databaseType: resolvedDatabaseType.value,
+ columnInfo: tableColumnForGridColumn(columnIndex) ?? resultColumnInfoForGridColumn(columnIndex),
});
}
@@ -4185,7 +4187,7 @@ function isIoTDBTimestampColumn(columnIndex: number): boolean {
}
function inlineCellEditorText(value: CellValue, columnIndex: number): string {
- const columnInfo = tableColumnForGridColumn(columnIndex);
+ const columnInfo = tableColumnForGridColumn(columnIndex) ?? resultColumnInfoForGridColumn(columnIndex);
const columnType = props.result.column_types?.[columnIndex] ?? columnInfo?.data_type;
return (
formatIoTDBTimestampEditorValue(value, resolvedDatabaseType.value, columnType, resolvedConnectionConfig.value?.url_params) ??
@@ -6054,8 +6056,8 @@ watch(activeCellDetail, (detail) => {
}
const value = dataGridCellEditorText({
value: detail.value,
- databaseType: props.databaseType,
- columnInfo: tableColumnForGridColumn(detail.colIndex),
+ databaseType: resolvedDatabaseType.value,
+ columnInfo: tableColumnForGridColumn(detail.colIndex) ?? resultColumnInfoForGridColumn(detail.colIndex),
});
detailEditValue.value = value;
detailEditOriginalValue.value = value;
@@ -9100,7 +9102,7 @@ async function copyDetailValue() {
if (!initialDetail || !(await hydrateLargeValueCell(initialDetail.rowId, initialDetail.colIndex))) return;
const detail = activeCellDetail.value;
if (!detail) return;
- const text = detail.value === null ? "" : displayCellValue(detail.value);
+ const text = detail.value === null ? "" : isBlobCellColumnType(detail.type) ? (binaryCellUtf8Text(detail.value, detail.type, resolvedDatabaseType.value) ?? displayCellValue(detail.value)) : displayCellValue(detail.value);
copyText(text);
}
@@ -13356,6 +13358,7 @@ function currentGridContextMenuItems(): ContextMenuItem[] {
:import-binary-value="importDetailBinaryValue"
:open-image-preview="openImagePreview"
:can-copy-sql-condition="canCopyPreparedDetailSqlCondition"
+ :database-type="resolvedDatabaseType"
@start-edit="startDetailEdit"
@compact-json="compactDetailJson"
@toggle-formatted="toggleCellDetailJsonFormatted"
@@ -13545,6 +13548,7 @@ function currentGridContextMenuItems(): ContextMenuItem[] {
:download-binary-value="downloadDetailBinaryValue"
:can-import-binary-value="canImportDetailBinaryValue"
:import-binary-value="importDetailBinaryValue"
+ :database-type="resolvedDatabaseType"
@edit="openDialogCellInSidePanel"
/>
diff --git a/apps/desktop/src/components/grid/DataGridCellDetailDialog.vue b/apps/desktop/src/components/grid/DataGridCellDetailDialog.vue
index c8bdc3882f..05ce03f866 100644
--- a/apps/desktop/src/components/grid/DataGridCellDetailDialog.vue
+++ b/apps/desktop/src/components/grid/DataGridCellDetailDialog.vue
@@ -9,10 +9,11 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover
import { useCellDetailEditor, type UseCellDetailEditorReturn } from "@/composables/useCellDetailEditor";
import { useTheme } from "@/composables/useTheme";
import { useSettingsStore } from "@/stores/settingsStore";
-import { BINARY_CELL_DOWNLOAD_MODES, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";
+import { BINARY_CELL_DOWNLOAD_MODES, binaryCellUtf8Text, isBlobCellColumnType, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";
import { isGeometryColumnType } from "@/lib/dataGrid/cellDetailPresentation";
import { isHexGeometry, renderWktOnCanvas } from "@/lib/dataGrid/geometryPreview";
import type { DataGridCellDetail } from "@/lib/dataGrid/dataGridDetail";
+import type { DatabaseType } from "@/types/database";
const { t } = useI18n();
const settingsStore = useSettingsStore();
@@ -27,6 +28,8 @@ 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 连接开启。 */
+ databaseType?: DatabaseType;
}>();
const emit = defineEmits<{
@@ -41,6 +44,8 @@ let jsonPreviewEditor: UseCellDetailEditorReturn | null = null;
const jsonFormatted = computed(() => settingsStore.editorSettings.cellDetailJsonFormatted);
const jsonView = computed(() => jsonFormatted.value && !!props.detail?.formattedJson);
+const binaryTextPreview = computed(() => (props.detail && isBlobCellColumnType(props.detail.type) ? binaryCellUtf8Text(props.detail.value, props.detail.type, props.databaseType) : null));
+const presentedValuePreview = computed(() => (binaryTextPreview.value === null ? props.detail?.rawValuePreview : props.detail?.displayValuePreview) ?? "");
function toggleJsonFormatted() {
settingsStore.updateEditorSettings({ cellDetailJsonFormatted: !jsonFormatted.value });
@@ -53,7 +58,7 @@ function copyCurrentValue() {
props.copyText(detail.formattedJson);
return;
}
- props.copyText(detail.value === null ? "" : detail.rawValue);
+ props.copyText(detail.value === null ? "" : (binaryTextPreview.value ?? detail.rawValue));
}
function copyColumnName() {
@@ -186,7 +191,7 @@ watch(
<img :src="detail.imagePreviewUrl" :alt="detail.column" loading="lazy" decoding="async" referrerpolicy="no-referrer" class="max-h-72 w-full object-contain" />
</a>
<div v-if="jsonView && detail.formattedJson" ref="jsonPreviewContainer" data-cell-detail-editor-root class="h-[44vh] min-h-60 overflow-hidden rounded border bg-muted/20 p-3" />
- <pre v-else class="dbx-data-grid-value-font max-h-[44vh] overflow-auto rounded border bg-muted/20 p-3 text-xs whitespace-pre-wrap break-words" :class="{ 'italic text-muted-foreground': detail.value === null }">{{ detail.rawValuePreview }}</pre>
+ <pre v-else class="dbx-data-grid-value-font max-h-[44vh] overflow-auto rounded border bg-muted/20 p-3 text-xs whitespace-pre-wrap break-words" :class="{ 'italic text-muted-foreground': detail.value === null }">{{ presentedValuePreview }}</pre>
<div v-if="detail.isValuePreviewTruncated && !jsonView" class="text-[11px] text-muted-foreground">
{{ t("grid.largeValuePreviewHint", { count: detail.rawValuePreview.length }) }}
</div>
diff --git a/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue b/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue
index f673ce6ea8..fcd54fb690 100644
--- a/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue
+++ b/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { toRef } from "vue";
+import { computed, toRef } from "vue";
import { Code2, Copy, Download, Eye, FileUp, Pencil, X } from "@lucide/vue";
import { useI18n } from "vue-i18n";
import { Button } from "@/components/ui/button";
@@ -8,11 +8,12 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover
import { TabsContent } from "@/components/ui/tabs";
import TemporalCellEditor from "@/components/grid/TemporalCellEditor.vue";
import { useDataGridCellDetail } from "@/composables/useDataGridCellDetail";
-import { BINARY_CELL_DOWNLOAD_MODES, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";
+import { BINARY_CELL_DOWNLOAD_MODES, binaryCellUtf8Text, isBlobCellColumnType, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";
import { isGeometryColumnType } from "@/lib/dataGrid/cellDetailPresentation";
import { isHexGeometry } from "@/lib/dataGrid/geometryPreview";
import type { DataGridCellDetail } from "@/lib/dataGrid/dataGridDetail";
import type { TemporalCellEditorConfig } from "@/lib/dataGrid/dataGridTemporalEditor";
+import type { DatabaseType } from "@/types/database";
const { t } = useI18n();
@@ -34,6 +35,8 @@ const props = defineProps<{
importBinaryValue: (detail: DataGridCellDetail | null) => void | Promise<void>;
openImagePreview: (src: string, title: string) => void;
canCopySqlCondition: () => boolean;
+ /** BLOB 文本预览与编辑写回一致,仅在 MySQL 连接开启。 */
+ databaseType?: DatabaseType;
}>();
const detailEditValue = defineModel<string>("value", { default: "" });
@@ -55,6 +58,9 @@ void geometryCanvas;
void detailsEditorContainer;
void sideJsonPreviewContainer;
+const binaryTextPreview = computed(() => (isBlobCellColumnType(props.detail.type) ? binaryCellUtf8Text(props.detail.value, props.detail.type, props.databaseType) : null));
+const presentedValuePreview = computed(() => (binaryTextPreview.value === null ? props.detail.rawValuePreview : props.detail.displayValuePreview));
+
function startJsonEditFromBlankArea(event: MouseEvent) {
const target = event.target as { closest?: (selector: string) => Element | null } | null;
const line = target?.closest?.(".cm-line");
@@ -181,7 +187,7 @@ defineExpose({ openSearch });
class="dbx-data-grid-value-font overflow-auto rounded border bg-muted/20 p-2 text-xs whitespace-pre-wrap break-words cursor-pointer hover:border-primary/50"
:class="[{ 'cursor-text': detail.isEditable }, panelIsBottom && detail.imagePreviewUrl ? 'min-h-24 max-h-32 shrink-0' : '', valueFillsHeight && !detail.imagePreviewUrl ? 'min-h-0 flex-1' : '']"
@dblclick="emit('startEdit')"
- >{{ detail.rawValuePreview }}</pre
+ >{{ presentedValuePreview }}</pre
>
<div v-if="detail.isValuePreviewTruncated && !sideJsonView" class="text-[11px] text-muted-foreground">{{ t("grid.largeValuePreviewHint", { count: detail.rawValuePreview.length }) }}</div>
</div>
diff --git a/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts
index c9c16d5c29..77a2177d83 100644
--- a/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts
+++ b/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts
@@ -1184,6 +1184,105 @@ describe("DataGridTextFilterWorkbench", () => {
});
describe("cell detail surfaces", () => {
+ it("presents printable LONG BLOB bytes as text and copies the presented value", async () => {
+ const copyText = vi.fn();
+ const blobDetail = detail({
+ type: "LONGBLOB",
+ value: "0x2332303035383035",
+ rawValue: "0x2332303035383035",
+ rawValuePreview: "0x2332303035383035",
+ displayValue: "#2005805",
+ displayValuePreview: "#2005",
+ formattedJson: "",
+ });
+ const dialog = mountComponent(DataGridCellDetailDialog, {
+ open: true,
+ detail: blobDetail,
+ typeColorClass: () => "",
+ openImagePreview: vi.fn(),
+ copyText,
+ canDownloadBinaryValue: () => true,
+ downloadBinaryValue: vi.fn(),
+ canImportBinaryValue: () => false,
+ importBinaryValue: vi.fn(),
+ databaseType: "mysql",
+ });
+ const panel = mountComponent(DataGridCellDetailPanel, {
+ detail: blobDetail,
+ panelIsBottom: true,
+ metadataCollapsed: false,
+ valueFillsHeight: false,
+ editing: false,
+ sideJsonView: false,
+ showCompactJson: false,
+ canCompactJson: false,
+ typeColorClass: () => "",
+ canDownloadBinaryValue: () => true,
+ downloadBinaryValue: vi.fn(),
+ canImportBinaryValue: () => false,
+ importBinaryValue: vi.fn(),
+ openImagePreview: vi.fn(),
+ canCopySqlCondition: () => true,
+ databaseType: "mysql",
+ });
+
+ expect(hostText(dialog.root)).toContain("#2005");
+ expect(hostText(dialog.root)).not.toContain("#2005805");
+ expect(hostText(panel.root)).toContain("#2005");
+ expect(hostText(panel.root)).not.toContain("#2005805");
+ dispatch(
+ findOne(dialog.root, (node) => node.props.title === "grid.copyValue"),
+ "click",
+ );
+ expect(copyText).toHaveBeenCalledWith("#2005805");
+ });
+
+ 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: "" }),
+ panelIsBottom: true,
+ metadataCollapsed: false,
+ valueFillsHeight: false,
+ editing: false,
+ sideJsonView: false,
+ showCompactJson: false,
+ canCompactJson: false,
+ typeColorClass: () => "",
+ canDownloadBinaryValue: () => true,
+ downloadBinaryValue: vi.fn(),
+ canImportBinaryValue: () => false,
+ importBinaryValue: vi.fn(),
+ openImagePreview: vi.fn(),
+ canCopySqlCondition: () => true,
+ databaseType: "sqlite",
+ });
+
+ expect(hostText(panel.root)).toContain("0x2332303035383035");
+ });
+
+ it("keeps non-text LONG BLOB values in hex", () => {
+ const panel = mountComponent(DataGridCellDetailPanel, {
+ detail: detail({ type: "LONGBLOB", value: "0x89504e470d0a1a0a", rawValue: "0x89504e470d0a1a0a", rawValuePreview: "0x89504e470d0a1a0a", formattedJson: "" }),
+ panelIsBottom: true,
+ metadataCollapsed: false,
+ valueFillsHeight: false,
+ editing: false,
+ sideJsonView: false,
+ showCompactJson: false,
+ canCompactJson: false,
+ typeColorClass: () => "",
+ canDownloadBinaryValue: () => true,
+ downloadBinaryValue: vi.fn(),
+ canImportBinaryValue: () => false,
+ importBinaryValue: vi.fn(),
+ openImagePreview: vi.fn(),
+ canCopySqlCondition: () => true,
+ databaseType: "mysql",
+ });
+
+ expect(hostText(panel.root)).toContain("0x89504e470d0a1a0a");
+ });
+
it("copies the presented value, emits edit, closes, and replaces the JSON result", async () => {
const copyText = vi.fn();
const edit = vi.fn();
diff --git a/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts b/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts
index 9136ac6348..53a1c818f1 100644
--- a/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts
+++ b/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts
@@ -114,6 +114,7 @@ const HEX_ESCAPE_RE = /^(?:\\x[0-9a-fA-F]{2}|\s)+$/;
const BINARY_TYPE_RE = /^(?:blob|tinyblob|mediumblob|longblob|bytea|bytes|binary|varbinary|image|raw|long\s+raw)(?:\b|\()/i;
const FIXED_BINARY_TYPE_RE = /^binary(?:\b|\()/i;
const BINARY_STRING_TYPE_RE = /^(?:binary|varbinary)(?:\b|\()/i;
+const BLOB_TYPE_RE = /^(?:blob|tinyblob|mediumblob|longblob)(?:\b|\()/i;
const MYSQL_FILE_IMPORT_TYPE_RE = /^(?:blob|tinyblob|mediumblob|longblob|binary|varbinary)(?:\b|\()/i;
function copyBytesForBlob(bytes: Uint8Array): Uint8Array<ArrayBuffer> {
@@ -182,6 +183,11 @@ export function isBinaryCellColumnType(columnType?: string): boolean {
return !!type && BINARY_TYPE_RE.test(type);
}
+export function isBlobCellColumnType(columnType?: string): boolean {
+ const type = (columnType ?? "").trim();
+ return !!type && BLOB_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);
@@ -200,14 +206,34 @@ export function binaryCellDisplayText(value: unknown, columnType?: string, origi
}
const bytes = parseBinaryCellBytes(value, columnType, databaseType);
if (!bytes || !isBinaryCellColumnType(columnType)) return null;
- if (BINARY_STRING_TYPE_RE.test((columnType ?? "").trim())) {
- const previewBytes = FIXED_BINARY_TYPE_RE.test((columnType ?? "").trim()) ? trimTrailingNullBytes(bytes) : bytes;
- const text = printableUtf8Text(previewBytes);
+ if (isBinaryCellTextPreviewColumn(columnType, databaseType)) {
+ const text = binaryCellUtf8TextBytes(bytes, columnType);
if (text !== null) return text;
}
return `${binaryCellDisplayLabel(columnType)} [${formatBinaryCellByteSize(bytes.length)}]`;
}
+export function binaryCellUtf8Text(value: unknown, columnType?: string, databaseType?: DatabaseType): string | null {
+ if (!isBinaryCellColumnType(columnType) || !isBinaryCellTextPreviewColumn(columnType, databaseType)) return null;
+ const bytes = parseBinaryCellBytes(value, columnType, databaseType);
+ if (!bytes) return null;
+ return binaryCellUtf8TextBytes(bytes, columnType);
+}
+
+// MySQL BLOB 的文本预览必须与编辑写回路径(coerceMysqlBlobTextValue,仅 mysql)走同一闸门:
+// SQLite/DuckDB/H2/Firebird 等库同样暴露 `blob` 列,若一律按文本预览会出现
+// “显示是文本、编辑器却是十六进制”的不一致,故 blob 文本预览仅在 mysql 连接开启。
+// binary/varbinary 的文本预览早于该特性存在(如 TDengine BINARY 文本),保持全库通用。
+function isBinaryCellTextPreviewColumn(columnType: string | undefined, databaseType: DatabaseType | undefined): boolean {
+ if (BINARY_STRING_TYPE_RE.test((columnType ?? "").trim())) return true;
+ return isBlobCellColumnType(columnType) && databaseType === "mysql";
+}
+
+function binaryCellUtf8TextBytes(bytes: Uint8Array, columnType?: string): string | null {
+ const previewBytes = FIXED_BINARY_TYPE_RE.test((columnType ?? "").trim()) ? trimTrailingNullBytes(bytes) : bytes;
+ return printableUtf8Text(previewBytes);
+}
+
function trimTrailingNullBytes(bytes: Uint8Array): Uint8Array {
let end = bytes.length;
while (end > 0 && bytes[end - 1] === 0) end--;
diff --git a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
index 4e5a0cd8c3..f5518bbb05 100644
--- a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
+++ b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
@@ -1,5 +1,6 @@
import type { GridCellValue } from "@/lib/dataGrid/dataGridSql";
import type { DatabaseType, ColumnInfo } from "@/types/database";
+import { binaryCellBytesToHexValue, binaryCellUtf8Text, isBlobCellColumnType } from "@/lib/dataGrid/binaryCellDownload";
import { isNumericColumnType } from "@/lib/dataGrid/dataGridColumnType";
import { isBooleanColumnType } from "@/lib/dataGrid/dataGridBooleanColumn";
@@ -17,6 +18,8 @@ export function coerceDataGridCellValue(options: CoerceDataGridCellValueOptions)
const { value, oldValue } = options;
if (value === "" && options.emptyStringAsNull) return null;
if (value === "" && oldValue === null && !options.preserveEmptyString) return null;
+ const blobValue = coerceMysqlBlobTextValue(options);
+ if (blobValue !== undefined) return blobValue;
const postgresArrayValue = coercePostgresArrayValue(options);
if (postgresArrayValue !== undefined) return postgresArrayValue;
// Excel-pasted values often carry thousands separators (10,000.00) that make
@@ -68,12 +71,24 @@ function parseBooleanInput(value: string, allowNumericAliases: boolean): boolean
export function dataGridCellEditorText(options: { value: GridCellValue | undefined; databaseType: DatabaseType | undefined; columnInfo: Pick<ColumnInfo, "data_type"> | undefined }): string {
const value = options.value ?? null;
if (value === null) return "";
+ if (options.databaseType === "mysql" && isBlobCellColumnType(options.columnInfo?.data_type)) {
+ const text = binaryCellUtf8Text(value, options.columnInfo?.data_type, options.databaseType);
+ if (text !== null) return text;
+ }
if (Array.isArray(value) && options.databaseType === "postgres" && isPostgresArrayColumn(options.columnInfo, value)) {
return formatPostgresArrayText(value);
}
return typeof value === "object" ? JSON.stringify(value) : String(value);
}
+function coerceMysqlBlobTextValue(options: CoerceDataGridCellValueOptions): GridCellValue | undefined {
+ if (options.databaseType !== "mysql" || !isBlobCellColumnType(options.columnInfo?.data_type)) 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;
+ return binaryCellBytesToHexValue(new TextEncoder().encode(options.value));
+}
+
export function dataGridCellDisplayText(options: { value: GridCellValue; databaseType: DatabaseType | undefined; columnInfo: Pick<ColumnInfo, "data_type"> | undefined }): string | undefined {
if (Array.isArray(options.value) && options.databaseType === "postgres" && isPostgresArrayColumn(options.columnInfo, options.value)) {
return formatPostgresArrayText(options.value);
diff --git a/packages/app-tests/binaryCellDownload.test.ts b/packages/app-tests/binaryCellDownload.test.ts
index b572204849..3156e184be 100644
--- a/packages/app-tests/binaryCellDownload.test.ts
+++ b/packages/app-tests/binaryCellDownload.test.ts
@@ -10,6 +10,8 @@ import {
canDownloadBinaryCellValue,
formatBinaryCellByteSize,
isBinaryCellColumnType,
+ binaryCellUtf8Text,
+ isBlobCellColumnType,
MAX_BINARY_CELL_IMPORT_BYTES,
parseBinaryCellBytes,
parseBinaryCellHexValue,
@@ -52,6 +54,8 @@ test("binary cell download detects common blob column types", () => {
assert.equal(isBinaryCellColumnType("RAW(2000)"), true);
assert.equal(isBinaryCellColumnType("long raw"), true);
assert.equal(isBinaryCellColumnType("varchar"), false);
+ assert.equal(isBlobCellColumnType("longblob"), true);
+ assert.equal(isBlobCellColumnType("varbinary(255)"), false);
});
test("binary cell download menu closes when hover moves to another cell", () => {
@@ -78,12 +82,16 @@ test("canDownloadBinaryCellValue allows displayed binary hex strings", () => {
test("binaryCellDisplayText previews printable binary strings without changing their raw bytes", () => {
assert.equal(binaryCellDisplayText("0x534e2d4130303031", "VARBINARY(8)"), "SN-A0001");
+ assert.equal(binaryCellDisplayText("0x534e2d4130303031", "VARBINARY(8)", undefined, "sqlite"), "SN-A0001");
assert.equal(binaryCellDisplayText("0x3135303031300000", "BINARY(8)"), "150010");
assert.equal(binaryCellDisplayText("0x0000", "BINARY(2)"), "");
assert.equal(binaryCellDisplayText("0x68690a", "VARBINARY(3)"), "hi\n");
assert.equal(binaryCellDisplayText("0x680069", "VARBINARY(3)"), "VARBINARY [3 bytes]");
assert.equal(binaryCellDisplayText("0xdeadbeef", "VARBINARY(4)"), "VARBINARY [4 bytes]");
+ assert.equal(binaryCellDisplayText("0x48656c6c6f", "LONGBLOB", undefined, "mysql"), "Hello");
+ assert.equal(binaryCellDisplayText("0xe8a1a8e8bebee5bc8f", "LONGBLOB", undefined, "mysql"), "表达式");
assert.equal(binaryCellDisplayText("0x89504e47", "BLOB"), "BLOB [4 bytes]");
+ assert.equal(binaryCellDisplayText("0x680069", "LONGBLOB", undefined, "mysql"), "BLOB [3 bytes]");
assert.equal(binaryCellDisplayText(`0x${"00".repeat(2048)}`, "VARBINARY(2048)"), "VARBINARY [2.0 KB]");
assert.equal(binaryCellDisplayText("0xffd8ffe000104a46...", "VARBINARY"), "VARBINARY [...]");
assert.equal(binaryCellDisplayText("0x89504e47...", "LONGBLOB"), "BLOB [...]");
@@ -92,6 +100,27 @@ test("binaryCellDisplayText previews printable binary strings without changing t
assert.equal(binaryCellDisplayText("0x", "VARBINARY(0)"), "");
});
+test("binaryCellUtf8Text only returns strict printable text", () => {
+ assert.equal(binaryCellUtf8Text("0x2332303035383035", "LONGBLOB", "mysql"), "#2005805");
+ assert.equal(binaryCellUtf8Text("0xfffe", "LONGBLOB", "mysql"), null);
+ assert.equal(binaryCellUtf8Text("0x0061", "LONGBLOB", "mysql"), null);
+ assert.equal(binaryCellUtf8Text("0x4869", "varchar", "mysql"), null);
+});
+
+// 回归:SQLite/DuckDB 等库同样有 `blob` 列,文本预览必须与编辑写回路径一样仅对 mysql 开启,
+// 否则出现“单元格/详情显示文本、编辑器却是十六进制”的不一致。
+test("BLOB text preview stays limited to MySQL connections", () => {
+ assert.equal(binaryCellUtf8Text("0x2332303035383035", "LONGBLOB", "sqlite"), null);
+ assert.equal(binaryCellUtf8Text("0x2332303035383035", "BLOB", "duckdb"), null);
+ assert.equal(binaryCellUtf8Text("0x2332303035383035", "LONGBLOB", undefined), null);
+ assert.equal(binaryCellDisplayText("0x2332303035383035", "LONGBLOB", undefined, "sqlite"), "BLOB [8 bytes]");
+ assert.equal(binaryCellDisplayText("0x2332303035383035", "BLOB", undefined, "duckdb"), "BLOB [8 bytes]");
+ assert.equal(binaryCellDisplayText("0x2332303035383035", "LONGBLOB", undefined), "BLOB [8 bytes]");
+ assert.equal(binaryCellDisplayText("0x2332303035383035", "LONGBLOB", undefined, "mysql"), "#2005805");
+ // binary/varbinary 的文本预览是既有行为(如 TDengine BINARY 文本),不受 mysql 闸门影响。
+ assert.equal(binaryCellDisplayText("0x534e2d4130303031", "VARBINARY(8)", undefined, "sqlite"), "SN-A0001");
+});
+
test("binaryCellDownloadPayload builds raw and decoded payloads", () => {
const binary = binaryCellDownloadPayload("0x4869", "binary");
assert.equal(binary.mimeType, "application/octet-stream");
diff --git a/packages/app-tests/dataGridCellCoercion.test.ts b/packages/app-tests/dataGridCellCoercion.test.ts
index 3cd783ed3f..606839dc63 100644
--- a/packages/app-tests/dataGridCellCoercion.test.ts
+++ b/packages/app-tests/dataGridCellCoercion.test.ts
@@ -192,3 +192,21 @@ test("changed PG array value returns new array reference", () => {
assert.notStrictEqual(result, oldValue);
assert.deepEqual(result, [1, 2, 3, 4]);
});
+
+test("MySQL text BLOB editor decodes UTF-8 and writes edited bytes as hex", () => {
+ const oldValue = "0x2332303035383035";
+ const columnInfo = { data_type: "longblob" };
+
+ assert.equal(dataGridCellEditorText({ value: oldValue, databaseType: "mysql", columnInfo }), "#2005805");
+ assert.strictEqual(coerceDataGridCellValue({ value: "#2005805", oldValue, databaseType: "mysql", columnInfo }), oldValue);
+ assert.equal(coerceDataGridCellValue({ value: "新表达式", oldValue, databaseType: "mysql", columnInfo }), "0xe696b0e8a1a8e8bebee5bc8f");
+ assert.equal(coerceDataGridCellValue({ value: "", oldValue, databaseType: "mysql", columnInfo }), "0x");
+});
+
+test("MySQL binary BLOB editor keeps non-text bytes in hex", () => {
+ const oldValue = "0x89504e470d0a1a0a";
+ const columnInfo = { data_type: "longblob" };
+
+ assert.equal(dataGridCellEditorText({ value: oldValue, databaseType: "mysql", columnInfo }), oldValue);
+ assert.equal(coerceDataGridCellValue({ value: oldValue, oldValue, databaseType: "mysql", columnInfo }), oldValue);
+});