Commit 734e4212 authored by Barry Lind's avatar Barry Lind

Bugfix for bug reported by Marcus Better (marcus@dactylis.com). When preforming

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.
parent f3efaf89
...@@ -404,7 +404,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -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 //Version 7.2 supports the bytea datatype for byte arrays
if (fields[columnIndex - 1].getPGType().equals("bytea")) if (fields[columnIndex - 1].getPGType().equals("bytea"))
{ {
return PGbytea.toBytes(getString(columnIndex)); return PGbytea.toBytes(this_row[columnIndex - 1]);
} }
else else
{ {
......
...@@ -331,7 +331,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -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 //Version 7.2 supports the bytea datatype for byte arrays
if (fields[columnIndex - 1].getPGType().equals("bytea")) if (fields[columnIndex - 1].getPGType().equals("bytea"))
{ {
return PGbytea.toBytes(getString(columnIndex)); return PGbytea.toBytes(this_row[columnIndex - 1]);
} }
else else
{ {
......
...@@ -5,40 +5,40 @@ import java.sql.*; ...@@ -5,40 +5,40 @@ import java.sql.*;
/* /*
* Converts to and from the postgresql bytea datatype used by the backend. * 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 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[] * 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) if (s == null)
return null; return null;
int slength = s.length(); int slength = s.length;
byte[] buf = new byte[slength]; byte[] buf = new byte[slength];
int bufpos = 0; int bufpos = 0;
int thebyte; int thebyte;
char nextchar; byte nextbyte;
char secondchar; byte secondbyte;
for (int i = 0; i < slength; i++) for (int i = 0; i < slength; i++)
{ {
nextchar = s.charAt(i); nextbyte = s[i];
if (nextchar == '\\') if (nextbyte == (byte)'\\')
{ {
secondchar = s.charAt(++i); secondbyte = s[++i];
if (secondchar == '\\') if (secondbyte == (byte)'\\')
{ {
//escaped \ //escaped \
buf[bufpos++] = (byte)'\\'; buf[bufpos++] = (byte)'\\';
} }
else 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) if (thebyte > 127)
thebyte -= 256; thebyte -= 256;
buf[bufpos++] = (byte)thebyte; buf[bufpos++] = (byte)thebyte;
...@@ -46,7 +46,7 @@ public class PGbytea ...@@ -46,7 +46,7 @@ public class PGbytea
} }
else else
{ {
buf[bufpos++] = (byte)nextchar; buf[bufpos++] = nextbyte;
} }
} }
byte[] l_return = new byte[bufpos]; byte[] l_return = new byte[bufpos];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment