package oracle.jdbc.driver;
import java.sql.*;
import oracle.jdbc.dbaccess.*;
/**
* The OracleDatabaseMetaData class implements the JDBC 1.0 DatabaseMetaData
* interface.
*/
public class OracleDatabaseMetaData implements DatabaseMetaData
{
OracleConnection connection;
public OracleDatabaseMetaData (OracleConnection conn)
{
connection = conn;
}
//----------------------------------------------------------------------
// First, a variety of minor information about the target database.
/**
* Can all the procedures returned by getProcedures be called by the
* current user?
*
* @return true if so
*/
public boolean allProceduresAreCallable()
throws SQLException
{
connection.trace ("allProceduresAreCallable");
return false;
}
/**
* Can all the tables returned by getTable be SELECTed by the
* current user?
*
* @return true if so
*/
public boolean allTablesAreSelectable()
throws SQLException
{
connection.trace ("allTablesAreSelectable");
return false;
}
/**
* What's the url for this database?
*
* @return the url or null if it can't be generated
*/
public String getURL()
throws SQLException
{
return connection.url;
}
/**
* What's our user name as known to the database?
*
* @return our database user name
*/
public String getUserName()
throws SQLException
{
connection.trace ("getUserName");
return connection.user;
}
/**
* Is the database in read-only mode?
*
* @return true if so
*/
public boolean isReadOnly()
throws SQLException
{
connection.trace ("isReadOnly");
return false;
}
/**
* Are NULL values sorted high?
*
* @return true if so
*/
public boolean nullsAreSortedHigh()
throws SQLException
{
connection.trace ("nullsAreSortedHigh");
return false;
}
/**
* Are NULL values sorted low?
*
* @return true if so
*/
public boolean nullsAreSortedLow()
throws SQLException
{
connection.trace ("nullsAreSortedLow");
return true;
}
/**
* Are NULL values sorted at the start regardless of sort order?
*
* @return true if so
*/
public boolean nullsAreSortedAtStart()
throws SQLException
{
connection.trace ("nullsAreSortedAtStart");
return false;
}
/**
* Are NULL values sorted at the end regardless of sort order?
*
* @return true if so
*/
public boolean nullsAreSortedAtEnd()
throws SQLException
{
connection.trace ("nullsAreSortedAtEnd");
return false;
}
/**
* What's the name of this database product?
*
* @return database product name
*/
public String getDatabaseProductName()
throws SQLException
{
return "Oracle";
}
/**
* What's the version of this database product?
*
* @return database version
*/
public String getDatabaseProductVersion()
throws SQLException
{
connection.trace ("getDatabaseProductVersion");
int error [] = new int [1];
try
{
connection.needLine ();
byte [] version = connection.db_access.getVersion ();
return connection.conversion.CharBytesToString (version, version.length);
}
catch (java.io.IOException e)
{
return null;
}
}
/**
* What's the name of this JDBC driver?
*
* @return JDBC driver name
*/
public String getDriverName()
throws SQLException
{
connection.trace ("getDriverName");
return "Oracle JDBC driver";
}
/**
* What's the version of this JDBC driver?
*
* @return JDBC driver version
*/
public String getDriverVersion()
throws SQLException
{
connection.trace ("getDriverVersion");
return "7.3.4";
}
/**
* What's this JDBC driver's major version number?
*
* @return JDBC driver major version
*/
public int getDriverMajorVersion()
{
connection.trace ("getDriverMajorVersion");
return 7;
}
/**
* What's this JDBC driver's minor version number?
*
* @return JDBC driver minor version number
*/
public int getDriverMinorVersion()
{
connection.trace ("getDriverMinorVersion");
return 3;
}
/**
* Does the database store tables in a local file?
*
* @return true if so
*/
public boolean usesLocalFiles()
throws SQLException
{
connection.trace ("usesLocalFiles");
return false;
}
/**
* Does the database use a file for each table?
*
* @return true if the database uses a local file for each table
*/
public boolean usesLocalFilePerTable()
throws SQLException
{
connection.trace ("usesLocalFilePerTable");
return false;
}
/**
* Does the database treat mixed case unquoted SQL identifiers as
* case sensitive and as a result store them in mixed case?
*
* A JDBC compliant driver will always return false.
*
* @return true if so
*/
public boolean supportsMixedCaseIdentifiers()
throws SQLException
{
connection.trace ("supportsMixedCaseIdentifiers");
return false;
}
/**
* Does the database treat mixed case unquoted SQL identifiers as
* case insensitive and store them in upper case?
*
* @return true if so
*/
public boolean storesUpperCaseIdentifiers()
throws SQLException
{
connection.trace ("storesUpperCaseIdentifiers");
return true;
}
/**
* Does the database treat mixed case unquoted SQL identifiers as
* case insensitive and store them in lower case?
*
* @return true if so
*/
public boolean storesLowerCaseIdentifiers()
throws SQLException
{
connection.trace ("storesLowerCaseIdentifiers");
return false;
}
/**
* Does the database treat mixed case unquoted SQL identifiers as
* case insensitive and store them in mixed case?
*
* @return true if so
*/
public boolean storesMixedCaseIdentifiers()
throws SQLException
{
connection.trace ("storesMixedCaseIdentifiers");
return false;
}
/**
* Does the database treat mixed case quoted SQL identifiers as
* case sensitive and as a result store them in mixed case?
*
* A JDBC compliant driver will always return false.
*
* @return true if so
*/
public boolean supportsMixedCaseQuotedIdentifiers()
throws SQLException
{
connection.trace ("supportsMixedCaseQuotedIdentifiers");
return true;
}
/**
* Does the database treat mixed case quoted SQL identifiers as
* case insensitive and store them in upper case?
*
* @return true if so
*/
public boolean storesUpperCaseQuotedIdentifiers()
throws SQLException
{
connection.trace ("storesUpperCaseQuotedIdentifiers");
return false;
}
/**
* Does the database treat mixed case quoted SQL identifiers as
* case insensitive and store them in lower case?
*
* @return true if so
*/
public boolean storesLowerCaseQuotedIdentifiers()
throws SQLException
{
connection.trace ("storesLowerCaseQuotedIdentifiers");
return false;
}
/**
* Does the database treat mixed case quoted SQL identifiers as
* case insensitive and store them in mixed case?
*
* @return true if so
*/
public boolean storesMixedCaseQuotedIdentifiers()
throws SQLException
{
connection.trace ("storesMixedCaseQuotedIdentifiers");
return true;
}
/**
* What's the string used to quote SQL identifiers?
* This returns a space " " if identifier quoting isn't supported.
*
* A JDBC compliant driver always uses a double quote character.
*
* @return the quoting string
*/
public String getIdentifierQuoteString()
throws SQLException
{
connection.trace ("getIdentifierQuoteString");
return ("\"");
}
/**
* Get a comma separated list of all a database's SQL keywords
* that are NOT also SQL92 keywords.
*
* @return the list
*/
public String getSQLKeywords()
throws SQLException
{
connection.trace ("getSQLKeywords");
return "ACCESS, ADD, ALTER, AUDIT, CLUSTER, COLUMN, COMMENT, COMPRESS, CONNECT, DATE, DROP, EXCLUSIVE, FILE, IDENTIFIED, IMMEDIATE, INCREMENT, INDEX, INITIAL, INTERSECT, LEVEL, LOCK, LONG, MAXEXTENTS, MINUS, MODE, NOAUDIT, NOCOMPRESS, NOWAIT, NUMBER, OFFLINE, ONLINE, PCTFREE, PRIOR, all_PL_SQL_reserved_ words";
}
/**
* Get a comma separated list of math functions.
*
* @return the list
*/
public String getNumericFunctions()
throws SQLException
{
connection.trace ("getNumericFunctions");
return "ABS, CEIL, COS, COSH, EXP, FLOOR, LN, LOG, MOD, POWER, ROUND, SIGN, SIN, SINH, SQRT, TAN, TANH, TRUNC, AVG, COUNT, GLB, LUB, MAX, MIN, STDDEV, SUM, VARIANCE";
}
/**
* Get a comma separated list of string functions.
*
* @return the list
*/
public String getStringFunctions()
throws SQLException
{
connection.trace ("getStringFunctions");
return "CHR, INITCAP, LOWER, LPAD, LTRIM, NLS,_INITCAP, NLS,_LOWER, NLS,_UPPER, REPLACE, RPAD, RTRIM, SOUNDEX, SUBSTR, SUBSTRB, TRANSLATE, UPPER, ASCII, INSTR, INSTRB, LENGTH, LENGTHB, NLSSORT, CHARTOROWID, CONVERT, HEXTORAW, RAWTOHEX, ROWIDTOCHAR, TO_CHAR, TO_DATE, TO_LABEL, TO_MULTI_BYTE, TO_NUMBER, TO_SINGLE_BYTE";
}
/**
* Get a comma separated list of system functions.
*
* @return the list
*/
public String getSystemFunctions()
throws SQLException
{
connection.trace ("getSystemFunctions");
return "DUMP, GREATEST, GREATEST_LB, LEAST, LEAST_UB, NVL, UID, USER, USERENV, VSIZE";
}
/**
* Get a comma separated list of time and date functions.
*
* @return the list
*/
public String getTimeDateFunctions()
throws SQLException
{
connection.trace ("getTimeDateFunctions");
return "ADD_MONTHS, LAST_DAY, MONTHS_BETWEEN, NEW_TIME, NEXT_DAY, ROUND, SYSDATE, TRUNC";
}
/**
* This is the string that can be used to escape '_' or '%' in
* the string pattern style catalog search parameters.
*
*
The '_' character represents any single character.
*
The '%' character represents any sequence of zero or
* more characters.
* @return the string used to escape wildcard characters
*/
public String getSearchStringEscape()
throws SQLException
{
connection.trace ("getSearchStringEscape");
return "//";
}
/**
* Get all the "extra" characters that can be used in unquoted
* identifier names (those beyond a-z, 0-9 and _).
*
* @return the string containing the extra characters
*/
public String getExtraNameCharacters()
throws SQLException
{
connection.trace ("getExtraNameCharacters");
return "$#";
}
//--------------------------------------------------------------------
// Functions describing which features are supported.
/**
* Is "ALTER TABLE" with add column supported?
*
* @return true if so
*/
public boolean supportsAlterTableWithAddColumn()
throws SQLException
{
connection.trace ("supportsAlterTableWithAddColumn");
return true;
}
/**
* Is "ALTER TABLE" with drop column supported?
*
* @return true if so
*/
public boolean supportsAlterTableWithDropColumn()
throws SQLException
{
connection.trace ("supportsAlterTableWithDropColumn");
return false;
}
/**
* Is column aliasing supported?
*
*
If so, the SQL AS clause can be used to provide names for
* computed columns or to provide alias names for columns as
* required.
*
* A JDBC compliant driver always returns true.
*
* @return true if so
*/
public boolean supportsColumnAliasing()
throws SQLException
{
connection.trace ("supportsColumnAliasing");
return true;
}
/**
* Are concatenations between NULL and non-NULL values NULL?
*
* A JDBC compliant driver always returns true.
*
* @return true if so
*/
public boolean nullPlusNonNullIsNull()
throws SQLException
{
connection.trace ("nullPlusNonNullIsNull");
return true;
}
/**
* Is the CONVERT function between SQL types supported?
*
* @return true if so
*/
public boolean supportsConvert()
throws SQLException
{
connection.trace ("supportsConvert");
return true;
}
/**
* Is CONVERT between the given SQL types supported?
*
* @param fromType the type to convert from
* @param toType the type to convert to
* @return true if so
* @see Types
*/
public boolean supportsConvert (int fromType, int toType)
throws SQLException
{
connection.trace ("supportsConvert");
// Prune the case tree a bit
if (fromType == toType
|| fromType == OracleTypes.CHAR || fromType == OracleTypes.VARCHAR
|| fromType == OracleTypes.LONGVARCHAR
|| toType == OracleTypes.CHAR || toType == OracleTypes.VARCHAR
|| toType == OracleTypes.LONGVARCHAR)
return true;
// Try the other types
switch (fromType)
{
case OracleTypes.NUMERIC:
case OracleTypes.DECIMAL:
return (toType == OracleTypes.TIME || toType == OracleTypes.TIMESTAMP
||toType == OracleTypes.DATE);
case OracleTypes.TIME:
case OracleTypes.TIMESTAMP:
case OracleTypes.DATE:
return (toType == OracleTypes.NUMERIC || toType == OracleTypes.DECIMAL);
default:
return false;
}
}
/**
* Are table correlation names supported?
*
* A JDBC compliant driver always returns true.
*
* @return true if so
*/
public boolean supportsTableCorrelationNames()
throws SQLException
{
connection.trace ("supportsTableCorrelationNames");
return true;
}
/**
* If table correlation names are supported, are they restricted
* to be different from the names of the tables?
*
* @return true if so
*/
public boolean supportsDifferentTableCorrelationNames()
throws SQLException
{
connection.trace ("supportsDifferentTableCorrelationNames");
return true;
}
/**
* Are expressions in "ORDER BY" lists supported?
*
* @return true if so
*/
public boolean supportsExpressionsInOrderBy()
throws SQLException
{
connection.trace ("supportsExpressionsInOrderBy");
return true;
}
/**
* Can an "ORDER BY" clause use columns not in the SELECT?
*
* @return true if so
*/
public boolean supportsOrderByUnrelated()
throws SQLException
{
connection.trace ("supportsOrderByUnrelated");
return true;
}
/**
* Is some form of "GROUP BY" clause supported?
*
* @return true if so
*/
public boolean supportsGroupBy()
throws SQLException
{
connection.trace ("supportsGroupBy");
return true;
}
/**
* Can a "GROUP BY" clause use columns not in the SELECT?
*
* @return true if so
*/
public boolean supportsGroupByUnrelated()
throws SQLException
{
connection.trace ("supportsGroupByUnrelated");
return true;
}
/**
* Can a "GROUP BY" clause add columns not in the SELECT
* provided it specifies all the columns in the SELECT?
*
* @return true if so
*/
public boolean supportsGroupByBeyondSelect()
throws SQLException
{
connection.trace ("supportsGroupByBeyondSelect");
return true;
}
/**
* Is the escape character in "LIKE" clauses supported?
*
* A JDBC compliant driver always returns true.
*
* @return true if so
*/
public boolean supportsLikeEscapeClause()
throws SQLException
{
connection.trace ("supportsLikeEscapeClause");
return true;
}
/**
* Are multiple ResultSets from a single execute supported?
*
* @return true if so
*/
public boolean supportsMultipleResultSets()
throws SQLException
{
connection.trace ("supportsMultipleResultSets");
return false;
}
/**
* Can we have multiple transactions open at once (on different
* connections)?
*
* @return true if so
*/
public boolean supportsMultipleTransactions()
throws SQLException
{
connection.trace ("supportsMultipleTransactions");
return true;
}
/**
* Can columns be defined as non-nullable?
*
* A JDBC compliant driver always returns true.
*
* @return true if so
*/
public boolean supportsNonNullableColumns()
throws SQLException
{
connection.trace ("supportsNonNullableColumns");
return true;
}
/**
* Is the ODBC Minimum SQL grammar supported?
*
* All JDBC compliant drivers must return true.
*
* @return true if so
*/
public boolean supportsMinimumSQLGrammar()
throws SQLException
{
connection.trace ("supportsMinimumSQLGrammar");
return true;
}
/**
* Is the ODBC Core SQL grammar supported?
*
* @return true if so
*/
public boolean supportsCoreSQLGrammar()
throws SQLException
{
connection.trace ("supportsCoreSQLGrammar");
return true;
}
/**
* Is the ODBC Extended SQL grammar supported?
*
* @return true if so
*/
public boolean supportsExtendedSQLGrammar()
throws SQLException
{
connection.trace ("supportsExtendedSQLGrammar");
return true;
}
/**
* Is the ANSI92 entry level SQL grammar supported?
*
* All JDBC compliant drivers must return true.
*
* @return true if so
*/
public boolean supportsANSI92EntryLevelSQL()
throws SQLException
{
connection.trace ("supportsANSI92EntryLevelSQL");
return false;
}
/**
* Is the ANSI92 intermediate SQL grammar supported?
*
* @return true if so
*/
public boolean supportsANSI92IntermediateSQL()
throws SQLException
{
connection.trace ("supportsANSI92IntermediateSQL");
return false;
}
/**
* Is the ANSI92 full SQL grammar supported?
*
* @return true if so
*/
public boolean supportsANSI92FullSQL()
throws SQLException
{
connection.trace ("supportsANSI92FullSQL");
return false;
}
/**
* Is the SQL Integrity Enhancement Facility supported?
*
* @return true if so
*/
public boolean supportsIntegrityEnhancementFacility()
throws SQLException
{
connection.trace ("supportsIntegrityEnhancementFacility");
return true;
}
/**
* Is some form of outer join supported?
*
* @return true if so
*/
public boolean supportsOuterJoins()
throws SQLException
{
connection.trace ("supportsOuterJoins");
return true;
}
/**
* Are full nested outer joins supported?
*
* @return true if so
*/
public boolean supportsFullOuterJoins()
throws SQLException
{
connection.trace ("supportsFullOuterJoins");
return true;
}
/**
* Is there limited support for outer joins? (This will be true
* if supportFullOuterJoins is true.)
*
* @return true if so
*/
public boolean supportsLimitedOuterJoins()
throws SQLException
{
connection.trace ("supportsLimitedOuterJoins");
return true;
}
/**
* What's the database vendor's preferred term for "schema"?
*
* @return the vendor term
*/
public String getSchemaTerm()
throws SQLException
{
connection.trace ("getSchemaTerm");
return "schema";
}
/**
* What's the database vendor's preferred term for "procedure"?
*
* @return the vendor term
*/
public String getProcedureTerm()
throws SQLException
{
connection.trace ("getProcedureTerm");
return "procedure";
}
/**
* What's the database vendor's preferred term for "catalog"?
*
* @return the vendor term
*/
public String getCatalogTerm()
throws SQLException
{
connection.trace ("getCatalogTerm");
return "";
}
/**
* Does a catalog appear at the start of a qualified table name?
* (Otherwise it appears at the end)
*
* @return true if it appears at the start
*/
public boolean isCatalogAtStart()
throws SQLException
{
connection.trace ("isCatalogAtStart");
return false;
}
/**
* What's the separator between catalog and table name?
*
* @return the separator string
*/
public String getCatalogSeparator()
throws SQLException
{
connection.trace ("getCatalogSeparator");
return "";
}
/**
* Can a schema name be used in a data manipulation statement?
*
* @return true if so
*/
public boolean supportsSchemasInDataManipulation()
throws SQLException
{
connection.trace ("supportsSchemasInDataManipulation");
return true;
}
/**
* Can a schema name be used in a procedure call statement?
*
* @return true if so
*/
public boolean supportsSchemasInProcedureCalls()
throws SQLException
{
connection.trace ("supportsSchemasInProcedureCalls");
return true;
}
/**
* Can a schema name be used in a table definition statement?
*
* @return true if so
*/
public boolean supportsSchemasInTableDefinitions()
throws SQLException
{
connection.trace ("supportsSchemasInTableDefinitions");
return true;
}
/**
* Can a schema name be used in an index definition statement?
*
* @return true if so
*/
public boolean supportsSchemasInIndexDefinitions()
throws SQLException
{
connection.trace ("supportsSchemasInIndexDefinitions");
return true;
}
/**
* Can a schema name be used in a privilege definition statement?
*
* @return true if so
*/
public boolean supportsSchemasInPrivilegeDefinitions()
throws SQLException
{
connection.trace ("supportsSchemasInPrivilegeDefinitions");
return true;
}
/**
* Can a catalog name be used in a data manipulation statement?
*
* @return true if so
*/
public boolean supportsCatalogsInDataManipulation()
throws SQLException
{
connection.trace ("supportsCatalogsInDataManipulation");
return false;
}
/**
* Can a catalog name be used in a procedure call statement?
*
* @return true if so
*/
public boolean supportsCatalogsInProcedureCalls()
throws SQLException
{
connection.trace ("supportsCatalogsInProcedureCalls");
return false;
}
/**
* Can a catalog name be used in a table definition statement?
*
* @return true if so
*/
public boolean supportsCatalogsInTableDefinitions()
throws SQLException
{
connection.trace ("supportsCatalogsInTableDefinitions");
return false;
}
/**
* Can a catalog name be used in a index definition statement?
*
* @return true if so
*/
public boolean supportsCatalogsInIndexDefinitions()
throws SQLException
{
connection.trace ("supportsCatalogsInIndexDefinitions");
return false;
}
/**
* Can a catalog name be used in a privilege definition statement?
*
* @return true if so
*/
public boolean supportsCatalogsInPrivilegeDefinitions()
throws SQLException
{
connection.trace ("supportsCatalogsInPrivilegeDefinitions");
return false;
}
/**
* Is positioned DELETE supported?
*
* @return true if so
*/
public boolean supportsPositionedDelete()
throws SQLException
{
connection.trace ("supportsPositionedDelete");
return true; // where current of
}
/**
* Is positioned UPDATE supported?
*
* @return true if so
*/
public boolean supportsPositionedUpdate()
throws SQLException
{
connection.trace ("supportsPositionedUpdate");
return true; // where current of
}
/**
* Is SELECT for UPDATE supported?
*
* @return true if so
*/
public boolean supportsSelectForUpdate()
throws SQLException
{
connection.trace ("supportsSelectForUpdate");
return true;
}
/**
* Are stored procedure calls using the stored procedure escape
* syntax supported?
*
* @return true if so
*/
public boolean supportsStoredProcedures()
throws SQLException
{
connection.trace ("supportsStoredProcedures");
return true;
}
/**
* Are subqueries in comparison expressions supported?
*
* A JDBC compliant driver always returns true.
*
* @return true if so
*/
public boolean supportsSubqueriesInComparisons()
throws SQLException
{
connection.trace ("supportsSubqueriesInComparisons");
return true;
}
/**
* Are subqueries in exists expressions supported?
*
* A JDBC compliant driver always returns true.
*
* @return true if so
*/
public boolean supportsSubqueriesInExists()
throws SQLException
{
connection.trace ("supportsSubqueriesInExists");
return true;
}
/**
* Are subqueries in "in" statements supported?
*
* A JDBC compliant driver always returns true.
*
* @return true if so
*/
public boolean supportsSubqueriesInIns()
throws SQLException
{
connection.trace ("supportsSubqueriesInIns");
return true;
}
/**
* Are subqueries in quantified expressions supported?
*
* A JDBC compliant driver always returns true.
*
* @return true if so
*/
public boolean supportsSubqueriesInQuantifieds()
throws SQLException
{
connection.trace ("supportsSubqueriesInQuantifieds");
return true;
}
/**
* Are correlated subqueries supported?
*
* A JDBC compliant driver always returns true.
*
* @return true if so
*/
public boolean supportsCorrelatedSubqueries()
throws SQLException
{
connection.trace ("supportsCorrelatedSubqueries");
return true;
}
/**
* Is SQL UNION supported?
*
* @return true if so
*/
public boolean supportsUnion()
throws SQLException
{
connection.trace ("supportsUnion");
return true;
}
/**
* Is SQL UNION ALL supported?
*
* @return true if so
*/
public boolean supportsUnionAll()
throws SQLException
{
connection.trace ("supportsUnionAll");
return true;
}
/**
* Can cursors remain open across commits?
*
* @return true if so
* @see Connection#disableAutoClose
*/
public boolean supportsOpenCursorsAcrossCommit()
throws SQLException
{
connection.trace ("supportsOpenCursorsAcrossCommit");
return false;
}
/**
* Can cursors remain open across rollbacks?
*
* @return true if so
* @see Connection#disableAutoClose
*/
public boolean supportsOpenCursorsAcrossRollback()
throws SQLException
{
connection.trace ("supportsOpenCursorsAcrossRollback");
return false;
}
/**
* Can statements remain open across commits?
*
* @return true if so
* @see Connection#disableAutoClose
*/
public boolean supportsOpenStatementsAcrossCommit()
throws SQLException
{
connection.trace ("supportsOpenStatementsAcrossCommit");
return false;
}
/**
* Can statements remain open across rollbacks?
*
* @return true if so
* @see Connection#disableAutoClose
*/
public boolean supportsOpenStatementsAcrossRollback()
throws SQLException
{
connection.trace ("supportsOpenStatementsAcrossRollback");
return false;
}
//----------------------------------------------------------------------
// 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
*/
public int getMaxBinaryLiteralLength()
throws SQLException
{
connection.trace ("getMaxBinaryLiteralLength");
return 1000;
}
/**
* What's the max length for a character literal?
*
* @return max literal length
*/
public int getMaxCharLiteralLength()
throws SQLException
{
connection.trace ("getMaxCharLiteralLength");
return 2000;
}
/**
* What's the limit on column name length?
*
* @return max literal length
*/
public int getMaxColumnNameLength()
throws SQLException
{
connection.trace ("getMaxColumnNameLength");
return 30;
}
/**
* What's the maximum number of columns in a "GROUP BY" clause?
*
* @return max number of columns
*/
public int getMaxColumnsInGroupBy()
throws SQLException
{
connection.trace ("getMaxColumnsInGroupBy");
return 0;
}
/**
* What's the maximum number of columns allowed in an index?
*
* @return max columns
*/
public int getMaxColumnsInIndex()
throws SQLException
{
connection.trace ("getMaxColumnsInIndex");
return 16;
}
/**
* What's the maximum number of columns in an "ORDER BY" clause?
*
* @return max columns
*/
public int getMaxColumnsInOrderBy()
throws SQLException
{
connection.trace ("getMaxColumnsInOrderBy");
return 0;
}
/**
* What's the maximum number of columns in a "SELECT" list?
*
* @return max columns
*/
public int getMaxColumnsInSelect()
throws SQLException
{
connection.trace ("getMaxColumnsInSelect");
return 0;
}
/**
* What's maximum number of columns in a table?
*
* @return max columns
*/
public int getMaxColumnsInTable()
throws SQLException
{
connection.trace ("getMaxColumnsInTable");
return 254;
}
/**
* How many active connections can we have at a time to this database?
*
* @return max connections
*/
public int getMaxConnections()
throws SQLException
{
connection.trace ("getMaxConnections");
return 0;
}
/**
* What's the maximum cursor name length?
*
* @return max cursor name length in bytes
*/
public int getMaxCursorNameLength()
throws SQLException
{
connection.trace ("getMaxCursorNameLength");
return 0;
}
/**
* What's the maximum length of an index (in bytes)?
*
* @return max index length in bytes
*/
public int getMaxIndexLength()
throws SQLException
{
connection.trace ("getMaxIndexLength");
return 0;
}
/**
* What's the maximum length allowed for a schema name?
*
* @return max name length in bytes
*/
public int getMaxSchemaNameLength()
throws SQLException
{
connection.trace ("getMaxSchemaNameLength");
return 30;
}
/**
* What's the maximum length of a procedure name?
*
* @return max name length in bytes
*/
public int getMaxProcedureNameLength()
throws SQLException
{
connection.trace ("getMaxProcedureNameLength");
return 30;
}
/**
* What's the maximum length of a catalog name?
*
* @return max name length in bytes
*/
public int getMaxCatalogNameLength()
throws SQLException
{
connection.trace ("getMaxCatalogNameLength");
return 0;
}
/**
* What's the maximum length of a single row?
*
* @return max row size in bytes
*/
public int getMaxRowSize()
throws SQLException
{
connection.trace ("getMaxRowSize");
return 0;
}
/**
* Did getMaxRowSize() include LONGVARCHAR and LONGVARBINARY
* blobs?
*
* @return true if so
*/
public boolean doesMaxRowSizeIncludeBlobs()
throws SQLException
{
connection.trace ("doesMaxRowSizeIncludeBlobs");
return true;
}
/**
* What's the maximum length of a SQL statement?
*
* @return max length in bytes
*/
public int getMaxStatementLength()
throws SQLException
{
connection.trace ("getMaxStatementLength");
return 65535;
}
/**
* How many active statements can we have open at one time to this
* database?
*
* @return the maximum
*/
public int getMaxStatements()
throws SQLException
{
connection.trace ("getMaxStatements");
return 0;
}
/**
* What's the maximum length of a table name?
*
* @return max name length in bytes
*/
public int getMaxTableNameLength()
throws SQLException
{
connection.trace ("getMaxTableNameLength");
return 30;
}
/**
* What's the maximum number of tables in a SELECT?
*
* @return the maximum
*/
public int getMaxTablesInSelect()
throws SQLException
{
connection.trace ("getMaxTablesInSelect");
return 0;
}
/**
* What's the maximum length of a user name?
*
* @return max name length in bytes
*/
public int getMaxUserNameLength()
throws SQLException
{
connection.trace ("getMaxUserNameLength");
return 30;
}
//----------------------------------------------------------------------
/**
* What's the database's default transaction isolation level? The
* values are defined in java.sql.Connection.
*
* @return the default isolation level
* @see Connection
*/
public int getDefaultTransactionIsolation()
throws SQLException
{
connection.trace ("getDefaultTransactionIsolation");
return Connection.TRANSACTION_READ_UNCOMMITTED;
}
/**
* Are transactions supported? If not, commit is a noop and the
* isolation level is TRANSACTION_NONE.
*
* @return true if transactions are supported
*/
public boolean supportsTransactions()
throws SQLException
{
connection.trace ("supportsTransactions");
return true;
}
/**
* Does the database support the given transaction isolation level?
*
* @param level the values are defined in java.sql.Connection
* @return true if so
* @see Connection
*/
public boolean supportsTransactionIsolationLevel (int level)
throws SQLException
{
connection.trace ("supportsTransactionIsolationLevel");
return level == Connection.TRANSACTION_READ_UNCOMMITTED;
}
/**
* Are both data definition and data manipulation statements
* within a transaction supported?
*
* @return true if so
*/
public boolean supportsDataDefinitionAndDataManipulationTransactions ()
throws SQLException
{
connection.trace ("supportsDataDefinitionAndDataManipulationTransactions");
return false;
}
/**
* Are only data manipulation statements within a transaction
* supported?
*
* @return true if so
*/
public boolean supportsDataManipulationTransactionsOnly()
throws SQLException
{
connection.trace ("supportsDataManipulationTransactionsOnly");
return true;
}
/**
* Does a data definition statement within a transaction force the
* transaction to commit?
*
* @return true if so
*/
public boolean dataDefinitionCausesTransactionCommit()
throws SQLException
{
connection.trace ("dataDefinitionCausesTransactionCommit");
return true;
}
/**
* Is a data definition statement within a transaction ignored?
*
* @return true if so
*/
public boolean dataDefinitionIgnoredInTransactions()
throws SQLException
{
connection.trace ("dataDefinitionIgnoredInTransactions");
return false;
}
/**
* Get a description of stored procedures available in a
* catalog.
*
*
Only procedure descriptions matching the schema and
* procedure name criteria are returned. They are ordered by
* PROCEDURE_SCHEM, and PROCEDURE_NAME.
*
*
Each procedure description has the the following columns:
*
* - PROCEDURE_CAT String => procedure catalog (may be null)
*
- PROCEDURE_SCHEM String => procedure schema (may be null)
*
- PROCEDURE_NAME String => procedure name
*
- reserved for future use
*
- reserved for future use
*
- reserved for future use
*
- REMARKS String => explanatory comment on the procedure
*
- PROCEDURE_TYPE short => kind of procedure:
*
* - procedureResultUnknown - May return a result
*
- procedureNoResult - Does not return a result
*
- procedureReturnsResult - Returns a result
*
*
*
* @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 procedureNamePattern a procedure name pattern
* @return ResultSet each row is a procedure description
* @see #getSearchStringEscape
*/
public synchronized
ResultSet getProcedures(String catalog, String schemaPattern,
String procedureNamePattern)
throws SQLException
{
PreparedStatement s = connection.prepareStatement (
"SELECT NULL AS procedure_cat,\n" +
" owner AS procedure_schem,\n" +
" object_name AS procedure_name,\n" +
" NULL,\n" +
" NULL,\n" +
" NULL,\n" +
" NULL AS remarks,\n" +
" DECODE (object_type, 'PROCEDURE', 1, 'FUNCTION', 2, 0) as procedure_type\n" +
"FROM all_objects\n" +
"WHERE (object_type = 'PROCEDURE' OR object_type = 'FUNCTION')\n" +
" AND owner LIKE ? ESCAPE '/'\n" +
" AND object_name LIKE ? ESCAPE '/'\n" +
"ORDER BY procedure_schem, procedure_name\n");
s.setString (1, schemaPattern == null ? "%" : schemaPattern);
s.setString (2, procedureNamePattern == null ? "%" : procedureNamePattern);
OracleResultSet rs = (OracleResultSet)s.executeQuery ();
rs.close_statement_on_close = true;
return rs;
}
/**
* PROCEDURE_TYPE - May return a result.
*/
int procedureResultUnknown = 0;
/**
* PROCEDURE_TYPE - Does not return a result.
*/
int procedureNoResult = 1;
/**
* PROCEDURE_TYPE - Returns a result.
*/
int procedureReturnsResult = 2;
/**
* Get a description of a catalog's stored procedure parameters
* and result columns.
*
* Only descriptions matching the schema, procedure and
* parameter name criteria are returned. They are ordered by
* PROCEDURE_SCHEM and PROCEDURE_NAME. Within this, the return value,
* if any, is first. Next are the parameter descriptions in call
* order. The column descriptions follow in column number order.
*
*
Each row in the ResultSet is a parameter desription or
* column description with the following fields:
*
* - PROCEDURE_CAT String => procedure catalog (may be null)
*
- PROCEDURE_SCHEM String => procedure schema (may be null)
*
- PROCEDURE_NAME String => procedure name
*
- COLUMN_NAME String => column/parameter name
*
- COLUMN_TYPE Short => kind of column/parameter:
*
* - procedureColumnUnknown - nobody knows
*
- procedureColumnIn - IN parameter
*
- procedureColumnInOut - INOUT parameter
*
- procedureColumnOut - OUT parameter
*
- procedureColumnReturn - procedure return value
*
- procedureColumnResult - result column in ResultSet
*
* - DATA_TYPE short => SQL type from java.sql.Types
*
- TYPE_NAME String => SQL type name
*
- PRECISION int => precision
*
- LENGTH int => length in bytes of data
*
- SCALE short => scale
*
- RADIX short => radix
*
- NULLABLE short => can it contain NULL?
*
* - procedureNoNulls - does not allow NULL values
*
- procedureNullable - allows NULL values
*
- procedureNullableUnknown - nullability unknown
*
* - REMARKS String => comment describing parameter/column
*
*
* Note: Some databases may not return the column
* descriptions for a procedure. Additional columns beyond
* REMARKS can be defined by the database.
*
* @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 procedureNamePattern a procedure name pattern
* @param columnNamePattern a column name pattern
* @return ResultSet each row is a stored procedure parameter or
* column description
* @see #getSearchStringEscape
*/
public synchronized
ResultSet getProcedureColumns(String catalog,
String schemaPattern,
String procedureNamePattern,
String columnNamePattern)
throws SQLException
{
// Let's use the catalog as the package name
PreparedStatement s = connection.prepareStatement (
"SELECT NULL AS procedure_cat,\n" +
" owner AS procedure_schem,\n" +
" object_name AS procedure_name,\n" +
" argument_name AS column_name,\n" +
" DECODE (position, NULL, 3,\n" +
" DECODE (in_out, 'IN', 1, 'OUT', 4, 'IN/OUT', 5, null))\n" +
" AS column_type,\n" +
" DECODE (data_type, 'CHAR', 1, 'VARCHAR2', 12, 'NUMBER', 3,\n" +
" 'LONG', -1, 'DATE', 93, 'RAW', -3, 'LONG RAW', -4, 1111)\n" +
" AS data_type,\n" +
" data_type AS type_name,\n" +
" DECODE (data_precision, NULL, data_length, data_precision)\n" +
" AS precision,\n" +
" data_length AS length,\n" +
" data_scale AS scale,\n" +
" 10 AS radix,\n" +
" 1 AS nullable,\n" +
" null AS remarks,\n" +
" package_name,\n" +
" sequence,\n" +
" overload\n" +
" FROM all_arguments\n" +
"WHERE (1 = ? or package_name LIKE ? ESCAPE '/')\n" +
" AND owner LIKE ? ESCAPE '/'\n" +
" AND object_name LIKE ? escape '/'\n" +
" AND argument_name LIKE ? escape '/'\n" +
"ORDER BY procedure_schem, procedure_name, overload, sequence\n");
s.setInt (1, catalog == null ? 1 : 0);
s.setString (2, catalog == null ? "%" : catalog);
s.setString (3, schemaPattern == null ? "%" : schemaPattern);
s.setString (4, procedureNamePattern == null ? "%" : procedureNamePattern);
s.setString (5, columnNamePattern == null ? "%" : columnNamePattern);
OracleResultSet rs = (OracleResultSet)s.executeQuery ();
rs.close_statement_on_close = true;
return rs;
}
/**
* COLUMN_TYPE - nobody knows.
*/
int procedureColumnUnknown = 0;
/**
* COLUMN_TYPE - IN parameter.
*/
int procedureColumnIn = 1;
/**
* COLUMN_TYPE - INOUT parameter.
*/
int procedureColumnInOut = 2;
/**
* COLUMN_TYPE - OUT parameter.
*/
int procedureColumnOut = 4;
/**
* COLUMN_TYPE - procedure return value.
*/
int procedureColumnReturn = 5;
/**
* COLUMN_TYPE - result column in ResultSet.
*/
int procedureColumnResult = 3;
/**
* TYPE NULLABLE - does not allow NULL values.
*/
int procedureNoNulls = 0;
/**
* TYPE NULLABLE - allows NULL values.
*/
int procedureNullable = 1;
/**
* TYPE NULLABLE - nullability unknown.
*/
int procedureNullableUnknown = 2;
/**
* Get a description of tables available in a catalog.
*
*
Only table descriptions matching the catalog, schema, table
* name and type criteria are returned. They are ordered by
* TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
*
*
Each table description has the following columns:
*
* - TABLE_CAT String => table catalog (may be null)
*
- TABLE_SCHEM String => table schema (may be null)
*
- TABLE_NAME String => table name
*
- TABLE_TYPE String => table type. Typical types are "TABLE",
* "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
* "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
*
- TABLE_REMARKS String => explanatory comment on the table
*
*
* Note: Some databases may not return information for
* all tables.
*
* @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 types a list of table types to include; null returns all types
* @return ResultSet each row is a table description
* @see #getSearchStringEscape
*/
public synchronized
ResultSet getTables (String catalog, String schemaPattern,
String tableNamePattern, String types[])
throws SQLException
{
String type_select = "";
if (types != null)
{
int i;
type_select =
" AND c.table_type IN (";
for (i = 0; i < types.length - 1; i++)
type_select = type_select + "'" + types [i] + "', ";
type_select = type_select + "'" + types [i] + "')\n";
}
String query;
if (connection.report_remarks)
query =
"SELECT NULL AS table_cat,\n" +
" c.owner AS table_schem,\n" +
" c.table_name AS table_name,\n" +
" c.table_type AS table_type,\n" +
" k.comments AS table_remarks\n" +
"FROM all_catalog c, all_tab_comments k\n" +
"WHERE c.owner LIKE ? escape '/'\n" +
" AND c.table_name LIKE ? escape '/'\n" +
type_select +
" AND c.owner = k.owner\n" +
" AND c.table_name = k.table_name (+)\n" +
"ORDER BY table_type, table_schem, table_name\n";
else
query =
"SELECT NULL AS table_cat,\n" +
" c.owner AS table_schem,\n" +
" c.table_name AS table_name,\n" +
" c.table_type AS table_type,\n" +
" null AS table_remarks\n" +
"FROM all_catalog c\n" +
"WHERE c.owner LIKE ? escape '/'\n" +
" AND c.table_name LIKE ? escape '/'\n" +
type_select +
"ORDER BY table_type, table_schem, table_name\n";
PreparedStatement s = connection.prepareStatement (query);
s.setString (1, schemaPattern == null ? "%" : schemaPattern);
s.setString (2, tableNamePattern == null ? "%" : tableNamePattern);
OracleResultSet rs = (OracleResultSet)s.executeQuery ();
rs.close_statement_on_close = true;
return rs;
}
/**
* Get the schema names available in this database. The results
* are ordered by schema name.
*
*
The schema column is:
*
* - TABLE_SCHEM String => schema name
*
*
* @return ResultSet each row has a single String column that is a
* schema name
*/
public ResultSet getSchemas ()
throws SQLException
{
Statement s = connection.createStatement ();
String basic_query =
"SELECT username AS table_schem FROM all_users ORDER BY table_schem";
OracleResultSet rs = (OracleResultSet)s.executeQuery (basic_query);
rs.close_statement_on_close = true;
return rs;
}
/**
* Get the catalog names available in this database. The results
* are ordered by catalog name.
*
* The catalog column is:
*
* - TABLE_CAT String => catalog name
*
*
* @return ResultSet each row has a single String column that is a
* catalog name
*/
public ResultSet getCatalogs()
throws SQLException
{
connection.trace ("getCatalogs");
Statement s = connection.createStatement ();
String query = "select 'nothing' as table_cat from dual where 1 = 2";
OracleResultSet rs = (OracleResultSet)s.executeQuery (query);
rs.close_statement_on_close = true;
return rs;
}
/**
* Get the table types available in this database. The results
* are ordered by table type.
*
* The table type is:
*
* - TABLE_TYPE String => table type. Typical types are "TABLE",
* "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
* "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
*
*
* @return ResultSet each row has a single String column that is a
* table type
*/
public ResultSet getTableTypes()
throws SQLException
{
Statement s = connection.createStatement ();
String query =
"select 'TABLE' as table_type from dual\n" +
"union select 'VIEW' as table_type from dual\n" +
"union select 'SYNONYM' as table_type from dual\n";
OracleResultSet rs = (OracleResultSet)s.executeQuery (query);
rs.close_statement_on_close = true;
return rs;
}
/**
* Get a description of table columns available in a catalog.
*
* 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.
*
*
Each column description has the following columns:
*
* - TABLE_CAT String => table catalog (may be null)
*
- TABLE_SCHEM String => table schema (may be null)
*
- TABLE_NAME String => table name
*
- COLUMN_NAME String => column name
*
- DATA_TYPE short => SQL type from java.sql.Types
*
- TYPE_NAME String => Data source dependent type name
*
- COLUMN_SIZE int => column size. For char or date
* types this is the maximum number of characters, for numeric or
* decimal types this is precision.
*
- BUFFER_LENGTH is not used.
*
- DECIMAL_DIGITS int => the number of fractional digits
*
- NUM_PREC_RADIX int => Radix (typically either 10 or 2)
*
- NULLABLE int => is NULL allowed?
*
* - columnNoNulls - might not allow NULL values
*
- columnNullable - definitely allows NULL values
*
- columnNullableUnknown - nullability unknown
*
* - REMARKS String => comment describing column (may be null)
*
- COLUMN_DEF String => default value (may be null)
*
- SQL_DATA_TYPE int => unused
*
- SQL_DATETIME_SUB int => unused
*
- CHAR_OCTET_LENGTH int => for char types the
* maximum number of bytes in the column
*
- ORDINAL_POSITION int => index of column in table
* (starting at 1)
*
- IS_NULLABLE String => "NO" means column definitely
* does not allow NULL values; "YES" means the column might
* allow NULL values. An empty string means nobody knows.
*
*
* @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
* @see #getSearchStringEscape
*/
public synchronized
ResultSet getColumns(String catalog, String schemaPattern,
String tableNamePattern, String columnNamePattern)
throws SQLException
{
String query;
if (!connection.report_remarks)
query =
"SELECT NULL AS table_cat,\n" +
" t.owner AS table_schem,\n" +
" t.table_name,\n" +
" t.column_name,\n" +
" DECODE (t.data_type, 'CHAR', 1, 'VARCHAR2', 12, 'NUMBER', 3,\n" +
" 'LONG', -1, 'DATE', 93, 'RAW', -3, 'LONG RAW', -4, 1111)\n" +
" AS data_type,\n" +
" t.data_type AS type_name,\n" +
" DECODE (t.data_precision, null, t.data_length, t.data_precision)\n" +
" AS column_size,\n" +
" 0 AS buffer_length,\n" +
" t.data_scale AS decimal_digits,\n" +
" 10 AS num_prec_radix,\n" +
" DECODE (t.nullable, 'N', 0, 1) AS nullable,\n" +
" null AS remarks,\n" +
" t.data_default AS column_def,\n" +
" 0 AS sql_data_type,\n" +
" 0 AS sql_datetime_sub,\n" +
" t.data_length AS char_octet_length,\n" +
" t.column_id AS ordinal_position,\n" +
" DECODE (t.nullable, 'N', 'NO', 'YES') AS is_nullable\n" +
"FROM all_tab_columns t\n" +
"WHERE t.owner LIKE ? ESCAPE '/'\n" +
" AND t.table_name LIKE ? ESCAPE '/'\n" +
" AND t.column_name LIKE ? ESCAPE '/'\n" +
"ORDER BY table_schem, table_name, ordinal_position\n";
else
query =
"SELECT NULL AS table_cat,\n" +
" t.owner AS table_schem,\n" +
" t.table_name,\n" +
" t.column_name,\n" +
" DECODE (t.data_type, 'CHAR', 1, 'VARCHAR2', 12, 'NUMBER', 3,\n" +
" 'LONG', -1, 'DATE', 93, 'RAW', -3, 'LONG RAW', -4, 1111)\n" +
" AS data_type,\n" +
" t.data_type AS type_name,\n" +
" DECODE (t.data_precision, null, t.data_length, t.data_precision)\n" +
" AS column_size,\n" +
" 0 AS buffer_length,\n" +
" t.data_scale AS decimal_digits,\n" +
" 10 AS num_prec_radix,\n" +
" DECODE (t.nullable, 'N', 0, 1) AS nullable,\n" +
" c.comments AS remarks,\n" +
" t.data_default AS column_def,\n" +
" 0 AS sql_data_type,\n" +
" 0 AS sql_datetime_sub,\n" +
" t.data_length AS char_octet_length,\n" +
" t.column_id AS ordinal_position,\n" +
" DECODE (t.nullable, 'N', 'NO', 'YES') AS is_nullable\n" +
"FROM all_tab_columns t, all_col_comments c\n" +
"WHERE t.owner LIKE ? ESCAPE '/'\n" +
" AND t.table_name LIKE ? ESCAPE '/'\n" +
" AND t.column_name LIKE ? ESCAPE '/'\n" +
" AND t.owner = c.owner (+)\n" +
" AND t.table_name = c.table_name (+)\n" +
" AND t.column_name = c.column_name (+)\n" +
"ORDER BY table_schem, table_name, ordinal_position\n";
PreparedStatement s = connection.prepareStatement (query);
s.setString (1, schemaPattern == null ? "%" : schemaPattern);
s.setString (2, tableNamePattern == null ? "%" : tableNamePattern);
s.setString (3, columnNamePattern == null ? "%" : columnNamePattern);
OracleResultSet rs = (OracleResultSet)s.executeQuery ();
rs.close_statement_on_close = true;
return rs;
}
/**
* COLUMN NULLABLE - might not allow NULL values.
*/
int columnNoNulls = 0;
/**
* COLUMN NULLABLE - definitely allows NULL values.
*/
int columnNullable = 1;
/**
* COLUMN NULLABLE - nullability unknown.
*/
int columnNullableUnknown = 2;
/**
* Get a description of the access rights for a table's columns.
*
* Only privileges matching the column name criteria are
* returned. They are ordered by COLUMN_NAME and PRIVILEGE.
*
*
Each privilige description has the following columns:
*
* - TABLE_CAT String => table catalog (may be null)
*
- TABLE_SCHEM String => table schema (may be null)
*
- TABLE_NAME String => table name
*
- COLUMN_NAME String => column name
*
- GRANTOR => grantor of access (may be null)
*
- GRANTEE String => grantee of access
*
- PRIVILEGE String => name of access (SELECT,
* INSERT, UPDATE, REFRENCES, ...)
*
- IS_GRANTABLE String => "YES" if grantee is permitted
* to grant to others; "NO" if not; null if unknown
*
*
* @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
*/
public synchronized
ResultSet getColumnPrivileges(String catalog, String schemaPattern,
String tableNamePattern,
String columnNamePattern)
throws SQLException
{
PreparedStatement s = connection.prepareStatement (
"SELECT NULL AS table_cat,\n" +
" table_schema AS table_schem,\n" +
" table_name,\n" +
" column_name,\n" +
" grantor,\n" +
" grantee,\n" +
" privilege,\n" +
" grantable AS is_grantable\n" +
"FROM all_col_privs\n" +
"WHERE table_schema LIKE ? ESCAPE '/'\n" +
" AND table_name LIKE ? ESCAPE '/'\n" +
" AND column_name LIKE ? ESCAPE '/'\n" +
"ORDER BY column_name, privilege\n");
s.setString (1, schemaPattern == null ? "%" : schemaPattern);
s.setString (2, tableNamePattern == null ? "%" : tableNamePattern);
s.setString (3, columnNamePattern == null ? "%" : columnNamePattern);
OracleResultSet rs = (OracleResultSet)s.executeQuery ();
rs.close_statement_on_close = true;
return rs;
}
/**
* Get a description of the access rights for each table available
* in a catalog.
*
* Only privileges matching the schema and table name
* criteria are returned. They are ordered by TABLE_SCHEM,
* TABLE_NAME, and PRIVILEGE.
*
*
Each privilige description has the following columns:
*
* - TABLE_CAT String => table catalog (may be null)
*
- TABLE_SCHEM String => table schema (may be null)
*
- TABLE_NAME String => table name
*
- COLUMN_NAME String => column name
*
- GRANTOR => grantor of access (may be null)
*
- GRANTEE String => grantee of access
*
- PRIVILEGE String => name of access (SELECT,
* INSERT, UPDATE, REFRENCES, ...)
*
- IS_GRANTABLE String => "YES" if grantee is permitted
* to grant to others; "NO" if not; null if unknown
*
*
* @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
*/
public synchronized
ResultSet getTablePrivileges(String catalog, String schemaPattern,
String tableNamePattern)
throws SQLException
{
PreparedStatement s = connection.prepareStatement (
"SELECT NULL AS table_cat,\n" +
" table_schema AS table_schem,\n" +
" table_name,\n" +
" null as column_name,\n" +
" grantor,\n" +
" grantee,\n" +
" privilege,\n" +
" grantable AS is_grantable\n" +
"FROM all_tab_privs\n" +
"WHERE table_schema LIKE ? ESCAPE '/'\n" +
" AND table_name LIKE ? ESCAPE '/'\n" +
"ORDER BY table_schem, table_name, privilege\n");
s.setString (1, schemaPattern == null ? "%" : schemaPattern);
s.setString (2, tableNamePattern == null ? "%" : tableNamePattern);
OracleResultSet rs = (OracleResultSet)s.executeQuery ();
rs.close_statement_on_close = true;
return rs;
}
/**
* Get a description of a table's optimal set of columns that
* uniquely identifies a row. They are ordered by SCOPE.
*
* Each column description has the following columns:
*
* - SCOPE short => actual scope of result
*
* - bestRowTemporary - very temporary, while using row
*
- bestRowTransaction - valid for remainder of current transaction
*
- bestRowSession - valid for remainder of current session
*
* - COLUMN_NAME String => column name
*
- DATA_TYPE short => SQL data type from java.sql.Types
*
- TYPE_NAME String => Data source dependent type name
*
- COLUMN_SIZE int => precision
*
- BUFFER_LENGTH int => not used
*
- DECIMAL_DIGITS short => scale
*
- PSEUDO_COLUMN short => is this a pseudo column
* like an Oracle ROWID
*
* - bestRowUnknown - may or may not be pseudo column
*
- bestRowNotPseudo - is NOT a pseudo column
*
- bestRowPseudo - is a pseudo column
*
*
*
* @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
*/
public synchronized
ResultSet getBestRowIdentifier(String catalog, String schema,
String table, int scope, boolean nullable)
throws SQLException
{
connection.trace ("getBestRowIdentifier");
PreparedStatement s = connection.prepareStatement (
"SELECT 1 AS scope, 'ROWID' AS column_name, -8 AS data_type,\n" +
" 'ROWID' AS type_name, 0 AS column_size, 0 AS buffer_length,\n" +
" 0 AS decimal_digits, 2 AS pseudo_column\n" +
"FROM DUAL\n" +
"WHERE ? = 1\n" +
"UNION\n" +
"SELECT 2 AS scope,\n" +
" t.column_name,\n" +
" DECODE (t.data_type, 'CHAR', 1, 'VARCHAR2', 12, 'NUMBER', 3,\n" +
" 'LONG', -1, 'DATE', 93, 'RAW', -3, 'LONG RAW', -4, 1111)\n" +
" AS data_type,\n" +
" t.data_type AS type_name,\n" +
" DECODE (t.data_precision, null, t.data_length, t.data_precision)\n" +
" AS column_size,\n" +
" 0 AS buffer_length,\n" +
" t.data_scale AS decimal_digits,\n" +
" 1 AS pseudo_column\n" +
"FROM all_tab_columns t, all_ind_columns i\n" +
"WHERE ? = 1\n" +
" AND t.table_name = ?\n" +
" AND t.owner like ? escape '/'\n" +
" AND t.nullable != ?\n" +
" AND t.owner = i.table_owner\n" +
" AND t.table_name = i.table_name\n" +
" AND t.column_name = i.column_name\n");
switch (scope)
{
case bestRowTemporary:
s.setInt (1, 0);
s.setInt (2, 0);
break;
case bestRowTransaction:
s.setInt (1, 1);
s.setInt (2, 1);
break;
case bestRowSession:
s.setInt (1, 0);
s.setInt (2, 1);
break;
}
s.setString (3, table);
s.setString (4, schema == null ? "%" : schema);
s.setString (5, nullable ? "X" : "Y");
OracleResultSet rs = (OracleResultSet)s.executeQuery ();
rs.close_statement_on_close = true;
return rs;
}
/**
* BEST ROW SCOPE - very temporary, while using row.
*/
static final int bestRowTemporary = 0;
/**
* BEST ROW SCOPE - valid for remainder of current transaction.
*/
static final int bestRowTransaction = 1;
/**
* BEST ROW SCOPE - valid for remainder of current session.
*/
static final int bestRowSession = 2;
/**
* BEST ROW PSEUDO_COLUMN - may or may not be pseudo column.
*/
static final int bestRowUnknown = 0;
/**
* BEST ROW PSEUDO_COLUMN - is NOT a pseudo column.
*/
static final int bestRowNotPseudo = 1;
/**
* BEST ROW PSEUDO_COLUMN - is a pseudo column.
*/
static final int bestRowPseudo = 2;
/**
* Get a description of a table's columns that are automatically
* updated when any value in a row is updated. They are
* unordered.
*
* Each column description has the following columns:
*
* - SCOPE short => is not used
*
- COLUMN_NAME String => column name
*
- DATA_TYPE short => SQL data type from java.sql.Types
*
- TYPE_NAME String => Data source dependent type name
*
- COLUMN_SIZE int => precision
*
- BUFFER_LENGTH int => length of column value in bytes
*
- DECIMAL_DIGITS short => scale
*
- PSEUDO_COLUMN short => is this a pseudo column
* like an Oracle ROWID
*
* - versionColumnUnknown - may or may not be pseudo column
*
- versionColumnNotPseudo - is NOT a pseudo column
*
- versionColumnPseudo - is a pseudo column
*
*
*
* @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
*/
public synchronized
ResultSet getVersionColumns (String catalog, String schema, String table)
throws SQLException
{
PreparedStatement s = connection.prepareStatement (
"SELECT 0 AS scope,\n" +
" t.column_name,\n" +
" DECODE (c.data_type, 'CHAR', 1, 'VARCHAR2', 12, 'NUMBER', 3,\n" +
" 'LONG', -1, 'DATE', 93, 'RAW', -3, 'LONG RAW', -4, 1111)\n" +
" AS data_type,\n" +
" c.data_type AS type_name,\n" +
" DECODE (c.data_precision, null, c.data_length, c.data_precision)\n" +
" AS column_size,\n" +
" 0 as buffer_length,\n" +
" c.data_scale as decimal_digits,\n" +
" 0 as pseudo_column\n" +
"FROM all_trigger_cols t, all_tab_columns c\n" +
"WHERE t.table_name = ?\n" +
" AND c.owner like ? escape '/'\n" +
" AND t.table_owner = c.owner\n" +
" AND t.table_name = c.table_name\n" +
" AND t.column_name = c.column_name\n");
s.setString (1, table);
s.setString (2, schema == null ? "%" : schema);
OracleResultSet rs = (OracleResultSet)s.executeQuery ();
rs.close_statement_on_close = true;
return rs;
}
/**
* VERSION COLUMNS PSEUDO_COLUMN - may or may not be pseudo column.
*/
int versionColumnUnknown = 0;
/**
* VERSION COLUMNS PSEUDO_COLUMN - is NOT a pseudo column.
*/
int versionColumnNotPseudo = 1;
/**
* VERSION COLUMNS PSEUDO_COLUMN - is a pseudo column.
*/
int versionColumnPseudo = 2;
/**
* Get a description of a table's primary key columns. They
* are ordered by COLUMN_NAME.
*
* Each column description has the following columns:
*
* - TABLE_CAT String => table catalog (may be null)
*
- TABLE_SCHEM String => table schema (may be null)
*
- TABLE_NAME String => table name
*
- COLUMN_NAME String => column name
*
- KEY_SEQ short => sequence number within primary key
*
- PK_NAME String => primary key name (may be null)
*
*
* @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
*/
public
ResultSet getPrimaryKeys(String catalog, String schema,
String table)
throws SQLException
{
PreparedStatement s = connection.prepareStatement (
"SELECT NULL AS table_cat,\n" +
" c.owner AS table_schem,\n" +
" c.table_name,\n" +
" c.column_name,\n" +
" c.position AS key_seq,\n" +
" c.constraint_name AS pk_name\n" +
"FROM all_cons_columns c, all_constraints k\n" +
"WHERE k.constraint_type = 'P'\n" +
" AND k.table_name = ?\n" +
" AND k.owner like ? escape '/'\n" +
" AND k.constraint_name = c.constraint_name \n" +
" AND k.table_name = c.table_name \n" +
" AND k.owner = c.owner \n" +
"ORDER BY column_name\n");
s.setString (1, table);
s.setString (2, schema == null ? "%" : schema);
OracleResultSet rs = (OracleResultSet)s.executeQuery ();
rs.close_statement_on_close = true;
return rs;
}
/* Return the common part of the query for the 3 entrypoints
getImportedKeys, getExportedKeys and getCrossReference.
If a schema or table is null it is not put in the where clause.
*/
String keys_query (String pSchema, String pTable,
String fSchema, String fTable)
{
return
"select null as pktable_cat,\n" +
" p.owner as pktable_schem,\n" +
" p.table_name as pktable_name,\n" +
" pc.column_name as pkcolumn_name,\n" +
" null as fktable_cat,\n" +
" f.owner as fktable_schem,\n" +
" f.table_name as fktable_name,\n" +
" fc.column_name as fkcolumn_name,\n" +
" fc.position as key_seq,\n" +
" null as update_rule,\n" +
" decode (f.delete_rule, 'CASCADE', 0, 1) as delete_rule,\n" +
" f.constraint_name as fk_name,\n" +
" p.constraint_name as pk_name,\n" +
" null as deferrability\n" +
"from all_constraints p, all_cons_columns pc,\n" +
" all_constraints f, all_cons_columns fc\n" +
"where 1 = 1\n" +
(pTable != null ? " and p.table_name = '" + pTable + "'\n" : "") +
(fTable != null ? " and f.table_name = '" + fTable + "'\n" : "") +
((pSchema != null && pSchema.length () > 0) ?
" and p.owner = '" + pSchema + "'\n" : "") +
((fSchema != null && fSchema.length () > 0) ?
" and f.owner = '" + fSchema + "'\n" : "") +
" and p.constraint_type = 'P'\n" +
" and f.constraint_type = 'R'\n" +
" and p.constraint_name = f.r_constraint_name\n" +
" and p.owner = pc.owner\n" +
" and p.constraint_name = pc.constraint_name\n" +
" and p.table_name = pc.table_name\n" +
" and f.owner = fc.owner\n" +
" and f.constraint_name = fc.constraint_name\n" +
" and f.table_name = fc.table_name\n" +
" and fc.position = pc.position\n";
}
/**
* 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.
*
* Each primary key column description has the following columns:
*
* - PKTABLE_CAT String => primary key table catalog
* being imported (may be null)
*
- PKTABLE_SCHEM String => primary key table schema
* being imported (may be null)
*
- PKTABLE_NAME String => primary key table name
* being imported
*
- PKCOLUMN_NAME String => primary key column name
* being imported
*
- FKTABLE_CAT String => foreign key table catalog (may be null)
*
- FKTABLE_SCHEM String => foreign key table schema (may be null)
*
- FKTABLE_NAME String => foreign key table name
*
- FKCOLUMN_NAME String => foreign key column name
*
- KEY_SEQ short => sequence number within foreign key
*
- UPDATE_RULE short => What happens to
* foreign key when primary is updated:
*
* - importedKeyCascade - change imported key to agree
* with primary key update
*
- importedKeyRestrict - do not allow update of primary
* key if it has been imported
*
- importedKeySetNull - change imported key to NULL if
* its primary key has been updated
*
* - DELETE_RULE short => What happens to
* the foreign key when primary is deleted.
*
* - importedKeyCascade - delete rows that import a deleted key
*
- importedKeyRestrict - do not allow delete of primary
* key if it has been imported
*
- importedKeySetNull - change imported key to NULL if
* its primary key has been deleted
*
* - FK_NAME String => foreign key name (may be null)
*
- PK_NAME String => primary key name (may be null)
*
*
* @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
* @see #getExportedKeys
*/
public synchronized
ResultSet getImportedKeys(String catalog, String schema,
String table)
throws SQLException
{
connection.trace ("getImportedKeys");
Statement s = connection.createStatement ();
String query =
keys_query (null, null, schema, table) +
"order by pktable_schem, pktable_name, key_seq\n";
OracleResultSet rs = (OracleResultSet)s.executeQuery (query);
rs.close_statement_on_close = true;
return rs;
}
/**
* IMPORT KEY UPDATE_RULE and DELETE_RULE - for update, change
* imported key to agree with primary key update; for delete,
* delete rows that import a deleted key.
*/
int importedKeyCascade = 0;
/**
* IMPORT KEY UPDATE_RULE and DELETE_RULE - do not allow update or
* delete of primary key if it has been imported.
*/
int importedKeyRestrict = 1;
/**
* IMPORT KEY UPDATE_RULE and DELETE_RULE - change imported key to
* NULL if its primary key has been updated or deleted.
*/
int importedKeySetNull = 2;
/**
* Get a description of a 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.
*
* Each foreign key column description has the following columns:
*
* - PKTABLE_CAT String => primary key table catalog (may be null)
*
- PKTABLE_SCHEM String => primary key table schema (may be null)
*
- PKTABLE_NAME String => primary key table name
*
- PKCOLUMN_NAME String => primary key column name
*
- FKTABLE_CAT String => foreign key table catalog (may be null)
* being exported (may be null)
*
- FKTABLE_SCHEM String => foreign key table schema (may be null)
* being exported (may be null)
*
- FKTABLE_NAME String => foreign key table name
* being exported
*
- FKCOLUMN_NAME String => foreign key column name
* being exported
*
- KEY_SEQ short => sequence number within foreign key
*
- UPDATE_RULE short => What happens to
* foreign key when primary is updated:
*
* - importedKeyCascade - change imported key to agree
* with primary key update
*
- importedKeyRestrict - do not allow update of primary
* key if it has been imported
*
- importedKeySetNull - change imported key to NULL if
* its primary key has been updated
*
* - DELETE_RULE short => What happens to
* the foreign key when primary is deleted.
*
* - importedKeyCascade - delete rows that import a deleted key
*
- importedKeyRestrict - do not allow delete of primary
* key if it has been imported
*
- importedKeySetNull - change imported key to NULL if
* its primary key has been deleted
*
* - FK_NAME String => foreign key identifier (may be null)
*
- PK_NAME String => primary key identifier (may be null)
*
*
* @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
* @see #getImportedKeys
*/
public
ResultSet getExportedKeys(String catalog, String schema,
String table)
throws SQLException
{
connection.trace ("getExportedKeys");
Statement s = connection.createStatement ();
String query =
keys_query (schema, table, null, null) +
"order by fktable_schem, fktable_name, key_seq\n";
OracleResultSet rs = (OracleResultSet)s.executeQuery (query);
rs.close_statement_on_close = true;
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.
*
* Each foreign key column description has the following columns:
*
* - PKTABLE_CAT String => primary key table catalog (may be null)
*
- PKTABLE_SCHEM String => primary key table schema (may be null)
*
- PKTABLE_NAME String => primary key table name
*
- PKCOLUMN_NAME String => primary key column name
*
- FKTABLE_CAT String => foreign key table catalog (may be null)
* being exported (may be null)
*
- FKTABLE_SCHEM String => foreign key table schema (may be null)
* being exported (may be null)
*
- FKTABLE_NAME String => foreign key table name
* being exported
*
- FKCOLUMN_NAME String => foreign key column name
* being exported
*
- KEY_SEQ short => sequence number within foreign key
*
- UPDATE_RULE short => What happens to
* foreign key when primary is updated:
*
* - importedKeyCascade - change imported key to agree
* with primary key update
*
- importedKeyRestrict - do not allow update of primary
* key if it has been imported
*
- importedKeySetNull - change imported key to NULL if
* its primary key has been updated
*
* - DELETE_RULE short => What happens to
* the foreign key when primary is deleted.
*
* - importedKeyCascade - delete rows that import a deleted key
*
- importedKeyRestrict - do not allow delete of primary
* key if it has been imported
*
- importedKeySetNull - change imported key to NULL if
* its primary key has been deleted
*
* - FK_NAME String => foreign key identifier (may be null)
*
- PK_NAME String => primary key identifier (may be null)
*
*
* @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
* @see #getImportedKeys
*/
public
ResultSet getCrossReference(String primaryCatalog, String primarySchema,
String primaryTable, String foreignCatalog,
String foreignSchema, String foreignTable)
throws SQLException
{
connection.trace ("getCrossReference");
Statement s = connection.createStatement ();
String query =
keys_query (primarySchema, primaryTable, foreignSchema, foreignTable) +
"order by fktable_schem, fktable_name, key_seq\n";
OracleResultSet rs = (OracleResultSet)s.executeQuery (query);
rs.close_statement_on_close = true;
return rs;
}
/**
* Get a description of all the standard SQL types supported by
* this database. They are ordered by DATA_TYPE and then by how
* closely the data type maps to the corresponding JDBC SQL type.
*
* Each type description has the following columns:
*
* - TYPE_NAME String => Type name
*
- DATA_TYPE short => SQL data type from java.sql.Types
*
- PRECISION int => maximum precision
*
- LITERAL_PREFIX String => prefix used to quote a literal
* (may be null)
*
- LITERAL_SUFFIX String => suffix used to quote a literal
(may be null)
*
- CREATE_PARAMS String => parameters used in creating
* the type (may be null)
*
- NULLABLE short => can you use NULL for this type?
*
* - typeNoNulls - does not allow NULL values
*
- typeNullable - allows NULL values
*
- typeNullableUnknown - nullability unknown
*
* - CASE_SENSITIVE boolean=> is it case sensitive?
*
- SEARCHABLE short => can you use "WHERE" based on this type:
*
* - typePredNone - No support
*
- typePredChar - Only supported with WHERE .. LIKE
*
- typePredBasic - Supported except for WHERE .. LIKE
*
- typeSearchable - Supported for all WHERE ..
*
* - UNSIGNED_ATTRIBUTE boolean => is it unsigned?
*
- FIXED_PREC_SCALE boolean => can it be a money value?
*
- AUTO_INCREMENT boolean => can it be used for an
* auto-increment value?
*
- LOCAL_TYPE_NAME String => localized version of type name
* (may be null)
*
- MINIMUM_SCALE short => minimum scale supported
*
- MAXIMUM_SCALE short => maximum scale supported
*
- SQL_DATA_TYPE int => unused
*
- SQL_DATETIME_SUB int => unused
*
- NUM_PREC_RADIX int => usually 2 or 10
*
*
* @return ResultSet each row is a SQL type description
*/
public ResultSet getTypeInfo()
throws SQLException
{
connection.trace ("getTypeInfo");
Statement s = connection.createStatement ();
String number_query =
"select\n" +
" 'NUMBER' as type_name, 2 as data_type, 38 as precision,\n" +
" NULL as literal_prefix, NULL as literal_suffix, NULL as create_params,\n" +
" 1 as nullable, 0 as case_sensitive, 1 as searchable,\n" +
" 0 as unsigned_attribute, 1 as fixed_prec_scale, 0 as auto_increment,\n" +
" 'NUMBER' as local_type_name, -84 as minimum_scale, 127 as maximum_scale,\n" +
" NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String bit_query =
"union select 'NUMBER' as type_name, -7 as data_type, 1 as precision,\n" +
"NULL as literal_prefix, NULL as literal_suffix, \n" +
"'(1)' as create_params, 1 as nullable, 0 as case_sensitive, 1 as searchable,\n" +
"0 as unsigned_attribute, 1 as fixed_prec_scale, 0 as auto_increment,\n" +
"'NUMBER' as local_type_name, -84 as minimum_scale, 127 as maximum_scale,\n" +
"NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String tinyint_query =
"union select 'NUMBER' as type_name, -6 as data_type, 3 as precision,\n" +
"NULL as literal_prefix, NULL as literal_suffix, \n" +
"'(3)' as create_params, 1 as nullable, 0 as case_sensitive, 1 as searchable,\n" +
"0 as unsigned_attribute, 1 as fixed_prec_scale, 0 as auto_increment,\n" +
"'NUMBER' as local_type_name, -84 as minimum_scale, 127 as maximum_scale,\n" +
"NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String smallint_query =
"union select 'NUMBER' as type_name, 5 as data_type, 5 as precision,\n" +
"NULL as literal_prefix, NULL as literal_suffix, \n" +
"'(5)' as create_params, 1 as nullable, 0 as case_sensitive, 1 as searchable,\n" +
"0 as unsigned_attribute, 1 as fixed_prec_scale, 0 as auto_increment,\n" +
"'NUMBER' as local_type_name, -84 as minimum_scale, 127 as maximum_scale,\n" +
"NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String integer_query =
"union select 'NUMBER' as type_name, 4 as data_type, 10 as precision,\n" +
"NULL as literal_prefix, NULL as literal_suffix, \n" +
"'(10)' as create_params, 1 as nullable, 0 as case_sensitive, 1 as searchable,\n" +
"0 as unsigned_attribute, 1 as fixed_prec_scale, 0 as auto_increment,\n" +
"'NUMBER' as local_type_name, -84 as minimum_scale, 127 as maximum_scale,\n" +
"NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String bigint_query =
"union select 'NUMBER' as type_name, -5 as data_type, 38 as precision,\n" +
"NULL as literal_prefix, NULL as literal_suffix, \n" +
"NULL as create_params, 1 as nullable, 0 as case_sensitive, 1 as searchable,\n" +
"0 as unsigned_attribute, 1 as fixed_prec_scale, 0 as auto_increment,\n" +
"'NUMBER' as local_type_name, -84 as minimum_scale, 127 as maximum_scale,\n" +
"NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String float_query =
"union select 'FLOAT' as type_name, 6 as data_type, 63 as precision,\n" +
"NULL as literal_prefix, NULL as literal_suffix, \n" +
"NULL as create_params, 1 as nullable, 0 as case_sensitive, 1 as searchable,\n" +
"0 as unsigned_attribute, 1 as fixed_prec_scale, 0 as auto_increment,\n" +
"'FLOAT' as local_type_name, -84 as minimum_scale, 127 as maximum_scale,\n" +
"NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String real_query =
"union select 'REAL' as type_name, 7 as data_type, 63 as precision,\n" +
"NULL as literal_prefix, NULL as literal_suffix, \n" +
"NULL as create_params, 1 as nullable, 0 as case_sensitive, 1 as searchable,\n" +
"0 as unsigned_attribute, 1 as fixed_prec_scale, 0 as auto_increment,\n" +
"'REAL' as local_type_name, -84 as minimum_scale, 127 as maximum_scale,\n" +
"NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String char_query =
"union select\n" +
" 'CHAR' as type_name, 1 as data_type, 255 as precision,\n" +
" '''' as literal_prefix, '''' as literal_suffix, NULL as create_params,\n" +
" 1 as nullable, 1 as case_sensitive, 1 as searchable,\n" +
" 0 as unsigned_attribute, 0 as fixed_prec_scale, 0 as auto_increment,\n" +
" 'CHAR' as local_type_name, 0 as minimum_scale, 0 as maximum_scale,\n" +
" NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String varchar2_query =
"union select\n" +
" 'VARCHAR2' as type_name, 12 as data_type, 2000 as precision,\n" +
" '''' as literal_prefix, '''' as literal_suffix, NULL as create_params,\n" +
" 1 as nullable, 1 as case_sensitive, 1 as searchable,\n" +
" 0 as unsigned_attribute, 0 as fixed_prec_scale, 0 as auto_increment,\n" +
" 'VARCHAR2' as local_type_name, 0 as minimum_scale, 0 as maximum_scale,\n" +
" NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String long_query =
"union select\n" +
" 'LONG' as type_name, -1 as data_type, 134217727 as precision,\n" +
" '''' as literal_prefix, '''' as literal_suffix, NULL as create_params,\n" +
" 1 as nullable, 1 as case_sensitive, 0 as searchable,\n" +
" 0 as unsigned_attribute, 0 as fixed_prec_scale, 0 as auto_increment,\n" +
" 'LONG' as local_type_name, 0 as minimum_scale, 0 as maximum_scale,\n" +
" NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String timestamp_query =
"union select\n" +
" 'DATE' as type_name, 93 as data_type, 7 as precision,\n" +
" NULL as literal_prefix, NULL as literal_suffix, NULL as create_params,\n" +
" 1 as nullable, 0 as case_sensitive, 1 as searchable,\n" +
" 0 as unsigned_attribute, 0 as fixed_prec_scale, 0 as auto_increment,\n" +
" 'DATE' as local_type_name, 0 as minimum_scale, 0 as maximum_scale,\n" +
" NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String raw_query =
"union select\n" +
" 'RAW' as type_name, -3 as data_type, 255 as precision,\n" +
" '''' as literal_prefix, '''' as literal_suffix, NULL as create_params,\n" +
" 1 as nullable, 0 as case_sensitive, 0 as searchable,\n" +
" 0 as unsigned_attribute, 0 as fixed_prec_scale, 0 as auto_increment,\n" +
" 'RAW' as local_type_name, 0 as minimum_scale, 0 as maximum_scale,\n" +
" NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String long_raw_query =
"union select\n" +
" 'LONG RAW' as type_name, -4 as data_type, 134217727 as precision,\n" +
" '''' as literal_prefix, '''' as literal_suffix, NULL as create_params,\n" +
" 1 as nullable, 0 as case_sensitive, 0 as searchable,\n" +
" 0 as unsigned_attribute, 0 as fixed_prec_scale, 0 as auto_increment,\n" +
" 'LONG RAW' as local_type_name, 0 as minimum_scale, 0 as maximum_scale,\n" +
" NULL as sql_data_type, NULL as sql_datetime_sub, 10 as num_prec_radix\n" +
"from dual\n";
String order_by =
"order by data_type\n";
// long and long_raw_query is in
String query = (number_query + char_query + varchar2_query
+ timestamp_query
+ raw_query
+ long_query + long_raw_query
// Non internal types (comment out if tests break)
+ bit_query
+ tinyint_query + smallint_query
+ integer_query + bigint_query + float_query + real_query
// ordering
+ order_by);
OracleResultSet rs = (OracleResultSet)s.executeQuery (query);
rs.close_statement_on_close = true;
return rs;
}
/**
* TYPE NULLABLE - does not allow NULL values.
*/
int typeNoNulls = 0;
/**
* TYPE NULLABLE - allows NULL values.
*/
int typeNullable = 1;
/**
* TYPE NULLABLE - nullability unknown.
*/
int typeNullableUnknown = 2;
/**
* TYPE INFO SEARCHABLE - No support.
*/
int typePredNone = 0;
/**
* TYPE INFO SEARCHABLE - Only supported with WHERE .. LIKE.
*/
int typePredChar = 1;
/**
* TYPE INFO SEARCHABLE - Supported except for WHERE .. LIKE.
*/
int typePredBasic = 2;
/**
* TYPE INFO SEARCHABLE - Supported for all WHERE ...
*/
int typeSearchable = 3;
/**
* Get a description of a table's indices and statistics. They are
* ordered by NON_UNIQUE, TYPE, INDEX_NAME, and ORDINAL_POSITION.
*
* Each index column description has the following columns:
*
* - TABLE_CAT String => table catalog (may be null)
*
- TABLE_SCHEM String => table schema (may be null)
*
- TABLE_NAME String => table name
*
- NON_UNIQUE boolean => Can index values be non-unique?
* false when TYPE is tableIndexStatistic
*
- INDEX_QUALIFIER String => index catalog (may be null);
* null when TYPE is tableIndexStatistic
*
- INDEX_NAME String => index name; null when TYPE is
* tableIndexStatistic
*
- TYPE short => index type:
*
* - tableIndexStatistic - this identifies table statistics that are
* returned in conjuction with a table's index descriptions
*
- tableIndexClustered - this is a clustered index
*
- tableIndexHashed - this is a hashed index
*
- tableIndexOther - this is some other style of index
*
* - ORDINAL_POSITION short => column sequence number
* within index; zero when TYPE is tableIndexStatistic
*
- COLUMN_NAME String => column name; null when TYPE is
* tableIndexStatistic
*
- ASC_OR_DESC String => column sort sequence, "A" => ascending,
* "D" => descending, may be null if sort sequence is not supported;
* null when TYPE is tableIndexStatistic
*
- CARDINALITY int => When TYPE is tableIndexStatisic then
* this is the number of rows in the table; otherwise it is the
* number of unique values in the index.
*
- PAGES int => When TYPE is tableIndexStatisic then
* this is the number of pages used for the table, otherwise it
* is the number of pages used for the current index.
*
- FILTER_CONDITION String => Filter condition, if any.
* (may be null)
*
*
* @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
* @param unique when true, return only indices for unique values;
* when false, return indices regardless of whether unique or not
* @param approximate when true, result is allowed to reflect approximate
* or out of data values; when false, results are requested to be
* accurate
* @return ResultSet each row is an index column description
*/
public synchronized
ResultSet getIndexInfo(String catalog, String schema, String table,
boolean unique, boolean approximate)
throws SQLException
{
connection.trace ("getIndexInfo");
Statement s = connection.createStatement ();
// Update the statistics first
String analyze = ("analyze table "
+ (schema == null ? "" : schema + ".")
+ table
+ (approximate ? " estimate statistics" : " compute statistics"));
connection.trace (analyze);
s.executeUpdate (analyze);
// The query for the table statistics
String table_query =
"select null as table_cat,\n" +
" owner as table_schem,\n" +
" table_name,\n" +
" 0 as NON_UNIQUE,\n" +
" null as index_qualifier,\n" +
" null as index_name, 0 as type,\n" +
" 0 as ordinal_position, null as column_name,\n" +
" null as asc_or_desc,\n" +
" num_rows as cardinality,\n" +
" blocks as pages,\n" +
" null as filter_condition\n" +
"from all_tables\n" +
"where table_name = '" + table + "'\n";
String table_schema_select = "";
if (schema != null && schema.length () > 0)
table_schema_select =
" and owner = '" + schema + "'\n";
// The query for the indexes
String index_query =
"select null as table_cat,\n" +
" i.owner as table_schem,\n" +
" i.table_name,\n" +
" decode (i.uniqueness, 'UNIQUE', 0, 1),\n" +
" null as index_qualifier,\n" +
" i.index_name,\n" +
" 1 as type,\n" +
" c.column_position as ordinal_position,\n" +
" c.column_name,\n" +
" null as asc_or_desc,\n" +
" i.distinct_keys as cardinality,\n" +
" i.leaf_blocks as pages,\n" +
" null as filter_condition\n" +
"from all_indexes i, all_ind_columns c\n" +
"where i.table_name = '" + table + "'\n";
String index_schema_select = "";
if (schema != null && schema.length () > 0)
index_schema_select =
" and i.owner = '" + schema + "'\n";
String index_unique_select = "";
if (unique)
index_unique_select =
" and i.uniqueness = 'UNIQUE'\n";
String index_join_select =
" and i.index_name = c.index_name\n" +
" and i.table_owner = c.table_owner\n" +
" and i.table_name = c.table_name\n" +
" and i.owner = c.index_owner\n";
String index_order_by =
"order by non_unique, type, index_name, ordinal_position\n";
String query = (table_query + table_schema_select + "union\n" +
index_query + index_schema_select + index_unique_select +
index_join_select + index_order_by);
OracleResultSet rs = (OracleResultSet)s.executeQuery (query);
rs.close_statement_on_close = true;
return rs;
}
/**
* INDEX INFO TYPE - this identifies table statistics that are
* returned in conjuction with a table's index descriptions
*/
short tableIndexStatistic = 0;
/**
* INDEX INFO TYPE - this identifies a clustered index
*/
short tableIndexClustered = 1;
/**
* INDEX INFO TYPE - this identifies a hashed index
*/
short tableIndexHashed = 2;
/**
* INDEX INFO TYPE - this identifies some other form of index
*/
short tableIndexOther = 3;
SQLException fail ()
{
SQLException ex = new SQLException ("Not implemented yet");
return ex;
}
}