pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: rlbdv (@rlbdv) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #3757: PreparedStatement.toString() fails for bytea parameters with at least 42.7.7
Date: Mon, 11 Aug 2025 16:59:31 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

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();
    }
```


view thread (17+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #3757: PreparedStatement.toString() fails for bytea parameters with at least 42.7.7
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox