A task for Binary decode?

Rodney Tamblyn rodneytamblyn at paradise.net.nz
Tue Aug 12 11:38:07 EDT 2003


Hi everyone,

I need to convert some data received from a postgreSQL database back  
into recognizable binary data.  The data was written there by a  
JDBC/Java application, and it appears that it stores the binary data in  
octets - but this is new territory for me so I am hoping someone more  
knowledgible here can help.

I'm retrieving this data using Revolution's database library.

I wonder whether binaryDecode or (possibly even) the convertOctals  
property could be useful in converting this data back into recognizable  
binary data.  Any ideas?

I am still trying to get the PostgreSQL database to allow me to upload  
blobs from Revolution, but so far without success...

Thanks very much.


~Rodney
(going to bed as is 4.30am, and although I enjoy programming in  
Revolution a lot... well, there are limits!)

-- sample of data

\377\330\377\341\025\342Exif\000\000MM\000*\000\000\000\010\000\014\001\ 
017\000\002\000\000\000\006\000\000\000\236\001\020\000\002\000\000\000\ 
023\000\000\000\244\001\022\000\003\000\000\000\001\000\001\000\000\001\ 
022\000\003\000\000\000\001\000\001\000\000\001\032\000\005\000\000\000\ 
001\000\000\000\270\001\033\000\005\000\000\000\001\000\000\000\300\001( 
\000\003\000\000\000\001\000\002\000\000\0011\000\002\000\000\000\016\00 
0\000\000\310\0012\000\002\000\000\000\024\000\000\000\326\001<\000\002\ 
000\000\000\020\000\000\000\352\002\023\000\003\000\000\000\001\000\001\ 
000\000\207i\000\004\000\000\000\001\000\000\000\372\000\000\003\240Cano 
n\000Canon PowerShot  
G3\000\000\000\264\000\000\000\001\000\000\000\264\000\000\000\001\000\0 
00QuickTime 6.1\0002003:08:03 17:56:50\000Mac OS X

-- sample of jdbc code used to write the object:
(I think this code is right, but - well -  possibly not the latest  
version, let me know if you are interested and
I will check)

Postgres supports inserting blobs through JDBC like Oracle:

CREATE TABLE images (imgname text, img bytea);

To insert an image, you would use:

  File file = new File("myimage.gif");
  FileInputStream fis = new FileInputStream(file);
  PreparedStatement ps = conn.prepareStatement("INSERT INTO images VALUES
(?, ?)");
  ps.setString(1, file.getName());
  ps.setBinaryStream(2, fis, file.length());
  ps.executeUpdate();
  ps.close();
  fis.close();

To retrieve it you:

PreparedStatement ps = con.prepareStatement("SELECT img FROM images  
WHERE
imgname=?");
  ps.setString(1, "myimage.gif");
  ResultSet rs = ps.executeQuery();
  if (rs != null) {
      while(rs.next()) {
          byte[] imgBytes = rs.getBytes(1);
          // use the stream in some way here
      }
      rs.close();
  }
  ps.close();




More information about the use-livecode mailing list