📄 jdbcdatabasemetadata.java
字号:
String primarySchema, String primaryTable, String foreignCatalog,
String foreignSchema, String foreignTable) throws SQLException {
try {
if (debug()) {
debugCode("getCrossReference("
+quote(primaryCatalog)+", "
+quote(primarySchema)+", "
+quote(primaryTable)+", "
+quote(foreignCatalog)+", "
+quote(foreignSchema)+", "
+quote(foreignTable)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "PKTABLE_CATALOG PKTABLE_CAT, "
+ "PKTABLE_SCHEMA PKTABLE_SCHEM, "
+ "PKTABLE_NAME PKTABLE_NAME, "
+ "PKCOLUMN_NAME, "
+ "FKTABLE_CATALOG FKTABLE_CAT, "
+ "FKTABLE_SCHEMA FKTABLE_SCHEM, "
+ "FKTABLE_NAME, "
+ "FKCOLUMN_NAME, "
+ "ORDINAL_POSITION KEY_SEQ, "
+ "UPDATE_RULE, "
+ "DELETE_RULE, "
+ "FK_NAME, "
+ "PK_NAME, "
+ "DEFERRABILITY "
+ "FROM INFORMATION_SCHEMA.CROSS_REFERENCES "
+ "WHERE PKTABLE_CATALOG LIKE ? "
+ "AND PKTABLE_SCHEMA LIKE ? "
+ "AND PKTABLE_NAME = ? "
+ "AND FKTABLE_CATALOG LIKE ? "
+ "AND FKTABLE_SCHEMA LIKE ? "
+ "AND FKTABLE_NAME = ? "
+ "ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, FK_NAME, KEY_SEQ");
prep.setString(1, getCatalogPattern(primaryCatalog));
prep.setString(2, getSchemaPattern(primarySchema));
prep.setString(3, primaryTable);
prep.setString(4, getCatalogPattern(foreignCatalog));
prep.setString(5, getSchemaPattern(foreignSchema));
prep.setString(6, foreignTable);
return prep.executeQuery();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of user defined data types.
* This call returns an empty result set.
*
* <ul>
* <li>1 TYPE_CAT (String) catalog
* </li><li>2 TYPE_SCHEM (String) schema
* </li><li>3 TYPE_NAME (String) type name
* </li><li>4 CLASS_NAME (String) Java class
* </li><li>5 DATA_TYPE (short) SQL Type - see also java.sql.Types
* </li><li>6 REMARKS (String) description
* </li><li>7 BASE_TYPE (short) base type - see also java.sql.Types
* </li></ul>
*
* @param catalog ignored
* @param schemaPattern ignored
* @param typeNamePattern ignored
* @param types ignored
* @return an empty result set
* @throws SQLException if the connection is closed
*/
public ResultSet getUDTs(String catalog, String schemaPattern,
String typeNamePattern, int[] types) throws SQLException {
try {
if (debug()) {
debugCode("getUDTs("
+quote(catalog)+", "
+quote(schemaPattern)+", "
+quote(typeNamePattern)+", "
+quoteIntArray(types)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "CATALOG_NAME TYPE_CAT, "
+ "CATALOG_NAME TYPE_SCHEM, "
+ "CATALOG_NAME TYPE_NAME, "
+ "CATALOG_NAME CLASS_NAME, "
+ "CAST(ZERO() AS SMALLINT) DATA_TYPE, "
+ "CATALOG_NAME REMARKS, "
+ "CAST(ZERO() AS SMALLINT) BASE_TYPE "
+ "FROM INFORMATION_SCHEMA.CATALOGS "
+ "WHERE FALSE");
return prep.executeQuery();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of data types. The result set is sorted by DATA_TYPE and
* afterwards by how closely the data type maps to the corresponding JDBC
* SQL type (best match first).
*
* <ul>
* <li>1 TYPE_NAME (String) type name </li>
* <li>2 DATA_TYPE (short) SQL data type - see also java.sql.Types </li>
* <li>3 PRECISION (int) maximum precision </li>
* <li>4 LITERAL_PREFIX (String) prefix used to quote a literal </li>
* <li>5 LITERAL_SUFFIX (String) suffix used to quote a literal </li>
* <li>6 CREATE_PARAMS (String) parameters used (may be null) </li>
* <li>7 NULLABLE (short) typeNoNulls (NULL not allowed) or typeNullable
* </li>
* <li>8 CASE_SENSITIVE (boolean) case sensitive </li>
* <li>9 SEARCHABLE (short) typeSearchable </li>
* <li>10 UNSIGNED_ATTRIBUTE (boolean) unsigned </li>
* <li>11 FIXED_PREC_SCALE (boolean) fixed precision </li>
* <li>12 AUTO_INCREMENT (boolean) auto increment </li>
* <li>13 LOCAL_TYPE_NAME (String) localized version of the data type </li>
* <li>14 MINIMUM_SCALE (short) minimum scale </li>
* <li>15 MAXIMUM_SCALE (short) maximum scale </li>
* <li>16 SQL_DATA_TYPE (int) unused </li>
* <li>17 SQL_DATETIME_SUB (int) unused </li>
* <li>18 NUM_PREC_RADIX (int) 2 for binary, 10 for decimal </li>
* </ul>
*
* @return the list of data types
* @throws SQLException if the connection is closed
*/
public ResultSet getTypeInfo() throws SQLException {
try {
debugCodeCall("getTypeInfo");
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TYPE_NAME, "
+ "DATA_TYPE, "
+ "PRECISION, "
+ "PREFIX LITERAL_PREFIX, "
+ "SUFFIX LITERAL_SUFFIX, "
+ "PARAMS CREATE_PARAMS, "
+ "NULLABLE, "
+ "CASE_SENSITIVE, "
+ "SEARCHABLE, "
+ "FALSE UNSIGNED_ATTRIBUTE, "
+ "FALSE FIXED_PREC_SCALE, "
+ "AUTO_INCREMENT, "
+ "TYPE_NAME LOCAL_TYPE_NAME, "
+ "MINIMUM_SCALE, "
+ "MAXIMUM_SCALE, "
+ "DATA_TYPE SQL_DATA_TYPE, "
+ "ZERO() SQL_DATETIME_SUB, "
+ "RADIX NUM_PREC_RADIX "
+ "FROM INFORMATION_SCHEMA.TYPE_INFO "
+ "ORDER BY DATA_TYPE, POS");
ResultSet rs = prep.executeQuery();
return rs;
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Checks if this database store data in local files.
*
* @return true
*/
public boolean usesLocalFiles() {
debugCodeCall("usesLocalFiles");
return true;
}
/**
* Checks if this database use one file per table.
*
* @return false
*/
public boolean usesLocalFilePerTable() {
debugCodeCall("usesLocalFilePerTable");
return false;
}
/**
* Returns the string used to quote identifiers.
*
* @return a double quote
*/
public String getIdentifierQuoteString() {
debugCodeCall("getIdentifierQuoteString");
return "\"";
}
/**
* Gets the comma-separated list of all SQL keywords that are not supported
* as table/column/index name, in addition to the SQL-92 keywords.
*
* @return a list with the keywords
*/
public String getSQLKeywords() {
debugCodeCall("getSQLKeywords");
return "";
}
/**
* Returns the list of numeric functions supported by this database.
*
* @return the list
*/
public String getNumericFunctions() throws SQLException {
debugCodeCall("getNumericFunctions");
return getFunctions("Functions (Numeric)");
}
/**
* Returns the list of string functions supported by this database.
*
* @return the list
*/
public String getStringFunctions() throws SQLException {
debugCodeCall("getStringFunctions");
return getFunctions("Functions (String)");
}
/**
* Returns the list of system functions supported by this database.
*
* @return the list
*/
public String getSystemFunctions() throws SQLException {
debugCodeCall("getSystemFunctions");
return getFunctions("Functions (System)");
}
/**
* Returns the list of date and time functions supported by this database.
*
* @return the list
*/
public String getTimeDateFunctions() throws SQLException {
debugCodeCall("getTimeDateFunctions");
return getFunctions("Functions (Time and Date)");
}
private String getFunctions(String section) throws SQLException {
try {
StringBuffer buff = new StringBuffer();
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT TOPIC "
+ "FROM INFORMATION_SCHEMA.HELP WHERE SECTION = ?");
prep.setString(1, section);
ResultSet rs = prep.executeQuery();
while (rs.next()) {
String s = rs.getString(1).trim();
String[] array = StringUtils.arraySplit(s, ',', true);
for (int i = 0; i < array.length; i++) {
if (buff.length() > 0) {
buff.append(",");
}
String f = array[i].trim();
if (f.indexOf(' ') >= 0) {
// remove 'Function' from 'INSERT Function'
f = f.substring(0, f.indexOf(' ')).trim();
}
buff.append(f);
}
}
rs.close();
prep.close();
return buff.toString();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Returns the default escape character for LIKE.
*
* @return the character '\'
*/
public String getSearchStringEscape() {
debugCodeCall("getSearchStringEscape");
return "" + Constants.DEFAULT_ESCAPE_CHAR;
}
/**
* Returns the characters that are allowed for identifiers in addiction to
* A-Z, a-z, 0-9 and '_'.
*
* @return an empty String ("")
*/
public String getExtraNameCharacters() {
debugCodeCall("getExtraNameCharacters");
return "";
}
/**
* Returns whether alter table with add column is supported.
* @return true
*/
public boolean supportsAlterTableWithAddColumn() {
debugCodeCall("supportsAlterTableWithAddColumn");
return true;
}
/**
* Returns whether alter table with drop column is supported.
*
* @return true
*/
public boolean supportsAlterTableWithDropColumn() {
debugCodeCall("supportsAlterTableWithDropColumn");
return true;
}
/**
* Returns whether column aliasing is supported.
*
* @return true
*/
public boolean supportsColumnAliasing() {
debugCodeCall("supportsColumnAliasing");
return true;
}
/**
* Returns whether NULL+1 is NULL or not.
*
* @return true
*/
public boolean nullPlusNonNullIsNull() {
debugCodeCall("nullPlusNonNullIsNull");
return true;
}
/**
* Returns whether CONVERT is supported.
*
* @return true
*/
public boolean supportsConvert() {
debugCodeCall("supportsConvert");
return true;
}
/**
* Returns whether CONVERT is supported for one datatype to another.
*
* @return true
*/
public boolean supportsConvert(int fromType, int toType) {
if (debug()) {
debugCode("supportsConvert("+fromType+", "+fromType+");");
}
return true;
}
/**
* Returns whether table correlation names (table alias) are supported.
*
* @return true
*/
public boolean supportsTableCorrelationNames() {
debugCodeCall("supportsTableCorrelationNames");
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -