Author: shawkins
Date: 2012-02-07 21:54:20 -0500 (Tue, 07 Feb 2012)
New Revision: 3853
Modified:
branches/7.7.x/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java
branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestDataTypeTransformer.java
branches/7.7.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java
Log:
TEIID-1927 fix for SerialClob getSubString
Modified: branches/7.7.x/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java
===================================================================
--- branches/7.7.x/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java 2012-02-07
15:30:30 UTC (rev 3852)
+++ branches/7.7.x/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java 2012-02-08
02:54:20 UTC (rev 3853)
@@ -229,7 +229,12 @@
return ((SQLXML)value).getString();
} else if (value instanceof Clob) {
Clob c = (Clob)value;
- return c.getSubString(1,
c.length()>Integer.MAX_VALUE?Integer.MAX_VALUE:(int)c.length());
+ long length = c.length();
+ if (length == 0) {
+ //there is a bug in SerialClob with 0 length
+ return ""; //$NON-NLS-1$
+ }
+ return c.getSubString(1,
length>Integer.MAX_VALUE?Integer.MAX_VALUE:(int)length);
}
return transform(value, String.class, "String"); //$NON-NLS-1$
}
Modified: branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestDataTypeTransformer.java
===================================================================
---
branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestDataTypeTransformer.java 2012-02-07
15:30:30 UTC (rev 3852)
+++
branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestDataTypeTransformer.java 2012-02-08
02:54:20 UTC (rev 3853)
@@ -22,24 +22,25 @@
package org.teiid.jdbc;
+import static org.junit.Assert.*;
+
import java.sql.Clob;
import java.sql.SQLException;
import javax.sql.rowset.serial.SerialClob;
-import org.teiid.jdbc.DataTypeTransformer;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class TestDataTypeTransformer extends TestCase {
+@SuppressWarnings("nls")
+public class TestDataTypeTransformer {
- public void testClobToStringConversion() throws Exception {
+ @Test public void testClobToStringConversion() throws Exception {
Clob clob = new SerialClob("foo".toCharArray()); //$NON-NLS-1$
String value = DataTypeTransformer.getString(clob);
assertEquals("foo", value); //$NON-NLS-1$
}
- public void testInvalidTransformation() throws Exception {
+ @Test public void testInvalidTransformation() throws Exception {
try {
DataTypeTransformer.getDate(Integer.valueOf(1));
fail("exception expected"); //$NON-NLS-1$
@@ -48,8 +49,17 @@
}
}
- public void testGetByte() throws Exception {
+ @Test public void testGetDefaultShort() throws Exception {
assertEquals(0, DataTypeTransformer.getShort(null));
}
+
+ @Test public void testGetDefaultByte() throws Exception {
+ assertEquals(0, DataTypeTransformer.getByte(null));
+ }
+
+ @Test public void testGetString() throws Exception {
+ assertEquals("", DataTypeTransformer.getString(new SerialClob(new
char[0])));
+ }
+
}
Modified:
branches/7.7.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java
===================================================================
---
branches/7.7.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java 2012-02-07
15:30:30 UTC (rev 3852)
+++
branches/7.7.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java 2012-02-08
02:54:20 UTC (rev 3853)
@@ -109,6 +109,13 @@
assertEquals("<root></root>", s.getResultSet().getString(1));
}
+ @Test public void testLobStreaming1() throws Exception {
+ Statement s = conn.createStatement();
+ assertTrue(s.execute("select cast('' as clob) from tables"));
+ s.getResultSet().next();
+ assertEquals("", s.getResultSet().getString(1));
+ }
+
@Test public void testXmlTableScrollable() throws Exception {
Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
assertTrue(s.execute("select * from xmltable('/root/row' passing (select
xmlelement(name \"root\", xmlagg(xmlelement(name \"row\",
xmlforest(t.name)) order by t.name)) from tables as t, columns as t1) columns
\"Name\" string) as x"));