提交 066f681b authored 作者: Thomas Mueller's avatar Thomas Mueller

Support for Java 6 DatabaseMetaData.getTables, getColumns, getProcedures, and getProcedureColumns.

上级 54441b1b
......@@ -18,8 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Issue 101: Rollback of a large transaction could fail.
</li><li>Various improvements in the page store mechanism (still experimental).
<ul><li>Support for Java 6 DatabaseMetaData.getTables, getColumns, getProcedures, and getProcedureColumns.
</li><li>Issue 101: Rollback of a large transaction could fail.
</li><li>Various bugfixes and improvements in the page store mechanism (still experimental).
</li><li>The functions LENGTH, OCTET_LENGTH, and BIT_LENGTH now return BIGINT.
</li><li>Data types CLOB and BLOB: the maximum precision was Integer.MAX_VALUE, it is now Long.MAX_VALUE.
</li><li>Multi-threaded kernel: creating and dropping temporary database objects
......
......@@ -106,7 +106,12 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* <li>3 TABLE_NAME (String) table name </li>
* <li>4 TABLE_TYPE (String) table type </li>
* <li>5 REMARKS (String) comment </li>
* <li>6 SQL (String) the create table statement or NULL for systems tables
* <li>6 TYPE_CAT (String) always null </li>
* <li>7 TYPE_SCHEM (String) always null </li>
* <li>8 TYPE_NAME (String) always null </li>
* <li>9 SELF_REFERENCING_COL_NAME (String) always null </li>
* <li>10 REF_GENERATION (String) always null </li>
* <li>11 SQL (String) the create table statement or NULL for systems tables
* </li>
* </ul>
*
......@@ -143,6 +148,11 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
+ "TABLE_NAME, "
+ "TABLE_TYPE, "
+ "REMARKS, "
+ "TYPE_NAME TYPE_CAT, "
+ "TYPE_NAME TYPE_SCHEM, "
+ "TYPE_NAME, "
+ "TYPE_NAME SELF_REFERENCING_COL_NAME, "
+ "TYPE_NAME REF_GENERATION, "
+ "SQL "
+ "FROM INFORMATION_SCHEMA.TABLES "
+ "WHERE TABLE_CATALOG LIKE ? "
......@@ -177,8 +187,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* <li>8 BUFFER_LENGTH (int) unused </li>
* <li>9 DECIMAL_DIGITS (int) scale (0 for INTEGER and VARCHAR) </li>
* <li>10 NUM_PREC_RADIX (int) radix (always 10) </li>
* <li>11 NULLABLE (int) nullable or not. columnNoNulls or columnNullable
* </li>
* <li>11 NULLABLE (int) columnNoNulls or columnNullable</li>
* <li>12 REMARKS (String) comment (always empty) </li>
* <li>13 COLUMN_DEF (String) default value </li>
* <li>14 SQL_DATA_TYPE (int) unused </li>
......@@ -186,6 +195,11 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* <li>16 CHAR_OCTET_LENGTH (int) unused </li>
* <li>17 ORDINAL_POSITION (int) the column index (1,2,...) </li>
* <li>18 IS_NULLABLE (String) "NO" or "YES" </li>
* <li>19 SCOPE_CATLOG (String) always null </li>
* <li>20 SCOPE_SCHEMA (String) always null </li>
* <li>21 SCOPE_TABLE (String) always null </li>
* <li>22 SOURCE_DATA_TYPE (short) null </li>
* <li>23 IS_AUTOINCREMENT (String) "NO" or "YES" </li>
* </ul>
*
* @param catalogPattern null (to get all objects) or the catalog name
......@@ -227,7 +241,12 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
+ "ZERO() SQL_DATETIME_SUB, "
+ "CHARACTER_OCTET_LENGTH CHAR_OCTET_LENGTH, "
+ "ORDINAL_POSITION, "
+ "IS_NULLABLE IS_NULLABLE "
+ "IS_NULLABLE IS_NULLABLE, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_CATLOG, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_SCHEMA, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_TABLE, "
+ "SOURCE_DATA_TYPE, "
+ "CASE WHEN SEQUENCE_NAME IS NULL THEN 'NO' ELSE 'YES' END IS_AUTOINCREMENT "
+ "FROM INFORMATION_SCHEMA.COLUMNS "
+ "WHERE TABLE_CATALOG LIKE ? "
+ "AND TABLE_SCHEMA LIKE ? "
......@@ -505,6 +524,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* <li>7 REMARKS (String) description </li>
* <li>8 PROCEDURE_TYPE (short) if this procedure returns a result
* (procedureNoResult or procedureReturnsResult) </li>
* <li>9 SPECIFIC_NAME (String) name </li>
* </ul>
*
* @param catalogPattern null or the catalog name
......@@ -531,7 +551,8 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
+ "ZERO() NUM_OUTPUT_PARAMS, "
+ "ZERO() NUM_RESULT_SETS, "
+ "REMARKS, "
+ "RETURNS_RESULT PROCEDURE_TYPE "
+ "RETURNS_RESULT PROCEDURE_TYPE, "
+ "ALIAS_NAME SPECIFIC_NAME "
+ "FROM INFORMATION_SCHEMA.FUNCTION_ALIASES "
+ "WHERE ALIAS_CATALOG LIKE ? "
+ "AND ALIAS_SCHEMA LIKE ? "
......@@ -566,8 +587,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* <li>11 RADIX (int) always 10 </li>
* <li>12 NULLABLE (short) nullable </li>
* <li>13 REMARKS (String) description </li>
* <li>14 NUM_INPUT_PARAMS (int) the parameter count </li>
* <li>15 POS (int) the parameter index </li>
* <li>14 COLUMN_DEF (String) always null </li>
* <li>15 SQL_DATA_TYPE (int) for future use, always 0 </li>
* <li>16 SQL_DATETIME_SUB (int) for future use, always 0 </li>
* <li>17 CHAR_OCTET_LENGTH (int) always null </li>
* <li>18 ORDINAL_POSITION (int) the parameter index
* starting from 1 (0 is the return value) </li>
* <li>19 IS_NULLABLE (String) always "YES" </li>
* <li>20 SPECIFIC_NAME (String) name </li>
* </ul>
*
* @param catalogPattern null or the catalog name
......@@ -603,14 +630,19 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
+ "RADIX, "
+ "NULLABLE, "
+ "REMARKS, "
+ "COLUMN_COUNT NUM_INPUT_PARAMS, "
+ "POS "
+ "COLUMN_DEFAULT COLUMN_DEF, "
+ "0 SQL_DATA_TYPE, "
+ "0 SQL_DATETIME_SUB, "
+ "0 CHAR_OCTET_LENGTH, "
+ "POS ORDINAL_POSITION, "
+ "'YES' IS_NULLABLE, "
+ "ALIAS_NAME SPECIFIC_NAME "
+ "FROM INFORMATION_SCHEMA.FUNCTION_COLUMNS "
+ "WHERE ALIAS_CATALOG LIKE ? "
+ "AND ALIAS_SCHEMA LIKE ? "
+ "AND ALIAS_NAME LIKE ? "
+ "AND COLUMN_NAME LIKE ? "
+ "ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, NUM_INPUT_PARAMS, POS");
+ "ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, ORDINAL_POSITION");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, getSchemaPattern(schemaPattern));
prep.setString(3, getPattern(procedureNamePattern));
......
......@@ -71,10 +71,6 @@ public class MetaTable extends Table {
*/
public static final long ROW_COUNT_APPROXIMATION = 1000;
// TODO INFORMATION_SCHEMA.tables: select table_name
// from INFORMATION_SCHEMA.tables where TABLE_TYPE = 'BASE TABLE'
// (currently 'TABLE'; like HSQLDB)
private static final int TABLES = 0;
private static final int COLUMNS = 1;
private static final int INDEXES = 2;
......@@ -135,7 +131,8 @@ public class MetaTable extends Table {
"SQL",
"REMARKS",
"LAST_MODIFICATION BIGINT",
"ID INT"
"ID INT",
"TYPE_NAME"
});
indexColumnName = "TABLE_NAME";
break;
......@@ -164,7 +161,8 @@ public class MetaTable extends Table {
"SELECTIVITY INT",
"CHECK_CONSTRAINT",
"SEQUENCE_NAME",
"REMARKS"
"REMARKS",
"SOURCE_DATA_TYPE SMALLINT"
});
indexColumnName = "TABLE_NAME";
break;
......@@ -315,7 +313,8 @@ public class MetaTable extends Table {
"RADIX SMALLINT",
"NULLABLE SMALLINT",
"COLUMN_TYPE SMALLINT",
"REMARKS"
"REMARKS",
"COLUMN_DEFAULT"
});
break;
case SCHEMATA:
......@@ -650,7 +649,9 @@ public class MetaTable extends Table {
// LAST_MODIFICATION
"" + table.getMaxDataModificationId(),
// ID
"" + table.getId()
"" + table.getId(),
// TYPE_NAME
null
});
}
break;
......@@ -710,7 +711,9 @@ public class MetaTable extends Table {
// SEQUENCE_NAME
sequence == null ? null : sequence.getName(),
// REMARKS
replaceNullWithEmpty(c.getComment())
replaceNullWithEmpty(c.getComment()),
// SOURCE_DATA_TYPE
null
});
}
}
......@@ -1141,7 +1144,9 @@ public class MetaTable extends Table {
// COLUMN_TYPE
"" + DatabaseMetaData.procedureColumnIn,
// REMARKS
""
"",
// COLUMN_DEFAULT
null
});
}
}
......
......@@ -302,19 +302,23 @@ public class TestMetaData extends TestBase {
stat.execute("CREATE ALIAS PROP FOR \"java.lang.System.getProperty(java.lang.String)\"");
stat.execute("CREATE ALIAS EXIT FOR \"java.lang.System.exit\"");
rs = meta.getProcedures(null, null, "EX%");
assertResultSetMeta(rs, 8, new String[] { "PROCEDURE_CAT", "PROCEDURE_SCHEM", "PROCEDURE_NAME",
"NUM_INPUT_PARAMS", "NUM_OUTPUT_PARAMS", "NUM_RESULT_SETS", "REMARKS", "PROCEDURE_TYPE" }, new int[] {
assertResultSetMeta(rs, 9, new String[] { "PROCEDURE_CAT", "PROCEDURE_SCHEM", "PROCEDURE_NAME",
"NUM_INPUT_PARAMS", "NUM_OUTPUT_PARAMS", "NUM_RESULT_SETS", "REMARKS", "PROCEDURE_TYPE",
"SPECIFIC_NAME"
}, new int[] {
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
Types.VARCHAR, Types.SMALLINT }, null, null);
Types.VARCHAR, Types.SMALLINT, Types.VARCHAR }, null, null);
assertResultSetOrdered(rs, new String[][] { { catalog, Constants.SCHEMA_MAIN, "EXIT", "1", "0", "0", "",
"" + DatabaseMetaData.procedureNoResult }, });
"" + DatabaseMetaData.procedureNoResult } });
rs = meta.getProcedureColumns(null, null, null, null);
assertResultSetMeta(rs, 15,
assertResultSetMeta(rs, 20,
new String[] { "PROCEDURE_CAT", "PROCEDURE_SCHEM", "PROCEDURE_NAME", "COLUMN_NAME", "COLUMN_TYPE",
"DATA_TYPE", "TYPE_NAME", "PRECISION", "LENGTH", "SCALE", "RADIX", "NULLABLE", "REMARKS", "NUM_INPUT_PARAMS", "POS" },
"DATA_TYPE", "TYPE_NAME", "PRECISION", "LENGTH", "SCALE", "RADIX", "NULLABLE", "REMARKS",
"COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION",
"IS_NULLABLE", "SPECIFIC_NAME" },
new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, Types.INTEGER,
Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.SMALLINT, Types.SMALLINT, Types.SMALLINT,
Types.VARCHAR , Types.INTEGER, Types.INTEGER}, null, null);
Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.SMALLINT, Types.SMALLINT, Types.SMALLINT, Types.VARCHAR,
Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR}, null, null);
assertResultSetOrdered(rs, new String[][] {
{ catalog, Constants.SCHEMA_MAIN, "EXIT", "P1", "" + DatabaseMetaData.procedureColumnIn,
"" + Types.INTEGER, "INTEGER", "10", "10", "0", "10", "" + DatabaseMetaData.procedureNoNulls },
......@@ -633,9 +637,10 @@ public class TestMetaData extends TestBase {
trace("getTables");
rs = meta.getTables(null, Constants.SCHEMA_MAIN, null, new String[] { "TABLE" });
assertResultSetMeta(rs, 6, new String[] { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "TABLE_TYPE", "REMARKS",
"SQL" }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
Types.VARCHAR }, null, null);
assertResultSetMeta(rs, 11, new String[] { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "TABLE_TYPE", "REMARKS",
"TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME", "SELF_REFERENCING_COL_NAME", "REF_GENERATION", "SQL" },
new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }, null, null);
if (rs.next()) {
fail("Database is not empty after dropping all tables");
}
......@@ -645,13 +650,14 @@ public class TestMetaData extends TestBase {
assertResultSetOrdered(rs, new String[][] { { catalog, Constants.SCHEMA_MAIN, "TEST", "TABLE", "" } });
trace("getColumns");
rs = meta.getColumns(null, null, "TEST", null);
assertResultSetMeta(rs, 18, new String[] { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE",
assertResultSetMeta(rs, 23, 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" }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
"IS_NULLABLE", "SCOPE_CATLOG", "SCOPE_SCHEMA", "SCOPE_TABLE", "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT" },
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 }, null, null);
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 }, null, null);
assertResultSetOrdered(rs,
new String[][] {
{ catalog, Constants.SCHEMA_MAIN, "TEST", "ID", "" + Types.INTEGER, "INTEGER", "10", "10", "0",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论