📄 databasemetadata.java
字号:
/**
* Can all the tables returned by getTable be SELECTed by the
* current user?
*
* @return true if so
* @exception SQLException if a database-access error occurs.
*/
public boolean allTablesAreSelectable() throws SQLException
{
// XXX Need to check for Sybase
// XXX This is dependent on the way we are implementing getTables()
// it may change in the future.
return false;
}
/**
* Does a data definition statement within a transaction force the
* transaction to commit?
*
* @return true if so
* @exception SQLException if a database-access error occurs.
*/
public boolean dataDefinitionCausesTransactionCommit()
throws SQLException
{
NotImplemented(); return false;
}
/**
* Is a data definition statement within a transaction ignored?
*
* @return true if so
* @exception SQLException if a database-access error occurs.
*/
public boolean dataDefinitionIgnoredInTransactions()
throws SQLException
{
NotImplemented(); return false;
}
/**
* Did getMaxRowSize() include LONGVARCHAR and LONGVARBINARY
* blobs?
*
* @return true if so
* @exception SQLException if a database-access error occurs.
*/
public boolean doesMaxRowSizeIncludeBlobs() throws SQLException
{
return false;
}
/**
* 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 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 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 if a database-access error occurs.
*/
public java.sql.ResultSet getBestRowIdentifier(
String catalog,
String schema,
String table,
int scope,
boolean nullable)
throws SQLException
{
debugPrintln("Inside getBestRowIdentifier with catalog=|" + catalog
+ "|, schema=|" + schema + "|, table=|" + table +"|, "
+ " scope=" + scope + ", nullable=" + nullable);
NotImplemented(); return null;
}
/**
* Get the catalog names available in this database. The results
* are ordered by catalog name.
*
* <P>The catalog column is:
* <OL>
* <LI><B>TABLE_CAT</B> String => catalog name
* </OL>
*
* @return ResultSet - each row has a single String column that is a
* catalog name
* @exception SQLException if a database-access error occurs.
*/
public java.sql.ResultSet getCatalogs()
throws SQLException
{
// XXX We should really clean up all these temporary tables.
String tmpName = "#t#" + UniqueId.getUniqueId();
final String sql =
" create table " + tmpName + " " +
" ( " +
" q char(30) not null, " +
" o char(30) null, " +
" n char(30) null, " +
" t char(30) null, " +
" r varchar(255) null " +
" ) " +
" " +
" insert into " + tmpName + " EXEC sp_tables ' ', ' ', '%', null " +
" " +
" select q from " + tmpName + " " +
"";
java.sql.Statement stmt = connection.createStatement();
java.sql.ResultSet rs;
if (stmt.execute(sql))
{
throw new SQLException("Internal error. Confused");
}
// Eat the data returned by the 'create table'
if (null != (rs = stmt.getResultSet()))
{
throw new SQLException("Internal error. Confused");
}
// Eat the data returned by the 'insert'
if (null != (rs = stmt.getResultSet()))
{
// RMK 2000-06-11: test t0051 gets the result set here.
// XXX we really need to figure out what the protocol is doing here.
// It appears that sometimes it returns an immediate result set
//and sometimes it doesn't.
return rs;
}
// now get the result set
if (null == (rs = stmt.getResultSet()))
{
throw new SQLException("Internal error. Confused");
}
return rs;
}
/**
* What's the separator between catalog and table name?
*
* @return the separator string
* @exception SQLException if a database-access error occurs.
*/
public String getCatalogSeparator() throws SQLException
{
return ".";
}
/**
* What's the database vendor's preferred term for "catalog"?
*
* @return the vendor term
* @exception SQLException if a database-access error occurs.
*/
public String getCatalogTerm() throws SQLException
{
return "database";
}
/**
* Get a description of the access rights for a table's columns.
*
* <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
* @exception SQLException if a database-access error occurs.
* @see #getSearchStringEscape
*/
public java.sql.ResultSet getColumnPrivileges(String catalog, String schema,
String table, String columnNamePattern)
throws SQLException
{
NotImplemented(); return null;
}
/**
* Get a description of table columns available in a catalog.
*
* <P>Only column descriptions matching the catalog, schema, table
* and column name criteria are returned. They are ordered by
* TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.
*
* <P>Each 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>DATA_TYPE</B> short => SQL type from java.sql.Types
* <LI><B>TYPE_NAME</B> String => Data source dependent type name
* <LI><B>COLUMN_SIZE</B> int => column size. For char or date
* types this is the maximum number of characters, for numeric or
* decimal types this is precision.
* <LI><B>BUFFER_LENGTH</B> is not used.
* <LI><B>DECIMAL_DIGITS</B> int => the number of fractional digits
* <LI><B>NUM_PREC_RADIX</B> int => Radix (typically either 10 or 2)
* <LI><B>NULLABLE</B> int => is NULL allowed?
* <UL>
* <LI> columnNoNulls - might not allow NULL values
* <LI> columnNullable - definitely allows NULL values
* <LI> columnNullableUnknown - nullability unknown
* </UL>
* <LI><B>REMARKS</B> String => comment describing column (may be null)
* <LI><B>COLUMN_DEF</B> String => default value (may be null)
* <LI><B>SQL_DATA_TYPE</B> int => unused
* <LI><B>SQL_DATETIME_SUB</B> int => unused
* <LI><B>CHAR_OCTET_LENGTH</B> int => for char types the
* maximum number of bytes in the column
* <LI><B>ORDINAL_POSITION</B> int => index of column in table
* (starting at 1)
* <LI><B>IS_NULLABLE</B> String => "NO" means column definitely
* does not allow NULL values; "YES" means the column might
* allow NULL values. An empty string means nobody knows.
* </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
* @param columnNamePattern a column name pattern
* @return ResultSet - each row is a column description
* @exception SQLException if a database-access error occurs.
* @see #getSearchStringEscape
*/
public java.sql.ResultSet getColumns(String catalog, String schemaPattern,
String tableNamePattern, String columnNamePattern)
throws SQLException
{
debugPrintln("Inside of getColumn");
debugPrintln(" catalog is |" + catalog + "|");
debugPrintln(" schemaPattern is " + schemaPattern);
debugPrintln(" tableNamePattern is " + tableNamePattern);
debugPrintln(" columnNamePattern is " + columnNamePattern);
return getColumns_SQLServer65(catalog, schemaPattern,
tableNamePattern, columnNamePattern);
}
private java.sql.ResultSet getColumns_SQLServer65(
String catalog,
String schemaPattern,
String tableNamePattern,
String columnNamePattern)
throws SQLException
{
int i;
String sql = null;
java.sql.Statement tmpTableStmt = connection.createStatement();
String catalogCriteria;
// XXX We need to come up with something better than a global temporary
// table. It could cause problems if two people try to getColumns().
// (note- it is _unlikely_, not impossible)
String tmpTableName = "##t#" + UniqueId.getUniqueId();
String lookup = "#l#" + UniqueId.getUniqueId();
// create a temporary table
sql =
"create table " + tmpTableName + " ( " +
" TABLE_CAT char(32) null, " +
" TABLE_SCHEM char(32) null, " +
" TABLE_NAME char(32) null, " +
" COLUMN_NAME char(32) null, " +
" DATA_TYPE integer null, " +
" TYPE_NAME char(32) null, " +
" COLUMN_SIZE integer null, " +
" BUFFER_LENGTH integer null, " +
" DECIMAL_DIGITS integer null, " +
" NUM_PREC_RADIX integer null, " +
" NULLABLE integer null, " +
" REMARKS char(255) null, " +
" COLUMN_DEF char(255) null, " +
" SQL_DATA_TYPE integer null, " +
" SQL_DATETIME_SUB integer null, " +
" CHAR_OCTET_LENGTH integer null, " +
" ORDINAL_POSITION integer null, " +
" IS_NULLABLE char(3)) " +
"";
tmpTableStmt.execute(sql);
// Create a lookup table for mapping between native and jdbc types
sql =
"create table " + lookup + " ( " +
" native_type integer primary key, " +
" jdbc_type integer not null) ";
tmpTableStmt.execute(sql);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -