提交 97cd4f5d authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not use SimpleResultSet in JdbcDatabaseMetaData

上级 85328719
...@@ -13,6 +13,7 @@ import java.sql.RowIdLifetime; ...@@ -13,6 +13,7 @@ import java.sql.RowIdLifetime;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import org.h2.engine.Constants; import org.h2.engine.Constants;
...@@ -23,9 +24,11 @@ import org.h2.engine.SysProperties; ...@@ -23,9 +24,11 @@ import org.h2.engine.SysProperties;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.message.Trace; import org.h2.message.Trace;
import org.h2.message.TraceObject; import org.h2.message.TraceObject;
import org.h2.tools.SimpleResultSet; import org.h2.result.SimpleResult;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.ValueInt;
import org.h2.value.ValueString;
/** /**
* Represents the meta data for a database. * Represents the meta data for a database.
...@@ -3179,13 +3182,22 @@ public class JdbcDatabaseMetaData extends TraceObject implements ...@@ -3179,13 +3182,22 @@ public class JdbcDatabaseMetaData extends TraceObject implements
@Override @Override
public ResultSet getClientInfoProperties() throws SQLException { public ResultSet getClientInfoProperties() throws SQLException {
Properties clientInfo = conn.getClientInfo(); Properties clientInfo = conn.getClientInfo();
SimpleResultSet result = new SimpleResultSet(); SimpleResult result = new SimpleResult();
result.addColumn("Name", Types.VARCHAR, 0, 0); result.addColumn("NAME", "NAME", Types.VARCHAR, 0, 0, Integer.MAX_VALUE);
result.addColumn("Value", Types.VARCHAR, 0, 0); result.addColumn("MAX_LEN", "MAX_LEN", Types.INTEGER, 0, 0, ValueInt.DISPLAY_SIZE);
for (Object key : clientInfo.keySet()) { result.addColumn("DEFAULT_VALUE", "DEFAULT_VALUE", Types.VARCHAR, 0, 0, Integer.MAX_VALUE);
result.addRow(key, clientInfo.get(key)); result.addColumn("DESCRIPTION", "DESCRIPTION", Types.VARCHAR, 0, 0, Integer.MAX_VALUE);
// Non-standard column
result.addColumn("VALUE", "VALUE", Types.VARCHAR, 0, 0, Integer.MAX_VALUE);
for (Entry<Object, Object> entry : clientInfo.entrySet()) {
result.addRow(ValueString.get((String) entry.getKey()), ValueInt.get(Integer.MAX_VALUE),
ValueString.EMPTY, ValueString.EMPTY, ValueString.get((String) entry.getValue()));
} }
return result; int id = getNextId(TraceObject.RESULT_SET);
if (isDebugEnabled()) {
debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "getClientInfoProperties()");
}
return new JdbcResultSet(conn, null, null, result, id, false, true, false);
} }
/** /**
......
...@@ -1253,6 +1253,12 @@ public class TestMetaData extends TestDb { ...@@ -1253,6 +1253,12 @@ public class TestMetaData extends TestDb {
assertNull(conn.getClientInfo("xxx")); assertNull(conn.getClientInfo("xxx"));
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getClientInfoProperties(); ResultSet rs = meta.getClientInfoProperties();
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals("NAME", rsMeta.getColumnName(1));
assertEquals("MAX_LEN", rsMeta.getColumnName(2));
assertEquals("DEFAULT_VALUE", rsMeta.getColumnName(3));
assertEquals("DESCRIPTION", rsMeta.getColumnName(4));
assertEquals("VALUE", rsMeta.getColumnName(5));
int count = 0; int count = 0;
while (rs.next()) { while (rs.next()) {
count++; count++;
...@@ -1264,6 +1270,7 @@ public class TestMetaData extends TestDb { ...@@ -1264,6 +1270,7 @@ public class TestMetaData extends TestDb {
// numServers // numServers
assertEquals(1, count); assertEquals(1, count);
} }
rs.close();
conn.close(); conn.close();
deleteDb("metaData"); deleteDb("metaData");
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论