提交 a2bc5e97 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Return also IS_GENERATEDCOLUMN from JdbcDatabaseMetaData.getTables()

上级 2bb8b6e3
......@@ -289,6 +289,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements
* <li>SCOPE_TABLE (String) always null</li>
* <li>SOURCE_DATA_TYPE (short) null</li>
* <li>IS_AUTOINCREMENT (String) "NO" or "YES"</li>
* <li>IS_GENERATEDCOLUMN (String) "NO" or "YES"</li>
* <li>SCOPE_CATLOG (String) always null (the typo is on purpose,
* for compatibility with the JDBC specification prior to 4.1)</li>
* </ol>
......@@ -343,6 +344,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements
+ "SCOPE_TABLE, "
+ "SOURCE_DATA_TYPE, "
+ "IS_AUTOINCREMENT, "
+ "IS_GENERATEDCOLUMN, "
+ "SCOPE_CATLOG "
+ "FROM ("
+ "SELECT "
......@@ -370,6 +372,8 @@ public class JdbcDatabaseMetaData extends TraceObject implements
+ "c.SOURCE_DATA_TYPE, "
+ "CASE WHEN c.SEQUENCE_NAME IS NULL THEN "
+ "CAST(?1 AS VARCHAR) ELSE CAST(?2 AS VARCHAR) END IS_AUTOINCREMENT, "
+ "CASE WHEN c.IS_COMPUTED THEN "
+ "CAST(?2 AS VARCHAR) ELSE CAST(?1 AS VARCHAR) END IS_GENERATEDCOLUMN, "
+ "CAST(c.SOURCE_DATA_TYPE AS VARCHAR) SCOPE_CATLOG "
+ "FROM INFORMATION_SCHEMA.COLUMNS c JOIN INFORMATION_SCHEMA.SYNONYMS s ON "
+ "s.SYNONYM_FOR = c.TABLE_NAME "
......@@ -405,6 +409,8 @@ public class JdbcDatabaseMetaData extends TraceObject implements
+ "SOURCE_DATA_TYPE, "
+ "CASE WHEN SEQUENCE_NAME IS NULL THEN "
+ "CAST(?1 AS VARCHAR) ELSE CAST(?2 AS VARCHAR) END IS_AUTOINCREMENT, "
+ "CASE WHEN IS_COMPUTED THEN "
+ "CAST(?2 AS VARCHAR) ELSE CAST(?1 AS VARCHAR) END IS_GENERATEDCOLUMN, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_CATLOG "
+ "FROM INFORMATION_SCHEMA.COLUMNS "
+ "WHERE TABLE_CATALOG LIKE ?3 ESCAPE ?7 "
......
......@@ -49,6 +49,7 @@ public class TestMetaData extends TestBase {
testColumnMetaData();
testColumnPrecision();
testColumnDefault();
testColumnGenerated();
testCrossReferences();
testProcedureColumns();
testUDTs();
......@@ -234,6 +235,24 @@ public class TestMetaData extends TestBase {
conn.close();
}
private void testColumnGenerated() throws SQLException {
Connection conn = getConnection("metaData");
DatabaseMetaData meta = conn.getMetaData();
ResultSet rs;
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(A INT, B INT AS A + 1)");
rs = meta.getColumns(null, null, "TEST", null);
rs.next();
assertEquals("A", rs.getString("COLUMN_NAME"));
assertEquals("NO", rs.getString("IS_GENERATEDCOLUMN"));
rs.next();
assertEquals("B", rs.getString("COLUMN_NAME"));
assertEquals("YES", rs.getString("IS_GENERATEDCOLUMN"));
assertFalse(rs.next());
stat.execute("DROP TABLE TEST");
conn.close();
}
private void testProcedureColumns() throws SQLException {
Connection conn = getConnection("metaData");
DatabaseMetaData meta = conn.getMetaData();
......@@ -704,20 +723,20 @@ public class TestMetaData extends TestBase {
Constants.SCHEMA_MAIN, "TEST", "TABLE", "" } });
trace("getColumns");
rs = meta.getColumns(null, null, "TEST", null);
assertResultSetMeta(rs, 24, new String[] { "TABLE_CAT", "TABLE_SCHEM",
assertResultSetMeta(rs, 25, new String[] { "TABLE_CAT", "TABLE_SCHEM",
"TABLE_NAME", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME",
"COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS",
"NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF",
"SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH",
"ORDINAL_POSITION", "IS_NULLABLE", "SCOPE_CATALOG",
"SCOPE_SCHEMA", "SCOPE_TABLE", "SOURCE_DATA_TYPE",
"IS_AUTOINCREMENT", "SCOPE_CATLOG" }, new int[] {
"IS_AUTOINCREMENT", "IS_GENERATEDCOLUMN", "SCOPE_CATLOG" }, new int[] {
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
Types.VARCHAR, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR },
Types.VARCHAR, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR },
null, null);
assertResultSetOrdered(rs, new String[][] {
{ CATALOG, Constants.SCHEMA_MAIN, "TEST", "ID",
......
......@@ -771,4 +771,4 @@ openoffice organize libre systemtables gmane sea borders announced millennium al
opti excessively
iterators tech enums incompatibilities loses reimplement readme reorganize milli subdirectory linkplain inspections
geometries sourceschema destschema
geometries sourceschema destschema generatedcolumn
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论