提交 3d8bb1e5 authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 407: The TriggerAdapter didn't work with CLOB and BLOB columns.

上级 8ff1491a
......@@ -478,21 +478,25 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
/**
* 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();
return asInputStream(get(columnIndex));
}
private static InputStream asInputStream(Object o) throws SQLException {
if (o == null) {
return null;
} else if (o instanceof Blob) {
return ((Blob) o).getBinaryStream();
}
return (InputStream) o;
}
/**
* 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
......@@ -510,8 +514,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
* @return the value
*/
public Blob getBlob(int columnIndex) throws SQLException {
Blob b = (Blob) get(columnIndex);
return b == null ? null : b;
return (Blob) get(columnIndex);
}
/**
......@@ -596,20 +599,29 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
/**
* Returns the value as a java.io.Reader.
* This is only supported for CLOB data.
* This is only supported if the
* result set was created using a Clob or Reader object.
*
* @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();
return asReader(get(columnIndex));
}
private static Reader asReader(Object o) throws SQLException {
if (o == null) {
return null;
} else if (o instanceof Clob) {
return ((Clob) o).getCharacterStream();
}
return (Reader) o;
}
/**
* Returns the value as a java.io.Reader.
* This is only supported if the
* result set was created using a Clob object.
* result set was created using a Clob or Reader object.
*
* @param columnLabel the column label
* @return the value
......
......@@ -120,11 +120,11 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
conn = getConnection("trigger");
stat = conn.createStatement();
stat.execute("drop table if exists test");
stat.execute("create table test(id int)");
stat.execute("create table test(id int, c clob, b blob)");
stat.execute("create table message(name varchar)");
stat.execute("create trigger test_insert before insert, update, delete on test " +
"for each row call \"" + TestTriggerAdapter.class.getName() + "\"");
stat.execute("insert into test values(1)");
stat.execute("insert into test values(1, 'hello', 'abcd')");
ResultSet rs;
rs = stat.executeQuery("select * from test");
rs.next();
......@@ -211,6 +211,8 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
throw new RuntimeException("Expected: 2 got: " + newRow.getString(1));
}
}
newRow.getCharacterStream(2);
newRow.getBinaryStream(3);
newRow.updateInt(1, newRow.getInt(1) * 10);
}
conn.createStatement().execute("insert into message values('" + buff.toString() + "')");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论