提交 373e16a7 authored 作者: Thomas Mueller's avatar Thomas Mueller

SimpleResultSet now how minimal BLOB and CLOB support.

上级 cc66deec
...@@ -652,7 +652,59 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -652,7 +652,59 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
* @return the value * @return the value
*/ */
public Array getArray(int columnIndex) throws SQLException { public Array getArray(int columnIndex) throws SQLException {
return new SimpleArray((Object[]) get(columnIndex)); Object[] o = (Object[]) get(columnIndex);
return o == null ? null : new SimpleArray(o);
}
/**
* Returns the value as a java.io.Reader.
* This is only supported for CLOB data.
*
* @param columnIndex (1,2,...)
* @return the value
*/
public Reader getCharacterStream(int columnIndex) throws SQLException {
Clob c = (Clob) get(columnIndex);
return c == null ? null : c.getCharacterStream();
}
/**
* Returns the value as a java.sql.Clob.
* This is only supported if the
* result set was created using a Clob object.
*
* @param columnIndex (1,2,...)
* @return the value
*/
public Clob getClob(int columnIndex) throws SQLException {
Clob c = (Clob) get(columnIndex);
return c == null ? null : c;
}
/**
* Returns the value as a java.sql.Blob.
* This is only supported if the
* result set was created using a Blob object.
*
* @param columnIndex (1,2,...)
* @return the value
*/
public Blob getBlob(int columnIndex) throws SQLException {
Blob b = (Blob) get(columnIndex);
return b == null ? null : b;
}
/**
* Returns the value as a java.io.InputStream.
* This is only supported if the
* result set was created using a Blob object.
*
* @param columnIndex (1,2,...)
* @return the value
*/
public InputStream getBinaryStream(int columnIndex) throws SQLException {
Blob b = (Blob) get(columnIndex);
return b == null ? null : b.getBinaryStream();
} }
/** /**
...@@ -725,6 +777,53 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -725,6 +777,53 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
return getArray(findColumn(columnLabel)); return getArray(findColumn(columnLabel));
} }
/**
* Returns the value as a java.io.Reader.
* This is only supported if the
* result set was created using a Clob object.
*
* @param columnLabel the column label
* @return the value
*/
public Reader getCharacterStream(String columnLabel) throws SQLException {
return getCharacterStream(findColumn(columnLabel));
}
/**
* Returns the value as a java.sql.Clob.
* This is only supported if the
* result set was created using a Clob object.
*
* @param columnLabel the column label
* @return the value
*/
public Clob getClob(String columnLabel) throws SQLException {
return getClob(findColumn(columnLabel));
}
/**
* Returns the value as a java.sql.Blob.
* This is only supported if the
* result set was created using a Blob object.
*
* @param columnLabel the column label
* @return the value
*/
public Blob getBlob(String columnLabel) throws SQLException {
return getBlob(findColumn(columnLabel));
}
/**
* Returns the value as a java.io.InputStream.
* This is only supported if the
* result set was created using a Blob object.
*
* @param columnLabel the column label
* @return the value
*/
public InputStream getBinaryStream(String columnLabel) throws SQLException {
return getBinaryStream(findColumn(columnLabel));
}
// ---- result set meta data --------------------------------------------- // ---- result set meta data ---------------------------------------------
...@@ -1177,13 +1276,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1177,13 +1276,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
return null; return null;
} }
/**
* INTERNAL
*/
public InputStream getBinaryStream(int columnIndex) {
return null;
}
/** /**
* @deprecated INTERNAL * @deprecated INTERNAL
*/ */
...@@ -1205,13 +1297,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1205,13 +1297,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
throw getUnsupportedException(); throw getUnsupportedException();
} }
/**
* INTERNAL
*/
public Reader getCharacterStream(int columnIndex) throws SQLException {
throw getUnsupportedException();
}
/** /**
* INTERNAL * INTERNAL
*/ */
...@@ -1331,13 +1416,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1331,13 +1416,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
throw getUnsupportedException(); throw getUnsupportedException();
} }
/**
* INTERNAL
*/
public Blob getBlob(int i) throws SQLException {
throw getUnsupportedException();
}
/** /**
* INTERNAL * INTERNAL
*/ */
...@@ -1345,13 +1423,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1345,13 +1423,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
throw getUnsupportedException(); throw getUnsupportedException();
} }
/**
* INTERNAL
*/
public Clob getClob(int i) throws SQLException {
throw getUnsupportedException();
}
/** /**
* INTERNAL * INTERNAL
*/ */
...@@ -1369,7 +1440,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1369,7 +1440,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
/** /**
* INTERNAL * INTERNAL
*/ */
public Ref getRef(int i) throws SQLException { public Ref getRef(int columnIndex) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
...@@ -1401,13 +1472,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1401,13 +1472,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
throw getUnsupportedException(); throw getUnsupportedException();
} }
/**
* INTERNAL
*/
public InputStream getBinaryStream(String columnLabel) throws SQLException {
throw getUnsupportedException();
}
/** /**
* @deprecated INTERNAL * @deprecated INTERNAL
*/ */
...@@ -1429,13 +1493,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1429,13 +1493,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
throw getUnsupportedException(); throw getUnsupportedException();
} }
/**
* INTERNAL
*/
public Reader getCharacterStream(String columnLabel) throws SQLException {
throw getUnsupportedException();
}
/** /**
* INTERNAL * INTERNAL
*/ */
...@@ -1460,7 +1517,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1460,7 +1517,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
/** /**
* INTERNAL * INTERNAL
*/ */
public Object getObject(int i, Map<String, Class<?>> map) throws SQLException { public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
throw getUnsupportedException(); throw getUnsupportedException();
} }
...@@ -1499,13 +1556,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1499,13 +1556,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
throw getUnsupportedException(); throw getUnsupportedException();
} }
/**
* INTERNAL
*/
public Blob getBlob(String colName) throws SQLException {
throw getUnsupportedException();
}
/** /**
* INTERNAL * INTERNAL
*/ */
...@@ -1513,13 +1563,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -1513,13 +1563,6 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
throw getUnsupportedException(); throw getUnsupportedException();
} }
/**
* INTERNAL
*/
public Clob getClob(String colName) throws SQLException {
throw getUnsupportedException();
}
/** /**
* INTERNAL * INTERNAL
*/ */
......
...@@ -10,12 +10,18 @@ import java.awt.Button; ...@@ -10,12 +10,18 @@ import java.awt.Button;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Date; import java.sql.Date;
import java.sql.DriverManager; import java.sql.DriverManager;
...@@ -220,13 +226,18 @@ public class TestTools extends TestBase { ...@@ -220,13 +226,18 @@ public class TestTools extends TestBase {
rs.addColumn("h", Types.ARRAY, 0, 0); rs.addColumn("h", Types.ARRAY, 0, 0);
rs.addColumn("i", Types.TIME, 0, 0); rs.addColumn("i", Types.TIME, 0, 0);
rs.addColumn("j", Types.TIMESTAMP, 0, 0); rs.addColumn("j", Types.TIMESTAMP, 0, 0);
rs.addColumn("k", Types.CLOB, 0, 0);
rs.addColumn("l", Types.BLOB, 0, 0);
Date d = Date.valueOf("2001-02-03"); Date d = Date.valueOf("2001-02-03");
byte[] b = {(byte) 0xab}; byte[] b = {(byte) 0xab};
Object[] a = {1, 2}; Object[] a = {1, 2};
Time t = Time.valueOf("10:20:30"); Time t = Time.valueOf("10:20:30");
Timestamp ts = Timestamp.valueOf("2002-03-04 10:20:30"); Timestamp ts = Timestamp.valueOf("2002-03-04 10:20:30");
rs.addRow(1, b, true, d, "10.3", Math.PI, "-3", a, t, ts); Clob clob = new SimpleClob("Hello World");
Blob blob = new SimpleBlob(new byte[]{(byte) 1, (byte) 2});
rs.addRow(1, b, true, d, "10.3", Math.PI, "-3", a, t, ts, clob, blob);
rs.addRow(null, null, null, null, null, null, null, null, null, null, null);
rs.next(); rs.next();
...@@ -280,11 +291,52 @@ public class TestTools extends TestBase { ...@@ -280,11 +291,52 @@ public class TestTools extends TestBase {
assertTrue(ts == rs.getTimestamp("j")); assertTrue(ts == rs.getTimestamp("j"));
assertTrue(ts == rs.getTimestamp(10)); assertTrue(ts == rs.getTimestamp(10));
assertTrue(clob == rs.getClob("k"));
assertTrue(clob == rs.getClob(11));
assertTrue(blob == rs.getBlob("l"));
assertTrue(blob == rs.getBlob(12));
assertThrows(ErrorCode.INVALID_VALUE_2, (ResultSet) rs). assertThrows(ErrorCode.INVALID_VALUE_2, (ResultSet) rs).
getString(11); getString(13);
assertThrows(ErrorCode.COLUMN_NOT_FOUND_1, (ResultSet) rs). assertThrows(ErrorCode.COLUMN_NOT_FOUND_1, (ResultSet) rs).
getString("NOT_FOUND"); getString("NOT_FOUND");
rs.next();
assertEquals(0, rs.getLong(1));
assertTrue(rs.wasNull());
assertEquals(null, rs.getBytes(2));
assertTrue(rs.wasNull());
assertFalse(rs.getBoolean(3));
assertTrue(rs.wasNull());
assertNull(rs.getDate(4));
assertTrue(rs.wasNull());
assertNull(rs.getBigDecimal(5));
assertTrue(rs.wasNull());
assertEquals(0.0, rs.getDouble(5));
assertTrue(rs.wasNull());
assertEquals(0.0, rs.getDouble(6));
assertTrue(rs.wasNull());
assertEquals(0.0, rs.getFloat(6));
assertTrue(rs.wasNull());
assertEquals(0, rs.getInt(7));
assertTrue(rs.wasNull());
assertNull(rs.getArray(8));
assertTrue(rs.wasNull());
assertNull(rs.getTime(9));
assertTrue(rs.wasNull());
assertNull(rs.getTimestamp(10));
assertTrue(rs.wasNull());
assertNull(rs.getClob(11));
assertTrue(rs.wasNull());
assertNull(rs.getCharacterStream(11));
assertTrue(rs.wasNull());
assertNull(rs.getBlob(12));
assertTrue(rs.wasNull());
assertNull(rs.getBinaryStream(12));
assertTrue(rs.wasNull());
// all 'updateX' methods are not supported // all 'updateX' methods are not supported
for (Method m: rs.getClass().getMethods()) { for (Method m: rs.getClass().getMethods()) {
if (m.getName().startsWith("update")) { if (m.getName().startsWith("update")) {
...@@ -329,6 +381,7 @@ public class TestTools extends TestBase { ...@@ -329,6 +381,7 @@ public class TestTools extends TestBase {
assertTrue(rs.next()); assertTrue(rs.next());
assertFalse(rs.isClosed()); assertFalse(rs.isClosed());
assertEquals(1, rs.getRow()); assertEquals(1, rs.getRow());
assertTrue(rs.next());
assertFalse(rs.next()); assertFalse(rs.next());
assertThrows(ErrorCode.NO_DATA_AVAILABLE, (ResultSet) rs). assertThrows(ErrorCode.NO_DATA_AVAILABLE, (ResultSet) rs).
getInt(1); getInt(1);
...@@ -819,4 +872,126 @@ public class TestTools extends TestBase { ...@@ -819,4 +872,126 @@ public class TestTools extends TestBase {
deleteDb("testSplit"); deleteDb("testSplit");
} }
/**
* A simple Clob implementation.
*/
class SimpleClob implements Clob {
private final String data;
SimpleClob(String data) {
this.data = data;
}
public void free() throws SQLException {
// ignore
}
public InputStream getAsciiStream() throws SQLException {
throw new UnsupportedOperationException();
}
public Reader getCharacterStream() throws SQLException {
throw new UnsupportedOperationException();
}
public Reader getCharacterStream(long pos, long length) throws SQLException {
throw new UnsupportedOperationException();
}
public String getSubString(long pos, int length) throws SQLException {
throw new UnsupportedOperationException();
}
public long length() throws SQLException {
return data.length();
}
public long position(String searchstr, long start) throws SQLException {
throw new UnsupportedOperationException();
}
public long position(Clob searchstr, long start) throws SQLException {
throw new UnsupportedOperationException();
}
public OutputStream setAsciiStream(long pos) throws SQLException {
throw new UnsupportedOperationException();
}
public Writer setCharacterStream(long pos) throws SQLException {
throw new UnsupportedOperationException();
}
public int setString(long pos, String str) throws SQLException {
throw new UnsupportedOperationException();
}
public int setString(long pos, String str, int offset, int len) throws SQLException {
throw new UnsupportedOperationException();
}
public void truncate(long len) throws SQLException {
throw new UnsupportedOperationException();
}
}
/**
* A simple Blob implementation.
*/
class SimpleBlob implements Blob {
private final byte[] data;
SimpleBlob(byte[] data) {
this.data = data;
}
public void free() throws SQLException {
// ignore
}
public InputStream getBinaryStream() throws SQLException {
throw new UnsupportedOperationException();
}
public InputStream getBinaryStream(long pos, long length) throws SQLException {
throw new UnsupportedOperationException();
}
public byte[] getBytes(long pos, int length) throws SQLException {
throw new UnsupportedOperationException();
}
public long length() throws SQLException {
return data.length;
}
public long position(byte[] pattern, long start) throws SQLException {
throw new UnsupportedOperationException();
}
public long position(Blob pattern, long start) throws SQLException {
throw new UnsupportedOperationException();
}
public OutputStream setBinaryStream(long pos) throws SQLException {
throw new UnsupportedOperationException();
}
public int setBytes(long pos, byte[] bytes) throws SQLException {
throw new UnsupportedOperationException();
}
public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
throw new UnsupportedOperationException();
}
public void truncate(long len) throws SQLException {
throw new UnsupportedOperationException();
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论