Message-ID: From: "rlbdv (@rlbdv)" To: "pgjdbc/pgjdbc" Date: Mon, 11 Aug 2025 16:59:31 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #3757: PreparedStatement.toString() fails for bytea parameters with at least 42.7.7 In-Reply-To: References: List-Id: X-GitHub-Author-Login: rlbdv X-GitHub-Comment-Id: 3175937240 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 3757 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3757#issuecomment-3175937240 Content-Type: text/plain; charset=utf-8 Would it be plausible to start with just support for the simpler hex format? If so, here's a very pedestrian attempt. Happy to make adjustments, and/or to add some tests, if this seems reasonable and I have time to figure that out. ```java if (value instanceof String) { String str = (String) value; StringBuilder sb = new StringBuilder(str.length() + 9); if (!str.startsWith("\\x")) throw new IllegalArgumentException(GT.tr("bytea string parameters must be hex format")); sb.append("'\\x"); int i = 2; while (i < str.length()) { while (Character.isWhitespace(str.charAt(i))) i++; if (i == str.length()) break; if (i + 2 > str.length()) throw new IllegalArgumentException(GT.tr("Truncated bytea hex format")); char c1 = str.charAt(i); char c2 = str.charAt(i + 1); if ("0123456789abcdefABCDEF".indexOf(c1) == -1) throw new IllegalArgumentException(GT.tr("Invalid bytea hex format character {0}", c1)); if ("0123456789abcdefABCDEF".indexOf(c2) == -1) throw new IllegalArgumentException(GT.tr("Invalid bytea hex format character {0}", c2)); sb.append(c1); sb.append(c2); i += 2; } sb.append("'::bytea"); return sb.toString(); } ```