📄 databasemetadata.java
字号:
sql =
"insert into " + lookup + " values ( 31, 1111) " + // VOID
"insert into " + lookup + " values ( 34, 1111) " + // IMAGE
"insert into " + lookup + " values ( 35, -1) " + // TEXT
"insert into " + lookup + " values ( 37, -3) " + // VARBINARY
"insert into " + lookup + " values ( 38, 4) " + // INTN
"insert into " + lookup + " values ( 39, 12) " + // VARCHAR
"insert into " + lookup + " values ( 45, -2) " + // BINARY
"insert into " + lookup + " values ( 47, 1) " + // CHAR
"insert into " + lookup + " values ( 48, -6) " + // INT1
"insert into " + lookup + " values ( 50, -7) " + // BIT
"insert into " + lookup + " values ( 52, 5) " + // INT2
"insert into " + lookup + " values ( 56, 4) " + // INT4
"insert into " + lookup + " values ( 58, 93) " + // DATETIME4
"insert into " + lookup + " values ( 59, 7) " + // REAL
"insert into " + lookup + " values ( 60, 1111) " + // MONEY
"insert into " + lookup + " values ( 61, 93) " + // DATETIME
"insert into " + lookup + " values ( 62, 8) " + // FLT8
"insert into " + lookup + " values (106, 3) " + // DECIMAL
"insert into " + lookup + " values (108, 2) " + // NUMERIC
"insert into " + lookup + " values (109, 8) " + // FLTN
"insert into " + lookup + " values (110, 1111) " + // MONEYN
"insert into " + lookup + " values (111, 93) " + // DATETIMN
"insert into " + lookup + " values (112, 1111) " + // MONEY4
"";
tmpTableStmt.execute(sql);
// For each table in the system add its columns
// Note- We have to do them one at a time in case
// there are databases we don't have access to.
java.sql.ResultSet rs = getTables(null, "%", "%", null);
while(rs.next())
{
String cat = rs.getString(1);
// XXX Security risk. It 'might' be possible to create
// a catalog name that when inserted into this sql statement could
// do other commands.
sql =
"insert into " + tmpTableName + " " +
"select " +
" TABLE_CAT='" + cat + "', " +
" TABLE_SCHEM=USER_NAME(o.uid), " +
" TABLE_NAME=o.name, " +
" COLUMN_NAME=c.name, " +
" DATA_TYPE=l.jdbc_type, " +
" TYPE_NAME=t.name, " +
" COLUMN_SIZE=c.prec, " +
" BUFFER_LENGTH=0, " +
" DECIMAL_DIGITS=c.scale, " +
" NUM_PREC_RADIX=10, " +
" NULLABLE=convert(integer, " +
" convert(bit, c.status&8)), " +
" REMARKS=null, " +
" COLUMN_DEF=null, " +
" SQL_DATATYPE=c.type, " +
" SQL_DATETIME_SUB=0, " +
" CHAR_OCTET_LENGTH=c.length, " +
" ORDINAL_POSITION=c.colid, " +
" IS_NULLABLE= " +
" convert(char(3), rtrim(substring " +
" ('NO YES', " +
" (c.status&8)+1,3))) " +
"from " +
" " + cat + ".dbo.sysobjects o, " +
" " + cat + ".dbo.syscolumns c, " +
" " + lookup + " l, " +
" systypes t " +
"where o.type in ('V', 'U') and o.id=c.id " +
" and t.type=c.type " +
" and l.native_type=c.type " +
"";
// System.out.println("Executing \n" + sql + "\n");
try
{
tmpTableStmt.executeUpdate(sql);
}
catch (SQLException e)
{
}
}
rs.close();
if (catalog == null)
{
catalog = "";
catalogCriteria = " (TABLE_CAT like '%' or TABLE_CAT=?) ";
}
else
{
catalogCriteria = " TABLE_CAT=? ";
}
sql =
"select distinct * from " + tmpTableName + " where " +
catalogCriteria + " and " +
" TABLE_SCHEM like ? and TABLE_NAME like ? and " +
" COLUMN_NAME like ? " +
"order by TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION " ;
System.out.println("The query is \n" + sql);
java.sql.PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1, catalog);
ps.setString(2, schemaPattern);
ps.setString(3, tableNamePattern);
ps.setString(4, columnNamePattern);
rs = ps.executeQuery();
// We need to do something about deleting the global temporary table
tmpTableStmt.close();
return rs;
}
/**
* Get a description of the foreign key columns in the foreign key
* table that reference the primary key columns of the primary key
* table (describe how one table imports another's key.) This
* should normally return a single foreign key/primary key pair
* (most tables only import a foreign key from a table once.) They
* are ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and
* KEY_SEQ.
*
* <P>Each foreign key column description has the following columns:
* <OL>
* <LI><B>PKTABLE_CAT</B> String => primary key table catalog (may be null)
* <LI><B>PKTABLE_SCHEM</B> String => primary key table schema (may be null)
* <LI><B>PKTABLE_NAME</B> String => primary key table name
* <LI><B>PKCOLUMN_NAME</B> String => primary key column name
* <LI><B>FKTABLE_CAT</B> String => foreign key table catalog (may be null)
* being exported (may be null)
* <LI><B>FKTABLE_SCHEM</B> String => foreign key table schema (may be null)
* being exported (may be null)
* <LI><B>FKTABLE_NAME</B> String => foreign key table name
* being exported
* <LI><B>FKCOLUMN_NAME</B> String => foreign key column name
* being exported
* <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> importedKeyRestrict - same as importedKeyNoAction
* (for ODBC 2.x compatibility)
* <LI> importedKeySetDefault - change imported key to default if
* its primary key has been deleted
* </UL>
* <LI><B>FK_NAME</B> String => foreign key name (may be null)
* <LI><B>PK_NAME</B> String => primary key name (may be null)
* <LI><B>DEFERRABILITY</B> short => can the evaluation of foreign key
* constraints be deferred until commit
* <UL>
* <LI> importedKeyInitiallyDeferred - see SQL92 for definition
* <LI> importedKeyInitiallyImmediate - see SQL92 for definition
* <LI> importedKeyNotDeferrable - see SQL92 for definition
* </UL>
* </OL>
*
* @param primaryCatalog a catalog name; "" retrieves those without a
* catalog; null means drop catalog name from the selection criteria
* @param primarySchema a schema name pattern; "" retrieves those
* without a schema
* @param primaryTable the table name that exports the key
* @param foreignCatalog a catalog name; "" retrieves those without a
* catalog; null means drop catalog name from the selection criteria
* @param foreignSchema a schema name pattern; "" retrieves those
* without a schema
* @param foreignTable the table name that imports the key
* @return ResultSet - each row is a foreign key column description
* @exception SQLException if a database-access error occurs.
* @see #getImportedKeys
*/
public java.sql.ResultSet getCrossReference(
String primaryCatalog, String primarySchema, String primaryTable,
String foreignCatalog, String foreignSchema, String foreignTable
) throws SQLException
{
NotImplemented(); return null;
}
/**
* What's the name of this database product?
*
* @return database product name
* @exception SQLException if a database-access error occurs.
*/
public String getDatabaseProductName() throws SQLException
{
return tds.getDatabaseProductName();
}
/**
* What's the version of this database product?
*
* @return database version
* @exception SQLException if a database-access error occurs.
*/
public String getDatabaseProductVersion() throws SQLException
{
return tds.getDatabaseProductVersion();
}
//----------------------------------------------------------------------
/**
* What's the database's default transaction isolation level? The
* values are defined in java.sql.Connection.
*
* @return the default isolation level
* @exception SQLException if a database-access error occurs.
* @see Connection
*/
public int getDefaultTransactionIsolation() throws SQLException
{
// XXX need to check this for Sybase
return Connection.TRANSACTION_READ_COMMITTED;
}
/**
* What's this JDBC driver's major version number?
*
* @return JDBC driver major version
*/
public int getDriverMajorVersion()
{
return DriverVersion.getDriverMajorVersion();
}
/**
* What's this JDBC driver's minor version number?
*
* @return JDBC driver minor version number
*/
public int getDriverMinorVersion()
{
return DriverVersion.getDriverMinorVersion();
}
/**
* What's the name of this JDBC driver?
*
* @return JDBC driver name
* @exception SQLException if a database-access error occurs.
*/
public String getDriverName() throws SQLException
{
return "InternetCDS Type 4 JDBC driver for MS SQLServer";
}
/**
* What's the version of this JDBC driver?
*
* @return JDBC driver version
* @exception SQLException if a database-access error occurs.
*/
public String getDriverVersion() throws SQLException
{
return getDriverMajorVersion() + "." + getDriverMinorVersion();
}
/**
* Get a description of the foreign key columns that reference a
* table's primary key columns (the foreign keys exported by a
* table). They are ordered by FKTABLE_CAT, FKTABLE_SCHEM,
* FKTABLE_NAME, and KEY_SEQ.
*
* <P>Each foreign key column description has the following columns:
* <OL>
* <LI><B>PKTABLE_CAT</B> String => primary key table catalog (may be null)
* <LI><B>PKTABLE_SCHEM</B> String => primary key table schema (may be null)
* <LI><B>PKTABLE_NAME</B> String => primary key table name
* <LI><B>PKCOLUMN_NAME</B> String => primary key column name
* <LI><B>FKTABLE_CAT</B> String => foreign key table catalog (may be null)
* being exported (may be null)
* <LI><B>FKTABLE_SCHEM</B> String => foreign key table schema (may be null)
* being exported (may be null)
* <LI><B>FKTABLE_NAME</B> String => foreign key table name
* being exported
* <LI><B>FKCOLUMN_NAME</B> String => foreign key column name
* being exported
* <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> importedKeyRestrict - same as importedKeyNoAction
* (for ODBC 2.x compatibility)
* <LI> importedKeySetDefault - change imported key to default if
* its primary key has been deleted
* </UL>
* <LI><B>FK_NAME</B> String => foreign key name (may be null)
* <LI><B>PK_NAME</B> String => primary key name (may be null)
* <LI><B>DEFERRABILITY</B> short => can the evaluation of foreign key
* constraints be deferred until commit
* <UL>
* <LI> importedKeyInitiallyDeferred - see SQL92 for definition
* <LI> importedKeyInitiallyImmediate - see SQL92 for definition
* <LI> importedKeyNotDeferrable - see SQL92 for definition
* </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 pattern; "" retrieves those
* without a schema
* @param table a table name
* @return ResultSet - each row is a foreign key column description
* @exception SQLException if a database-access error occurs.
* @see #getImportedKeys
*/
public java.sql.ResultSet getExportedKeys(String catalog, String schema,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -