Skip to Content.
Sympa Menu

freetds - [freetds] Reading table char fields with binary info.

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Pedro J. Kania" <pedro.kania AT corhoma.com.ar>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] Reading table char fields with binary info.
  • Date: Fri, 28 Feb 2003 12:17:00 -0300

Dear members,

We have a trouble at the time of reading information trough the use
ofTDS JDBC T4 driver

-------- Our context is:

- Windows 2000 with SQL Server 2000
- FreeTDS JDBC Driver
-
Class.forName("jdbc:freetds:sqlserver://server/DBaseName");
- Connection con =
DriverManager.getConnection("com.internetcds.jdbc.tds.Driver",
"usr", "pasw" );

-------- The problem:

We had information stored in a table field defined as a type CHAR
(size 12) and we use to read and write binary information on it.
( from hex 00 to FF )

Uptil now our application were using ODBC without problem.
For exaple if we read ( e.g. trough the MS SQL Query Analizer by
using:

"SELECT field_bin, CAST(field_bin AS varbinary(12)) from
DBaseTable"

we got :

(1) => 0x12 0x77 0x12 0x69 ||0x81|| 0x63 0xAC 0x01 0x4C 0x69
0xEF0x74


We pretend to use java plus JDBC e.g. by using code like this:
...............
...............
byte[] bCharBin = new byte[12];
if(rs.next()) {
InputStream in = rs.getBinaryStream("field_bin");
while ((c = in.read()) != -1) {
bCharBin[i++] = (byte)c;
}
}
..............
..............

If we use the SUN JDBCtoODBC bridge to do so we can read the info
without problem.

read with JdbcOdbcDriver bridge

(2)=> 0x12 0x77 0x12 0x69 ||0x81|| 0x63 0xAC 0x01 0x4C 0x69 0xEF
0x74

but if we try to do it with FreeTDS, some bytes with this info :

0x81 , 0x90 , 0x8F, 0x9D, 0x8F are changed by 0x3F.

The following hex dump shows the bytes as we got them trough TDS:

read with TDS Jdbc T4 Driver

(3)=> 0x12 0x77 0x12 0x69 ||0x3F|| 0x63 0xAC 0x01 0x4C 0x69 0xEF
0x74

Note the original info (1) and (2) compared with (3) .
The byte with 0x81 is sistematically replaced with 0x3F

-------- Questions:

Could you help us by recomend what to modify or what is wrong ?

Is there any procedure to avoid this ?

Is there any procedure to follow with TDS to handle this situation ?.

We will thank your help to solve this. Thank all of you in advance.



Jorge A. Blasi
jorge.blasi AT corhoma.com.ar

------- End of forwarded message -------




Archive powered by MHonArc 2.6.24.

Top of Page