提交 be2a85a5 authored 作者: Thomas Mueller's avatar Thomas Mueller

The ResultSetMetaData methods getSchemaName and getTableName could return null…

The ResultSetMetaData methods getSchemaName and getTableName could return null instead of "" (an empty string) as specified in the JDBC API.
上级 80976a77
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>-
<ul><li>The ResultSetMetaData methods getSchemaName and getTableName
could return null instead of "" (an empty string) as specified in the JDBC API.
</li></ul>
<h2>Version 1.3.168 (2012-07-13)</h2>
......
......@@ -128,14 +128,15 @@ public class JdbcResultSetMetaData extends TraceObject implements ResultSetMetaD
* Returns the schema name.
*
* @param column the column index (1,2,...)
* @return the schema name
* @return the schema name, or "" (an empty string) if not applicable
* @throws SQLException if the result set is closed or invalid
*/
public String getSchemaName(int column) throws SQLException {
try {
debugCodeCall("getSchemaName", column);
checkColumnIndex(column);
return result.getSchemaName(--column);
String schema = result.getSchemaName(--column);
return schema == null ? "" : schema;
} catch (Exception e) {
throw logAndConvert(e);
}
......@@ -152,7 +153,8 @@ public class JdbcResultSetMetaData extends TraceObject implements ResultSetMetaD
try {
debugCodeCall("getTableName", column);
checkColumnIndex(column);
return result.getTableName(--column);
String table = result.getTableName(--column);
return table == null ? "" : table;
} catch (Exception e) {
throw logAndConvert(e);
}
......@@ -169,7 +171,7 @@ public class JdbcResultSetMetaData extends TraceObject implements ResultSetMetaD
try {
debugCodeCall("getCatalogName", column);
checkColumnIndex(column);
return catalog;
return catalog == null ? "" : catalog;
} catch (Exception e) {
throw logAndConvert(e);
}
......
......@@ -230,6 +230,15 @@ public class TestMetaData extends TestBase {
assertTrue(rs.getObject(1) instanceof java.sql.ResultSet);
assertEquals("org.h2.tools.SimpleResultSet", rs.getObject(1).getClass().getName());
stat.executeUpdate("drop alias x");
rs = stat.executeQuery("select 1 from dual");
rs.next();
rsMeta = rs.getMetaData();
assertTrue(rsMeta.getCatalogName(1) != null);
assertEquals("1", rsMeta.getColumnLabel(1));
assertEquals("1", rsMeta.getColumnName(1));
assertEquals("", rsMeta.getSchemaName(1));
assertEquals("", rsMeta.getTableName(1));
stat.executeUpdate("drop table test");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论