private static IRubyObject jdbc_to_ruby(Ruby runtime, int row, int type, int scale, ResultSet rs)
try {
int n;
switch (type) {
case Types.BINARY:
case Types.BLOB:
case Types.LONGVARBINARY:
case Types.VARBINARY:
InputStream is = rs.getBinaryStream(row);
if (is == null || rs.wasNull()) {
return runtime.getNil();
}
ByteList str = new ByteList(2048);
byte[] buf = new byte[2048];
while ((n = is.read(buf)) != -1) {
str.append(buf, 0, n);
}
is.close();
return runtime.newString(str);
case Types.LONGVARCHAR:
case Types.CLOB:
Reader rss = rs.getCharacterStream(row);
if (rss == null || rs.wasNull()) {
return runtime.getNil();
}
StringBuffer str2 = new StringBuffer(2048);
char[] cuf = new char[2048];
while ((n = rss.read(cuf)) != -1) {
str2.append(cuf, 0, n);
}
rss.close();
return RubyString.newUnicodeString(runtime, str2.toString());
case Types.TIMESTAMP: