📄 jtdsdatabasemetadata.java
字号:
* whether unique or not
* @param approximate when <code>true</code>, result is allowed to reflect
* approximate or out of data values; when <code>false</code>, results
* are requested to be accurate
* @return ResultSet - each row is an index column description
* @throws SQLException if a database-access error occurs.
*/
public java.sql.ResultSet getIndexInfo(String catalog,
String schema,
String table,
boolean unique,
boolean approximate)
throws SQLException {
String colNames[] = {"TABLE_CAT", "TABLE_SCHEM",
"TABLE_NAME", "NON_UNIQUE",
"INDEX_QUALIFIER", "INDEX_NAME",
"TYPE", "ORDINAL_POSITION",
"COLUMN_NAME", "ASC_OR_DESC",
"CARDINALITY", "PAGES",
"FILTER_CONDITION"};
int colTypes[] = {Types.VARCHAR, Types.VARCHAR,
Types.VARCHAR, Types.BIT,
Types.VARCHAR, Types.VARCHAR,
Types.SMALLINT, Types.SMALLINT,
Types.VARCHAR, Types.VARCHAR,
Types.INTEGER, Types.INTEGER,
Types.VARCHAR};
String query = "sp_statistics ?, ?, ?, ?, ?, ?";
CallableStatement s = connection.prepareCall(syscall(catalog, query));
s.setString(1, table);
s.setString(2, schema);
s.setString(3, catalog);
s.setString(4, "%");
s.setString(5, unique ? "Y" : "N");
s.setString(6, approximate ? "Q" : "E");
JtdsResultSet rs = (JtdsResultSet) s.executeQuery();
int colCnt = rs.getMetaData().getColumnCount();
CachedResultSet rsTmp = new CachedResultSet((JtdsStatement)s, colNames, colTypes);
rsTmp.moveToInsertRow();
while (rs.next()) {
for (int i = 1; i <= colCnt; i++) {
rsTmp.updateObject(i, rs.getObject(i));
}
rsTmp.insertRow();
}
rs.close();
rsTmp.moveToCurrentRow();
rsTmp.setConcurrency(ResultSet.CONCUR_READ_ONLY);
return rsTmp;
}
//----------------------------------------------------------------------
// The following group of methods exposes various limitations
// based on the target database with the current driver.
// Unless otherwise specified, a result of zero means there is no
// limit, or the limit is not known.
/**
* How many hex characters can you have in an inline binary literal?
*
* @return max literal length
* @throws SQLException if a database-access error occurs.
*/
public int getMaxBinaryLiteralLength() throws SQLException {
// Sybase jConnect says 255
// Actual value is 16384 for Sybase 12.5
// MS JDBC says 0
// Probable maximum size for MS is 65,536 * network packet size
return 131072;
// per "Programming ODBC for SQLServer" Appendix A
}
/**
* What's the maximum length of a catalog name?
*
* @return max name length in bytes
* @throws SQLException if a database-access error occurs.
*/
public int getMaxCatalogNameLength() throws SQLException {
return sysnameLength;
}
/**
* What's the max length for a character literal?
*
* @return max literal length
* @throws SQLException if a database-access error occurs.
*/
public int getMaxCharLiteralLength() throws SQLException {
// Sybase jConnect says 255
// Actual value is 16384 for Sybase 12.5
// MS JDBC says 0
// Probable maximum size for MS is 65,536 * network packet size
return 131072;
// per "Programming ODBC for SQLServer" Appendix A
}
/**
* What's the limit on column name length?
*
* @return max literal length
* @throws SQLException if a database-access error occurs.
*/
public int getMaxColumnNameLength() throws SQLException {
// per "Programming ODBC for SQLServer" Appendix A
return sysnameLength;
}
/**
* What's the maximum number of columns in a "GROUP BY" clause?
*
* @return max number of columns
* @throws SQLException if a database-access error occurs.
*/
public int getMaxColumnsInGroupBy() throws SQLException {
// Sybase jConnect says 16
// MS JDBC says 16
// per "Programming ODBC for SQLServer" Appendix A
// Actual MS value is 8060 / average bytes per column
return (tdsVersion >= Driver.TDS70) ? 0 : 16;
}
/**
* What's the maximum number of columns allowed in an index?
*
* @return max columns
* @throws SQLException if a database-access error occurs.
*/
public int getMaxColumnsInIndex() throws SQLException {
// per SQL Server Books Online "Administrator's Companion",
// Part 1, Chapter 1.
// Sybase 12.5 is 31
return 16;
}
/**
* What's the maximum number of columns in an "ORDER BY" clause?
*
* @return max columns
* @throws SQLException if a database-access error occurs.
*/
public int getMaxColumnsInOrderBy() throws SQLException {
// per "Programming ODBC for SQLServer" Appendix A
// Sybase 12.5 is 31
// Actual MS value is 8060 / average bytes per column
return (tdsVersion >= Driver.TDS70) ? 0 : 16;
}
/**
* What's the maximum number of columns in a "SELECT" list?
*
* @return max columns
* @throws SQLException if a database-access error occurs.
*/
public int getMaxColumnsInSelect() throws SQLException {
// Sybase jConnect says 0
// per "Programming ODBC for SQLServer" Appendix A
return 4096;
}
/**
* What's the maximum number of columns in a table?
*
* @return max columns
* @throws SQLException if a database-access error occurs.
*/
public int getMaxColumnsInTable() throws SQLException {
// Sybase jConnect says 250
// per "Programming ODBC for SQLServer" Appendix A
// MS 2000 should be 4096
// Sybase 12.5 is now 1024
return (tdsVersion >= Driver.TDS70) ? 1024 : 250;
}
/**
* How many active connections can we have at a time to this database?
*
* @return max connections
* @throws SQLException if a database-access error occurs.
*/
public int getMaxConnections() throws SQLException {
// Sybase - could query syscurconfigs to get actual value
// which in practice will be a lot less than 32767!
// per SQL Server Books Online "Administrator's Companion",
// Part 1, Chapter 1.
return 32767;
}
/**
* What's the maximum cursor name length?
*
* @return max cursor name length in bytes
* @throws SQLException if a database-access error occurs.
*/
public int getMaxCursorNameLength() throws SQLException {
// per "Programming ODBC for SQLServer" Appendix A
return sysnameLength;
}
/**
* What's the maximum length of an index (in bytes)?
*
* @return max index length in bytes
* @throws SQLException if a database-access error occurs.
*/
public int getMaxIndexLength() throws SQLException {
// Sybase JConnect says 255
// Actual Sybase 12.5 is 600 - 5300 depending on page size
// per "Programming ODBC for SQLServer" Appendix A
return (tdsVersion >= Driver.TDS70) ? 900 : 255;
}
/**
* What's the maximum length of a procedure name?
*
* @return max name length in bytes
* @throws SQLException if a database-access error occurs.
*/
public int getMaxProcedureNameLength() throws SQLException {
// per "Programming ODBC for SQLServer" Appendix A
return sysnameLength;
}
/**
* What's the maximum length of a single row?
*
* @return max row size in bytes
* @throws SQLException if a database-access error occurs.
*/
public int getMaxRowSize() throws SQLException {
// Sybase jConnect says 1962 but this can be more with wide tables.
// per SQL Server Books Online "Administrator's Companion",
// Part 1, Chapter 1.
return (tdsVersion >= Driver.TDS70) ? 8060 : 1962;
}
/**
* What's the maximum length allowed for a schema name?
*
* @return max name length in bytes
* @throws SQLException if a database-access error occurs.
*/
public int getMaxSchemaNameLength() throws SQLException {
return sysnameLength;
}
/**
* What's the maximum length of a SQL statement?
*
* @return max length in bytes
* @throws SQLException if a database-access error occurs.
*/
public int getMaxStatementLength() throws SQLException {
// I think this should return 0 (no limit)
// actual limit for SQL 7/2000 is 65536 * packet size!
// Sybase JConnect says 0
// MS JDBC says 0
// per "Programming ODBC for SQLServer" Appendix A
return 0;
}
/**
* How many active statements can we have open at one time to this
* database?
*
* @return the maximum
* @throws SQLException if a database-access error occurs.
*/
public int getMaxStatements() throws SQLException {
return 0;
}
/**
* What's the maximum length of a table name?
*
* @return max name length in bytes
* @throws SQLException if a database-access error occurs.
*/
public int getMaxTableNameLength() throws SQLException {
// per "Programming ODBC for SQLServer" Appendix A
return sysnameLength;
}
/**
* What's the maximum number of tables in a SELECT?
*
* @return the maximum
* @throws SQLException if a database-access error occurs.
*/
public int getMaxTablesInSelect() throws SQLException {
// Sybase JConnect says 256
// MS JDBC says 32!
// Actual Sybase 12.5 is 50
// per "Programming ODBC for SQLServer" Appendix A
return (tdsVersion > Driver.TDS50) ? 256 : 16;
}
/**
* What's the maximum length of a user name?
*
* @return max name length in bytes
* @throws SQLException if a database-access error occurs.
*/
public int getMaxUserNameLength() throws SQLException {
return sysnameLength;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -