Subject | OCTETS as binary (and another problem with CachedRowSetImpl) |
---|---|
Author | Fabiano |
Post date | 2012-07-19T13:45:16Z |
Hi all!
It seems Jaybird is treating "CHAR/VARCHAR CHARACTER SET OCTETS" internally as Strings. I personally donĀ“t think it is correct, as OCTETS are used to store binary data. What do you think about this?
I tried to look at Jaybird code some months ago to offer a fix, but at that time, it seemed to me it would need a bunch of changes to make it work.
This is bringing some problems to CachedRowSetImpl:
public static void main(String[] args) throws Exception {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Connection connection = DriverManager.getConnection(URL);
PreparedStatement preparedStatement = connection.prepareStatement("select id from test");
ResultSet resultSet = preparedStatement.executeQuery();
resultSet.next();
System.out.println(resultSet.getString(1));
// shows ABC ABC ABC ABC
System.out.println(Arrays.toString(resultSet.getBytes(1)));
// shows [65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0]
resultSet = preparedStatement.executeQuery();
CachedRowSet cachedRowSet = new CachedRowSetImpl();
cachedRowSet.populate(resultSet);
cachedRowSet.next();
System.out.println(cachedRowSet.getString(1));
// shows ABC ABC ABC ABC
System.out.println(Arrays.toString(cachedRowSet.getBytes(1)));
// throws java.sql.SQLException: Incompatible DataType
}
If i cast "id" to "BLOB SUB_TYPE 0" it works, but shows <> results in the method "toString()"
public static void main(String[] args) throws Exception {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Connection connection = DriverManager.getConnection(URL);
PreparedStatement preparedStatement = connection.prepareStatement("select cast(id as blob sub_type 0) from test");
ResultSet resultSet = preparedStatement.executeQuery();
resultSet.next();
System.out.println(resultSet.getString(1));
// shows ABC ABC ABC ABC
System.out.println(Arrays.toString(resultSet.getBytes(1)));
// shows [65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0]
resultSet = preparedStatement.executeQuery();
CachedRowSet cachedRowSet = new CachedRowSetImpl();
cachedRowSet.populate(resultSet);
cachedRowSet.next();
System.out.println(cachedRowSet.getString(1));
// shows [B@11a59ce
System.out.println(Arrays.toString(cachedRowSet.getBytes(1)));
// shows [65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0]
}
Regards,
Fabiano
It seems Jaybird is treating "CHAR/VARCHAR CHARACTER SET OCTETS" internally as Strings. I personally donĀ“t think it is correct, as OCTETS are used to store binary data. What do you think about this?
I tried to look at Jaybird code some months ago to offer a fix, but at that time, it seemed to me it would need a bunch of changes to make it work.
This is bringing some problems to CachedRowSetImpl:
public static void main(String[] args) throws Exception {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Connection connection = DriverManager.getConnection(URL);
PreparedStatement preparedStatement = connection.prepareStatement("select id from test");
ResultSet resultSet = preparedStatement.executeQuery();
resultSet.next();
System.out.println(resultSet.getString(1));
// shows ABC ABC ABC ABC
System.out.println(Arrays.toString(resultSet.getBytes(1)));
// shows [65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0]
resultSet = preparedStatement.executeQuery();
CachedRowSet cachedRowSet = new CachedRowSetImpl();
cachedRowSet.populate(resultSet);
cachedRowSet.next();
System.out.println(cachedRowSet.getString(1));
// shows ABC ABC ABC ABC
System.out.println(Arrays.toString(cachedRowSet.getBytes(1)));
// throws java.sql.SQLException: Incompatible DataType
}
If i cast "id" to "BLOB SUB_TYPE 0" it works, but shows <> results in the method "toString()"
public static void main(String[] args) throws Exception {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Connection connection = DriverManager.getConnection(URL);
PreparedStatement preparedStatement = connection.prepareStatement("select cast(id as blob sub_type 0) from test");
ResultSet resultSet = preparedStatement.executeQuery();
resultSet.next();
System.out.println(resultSet.getString(1));
// shows ABC ABC ABC ABC
System.out.println(Arrays.toString(resultSet.getBytes(1)));
// shows [65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0]
resultSet = preparedStatement.executeQuery();
CachedRowSet cachedRowSet = new CachedRowSetImpl();
cachedRowSet.populate(resultSet);
cachedRowSet.next();
System.out.println(cachedRowSet.getString(1));
// shows [B@11a59ce
System.out.println(Arrays.toString(cachedRowSet.getBytes(1)));
// shows [65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0, 65, 66, 67, 0]
}
Regards,
Fabiano