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。

fix(grid): display readable UUID string when editing MariaDB UUID cells (#12920)

lxk955bd469c49f6b6
diff --git a/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts
index b3a7931bd6..c1328f62f6 100644
--- a/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts
+++ b/apps/desktop/src/lib/__tests__/dataGrid/dataGridCellCoercion.spec.ts
@@ -1,5 +1,70 @@
import { describe, expect, it } from "vitest";
import { coerceDataGridCellValue, dataGridCellDisplayText, dataGridCellEditorText } from "@/lib/dataGrid/dataGridCellCoercion";
+import { binaryCellClipboardText, canDownloadBinaryCellValue, parseBinaryCellBytes } from "@/lib/dataGrid/binaryCellDownload";
+
+describe("dataGridCellEditorText", () => {
+ it("decodes hex-encoded ASCII UUID values to readable UUID strings in uuid columns (#12911)", () => {
+ const hex = "0x30316130353762662d326262642d373061362d623363332d353665623430396130663935";
+ expect(
+ dataGridCellEditorText({
+ value: hex,
+ databaseType: "mysql",
+ columnInfo: { data_type: "uuid" },
+ }),
+ ).toBe("01a057bf-2bbd-70a6-b3c3-56eb409a0f95");
+
+ // Ordinary binary and varbinary columns preserve canonical hex form
+ expect(
+ dataGridCellEditorText({
+ value: hex,
+ databaseType: "mysql",
+ columnInfo: { data_type: "binary(36)" },
+ }),
+ ).toBe(hex);
+ expect(
+ dataGridCellEditorText({
+ value: hex,
+ databaseType: "mysql",
+ columnInfo: { data_type: "varbinary(36)" },
+ }),
+ ).toBe(hex);
+ expect(
+ dataGridCellEditorText({
+ value: hex,
+ databaseType: "mysql",
+ columnInfo: { data_type: "binary" },
+ }),
+ ).toBe(hex);
+ });
+
+ it("decodes 16-byte raw hex UUIDs in uuid columns to hyphenated UUID strings", () => {
+ expect(
+ dataGridCellEditorText({
+ value: "0x01a057bf2bbd70a6b3c356eb409a0f95",
+ databaseType: "mysql",
+ columnInfo: { data_type: "uuid" },
+ }),
+ ).toBe("01a057bf-2bbd-70a6-b3c3-56eb409a0f95");
+ });
+
+ it("preserves plain UUID strings and arbitrary binary data", () => {
+ expect(
+ dataGridCellEditorText({
+ value: "01a057bf-2bbd-70a6-b3c3-56eb409a0f95",
+ databaseType: "mysql",
+ columnInfo: { data_type: "uuid" },
+ }),
+ ).toBe("01a057bf-2bbd-70a6-b3c3-56eb409a0f95");
+
+ expect(
+ dataGridCellEditorText({
+ value: "0x01020304",
+ databaseType: "mysql",
+ columnInfo: { data_type: "binary(4)" },
+ }),
+ ).toBe("0x01020304");
+ });
+});
describe("dataGridCellDisplayText", () => {
it("keeps precision-sensitive decimal text through editor display and unchanged commit coercion", () => {
@@ -375,4 +440,106 @@ describe("coerceDataGridCellValue", () => {
}),
).toBe("1,23");
});
+
+ it("handles UUID cell edits cleanly (#12911)", () => {
+ const hex = "0x30316130353762662d326262642d373061362d623363332d353665623430396130663935";
+ // Unchanged value preserves original hex oldValue
+ expect(
+ coerceDataGridCellValue({
+ value: "01a057bf-2bbd-70a6-b3c3-56eb409a0f95",
+ oldValue: hex,
+ databaseType: "mysql",
+ columnInfo: { data_type: "uuid" },
+ }),
+ ).toBe(hex);
+
+ // Edited value in uuid column returns clean UUID string
+ expect(
+ coerceDataGridCellValue({
+ value: "01a057bf-2bbd-70a6-b3c3-56eb409a0f99",
+ oldValue: hex,
+ databaseType: "mysql",
+ columnInfo: { data_type: "uuid" },
+ }),
+ ).toBe("01a057bf-2bbd-70a6-b3c3-56eb409a0f99");
+
+ // Cleared value returns null
+ expect(
+ coerceDataGridCellValue({
+ value: "",
+ oldValue: hex,
+ databaseType: "mysql",
+ columnInfo: { data_type: "uuid" },
+ }),
+ ).toBeNull();
+ });
+
+ it("preserves canonical hex edits in BINARY(36) and VARBINARY(36)", () => {
+ const hex = "0x30316130353762662d326262642d373061362d623363332d353665623430396130663935";
+ // Unchanged hex preserves oldValue
+ expect(
+ coerceDataGridCellValue({
+ value: hex,
+ oldValue: hex,
+ databaseType: "mysql",
+ columnInfo: { data_type: "binary(36)" },
+ }),
+ ).toBe(hex);
+
+ // Edited hex preserves new hex value
+ const newHex = "0x30316130353762662d326262642d373061362d623363332d353665623430396130663939";
+ expect(
+ coerceDataGridCellValue({
+ value: newHex,
+ oldValue: hex,
+ databaseType: "mysql",
+ columnInfo: { data_type: "binary(36)" },
+ }),
+ ).toBe(newHex);
+
+ expect(
+ coerceDataGridCellValue({
+ value: newHex,
+ oldValue: hex,
+ databaseType: "mysql",
+ columnInfo: { data_type: "varbinary(36)" },
+ }),
+ ).toBe(newHex);
+ });
+});
+
+describe("binaryCellClipboardText", () => {
+ it("copies hex-encoded UUID values as readable text for uuid columns (#12911)", () => {
+ const hex = "0x30316130353762662d326262642d373061362d623363332d353665623430396130663935";
+ expect(binaryCellClipboardText(hex, "uuid", "mysql")).toBe("01a057bf-2bbd-70a6-b3c3-56eb409a0f95");
+ expect(binaryCellClipboardText("0x01a057bf2bbd70a6b3c356eb409a0f95", "uuid", "mysql")).toBe("01a057bf-2bbd-70a6-b3c3-56eb409a0f95");
+ });
+
+ it("preserves canonical hex or standard copy behavior for binary/varbinary storing ASCII UUID", () => {
+ const hex = "0x30316130353762662d326262642d373061362d623363332d353665623430396130663935";
+ // BINARY(36) keeps canonical hex (null return signals clipboard to copy raw hex)
+ expect(binaryCellClipboardText(hex, "binary(36)", "mysql")).toBeNull();
+ expect(binaryCellClipboardText(hex, "binary", "mysql")).toBeNull();
+ // VARBINARY(36) in MySQL copies UTF-8 printable string per #7471
+ expect(binaryCellClipboardText(hex, "varbinary(36)", "mysql")).toBe("01a057bf-2bbd-70a6-b3c3-56eb409a0f95");
+ expect(binaryCellClipboardText("0x01020304", "binary", "mysql")).toBeNull();
+ });
+});
+
+describe("canDownloadBinaryCellValue and parseBinaryCellBytes", () => {
+ it("allows downloading canonical hex in BINARY(36) and VARBINARY(36) even when storing ASCII UUID bytes", () => {
+ const hex = "0x30316130353762662d326262642d373061362d623363332d353665623430396130663935";
+ expect(canDownloadBinaryCellValue(hex, "binary(36)", "mysql")).toBe(true);
+ expect(canDownloadBinaryCellValue(hex, "varbinary(36)", "mysql")).toBe(true);
+
+ const binaryBytes = parseBinaryCellBytes(hex, "binary(36)", "mysql");
+ expect(binaryBytes).not.toBeNull();
+ expect(binaryBytes?.length).toBe(36);
+ expect(new TextDecoder().decode(binaryBytes!)).toBe("01a057bf-2bbd-70a6-b3c3-56eb409a0f95");
+
+ const varbinaryBytes = parseBinaryCellBytes(hex, "varbinary(36)", "mysql");
+ expect(varbinaryBytes).not.toBeNull();
+ expect(varbinaryBytes?.length).toBe(36);
+ expect(new TextDecoder().decode(varbinaryBytes!)).toBe("01a057bf-2bbd-70a6-b3c3-56eb409a0f95");
+ });
});
diff --git a/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts b/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts
index 06d98291c1..88bdfad300 100644
--- a/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts
+++ b/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts
@@ -1,6 +1,7 @@
import type { CellValue } from "@/lib/dataGrid/cellValue";
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
import type { DatabaseType } from "@/types/database";
+import { isUuidColumnType } from "@/lib/dataGrid/dataGridColumnType";
export type BinaryCellDownloadMode = "binary" | "utf8" | "gbk";
@@ -111,6 +112,9 @@ const HEX_VALUE_RE = /^(?:0[xX]|\\x)([0-9a-fA-F\s]*)$/;
const TRUNCATED_HEX_VALUE_RE = /^(?:0[xX]|\\x)[0-9a-fA-F\s]+\.\.\.$/;
const BARE_HEX_RE = /^[0-9a-fA-F\s]+$/;
const HEX_ESCAPE_RE = /^(?:\\x[0-9a-fA-F]{2}|\s)+$/;
+const UUID_HEX_ASCII_RE = /^(?:0[xX])([0-9a-fA-F]{72})$/;
+const UUID_HEX_RAW_RE = /^(?:0[xX])([0-9a-fA-F]{32})$/;
+const UUID_CANONICAL_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
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;
@@ -131,6 +135,33 @@ export function parseBinaryCellHexValue(value: CellValue): Uint8Array | null {
return bytesFromHex(match[1]);
}
+export function decodeBinaryUuidText(value: unknown, columnType?: string): string | null {
+ if (!isUuidColumnType(columnType)) return null;
+ if (typeof value !== "string") return null;
+ const trimmed = value.trim();
+
+ const matchAscii = trimmed.match(UUID_HEX_ASCII_RE);
+ if (matchAscii) {
+ const bytes = parseBinaryCellHexValue(trimmed);
+ if (bytes && bytes.length === 36) {
+ try {
+ const decoded = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
+ if (UUID_CANONICAL_RE.test(decoded)) return decoded;
+ } catch {
+ // Not valid UTF-8
+ }
+ }
+ }
+
+ const matchRaw = trimmed.match(UUID_HEX_RAW_RE);
+ if (matchRaw) {
+ const hex = matchRaw[1].toLowerCase();
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
+ }
+
+ return null;
+}
+
function bytesFromHex(value: string): Uint8Array | null {
const hex = value.replace(/\s+/g, "");
if (hex.length === 0) return new Uint8Array();
@@ -222,6 +253,8 @@ export function binaryCellDisplayText(value: unknown, columnType?: string, origi
const size = originalBytes === undefined ? "..." : formatBinaryCellByteSize(originalBytes);
return `${binaryCellDisplayLabel(columnType)} [${size}]`;
}
+ const uuidText = decodeBinaryUuidText(value, columnType);
+ if (uuidText !== null) return uuidText;
const bytes = parseBinaryCellBytes(value, columnType, databaseType);
if (!bytes || !isBinaryCellColumnType(columnType)) return null;
if (isBinaryCellTextPreviewColumn(columnType, databaseType)) {
@@ -291,6 +324,8 @@ export function binaryCellTextPreview(value: unknown, encoding: BinaryCellTextEn
// VARBINARY,避免改变 MySQL BINARY/BLOB、SQL Server VARBINARY、PostgreSQL BYTEA、
// Oracle RAW 等现有语义。
export function binaryCellClipboardText(value: unknown, columnType?: string, databaseType?: DatabaseType): string | null {
+ const uuidText = decodeBinaryUuidText(value, columnType);
+ if (uuidText !== null) return uuidText;
// 覆盖上方注释里「严格限于 VARBINARY」的旧范围(#12413):网格已经对文本型 BLOB
// 显示文本预览(MySQL 与 Oracle 家族;AES_DECRYPT 这类表达式的结果列常报成 BLOB),
// 显示 `secret` 却复制出 hex 与预览自相矛盾,因此并入同一闸门;严格往返校验与 hex
diff --git a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
index e03f4b09fd..db9977d8b2 100644
--- a/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
+++ b/apps/desktop/src/lib/dataGrid/dataGridCellCoercion.ts
@@ -1,7 +1,7 @@
import type { GridCellValue } from "@/lib/dataGrid/dataGridSql";
import type { DatabaseType, ColumnInfo } from "@/types/database";
-import { binaryCellBytesToHexValue, binaryCellUtf8Text, isBlobCellColumnType, isBlobTextPreviewDatabase } from "@/lib/dataGrid/binaryCellDownload";
-import { isNumericColumnType, resolveDataGridTypeVisualKind } from "@/lib/dataGrid/dataGridColumnType";
+import { binaryCellBytesToHexValue, binaryCellUtf8Text, decodeBinaryUuidText, isBlobCellColumnType, isBlobTextPreviewDatabase } from "@/lib/dataGrid/binaryCellDownload";
+import { isNumericColumnType, isUuidColumnType, resolveDataGridTypeVisualKind } from "@/lib/dataGrid/dataGridColumnType";
import { isBooleanColumnType } from "@/lib/dataGrid/dataGridBooleanColumn";
export interface CoerceDataGridCellValueOptions {
@@ -26,6 +26,8 @@ export function coerceDataGridCellValue(options: CoerceDataGridCellValueOptions)
const { value, oldValue } = options;
if (value === "" && options.emptyStringAsNull) return null;
if (value === "" && oldValue === null && !keepsEmptyStringInColumn(options)) return null;
+ const uuidValue = coerceUuidTextValue(options);
+ if (uuidValue !== undefined) return uuidValue;
const blobValue = coerceBlobTextValue(options);
if (blobValue !== undefined) return blobValue;
const postgresArrayValue = coercePostgresArrayValue(options);
@@ -92,6 +94,8 @@ 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 "";
+ const uuidText = decodeBinaryUuidText(value, options.columnInfo?.data_type);
+ if (uuidText !== null) return uuidText;
if (isBlobTextPreviewDatabase(options.databaseType) && isBlobCellColumnType(options.columnInfo?.data_type)) {
const text = binaryCellUtf8Text(value, options.columnInfo?.data_type, options.databaseType);
if (text !== null) return text;
@@ -102,6 +106,23 @@ export function dataGridCellEditorText(options: { value: GridCellValue | undefin
return typeof value === "object" ? JSON.stringify(value) : String(value);
}
+function coerceUuidTextValue(options: CoerceDataGridCellValueOptions): GridCellValue | undefined {
+ if (!isUuidColumnType(options.columnInfo?.data_type)) return undefined;
+ const originalUuid = decodeBinaryUuidText(options.oldValue, options.columnInfo?.data_type);
+ if (originalUuid !== null) {
+ if (options.value === originalUuid) return options.oldValue;
+ if (options.value.trim() === "") return null;
+ return options.value.trim();
+ }
+ if (typeof options.oldValue === "string") {
+ if (options.value === options.oldValue) return options.oldValue;
+ if (options.value.trim() === "") return null;
+ return options.value.trim();
+ }
+ if (options.value.trim() === "") return null;
+ return options.value.trim();
+}
+
function coerceBlobTextValue(options: CoerceDataGridCellValueOptions): GridCellValue | undefined {
if (!isBlobTextPreviewDatabase(options.databaseType) || !isBlobCellColumnType(options.columnInfo?.data_type)) return undefined;
const originalText = binaryCellUtf8Text(options.oldValue, options.columnInfo?.data_type, options.databaseType);
diff --git a/apps/desktop/src/lib/dataGrid/dataGridColumnType.ts b/apps/desktop/src/lib/dataGrid/dataGridColumnType.ts
index 34c5b63979..3ff6007308 100644
--- a/apps/desktop/src/lib/dataGrid/dataGridColumnType.ts
+++ b/apps/desktop/src/lib/dataGrid/dataGridColumnType.ts
@@ -340,6 +340,12 @@ function dataGridColumnTypeBase(dataType: string): { base: string; array: boolea
return { base, array: unwrapped.array };
}
+export function isUuidColumnType(dataType: string | undefined): boolean {
+ if (!dataType?.trim()) return false;
+ const { base, array } = dataGridColumnTypeBase(dataType);
+ return !array && (base === "uuid" || base === "uniqueidentifier");
+}
+
/**
* Collapse driver-specific SQL type names into the small semantic palette used
* by grid headers and values. Unknown types deliberately stay neutral.
diff --git a/crates/dbx-driver-mysql/src/mysql.rs b/crates/dbx-driver-mysql/src/mysql.rs
index 429a0ac095..f1fc018588 100644
--- a/crates/dbx-driver-mysql/src/mysql.rs
+++ b/crates/dbx-driver-mysql/src/mysql.rs
@@ -9183,6 +9183,17 @@ mod tests {
assert_eq!(mysql_bytes_to_json(b"TEXT-001".to_vec(), &text_column), serde_json::json!("TEXT-001"));
}
+ #[test]
+ fn mysql_binary_string_preserves_canonical_hex_for_ascii_uuid() {
+ let binary_column = mysql_test_column(ColumnType::MYSQL_TYPE_STRING, 63, ColumnFlags::BINARY_FLAG, 36);
+ let uuid_bytes = b"01a057bf-2bbd-70a6-b3c3-56eb409a0f95".to_vec();
+
+ assert_eq!(
+ mysql_bytes_to_json(uuid_bytes, &binary_column),
+ serde_json::json!("0x30316130353762662d326262642d373061362d623363332d353665623430396130663935")
+ );
+ }
+
#[test]
fn mysql_binary_values_preserve_all_bytes_as_hex() {
let binary_column = mysql_test_column(ColumnType::MYSQL_TYPE_STRING, 63, ColumnFlags::BINARY_FLAG, 8);
diff --git a/crates/dbx-sql-data/src/data_grid_sql.rs b/crates/dbx-sql-data/src/data_grid_sql.rs
index efc4d99034..824bd50412 100644
--- a/crates/dbx-sql-data/src/data_grid_sql.rs
+++ b/crates/dbx-sql-data/src/data_grid_sql.rs
@@ -2843,6 +2843,11 @@ pub fn format_grid_sql_literal_with_identifier_quote(
return timestamp.to_string();
}
}
+ if column_info.map(|column| is_uuid_column_type(&column.data_type)).unwrap_or(false) {
+ if let Some(literal) = format_hex_uuid_literal(&text) {
+ return literal;
+ }
+ }
if is_mysql_binary_literal_column(database_type, column_info) {
if let Some(literal) = format_mysql_binary_literal_text(&text) {
// DBX result values expose binary columns as prefixed hex; keep them
@@ -3305,6 +3310,53 @@ fn is_mysql_binary_column_type(data_type: &str) -> bool {
matches!(base, "binary" | "varbinary" | "blob" | "tinyblob" | "mediumblob" | "longblob")
}
+fn is_uuid_column_type(data_type: &str) -> bool {
+ let lower = data_type.trim().to_ascii_lowercase();
+ let base = lower.split(['(', ':', ' ']).next().unwrap_or("").trim();
+ matches!(base, "uuid" | "uniqueidentifier")
+}
+
+fn format_hex_uuid_literal(text: &str) -> Option<String> {
+ let trimmed = text.trim();
+ let hex = trimmed.strip_prefix("0x").or_else(|| trimmed.strip_prefix("0X"))?;
+ if !hex.is_ascii() {
+ return None;
+ }
+ let hex_bytes = hex.as_bytes();
+ if hex_bytes.len() == 72 && hex_bytes.iter().all(|b| b.is_ascii_hexdigit()) {
+ let mut bytes = Vec::with_capacity(36);
+ for chunk in hex_bytes.chunks_exact(2) {
+ let s = std::str::from_utf8(chunk).ok()?;
+ let byte = u8::from_str_radix(s, 16).ok()?;
+ bytes.push(byte);
+ }
+ if bytes.len() == 36
+ && bytes.iter().enumerate().all(|(idx, &b)| {
+ if idx == 8 || idx == 13 || idx == 18 || idx == 23 {
+ b == b'-'
+ } else {
+ b.is_ascii_hexdigit()
+ }
+ })
+ {
+ let uuid_str = std::str::from_utf8(&bytes).ok()?;
+ return Some(format!("'{uuid_str}'"));
+ }
+ }
+ if hex_bytes.len() == 32 && hex_bytes.iter().all(|b| b.is_ascii_hexdigit()) {
+ let lower = hex.to_ascii_lowercase();
+ return Some(format!(
+ "'{}-{}-{}-{}-{}'",
+ &lower[0..8],
+ &lower[8..12],
+ &lower[12..16],
+ &lower[16..20],
+ &lower[20..32]
+ ));
+ }
+ None
+}
+
fn format_mysql_binary_literal_text(text: &str) -> Option<String> {
let trimmed = text.trim();
let hex = trimmed.strip_prefix("0x")?;
@@ -10994,6 +11046,73 @@ mod tests {
);
}
+ #[test]
+ fn uuid_column_literals_decode_prefixed_hex_values() {
+ let uuid_col = column("id", "uuid", false, None);
+ assert_eq!(
+ format_grid_sql_literal(
+ &json!("0x30316130353762662d326262642d373061362d623363332d353665623430396130663935"),
+ Some(DatabaseType::Mysql),
+ Some(&uuid_col)
+ ),
+ "'01a057bf-2bbd-70a6-b3c3-56eb409a0f95'"
+ );
+ assert_eq!(
+ format_grid_sql_literal(
+ &json!("0x01a057bf2bbd70a6b3c356eb409a0f95"),
+ Some(DatabaseType::Mysql),
+ Some(&uuid_col)
+ ),
+ "'01a057bf-2bbd-70a6-b3c3-56eb409a0f95'"
+ );
+ assert_eq!(
+ format_grid_sql_literal(
+ &json!("01a057bf-2bbd-70a6-b3c3-56eb409a0f95"),
+ Some(DatabaseType::Mysql),
+ Some(&uuid_col)
+ ),
+ "'01a057bf-2bbd-70a6-b3c3-56eb409a0f95'"
+ );
+ }
+
+ #[test]
+ fn uuid_column_literals_handle_malformed_unicode_safely() {
+ let uuid_col = column("id", "uuid", false, None);
+
+ // 3-byte UTF-8 char '你' + 69 ASCII chars = 72 bytes. Slicing at byte index 2 must not panic.
+ let malformed_72_bytes = format!("0x你{}", "0".repeat(69));
+ assert_eq!(malformed_72_bytes.len(), 2 + 3 + 69); // 74 bytes with prefix '0x'
+ assert_eq!(format_hex_uuid_literal(&malformed_72_bytes), None);
+ // format_grid_sql_literal falls back safely to quoted string without panicking
+ assert_eq!(
+ format_grid_sql_literal(&json!(malformed_72_bytes), Some(DatabaseType::Mysql), Some(&uuid_col)),
+ format!("'{}'", malformed_72_bytes.replace('\\', "\\\\").replace('\'', "\\'"))
+ );
+
+ // 10 3-byte UTF-8 chars (30 bytes) + 2 ASCII chars = 32 bytes
+ let malformed_32_bytes = format!("0x{}00", "你".repeat(10));
+ assert_eq!(format_hex_uuid_literal(&malformed_32_bytes), None);
+
+ // Non-hex ASCII chars
+ let non_hex_72 = format!("0x{}", "g".repeat(72));
+ assert_eq!(format_hex_uuid_literal(&non_hex_72), None);
+ let non_hex_32 = format!("0x{}", "z".repeat(32));
+ assert_eq!(format_hex_uuid_literal(&non_hex_32), None);
+ }
+
+ #[test]
+ fn binary_columns_preserve_canonical_hex_for_ascii_uuid() {
+ let binary_col = column("payload", "binary(36)", false, None);
+ let varbinary_col = column("payload", "varbinary(36)", false, None);
+ let hex = "0x30316130353762662d326262642d373061362d623363332d353665623430396130663935";
+
+ // MySQL binary columns emit the canonical 0x<hex> literal unchanged;
+ // the important part of the fix is that content-shape UUID guessing
+ // no longer turns this into a quoted '01a057bf-...' UUID string.
+ assert_eq!(format_grid_sql_literal(&json!(hex), Some(DatabaseType::Mysql), Some(&binary_col)), hex);
+ assert_eq!(format_grid_sql_literal(&json!(hex), Some(DatabaseType::Mysql), Some(&varbinary_col)), hex);
+ }
+
#[test]
fn postgres_bytea_literals_decode_prefixed_hex_values() {
let bytea = column("payload", "bytea", true, None);