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