Skip to content

Commit 734e421

Browse files
author
Barry Lind
committed
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.
1 parent f3efaf8 commit 734e421

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ else if (connection.haveMinimumCompatibleVersion("7.2"))
404404
//Version 7.2 supports the bytea datatype for byte arrays
405405
if (fields[columnIndex - 1].getPGType().equals("bytea"))
406406
{
407-
return PGbytea.toBytes(getString(columnIndex));
407+
return PGbytea.toBytes(this_row[columnIndex - 1]);
408408
}
409409
else
410410
{

src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ else if (connection.haveMinimumCompatibleVersion("7.2"))
331331
//Version 7.2 supports the bytea datatype for byte arrays
332332
if (fields[columnIndex - 1].getPGType().equals("bytea"))
333333
{
334-
return PGbytea.toBytes(getString(columnIndex));
334+
return PGbytea.toBytes(this_row[columnIndex - 1]);
335335
}
336336
else
337337
{

src/interfaces/jdbc/org/postgresql/util/PGbytea.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,48 @@
55
/*
66
* Converts to and from the postgresql bytea datatype used by the backend.
77
*
8-
* $Id: PGbytea.java,v 1.3 2001/11/19 22:33:39 momjian Exp $
8+
* $Id: PGbytea.java,v 1.4 2002/01/05 22:26:23 barry Exp $
99
*/
1010

1111
public class PGbytea
1212
{
1313

1414
/*
15-
* Converts a PG bytea string (i.e. the text representation
15+
* Converts a PG bytea raw value (i.e. the raw binary representation
1616
* of the bytea data type) into a java byte[]
1717
*/
18-
public static byte[] toBytes(String s) throws SQLException
18+
public static byte[] toBytes(byte[] s) throws SQLException
1919
{
2020
if (s == null)
2121
return null;
22-
int slength = s.length();
22+
int slength = s.length;
2323
byte[] buf = new byte[slength];
2424
int bufpos = 0;
2525
int thebyte;
26-
char nextchar;
27-
char secondchar;
26+
byte nextbyte;
27+
byte secondbyte;
2828
for (int i = 0; i < slength; i++)
2929
{
30-
nextchar = s.charAt(i);
31-
if (nextchar == '\\')
30+
nextbyte = s[i];
31+
if (nextbyte == (byte)'\\')
3232
{
33-
secondchar = s.charAt(++i);
34-
if (secondchar == '\\')
33+
secondbyte = s[++i];
34+
if (secondbyte == (byte)'\\')
3535
{
3636
//escaped \
3737
buf[bufpos++] = (byte)'\\';
3838
}
3939
else
4040
{
41-
thebyte = (secondchar - 48) * 64 + (s.charAt(++i) - 48) * 8 + (s.charAt(++i) - 48);
41+
thebyte = (secondbyte - 48) * 64 + (s[++i] - 48) * 8 + (s[++i] - 48);
4242
if (thebyte > 127)
4343
thebyte -= 256;
4444
buf[bufpos++] = (byte)thebyte;
4545
}
4646
}
4747
else
4848
{
49-
buf[bufpos++] = (byte)nextchar;
49+
buf[bufpos++] = nextbyte;
5050
}
5151
}
5252
byte[] l_return = new byte[bufpos];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy