Bugfix for bug reported by Marcus Better ([email protected]). When preforming
authorBarry Lind
Sat, 5 Jan 2002 22:26:23 +0000 (22:26 +0000)
committerBarry Lind
Sat, 5 Jan 2002 22:26:23 +0000 (22:26 +0000)
a get on a bytea value the code was running the raw value from the server
through character set conversion, which if the character set was SQL_ASCII
would cause all 8bit characters to become ?'s.

src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
src/interfaces/jdbc/org/postgresql/util/PGbytea.java

index b20d2f8a880ec4be51f78711aff11ca52c8b3a47..c5cf5619bb16cc8ec33c1a298c607d5072e7a438 100644 (file)
@@ -404,7 +404,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
                //Version 7.2 supports the bytea datatype for byte arrays
                if (fields[columnIndex - 1].getPGType().equals("bytea"))
                {
-                   return PGbytea.toBytes(getString(columnIndex));
+                   return PGbytea.toBytes(this_row[columnIndex - 1]);
                }
                else
                {
index 565847db9f16f4ab0c56693d85a6bf4a9e4b7e88..58773b819baf1ad0a0994796fb261065efaea6aa 100644 (file)
@@ -331,7 +331,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
                //Version 7.2 supports the bytea datatype for byte arrays
                if (fields[columnIndex - 1].getPGType().equals("bytea"))
                {
-                   return PGbytea.toBytes(getString(columnIndex));
+                   return PGbytea.toBytes(this_row[columnIndex - 1]);
                }
                else
                {
index c424ae27ceed1ab5e318d0588dca3c07d554b907..93e8afae5ae0dd6bde6deb57cb339447a1ff11e1 100644 (file)
@@ -5,40 +5,40 @@ import java.sql.*;
 /*
  * Converts to and from the postgresql bytea datatype used by the backend.
  *
- * $Id: PGbytea.java,v 1.3 2001/11/19 22:33:39 momjian Exp $
+ * $Id: PGbytea.java,v 1.4 2002/01/05 22:26:23 barry Exp $
  */
 
 public class PGbytea
 {
 
    /*
-    * Converts a PG bytea string (i.e. the text representation
+    * Converts a PG bytea raw value (i.e. the raw binary representation
     * of the bytea data type) into a java byte[]
     */
-   public static byte[] toBytes(String s) throws SQLException
+   public static byte[] toBytes(byte[] s) throws SQLException
    {
        if (s == null)
            return null;
-       int slength = s.length();
+                int slength = s.length;
        byte[] buf = new byte[slength];
        int bufpos = 0;
        int thebyte;
-       char nextchar;
-       char secondchar;
+       byte nextbyte;
+       byte secondbyte;
        for (int i = 0; i < slength; i++)
        {
-           nextchar = s.charAt(i);
-           if (nextchar == '\\')
+           nextbyte = s[i];
+           if (nextbyte == (byte)'\\')
            {
-               secondchar = s.charAt(++i);
-               if (secondchar == '\\')
+               secondbyte = s[++i];
+               if (secondbyte == (byte)'\\')
                {
                    //escaped \
                    buf[bufpos++] = (byte)'\\';
                }
                else
                {
-                   thebyte = (secondchar - 48) * 64 + (s.charAt(++i) - 48) * 8 + (s.charAt(++i) - 48);
+                   thebyte = (secondbyte - 48) * 64 + (s[++i] - 48) * 8 + (s[++i] - 48);
                    if (thebyte > 127)
                        thebyte -= 256;
                    buf[bufpos++] = (byte)thebyte;
@@ -46,7 +46,7 @@ public class PGbytea
            }
            else
            {
-               buf[bufpos++] = (byte)nextchar;
+               buf[bufpos++] = nextbyte;
            }
        }
        byte[] l_return = new byte[bufpos];