Problem with bytea

From: Daniel Carlsson <daniel(dot)carlsson(at)gimlisoft(dot)se>
To: pgsql-general(at)postgresql(dot)org
Subject: Problem with bytea
Date: 2003-06-05 16:33:43
Message-ID: buffalo1_3edf70c563b0d@webmail.buffalosoftware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

When a fetch binary data from a bytea column the data gets messed up.

Se the attached code, postgresql returns 13744 bytes when it should be only 10000. After studing the output I saw that bytes representing common characters are fetched ok but bytes representing unusual characters such as special swedish characters are messed up. Is the binary data somewhere treated as character data? Could something else be the problem?

I use RedHat 8.0, Postgresql 7.3.2 and jdbc driver pg73jdbc3.jar released 26:th of may.

Code:

Connection c = DriverManager.getConnection(jdbc);
Statement s = c.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
ResultSet r;

byte b[] = new byte[10000];

for(int i=0;i<b.length;i++)
b[i] = (byte)(i%256);

/* Update bytea with 10000 bytes */
s.executeUpdate("update document set file_=null where documentid=12");
r = s.executeQuery("select file_,documentid from document where documentid=17");
r.next();
r.updateBytes(1,b);
r.updateRow();

/* Fetch the bytea value */
r = s.executeQuery("select file_,documentid from document where documentid=17");
r.next();
b = r.getBytes(1);

/* This outputs 13744 !?!? */
System.out.println("Length: " + b.length);

Med vänliga hälsningar

Daniel Carlsson
Gimlisoft AB
Email: daniel(dot)carlsson(at)gimlisoft(dot)se
Tel: 0709-744570, 031-189024

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Nick Barr 2003-06-05 16:38:21 Create index on the year of a date column
Previous Message scott.marlowe 2003-06-05 16:01:40 Re: Nulls get converted to 0 problem