dbTalk Databases Forums  

[BUGS] BUG #1594: ResultSet.getBytes() vs db encoding latin1

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #1594: ResultSet.getBytes() vs db encoding latin1 in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Pascal Lambert
 
Posts: n/a

Default [BUGS] BUG #1594: ResultSet.getBytes() vs db encoding latin1 - 04-12-2005 , 11:17 PM







The following bug has been logged online:

Bug reference: 1594
Logged by: Pascal Lambert
Email address: pascall (AT) caddy (DOT) ca
PostgreSQL version: 7.3.9
Operating system: linux
Description: ResultSet.getBytes() vs db encoding latin1
Details:

The bug is related with the jdbc driver.

The getBytes() method of the ResultSet didn't return the correct bytes. It
can be reprodure easly with the following with a database using encoding
LATIN1. But it work fine when using UNICODE encoding.

__________________________________________________ _______
/**
* CREATE DATABASE BUGBYTEA WITH ENCODING='LATIN1';
* CREATE TABLE IMAGES ( IMAGE BYTEA );
*/
public class BugBytea
{
public static void main(String[] args)
{
try {
BugBytea o = new BugBytea();
o.run();
} catch (Exception e) {
e.printStackTrace();
}
}

private void run() throws Exception
{
Class.forName("org.postgresql.Driver");
Connection con =
DriverManager.getConnection("jdbcostgresql://caddy_java/bugbytea",
"postgres", "");

Statement stmt = con.createStatement();
stmt.executeUpdate("truncate table images");
PreparedStatement pstmt = con.prepareStatement("insert into images
values (?)");

byte[] bytes = {-84, -19, 0, 5};
pstmt.setBytes(1, bytes);
pstmt.execute();

ResultSet rs = stmt.executeQuery("select image from images");
rs.next();
byte[] result = rs.getBytes(1);

System.out.println("bytes=");
this.printByte(bytes);
System.out.println("result=");
this.printByte(result);
}

private void printByte(byte[] bytes)
{
for (int i=0; i<bytes.length; i++)
{
if (i>0) System.out.print(", ");
System.out.print(bytes[i]);
}
System.out.println("");
}
}

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Reply With Quote
  #2  
Old   
Kris Jurka
 
Posts: n/a

Default Re: [BUGS] BUG #1594: ResultSet.getBytes() vs db encoding latin1 - 04-13-2005 , 03:20 AM








On Tue, 12 Apr 2005, Pascal Lambert wrote:

Quote:
Bug reference: 1594
Logged by: Pascal Lambert
Email address: pascall (AT) caddy (DOT) ca
PostgreSQL version: 7.3.9
Description: ResultSet.getBytes() vs db encoding latin1

The getBytes() method of the ResultSet didn't return the correct bytes. It
can be reprodure easly with the following with a database using encoding
LATIN1. But it work fine when using UNICODE encoding.
This is actually a server bug, not a driver bug. The server is trying to
do client encoding conversion of binary data, which it shouldn't. Are you
sure you are using version 7.3.9? Here I have 7.3.0, 7.3.1, 7.3.2, and
7.3.9. The only one that has that bug is 7.3.2. I don't know when this
was fixed, but I have no trouble with 7.3.9.

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.