📄 embeddatabasemetadata.java
字号:
* <P>Only privileges matching the column name criteria are * returned. They are ordered by COLUMN_NAME and PRIVILEGE. * * <P>Each privilige description has the following columns: * <OL> * <LI><B>TABLE_CAT</B> String => table catalog (may be null) * <LI><B>TABLE_SCHEM</B> String => table schema (may be null) * <LI><B>TABLE_NAME</B> String => table name * <LI><B>COLUMN_NAME</B> String => column name * <LI><B>GRANTOR</B> => grantor of access (may be null) * <LI><B>GRANTEE</B> String => grantee of access * <LI><B>PRIVILEGE</B> String => name of access (SELECT, * INSERT, UPDATE, REFRENCES, ...) * <LI><B>IS_GRANTABLE</B> String => "YES" if grantee is permitted * to grant to others; "NO" if not; null if unknown * </OL> * * @param catalog a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schema a schema name; "" retrieves those without a schema * @param table a table name * @param columnNamePattern a column name pattern * @return ResultSet - each row is a column privilege description * @see #getSearchStringEscape * @exception SQLException thrown on failure. */ public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException { PreparedStatement s = getPreparedQuery("getColumnPrivileges"); s.setString(1, swapNull(catalog)); s.setString(2, swapNull(schema)); s.setString(3, swapNull(table)); s.setString(4, swapNull(columnNamePattern)); return s.executeQuery(); } /** * Get a description of the access rights for each table available * in a catalog. Note that a table privilege applies to one or * more columns in the table. It would be wrong to assume that * this priviledge applies to all columns (this may be true for * some systems but is not true for all.) * * <P>Only privileges matching the schema and table name * criteria are returned. They are ordered by TABLE_SCHEM, * TABLE_NAME, and PRIVILEGE. * * <P>Each privilige description has the following columns: * <OL> * <LI><B>TABLE_CAT</B> String => table catalog (may be null) * <LI><B>TABLE_SCHEM</B> String => table schema (may be null) * <LI><B>TABLE_NAME</B> String => table name * <LI><B>GRANTOR</B> => grantor of access (may be null) * <LI><B>GRANTEE</B> String => grantee of access * <LI><B>PRIVILEGE</B> String => name of access (SELECT, * INSERT, UPDATE, REFRENCES, ...) * <LI><B>IS_GRANTABLE</B> String => "YES" if grantee is permitted * to grant to others; "NO" if not; null if unknown * </OL> * * @param catalog a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schemaPattern a schema name pattern; "" retrieves those * without a schema * @param tableNamePattern a table name pattern * @return ResultSet - each row is a table privilege description * @see #getSearchStringEscape * @exception SQLException thrown on failure. */ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { PreparedStatement s = getPreparedQuery("getTablePrivileges"); s.setString(1, swapNull(catalog)); s.setString(2, swapNull(schemaPattern)); s.setString(3, swapNull(tableNamePattern)); return s.executeQuery(); } /** * Get a description of a table's optimal set of columns that * uniquely identifies a row. They are ordered by SCOPE. * * <P>Each column description has the following columns: * <OL> * <LI><B>SCOPE</B> short => actual scope of result * <UL> * <LI> bestRowTemporary - very temporary, while using row * <LI> bestRowTransaction - valid for remainder of current transaction * <LI> bestRowSession - valid for remainder of current session * </UL> * <LI><B>COLUMN_NAME</B> String => column name * <LI><B>DATA_TYPE</B> short => SQL data type from java.sql.Types * <LI><B>TYPE_NAME</B> String => Data source dependent type name * <LI><B>COLUMN_SIZE</B> int => precision * <LI><B>BUFFER_LENGTH</B> int => not used * <LI><B>DECIMAL_DIGITS</B> short => scale * <LI><B>PSEUDO_COLUMN</B> short => is this a pseudo column * like an Oracle ROWID * <UL> * <LI> bestRowUnknown - may or may not be pseudo column * <LI> bestRowNotPseudo - is NOT a pseudo column * <LI> bestRowPseudo - is a pseudo column * </UL> * </OL> * * @param catalogPattern a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schemaPattern a schema name; "" retrieves those without a schema * @param tablePattern a table name * @param scope the scope of interest; use same values as SCOPE * @param nullable include columns that are nullable? * @return ResultSet - each row is a column description * @exception SQLException thrown on failure. */ public ResultSet getBestRowIdentifier ( String catalogPattern, String schemaPattern, String tablePattern, int scope, boolean nullable ) throws SQLException { return doGetBestRowId(catalogPattern, schemaPattern, tablePattern, scope, nullable, ""); } /** * Get a description of a table's optimal set of columns that * uniquely identifies a row. They are ordered by SCOPE. * Same as getBestRowIdentifier() above, except that the result * set will conform to ODBC specifications. */ public ResultSet getBestRowIdentifierForODBC(String catalogPattern, String schemaPattern, String tablePattern, int scope, boolean nullable) throws SQLException { return doGetBestRowId(catalogPattern, schemaPattern, tablePattern, scope, nullable, "odbc_"); } /** * Does the actual work for the getBestRowIdentifier metadata * calls. See getBestRowIdentifier() method above for parameter * descriptions. * @param queryPrefix Prefix to be appended to the names of * the queries used in this method. This is used * to determine whether the result set should conform to * JDBC or ODBC specifications. */ private ResultSet doGetBestRowId(String catalogPattern, String schemaPattern, String tablePattern, int scope, boolean nullable, String queryPrefix) throws SQLException { int nullableInIntForm = 0; if (nullable) nullableInIntForm = 1; if (catalogPattern == null) { catalogPattern = "%"; } if (schemaPattern == null) { schemaPattern = "%"; } if (tablePattern == null) { tablePattern = "%"; } PreparedStatement ps; boolean done; // scope value is bad, return an empty result if (scope < 0 || scope > 2) { ps = getPreparedQuery("getBestRowIdentifierEmpty"); return ps.executeQuery(); } // see if there is a primary key, use it. ps = getPreparedQuery("getBestRowIdentifierPrimaryKey"); ps.setString(1,catalogPattern); ps.setString(2,schemaPattern); ps.setString(3,tablePattern); ResultSet rs = ps.executeQuery(); done = rs.next(); String constraintId = ""; if (done) { constraintId = rs.getString(1); } rs.close(); ps.close(); if (done) { // this one's it, do the real thing and return it. // we don't need to check catalog, schema, table name // or scope again. ps = getPreparedQuery(queryPrefix + "getBestRowIdentifierPrimaryKeyColumns"); ps.setString(1,constraintId); ps.setString(2,constraintId); // note, primary key columns aren't nullable, // so we skip the nullOk parameter. return ps.executeQuery(); } // get the unique constraint with the fewest columns. ps = getPreparedQuery("getBestRowIdentifierUniqueConstraint"); ps.setString(1,catalogPattern); ps.setString(2,schemaPattern); ps.setString(3,tablePattern); rs = ps.executeQuery(); done = rs.next(); if (done) { constraintId = rs.getString(1); } // REMIND: we need to actually check for null columns // and toss out constraints with null columns if they aren't // desired... recode this as a WHILE returning at the // first match or falling off the end. rs.close(); ps.close(); if (done) { // this one's it, do the real thing and return it. ps = getPreparedQuery(queryPrefix + "getBestRowIdentifierUniqueKeyColumns"); ps.setString(1,constraintId); ps.setString(2,constraintId); ps.setInt(3,nullableInIntForm); return ps.executeQuery(); } // second-to last try -- unique index with minimal # columns // (only non null columns if so required) ps = getPreparedQuery("getBestRowIdentifierUniqueIndex"); ps.setString(1,catalogPattern); ps.setString(2,schemaPattern); ps.setString(3,tablePattern); rs = ps.executeQuery(); done = rs.next(); long indexNum = 0; if (done) { indexNum = rs.getLong(1); } // REMIND: we need to actually check for null columns // and toss out constraints with null columns if they aren't // desired... recode this as a WHILE returning at the // first match or falling off the end. rs.close(); ps.close(); if (done) { // this one's it, do the real thing and return it. ps = getPreparedQuery(queryPrefix + "getBestRowIdentifierUniqueIndexColumns"); ps.setLong(1,indexNum); ps.setInt(2,nullableInIntForm); return ps.executeQuery(); } // last try -- just return all columns of the table // the not null ones if that restriction is upon us. ps = getPreparedQuery(queryPrefix + "getBestRowIdentifierAllColumns"); ps.setString(1,catalogPattern); ps.setString(2,schemaPattern); ps.setString(3,tablePattern); ps.setInt(4,scope); ps.setInt(5,nullableInIntForm); return ps.executeQuery(); } /** * Get a description of a table's columns that are automatically * updated when any value in a row is updated. They are * unordered. * * <P>Each column description has the following columns: * <OL> * <LI><B>SCOPE</B> short => is not used * <LI><B>COLUMN_NAME</B> String => column name * <LI><B>DATA_TYPE</B> short => SQL data type from java.sql.Types * <LI><B>TYPE_NAME</B> String => Data source dependent type name * <LI><B>COLUMN_SIZE</B> int => precision * <LI><B>BUFFER_LENGTH</B> int => length of column value in bytes * <LI><B>DECIMAL_DIGITS</B> short => scale * <LI><B>PSEUDO_COLUMN</B> short => is this a pseudo column * like an Oracle ROWID * <UL> * <LI> versionColumnUnknown - may or may not be pseudo column * <LI> versionColumnNotPseudo - is NOT a pseudo column * <LI> versionColumnPseudo - is a pseudo column * </UL> * </OL> * * @param catalog a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schema a schema name; "" retrieves those without a schema * @param table a table name * @return ResultSet - each row is a column description * @exception SQLException thrown on failure. */ public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { return doGetVersionCols(catalog, schema, table, "getVersionColumns"); } /** * Get a description of a table's columns that are automatically * updated when any value in a row is updated. They are * unordered. Same as getVersionColumns() above, except that * the result set will conform to ODBC specifications. */ public ResultSet getVersionColumnsForODBC(String catalog, String schema, String table) throws SQLException { return doGetVersionCols(catalog, schema, table, "odbc_getVersionColumns"); } /** * Does the actual work for the getVersionColumns metadata * calls. See getVersionColumns() method above for parameter * descriptions. * @param queryName Name of the query to execute; is used * to determine whether the result set should conform to * JDBC or ODBC specifications. */ private ResultSet doGetVersionCols(String catalog, String schema, String table, String queryName) throws SQLException { PreparedStatement s = getPreparedQuery(queryName); s.setString(1, swapNull(catalog)); s.setString(2, swapNull(schema)); s.setString(3, swapNull(table)); return s.executeQuery(); } /** * Get a description of a table's primary key columns. They * are ordered by COLUMN_NAME. * * <P>Each primary key column description has the following columns: * <OL> * <LI><B>TABLE_CAT</B> String => table catalog (may be null) * <LI><B>TABLE_SCHEM</B> String => table schema (may be null) * <LI><B>TABLE_NAME</B> String => table name * <LI><B>COLUMN_NAME</B> String => column name * <LI><B>KEY_SEQ</B> short => sequence number within primary key * <LI><B>PK_NAME</B> String => primary key name (may be null) * </OL> * * @param catalog a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schema a schema name pattern; "" retrieves those * without a schema * @param table a table name * @return ResultSet - each row is a primary key column description * @exception SQLException thrown on failure. */ public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { return doGetPrimaryKeys(catalog, schema, table, "getPrimaryKeys"); } /** * Get a description of a table's primary key columns. They * are ordered by COLUMN_NAME. Same as getPrimaryKeys above, * except that the result set will conform to ODBC specifications. */ public ResultSet getPrimaryKeysForODBC(String catalog, String schema, String table) throws SQLException { return doGetPrimaryKeys(catalog, schema, table, "odbc_getPrimaryKeys"); } /** * Does the actual work for the getPrimaryKeys metadata * calls. See getPrimaryKeys() method above for parameter * descriptions. * @param queryName Name of the query to execute; is used * to determine whether the result set should conform to * JDBC or ODBC specifications. */ private ResultSet doGetPrimaryKeys(String catalog, String schema, String table, String queryName) throws SQLException { PreparedStatement s = getPreparedQuery(queryName); s.setString(1, swapNull(catalog)); s.setString(2, swapNull(schema)); s.setString(3, swapNull(table)); return s.executeQuery(); } /** * Get a description of the primary key columns that are * referenced by a table's foreign key columns (the primary keys * imported by a table). They are ordered by PKTABLE_CAT, * PKTABLE_SCHEM, PKTABLE_NAME, and KEY_SEQ. * * <P>Each primary key column description has the following columns: * <OL> * <LI><B>PKTABLE_CAT</B> String => primary key table catalog * being imported (may be null) * <LI><B>PKTABLE_SCHEM</B> String => primary key table schema * being imported (may be null) * <LI><B>PKTABLE_NAME</B> String => primary key table name * being imported * <LI><B>PKCOLUMN_NAME</B> String => primary key column name * being imported * <LI><B>FKTABLE_CAT</B> String => foreign key table catalog (may be null) * <LI><B>FKTABLE_SCHEM</B> String => foreign key table schema (may be null) * <LI><B>FKTABLE_NAME</B> String => foreign key table name * <LI><B>FKCOLUMN_NAME</B> String => foreign key column name * <LI><B>KEY_SEQ</B> short => sequence number within foreign key * <LI><B>UPDATE_RULE</B> short => What happens to * foreign key when primary is updated: * <UL> * <LI> importedNoAction - do not allow update of primary * key if it has been imported * <LI> importedKeyCascade - change imported key to agree * with primary key update * <LI> importedKeySetNull - change imported key to NULL if * its primary key has been updated * <LI> importedKeySetDefault - change imported key to default values * if its primary key has been updated * <LI> importedKeyRestrict - same as importedKeyNoAction * (for ODBC 2.x compatibility) * </UL> * <LI><B>DELETE_RULE</B> short => What happens to * the foreign key when primary is deleted. * <UL> * <LI> importedKeyNoAction - do not allow delete of primary * key if it has been imported * <LI> importedKeyCascade - delete rows that import a deleted key * <LI> importedKeySetNull - change imported key to NULL if * its primary key has been deleted * <LI>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -